List of usage examples for org.dom4j DocumentHelper createQName
public static QName createQName(String localName, Namespace namespace)
From source file:com.alibaba.citrus.springext.impl.SchemaImpl.java
License:Open Source License
/** * ?schema??//from w ww . ja v a 2 s .com * <ol> * <li>targetNamespace</li> * <li>include name</li> * </ol> */ @Override protected void doAnalyze() { Document doc = getDocument(); // ??null org.dom4j.Element root = doc.getRootElement(); // return if not a schema file if (!W3C_XML_SCHEMA_NS_URI.equals(root.getNamespaceURI()) || !"schema".equals(root.getName())) { return; } // parse targetNamespace if (parsingTargetNamespace) { Attribute attr = root.attribute("targetNamespace"); if (attr != null) { targetNamespace = trimToNull(attr.getStringValue()); } } // parse include Namespace xsd = DocumentHelper.createNamespace("xsd", W3C_XML_SCHEMA_NS_URI); QName includeName = DocumentHelper.createQName("include", xsd); List<String> includeNames = createLinkedList(); // for each <xsd:include> for (Iterator<?> i = root.elementIterator(includeName); i.hasNext();) { org.dom4j.Element includeElement = (org.dom4j.Element) i.next(); String schemaLocation = trimToNull(includeElement.attributeValue("schemaLocation")); if (schemaLocation != null) { includeNames.add(schemaLocation); } } includes = includeNames.toArray(new String[includeNames.size()]); // parse xsd:element QName elementName = DocumentHelper.createQName("element", xsd); // for each <xsd:element> for (Iterator<?> i = root.elementIterator(elementName); i.hasNext();) { Element element = new ElementImpl((org.dom4j.Element) i.next()); if (element.getName() != null) { this.elements.put(element.getName(), element); } } }
From source file:com.alibaba.citrus.springext.support.SchemaUtil.java
License:Open Source License
/** schema?includes */ public static Transformer getTransformerWhoAddsIndirectIncludes(final Map<String, Schema> includes) { return new Transformer() { public void transform(Document document, String systemId) { Element root = document.getRootElement(); root.addNamespace("xsd", W3C_XML_SCHEMA_NS_URI); // <xsd:schema> if (W3C_XML_SCHEMA_NS_URI.equals(root.getNamespaceURI()) && "schema".equals(root.getName())) { Namespace xsd = DocumentHelper.createNamespace("xsd", W3C_XML_SCHEMA_NS_URI); QName includeName = DocumentHelper.createQName("include", xsd); // for each <xsd:include> for (Iterator<?> i = root.elementIterator(includeName); i.hasNext();) { i.next();/*w w w . j ava 2 s . c o m*/ i.remove(); } // includes @SuppressWarnings("unchecked") List<Node> nodes = root.elements(); int i = 0; for (Schema includedSchema : includes.values()) { Element includeElement = DocumentHelper.createElement(includeName); nodes.add(i++, includeElement); includeElement.addAttribute("schemaLocation", includedSchema.getName()); } } } }; }
From source file:com.alibaba.citrus.springext.support.SchemaUtil.java
License:Open Source License
/** ?URI? */ public static Transformer getAddPrefixTransformer(final SchemaSet schemas, String prefix) { if (prefix != null) { if (!prefix.endsWith("/")) { prefix += "/"; }/*ww w .ja va 2 s. c o m*/ } final String normalizedPrefix = prefix; return new Transformer() { public void transform(Document document, String systemId) { if (normalizedPrefix != null) { Element root = document.getRootElement(); // <xsd:schema> if (W3C_XML_SCHEMA_NS_URI.equals(root.getNamespaceURI()) && "schema".equals(root.getName())) { Namespace xsd = DocumentHelper.createNamespace("xsd", W3C_XML_SCHEMA_NS_URI); QName includeName = DocumentHelper.createQName("include", xsd); QName importName = DocumentHelper.createQName("import", xsd); // for each <xsd:include> for (Iterator<?> i = root.elementIterator(includeName); i.hasNext();) { Element includeElement = (Element) i.next(); String schemaLocation = trimToNull(includeElement.attributeValue("schemaLocation")); if (schemaLocation != null) { schemaLocation = getNewSchemaLocation(schemaLocation, null, systemId); if (schemaLocation != null) { includeElement.addAttribute("schemaLocation", schemaLocation); } } } // for each <xsd:import> for (Iterator<?> i = root.elementIterator(importName); i.hasNext();) { Element importElement = (Element) i.next(); String schemaLocation = importElement.attributeValue("schemaLocation"); String namespace = trimToNull(importElement.attributeValue("namespace")); if (schemaLocation != null || namespace != null) { schemaLocation = getNewSchemaLocation(schemaLocation, namespace, systemId); if (schemaLocation != null) { importElement.addAttribute("schemaLocation", schemaLocation); } } } } } } private String getNewSchemaLocation(String schemaLocation, String namespace, String systemId) { // ?schemaLocation if (schemaLocation != null) { Schema schema = schemas.findSchema(schemaLocation); if (schema != null) { return normalizedPrefix + schema.getName(); } else { return schemaLocation; // location?? } } // ??namespace if (namespace != null) { Set<Schema> nsSchemas = schemas.getNamespaceMappings().get(namespace); if (nsSchemas != null && !nsSchemas.isEmpty()) { // ?nsschema?schema String versionedExtension = getVersionedExtension(systemId); if (versionedExtension != null) { for (Schema schema : nsSchemas) { if (schema.getName().endsWith(versionedExtension)) { return normalizedPrefix + schema.getName(); } } } // schema?beans.xsd?beans-2.5.xsd?beans-2.0.xsd return normalizedPrefix + nsSchemas.iterator().next().getName(); } } return null; } /** spring-aop-2.5.xsd?-2.5.xsd */ private String getVersionedExtension(String systemId) { if (systemId != null) { int dashIndex = systemId.lastIndexOf("-"); int slashIndex = systemId.lastIndexOf("/"); if (dashIndex > slashIndex) { return systemId.substring(dashIndex); } } return null; } }; }
From source file:com.liferay.portal.xml.SAXReaderImpl.java
License:Open Source License
public QName createQName(String localName, Namespace namespace) { NamespaceImpl namespaceImpl = (NamespaceImpl) namespace; return new QNameImpl(DocumentHelper.createQName(localName, namespaceImpl.getWrappedNamespace())); }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.AbstractStudyCalendarXmlSerializer.java
License:BSD License
protected Element element(String elementName) { // Using QName is the only way to attach the namespace to the element QName qNode = DocumentHelper.createQName(elementName, DEFAULT_NAMESPACE); return DocumentHelper.createElement(qNode); }
From source file:nz.co.senanque.schemaparser.SchemaVisitorDom4j.java
License:Apache License
@Override public void initialize(String xsdpackageName, String targetNamespace) { Element root = document.addElement(rootName); Namespace xsi = DocumentHelper.createNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.add(xsi);/* w w w . jav a 2 s.c o m*/ if (targetNamespace != null) { Namespace tns = DocumentHelper.createNamespace("tns", targetNamespace); root.add(tns); QName schemaLocation = DocumentHelper.createQName("schemaLocation", xsi); Attribute attribute = DocumentHelper.createAttribute(root, schemaLocation, targetNamespace + " " + location + " " + rootName.getNamespaceURI() + " " + rootLocation); root.add(attribute); } elements.push(root); }
From source file:org.jage.platform.config.xml.loaders.ComponentsNormalizer.java
License:Open Source License
@Override public Document loadDocument(final String path) throws ConfigurationException { final Document document = getDelegate().loadDocument(path); Namespace namespace = createNamespace("", ConfigNamespaces.DEFAULT.getUri()); for (Element element : selectNodes(AGENTS, document)) { element.setQName(DocumentHelper.createQName(COMPONENT.toString(), namespace)); element.addAttribute(IS_SINGLETON.toString(), "false"); }/*from w ww . j a va 2 s . c o m*/ for (Element element : selectNodes(STRATEGIES, document)) { element.setQName(DocumentHelper.createQName(COMPONENT.toString(), namespace)); element.addAttribute(IS_SINGLETON.toString(), "true"); } return document; }
From source file:org.jivesoftware.openfire.fastpath.providers.ChatMetadataProvider.java
License:Open Source License
public Element getMetaDataElement(Map<String, String> metaData) { QName qName = DocumentHelper.createQName("metadata", DocumentHelper.createNamespace("", "http://jivesoftware.com/protocol/workgroup")); Element metaDataElement = DocumentHelper.createElement(qName); for (Map.Entry<String, String> entry : metaData.entrySet()) { String name = entry.getKey(); String value = entry.getValue(); Element elem = metaDataElement.addElement("value"); elem.addAttribute("name", name).setText(value); }//ww w. ja v a2s . c o m return metaDataElement; }
From source file:org.jivesoftware.xmpp.workgroup.request.InvitationRequest.java
License:Open Source License
@Override public Element getSessionElement() { // Add the workgroup of the original user request QName qName = DocumentHelper.createQName("session", DocumentHelper.createNamespace("", "http://jivesoftware.com/protocol/workgroup")); Element sessionElement = DocumentHelper.createElement(qName); sessionElement.addAttribute("id", sessionID); sessionElement.addAttribute("workgroup", userRequest.getWorkgroup().getJID().toString()); return sessionElement; }
From source file:org.jivesoftware.xmpp.workgroup.request.Request.java
License:Open Source License
public Element getMetaDataElement() { QName qName = DocumentHelper.createQName("metadata", DocumentHelper.createNamespace("", "http://jivesoftware.com/protocol/workgroup")); Element metaDataElement = DocumentHelper.createElement(qName); for (String name : metaData.keySet()) { List<String> values = metaData.get(name); for (String value : values) { Element elem = metaDataElement.addElement("value"); elem.addAttribute("name", name).setText(value); }/*from w w w . j a v a2s . com*/ } return metaDataElement; }