public String getAttributeValue(String namespaceUri, String name) { Attribute attribute = getAttribute(namespaceUri, name); if (attribute == null) return null; else return attribute.getValue(); }
public Renderer(XMLElement element) { this.topElement = element; ResolverNamespaceResolver nsResolver = new ResolverNamespaceResolver(); renderXMLElement(topElement, nsResolver, openElementBuffer, elementContentBuffer, closeElementBuffer); }
private String getInnerElementText(XMLElement element, String childName) { try { XMLElement childElm = element.getSingleInnerElementsNamed(childName); if (childElm != null && childElm.getInnerText() != null) { return childElm.getInnerText().getText(); } else { return null; } } catch (XMLSemanticError e) { return null; } }
private String getFieldValue(List<XMLElement> fields, String var) { for(XMLElement field : fields) { if(var.equals(field.getAttributeValue("var"))) { try { return field.getSingleInnerElementsNamed("value", NamespaceURIs.JABBER_X_DATA).getInnerText().getText(); } catch (XMLSemanticError e) { return null; } } } return null; }
public static XMLElement createElementWithInnerText(String namespaceURI, String name, String text) { return new XMLElement(namespaceURI, name, null, null, asList(new XMLText(text)), null); }
private void renderAttribute(StringBuilder buffer, Attribute attribute, ResolverNamespaceResolver nsResolver) { String qname; if (!attribute.getNamespaceUri().equals("")) { // attribute is in a namespace, resolve prefix qname = nsResolver.resolvePrefix(attribute.getNamespaceUri()) + ":" + attribute.getName(); } else { qname = attribute.getName(); } renderAttribute(buffer, qname, attribute.getValue()); }
protected XMLElement createTextOnlyElement(String namespaceURI, String elementName, String text) { return new XMLElement(namespaceURI, elementName, null, null, new XMLFragment[] { new XMLText(text) }); } }
public String getUniqueXMLNSValue() { Attribute found = null; for (Attribute attribute : element.getAttributes()) { if (isNamespaceAttribute(attribute)) { if (found != null) return null; // not unique else { found = attribute; } } } if (found == null) return null; return found.getValue(); }
public XMLElement getSingleInnerElementsNamed(String name, String namespaceUri) throws XMLSemanticError { List<XMLElement> innerElements = getInnerElementsNamed(name, namespaceUri); if (innerElements == null) return null; if (innerElements.isEmpty()) return null; if (innerElements.size() > 1) throw new XMLSemanticError("element has more than one inner element named: " + name); return innerElements.get(0); }
/** * show text must be from set {away, chat, dnd, xa} for not-extended namespaces * @return * @throws XMLSemanticError */ public String getShow() throws XMLSemanticError { XMLElement element = getSingleInnerElementsNamed("show"); if (element == null) return null; // show is optional, see RFC3921/2.2.2.1 return element.getSingleInnerText().getText(); }
public B addAttribute(String namespaceUris, String name, String value) { addAttribute(new Attribute(namespaceUris, name, value)); return (B) this; }
@Override public String toString() { return getText(); } }
/** * collects all inner elements named as given parameter * @param name - must not be NULL */ public List<XMLElement> getInnerElementsNamed(String name) { return getInnerElementsNamed(name, null); }
public B addText(String text) { checkReset(); currentElement.innerFragments.add(new XMLText(text)); return (B) this; }
public XMLText getSingleInnerText() throws XMLSemanticError { List<XMLText> innerTexts = getInnerTexts(); if (innerTexts == null || innerTexts.isEmpty()) return null; if (innerTexts.size() > 1) throw new XMLSemanticError("element has more than one inner text fragment"); return innerTexts.get(0); }
public XMLElementVerifier getVerifier() { if (xmlElementVerifier == null) xmlElementVerifier = new XMLElementVerifier(this); return xmlElementVerifier; } }
public static XMLElement createElementWithInnerText(String name, String text) { return createElementWithInnerText(null, name, text); }
/** * * @return thread identifier, or NULL, if not given * @throws XMLSemanticError - if thread element is not unique, or no unqiue inner text * is given, RFC3921 2.1.2.3 */ public String getThread() throws XMLSemanticError { XMLElement element = getSingleInnerElementsNamed("thread"); if (element == null) return null; // thread is optional, see RFC3921/2.1.2.3 return element.getSingleInnerText().getText(); }
public B addAttribute(String name, String value) { addAttribute(new Attribute(name, value)); return (B) this; }