public Element setNamespace(Namespace namespace) { return element.setNamespace(namespace); }
public static void propagateNamespace(Element element, Namespace namespace) { element.setNamespace(namespace); for (Object childElement : element.getChildren()) { propagateNamespace((Element) childElement, namespace); } }
private void setNamespace(Element element, Namespace namespace) { element.setNamespace(namespace); for (Iterator iter = element.getChildren().iterator(); iter.hasNext();) { setNamespace((Element)iter.next(), namespace); } } }
/** * Creates a new element with the supplied (local) name and namespace. If * the provided namespace is null, the element will have no namespace. * * @param name local name of the element * @param namespace namespace for the element * @throws IllegalNameException if the given name is illegal as an element * name */ public Element(final String name, final Namespace namespace) { setName(name); setNamespace(namespace); }
@Override public void visit(Element current) { current.setNamespace(Namespace.getNamespace("", ns.toURI())); List<?> kids = current.getChildren(); if (kids.size() > 0) { Iterator<?> iter = kids.iterator(); while (iter.hasNext()) { Element kid = (Element) iter.next(); visit(kid); } } }
/** * Produce meta elements that can easily be put into the head. * * @return List of elements */ public List<Element> disseminateList() { List<Element> metas = new ArrayList<Element>(); for (Entry<String, String> m : getMappings()) { Element e = new Element("meta"); e.setNamespace(null); e.setAttribute("name", m.getKey()); e.setAttribute("content", m.getValue()); metas.add(e); } return metas; }
public class XMLObjectFactory { private static Namespace DEFAULT_NS = Namespace.getNamespace("http://tempuri.org/"); public static Object createObject(InputStream in) { try { SAXBuilder sb = new SAXBuilder(false); Document doc = sb.build(in); setNamespace(doc.getRootElement(), DEFAULT_NS, true); Source src = new JDOMSource(doc); JAXBContext context = JAXBContext.newInstance("org.tempuri"); Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement root = unmarshaller.unmarshal(src); return root.getValue(); } catch (Exception e) { throw new RuntimeException("Failed to create Object", e); } } private static void setNamespace(Element elem, Namespace ns, boolean recurse) { elem.setNamespace(ns); if (recurse) { for (Object o : elem.getChildren()) { setNamespace((Element) o, ns, recurse); } } }
/** * Updates the element namespace, and also iterates all descendant elements. * If these elements have no default namespace, or is blank then it is also * set to namespaceURI (JDOM by default will not set the child elements to * the same namespace as the element modified but will override them with * blank namespaces). * * @param dataElement * @param namespaceURI */ private void updateElementNamespace(Element dataElement, String namespaceURI) { dataElement.setNamespace(Namespace.getNamespace(namespaceURI)); Iterator iterator = dataElement.getDescendants(); while (iterator.hasNext()) { Object descendantObject = iterator.next(); if (descendantObject instanceof Element) { Element childElement = (Element) descendantObject; if (childElement.getNamespaceURI() == null || childElement.getNamespaceURI().length() == 0) childElement.setNamespace(Namespace .getNamespace(namespaceURI)); } } }
/** * Updates the element namespace, and also iterates all descendant elements. * If these elements have no default namespace, or is blank then it is also * set to namespaceURI (JDOM by default will not set the child elements to * the same namespace as the element modified but will override them with * blank namespaces). * * @param dataElement * @param namespaceURI */ private void updateElementNamespace(Element dataElement, String namespaceURI) { dataElement.setNamespace(Namespace.getNamespace(namespaceURI)); Iterator<?> iterator = dataElement.getDescendants(); while (iterator.hasNext()) { Object descendantObject = iterator.next(); if (descendantObject instanceof Element) { Element childElement = (Element) descendantObject; if (childElement.getNamespaceURI() == null || childElement.getNamespaceURI().length() == 0) childElement.setNamespace(Namespace .getNamespace(namespaceURI)); } } }
private String parseTextConstructToString(Element e) { String value = null; String type = getAttributeValue(e, "type"); type = (type!=null) ? type : Content.TEXT; if (type.equals(Content.XHTML) || (type.indexOf("/xml")) != -1 || (type.indexOf("+xml")) != -1) { // XHTML content needs special handling XMLOutputter outputter = new XMLOutputter(); List eContent = e.getContent(); Iterator i = eContent.iterator(); while (i.hasNext()) { org.jdom.Content c = (org.jdom.Content) i.next(); if (c instanceof Element) { Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element)c).setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(eContent); } else { // Everything else comes in verbatim value = e.getText(); } return value; }
private String parseTextConstructToString(Element e) { String value = null; String type = getAttributeValue(e, "type"); type = (type!=null) ? type : Content.TEXT; if (type.equals(Content.XHTML) || (type.indexOf("/xml")) != -1 || (type.indexOf("+xml")) != -1) { // XHTML content needs special handling XMLOutputter outputter = new XMLOutputter(); List eContent = e.getContent(); Iterator i = eContent.iterator(); while (i.hasNext()) { org.jdom.Content c = (org.jdom.Content) i.next(); if (c instanceof Element) { Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element)c).setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(eContent); } else { // Everything else comes in verbatim value = e.getText(); } return value; }
@Override public String writeUser(UserData userData) { Namespace ns = Namespace.getNamespace(USERCATALOG_NAMESPACE_PREFIX, USERCATALOG_NAMESPACE); Namespace nsXsi = Namespace.getNamespace(XSI_NAMESPACE_PREFIX, XSI_NAMESPACE); Document doc = new Document(dumpUser(userData, ns)); doc.getRootElement().setNamespace(ns); doc.getRootElement().addNamespaceDeclaration(nsXsi); doc.getRootElement().setAttribute( new Attribute("schemaLocation", USERCATALOG_NAMESPACE + " " + USER_SCHEMA_LOCATION, nsXsi)); XMLOutputter xmlOutputter = getOutputter(); String xml = xmlOutputter.outputString(doc); SAXBuilder saxBuilder = getBuilder(USER_SCHEMA_RESOURCE); try { saxBuilder.build(IOUtils.toInputStream(xml)); return xml; } catch (Exception e) { throw new ExportException("Error during validating output.", e); } }
@Override public String writeGroup(Group group) { Namespace ns = Namespace.getNamespace(USERCATALOG_NAMESPACE_PREFIX, USERCATALOG_NAMESPACE); Namespace nsXsi = Namespace.getNamespace(XSI_NAMESPACE_PREFIX, XSI_NAMESPACE); Document doc = new Document(dumpGroup(group, ns)); doc.getRootElement().setNamespace(ns); doc.getRootElement().addNamespaceDeclaration(nsXsi); doc.getRootElement().setAttribute( new Attribute("schemaLocation", USERCATALOG_NAMESPACE + " " + GROUP_SCHEMA_LOCATION, nsXsi)); XMLOutputter xmlOutputter = getOutputter(); String xml = xmlOutputter.outputString(doc); SAXBuilder saxBuilder = getBuilder(GROUP_SCHEMA_RESOURCE); try { saxBuilder.build(IOUtils.toInputStream(xml)); return xml; } catch (Exception e) { throw new ExportException("Error during validating output.", e); } }
@Override public String writeGroup(Group group) throws ExportException { Namespace ns = Namespace.getNamespace(USERCATALOG_NAMESPACE_PREFIX, USERCATALOG_NAMESPACE); Namespace nsXsi = Namespace.getNamespace(XSI_NAMESPACE_PREFIX, XSI_NAMESPACE); Document doc = new Document(dumpGroup(group, ns)); doc.getRootElement().setNamespace(ns); doc.getRootElement().addNamespaceDeclaration(nsXsi); doc.getRootElement().setAttribute( new Attribute("schemaLocation", USERCATALOG_NAMESPACE + " " + GROUP_SCHEMA_LOCATION, nsXsi)); XMLOutputter xmlOutputter = getOutputter(); String xml = xmlOutputter.outputString(doc); SAXBuilder saxBuilder = getBuilder(GROUP_SCHEMA_RESOURCE); try { saxBuilder.build(IOUtils.toInputStream(xml)); return xml; } catch (Exception e) { throw new ExportException("Error during validating output.", e); } }
@Override public String writeUser(UserData userData) throws ExportException { Namespace ns = Namespace.getNamespace(USERCATALOG_NAMESPACE_PREFIX, USERCATALOG_NAMESPACE); Namespace nsXsi = Namespace.getNamespace(XSI_NAMESPACE_PREFIX, XSI_NAMESPACE); Document doc = new Document(dumpUser(userData, ns)); doc.getRootElement().setNamespace(ns); doc.getRootElement().addNamespaceDeclaration(nsXsi); doc.getRootElement().setAttribute( new Attribute("schemaLocation", USERCATALOG_NAMESPACE + " " + USER_SCHEMA_LOCATION, nsXsi)); XMLOutputter xmlOutputter = getOutputter(); String xml = xmlOutputter.outputString(doc); SAXBuilder saxBuilder = getBuilder(USER_SCHEMA_RESOURCE); try { saxBuilder.build(IOUtils.toInputStream(xml)); return xml; } catch (Exception e) { throw new ExportException("Error during validating output.", e); } }
Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element)c).setNamespace(Namespace.NO_NAMESPACE);
Element eC = (Element) c; if (eC.getNamespace().equals(getAtomNamespace())) { ((Element)c).setNamespace(Namespace.NO_NAMESPACE);
private BPELInternalMessage formatAsRpc(final BPELInternalMessage internalMessage, final BindingOperation bOp, final Operation op, final String direction) throws BPELException { final BPELInternalMessage formattedMessage = new BPELInternalMessageImpl(); if(internalMessage != null) { formattedMessage.setEndpoint(internalMessage.getEndpoint()); formattedMessage.setQName(internalMessage.getQName()); formattedMessage.setService(internalMessage.getService()); // change message name by the binding operation name final org.jdom.Element elmt = (org.jdom.Element) internalMessage.getContent().clone(); String operationName = bOp.getQName().getLocalPart(); if(direction.equals(RESPONSE)) { operationName = operationName + "Response"; } elmt.setName(operationName); if(!elmt.getNamespaceURI().equals(bOp.getQName().getNamespaceURI())) { elmt.setNamespace(Namespace.getNamespace(bOp.getQName().getNamespaceURI())); } if(((op.getInput().getParts() != null)&& (op.getInput().getParts().size() > 0)) || op.getInput().getElement() != null) { final org.jdom.Document doc = new org.jdom.Document(elmt); formattedMessage.setContent(doc.getRootElement()); } } else { throw new BPELException("Internal message cannot be null."); } return formattedMessage; }
root.setNamespace( pomNamespace );