List of usage examples for org.dom4j QName QName
public QName(String name, Namespace namespace)
From source file:CallXSLT.java
License:Open Source License
public void generateMyoutput(PipelineContext pipelineContext, XMLReceiver xmlReceiver) throws SAXException { // Define the name of the processor (this is a QName) final QName processorName = new QName("xslt", XMLConstants.OXF_PROCESSORS_NAMESPACE); // Get a factory for this processor final ProcessorFactory processorFactory = ProcessorFactoryRegistry.lookup(processorName); if (processorFactory == null) throw new OXFException("Cannot find processor factory with name '" + processorName.getNamespacePrefix() + ":" + processorName.getName() + "'"); // Create processor final Processor processor = processorFactory.createInstance(); // Connect inputs (one from URL, the other one from a DOM) final URLGenerator urlGeneratorConfig = new URLGenerator("oxf:/apps/java-api/transform.xsl"); PipelineUtils.connect(urlGeneratorConfig, "data", processor, "config"); final Document dataInputDocument = readInputAsDOM4J(pipelineContext, "myinput"); final DOMGenerator domGeneratorData = PipelineUtils.createDOMGenerator(dataInputDocument, "data input", DOMGenerator.ZeroValidity, DOMGenerator.DefaultContext); PipelineUtils.connect(domGeneratorData, "data", processor, "data"); // Connect outputs final DOMSerializer domSerializerData = new DOMSerializer(); PipelineUtils.connect(processor, "data", domSerializerData, "data"); // Candidate for Scala withPipelineContext boolean success = false; final PipelineContext newPipelineContext = new PipelineContext(); // here we decide to use our own PipelineContext try {/* ww w.j a v a 2s . c o m*/ domSerializerData.start(newPipelineContext); final Document result = domSerializerData.runGetDocument(newPipelineContext); success = true; } finally { newPipelineContext.destroy(success); } // Serialize result to output TransformerUtils.writeDom4j(result, xmlReceiver); }
From source file:com.alibaba.citrus.dev.handler.util.ConfigurationFileReader.java
License:Open Source License
private ConfigurationFile parseConfigurationFile(final NamedResource namedResource, final Set<String> parsedNames) { URL url;// w w w .j a v a2s . c om try { url = namedResource.resource.getURL(); } catch (IOException e) { unexpectedException(e); return null; } String name = url.toExternalForm(); if (name.startsWith(baseURL)) { name = name.substring(baseURL.length()); } if (parsedNames.contains(name)) { return null; } parsedNames.add(name); final List<ConfigurationFile> importedConfigurationFiles = createLinkedList(); Element rootElement; try { rootElement = DomUtil.readDocument(name, url, new ElementFilter() { public org.dom4j.Element filter(org.dom4j.Element e) throws Exception { // schemaLocation org.dom4j.Attribute attr = e.attribute(new QName("schemaLocation", new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"))); if (attr != null) { e.remove(attr); } // beans:importelement if ("http://www.springframework.org/schema/beans".equals(e.getNamespaceURI()) && "import".equals(e.getName())) { String importedResourceName = trimToNull(e.attributeValue("resource")); if (importedResourceName != null) { Resource importedResource; if (importedResourceName.contains(":")) { importedResource = loader.getResource(importedResourceName); } else { importedResource = namedResource.resource.createRelative(importedResourceName); } ConfigurationFile importedConfigurationFile = parseConfigurationFile( new NamedResource(importedResourceName, importedResource), parsedNames); if (importedConfigurationFile != null) { importedConfigurationFiles.add(importedConfigurationFile); } } return null; } return e; } }); } catch (Exception e) { rootElement = new Element("read-error").setText(getStackTrace(getRootCause(e))); } return new ConfigurationFile(namedResource.name, url, importedConfigurationFiles.toArray(new ConfigurationFile[importedConfigurationFiles.size()]), rootElement); }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * Return the child element with the given name. The element must be in the * same name space as the parent element. * /*from w w w .ja va 2s. c o m*/ * @param element * The parent element * @param name * The child element name * @return The child element */ public static Element child(Element element, String name) { return element.element(new QName(name, element.getNamespace())); }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * ?//from w w w . j av a 2 s . co m * * * * @param element * * @param name * ??? * * * * @param optional * ?? * @return ? * * * * @throws XMLDocException * @throws BaseException */ public static Element child(Element element, String name, boolean optional) throws BaseException { Element child = element.element(new QName(name, element.getNamespace())); if (child == null && !optional) { throw new BaseException("UTIL-0001", name + " element expected as child of " + element.getName() + "."); } return child; }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * Return the child elements with the given name. The elements must be in * the same name space as the parent element. * /*from w w w . j a va 2s . c o m*/ * @param element * The parent element * @param name * The child element name * @return The child elements */ public static List<Element> children(Element element, String name) { return element.elements(new QName(name, element.getNamespace())); }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * /*from w w w. j a v a 2 s . c o m*/ * * * * @param element * * @param name * * * * * @param optional * * @return * @throws XMLDocException * @throws BaseException */ public static Element getFirstChild(Element element, String name, boolean optional) throws BaseException { List list = element.elements(new QName(name, element.getNamespace())); // 0 if (list.size() > 0) { return (Element) list.get(0); } else { if (!optional) { throw new BaseException("UTIL-0001", name + " element expected as first child of " + element.getName() + "."); } else { return null; } } }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * ElementString/*from ww w .j ava 2 s . co m*/ * * @param parent * * @param name * * * * * @param value * * @return element * @throws XMLDocException */ public static Element appendChild(Element parent, String name, String value) { Element element = parent.addElement(new QName(name, parent.getNamespace())); if (value != null) { element.addText(value); } return element; }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * Element//w w w . j a v a2s .c om * * @param parent * * @param name * * * * * @return Element * @throws XMLDocException */ public static Element appendChild(Element parent, String name) { return parent.addElement(new QName(name, parent.getNamespace())); }
From source file:com.cladonia.xml.XAttribute.java
License:Open Source License
/** * Constructs a default element with an initial type. * * @param name the unmutable name.//w w w . ja v a2s . c o m */ public XAttribute(String name, String namespace, String value) { this(new QName(name, Namespace.get(namespace)), value); }
From source file:com.cladonia.xml.XElement.java
License:Open Source License
/** * Constructs a default element with an initial type. * * @param name the unmutable name./*www . j ava 2 s . c om*/ */ public XElement(String name, String namespace) { this(new QName(name, Namespace.get(namespace)), true); }