Java源码示例:org.jivesoftware.smack.packet.NamedElement

示例1
void processMetadataEvent(JID jid, ItemsExtension itemsExt) {
    List<? extends NamedElement> items = itemsExt.getItems();
    if (items.isEmpty()) {
        LOGGER.warning("no items in items event");
        return;
    }

    // there should be only one item
    NamedElement e = items.get(0);
    if (!(e instanceof PayloadItem)) {
        LOGGER.warning("element not a payloaditem");
        return;
    }

    PayloadItem item = (PayloadItem) e;
    ExtensionElement metadataExt = item.getPayload();
    if (!(metadataExt instanceof AvatarMetadataExtension)) {
        LOGGER.warning("payload not avatar metadata");
        return;
    }
    AvatarMetadataExtension metadata = (AvatarMetadataExtension) metadataExt;
    List<AvatarMetadataExtension.Info> infos = metadata.getInfos();
    if (infos.isEmpty()) {
        // this means the contact disabled avatar publishing
        mHandler.onNotify(jid, "");
        return;
    }
    // assuming infos are always in the same order
    for (AvatarMetadataExtension.Info info : infos) {
        if (AvatarHandler.SUPPORTED_TYPES.contains(info.getType())) {
            mHandler.onNotify(jid, info.getId());
            break;
        } else {
            LOGGER.info("image type not supported: "+info.getType());
        }
    }
}
 
示例2
public XmlStringBuilder optTextChild(CharSequence sqc, NamedElement parentElement) {
    if (sqc == null) {
        return closeEmptyElement();
    }
    rightAngleBracket();
    escape(sqc);
    closeElement(parentElement);
    return this;
}
 
示例3
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    // Upcast to NamedElement since we don't want a xmlns attribute
    XmlStringBuilder xml = new XmlStringBuilder((NamedElement) this);
    xml.attribute("name", name);
    xml.rightAngleBracket();
    xml.escape(value);
    xml.closeElement(this);
    return xml;
}
 
示例4
protected JingleContentDescription(List<? extends NamedElement> payloads) {
    if (payloads != null) {
        this.payloads = Collections.unmodifiableList(payloads);
    }
    else {
        this.payloads = Collections.emptyList();
    }
}
 
示例5
/**
 * Parses Data element if any.
 *
 * @param parser parser
 * @return Data or null if no data
 *
 * @throws XmlPullParserException if an error in the XML parser occurred.
 * @throws IOException if an I/O error occurred.
 */
protected AbstractHttpOverXmpp.Data parseData(XmlPullParser parser) throws XmlPullParserException, IOException {
    NamedElement child = null;
    boolean done = false;
    AbstractHttpOverXmpp.Data data = null;
    /* We are either at start of data or end of req/res */
    if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT) {
        while (!done) {
            XmlPullParser.Event eventType = parser.next();

            if (eventType == XmlPullParser.Event.START_ELEMENT) {
                switch (parser.getName()) {
                case ELEMENT_TEXT:
                    child = parseText(parser);
                    break;
                case ELEMENT_BASE_64:
                    child = parseBase64(parser);
                    break;
                case ELEMENT_CHUNKED_BASE_64:
                    child = parseChunkedBase64(parser);
                    break;
                case ELEMENT_XML:
                    child = parseXml(parser);
                    break;
                case ELEMENT_IBB:
                    child = parseIbb(parser);
                    break;
                case ELEMENT_SIPUB:
                    // TODO: sipub is allowed by xep-0332, but is not
                    // implemented yet
                    throw new UnsupportedOperationException("sipub is not supported yet");
                case ELEMENT_JINGLE:
                    // TODO: jingle is allowed by xep-0332, but is not
                    // implemented yet
                    throw new UnsupportedOperationException("jingle is not supported yet");
                default:
                    // other elements are not allowed
                    throw new IllegalArgumentException("unsupported child tag: " + parser.getName());
                }
            } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
                if (parser.getName().equals(ELEMENT_DATA)) {
                    done = true;
                }
            }
        }
        data = new AbstractHttpOverXmpp.Data(child);
    }
    return data;
}
 
示例6
public XmlStringBuilder(NamedElement e) {
    this();
    halfOpenElement(e.getElementName());
}
 
示例7
public XmlStringBuilder halfOpenElement(NamedElement namedElement) {
    return halfOpenElement(namedElement.getElementName());
}
 
示例8
public XmlStringBuilder closeElement(NamedElement e) {
    closeElement(e.getElementName());
    return this;
}
 
示例9
public List<NamedElement> getJingleContentDescriptionChildren() {
    return payloads;
}
 
示例10
/**
 * Creates Data element.
 *
 * @param child element nested by Data
 */
public Data(NamedElement child) {
    this.child = child;
}
 
示例11
/**
 * Returns element nested by Data.
 *
 * @return element nested by Data
 */
public NamedElement getChild() {
    return child;
}
 
示例12
/**
 * Construct an instance with a list representing items that have been published or deleted.
 *
 * <p>Valid scenarios are:</p>
 * <ul>
 * <li>Request items from node - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and an
 * optional value for the <b>max_items</b> attribute.
 * <li>Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of {@link Item} containing
 * only id's and an optional value for the <b>notify</b> attribute.
 * <li>Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and
 * attributeValue = <code>null</code>
 * <li>Items deleted event -  itemsType = {@link ItemsElementType#items}, items = list of {@link RetractItem} and
 * attributeValue = <code>null</code>
 * </ul>
 *
 * @param itemsType Type of representation
 * @param nodeId The node to which the items are being sent or deleted
 * @param items The list of {@link Item} or {@link RetractItem}
 */
public ItemsExtension(ItemsElementType itemsType, String nodeId, List<? extends NamedElement> items) {
    super(itemsType.getNodeElement(), nodeId);
    type = itemsType;
    this.items = items;
}
 
示例13
/**
 * Gets the items related to the type of request or event.
 *
 * @return List of {@link Item}, {@link RetractItem}, or null
 */
// TODO: Shouldn't this return List<Item>? Why is RetractItem not a subtype of item?
public List<? extends NamedElement> getItems() {
    return items;
}