@Override public XmlElement setAttribute(String name, String value) { if (name.startsWith("xmlns")) try { String prefix = name.split(":")[1]; internal.add(new Namespace(prefix, value)); } catch (Exception e) { if (name.equals("xmlns")) internal.setQName(QName.get(internal.getName(), value)); } internal.addAttribute(name, value); return this; }
private void populate(Element copy, Date delay, JID delayFrom) { copy.setQName(QName.get("message", "jabber:client")); for (Object element : copy.elements()) { if (element instanceof Element) { Element el = (Element) element; // Only set the "jabber:client" namespace if the namespace is empty (otherwise the resulting // xml would look like <body xmlns=""/>) if ("".equals(el.getNamespace().getStringValue())) { el.setQName(QName.get(el.getName(), "jabber:client")); } } } if (delay != null) { Element delayInfo = element.addElement("delay", "urn:xmpp:delay"); delayInfo.addAttribute("stamp", XMPPDateTimeFormat.format(delay)); if (delayFrom != null) { // Set the Full JID as the "from" attribute delayInfo.addAttribute("from", delayFrom.toString()); } } element.add(copy); }
/** * This will take an attribute name and it's values and return a DSML attribute element. * * @param attrName <code>String</code> * @param attrValues <code>List</code> * @param ns <code>Namespace</code> of DSML * @return <code>Element</code> */ protected Element createDsmlAttribute( final String attrName, final List<?> attrValues, final Namespace ns) { Element attrElement = DocumentHelper.createElement(""); if (attrName != null) { if (attrName.equalsIgnoreCase("objectclass")) { attrElement.setQName(new QName("objectclass", ns)); if (attrValues != null) { final Iterator<?> i = attrValues.iterator(); while (i.hasNext()) { final Object rawValue = i.next(); String value = null; boolean isBase64 = false; if (rawValue instanceof String) { value = (String) rawValue; } else if (rawValue instanceof byte[]) { value = LdapUtil.base64Encode((byte[]) rawValue); isBase64 = true; } else { if (this.logger.isWarnEnabled()) { this.logger.warn("Could not cast attribute value as a byte[]" + " or a String"); } } if (value != null) { final Element ocValueElement = attrElement.addElement(new QName("oc-value", ns)); ocValueElement.addText(value); if (isBase64) { ocValueElement.addAttribute("encoding", "base64"); } } } } } else { attrElement = super.createDsmlAttribute(attrName, attrValues, ns); } } return attrElement; }