正在查看: bbinstant v6.24.0 应用的 AMPExtension.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: bbinstant v6.24.0 应用的 AMPExtension.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.jivesoftware.smackx.amp.packet;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jivesoftware.smack.packet.ExtensionElement;
public class AMPExtension implements ExtensionElement {
public static final String ELEMENT = "amp";
public static final String NAMESPACE = "http://jabber.org/protocol/amp";
private final String from;
private boolean perHop;
private CopyOnWriteArrayList<Rule> rules;
private final Status status;
private final String to;
public enum Action {
alert,
drop,
error,
notify;
public static final String ATTRIBUTE_NAME = "action";
}
public interface Condition {
public static final String ATTRIBUTE_NAME = "condition";
String getName();
String getValue();
}
public static class Rule {
public static final String ELEMENT = "rule";
private final Action action;
private final Condition condition;
public Rule(Action action, Condition condition) {
if (action == null) {
throw new NullPointerException("Can't create Rule with null action");
}
if (condition == null) {
throw new NullPointerException("Can't create Rule with null condition");
}
this.action = action;
this.condition = condition;
}
public String toXML() {
return "<rule action=\"" + this.action.toString() + "\" " + Condition.ATTRIBUTE_NAME + "=\"" + this.condition.getName() + "\" value=\"" + this.condition.getValue() + "\"/>";
}
public Action getAction() {
return this.action;
}
public Condition getCondition() {
return this.condition;
}
}
public enum Status {
alert,
error,
notify
}
public AMPExtension(String str, String str2, Status status) {
this.rules = new CopyOnWriteArrayList<>();
this.perHop = false;
this.from = str;
this.to = str2;
this.status = status;
}
public void addRule(Rule rule) {
this.rules.add(rule);
}
@Override
public String getElementName() {
return ELEMENT;
}
public String getFrom() {
return this.from;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
public List<Rule> getRules() {
return Collections.unmodifiableList(this.rules);
}
public int getRulesCount() {
return this.rules.size();
}
public Status getStatus() {
return this.status;
}
public String getTo() {
return this.to;
}
public synchronized boolean isPerHop() {
return this.perHop;
}
public synchronized void setPerHop(boolean z) {
this.perHop = z;
}
@Override
public String toXML() {
StringBuilder sb = new StringBuilder();
sb.append('<');
sb.append(getElementName());
sb.append(" xmlns=\"");
sb.append(getNamespace());
sb.append('\"');
if (this.status != null) {
sb.append(" status=\"");
sb.append(this.status.toString());
sb.append('\"');
}
if (this.to != null) {
sb.append(" to=\"");
sb.append(this.to);
sb.append('\"');
}
if (this.from != null) {
sb.append(" from=\"");
sb.append(this.from);
sb.append('\"');
}
if (this.perHop) {
sb.append(" per-hop=\"true\"");
}
sb.append('>');
Iterator<Rule> it = getRules().iterator();
while (it.hasNext()) {
sb.append(it.next().toXML());
}
sb.append("</");
sb.append(getElementName());
sb.append('>');
return sb.toString();
}
public AMPExtension() {
this.rules = new CopyOnWriteArrayList<>();
this.perHop = false;
this.from = null;
this.to = null;
this.status = null;
}
}