List of usage examples for org.dom4j QName getNamespacePrefix
public String getNamespacePrefix()
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 {/*from w w w. j a v a 2s . co 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.liferay.util.xml.XMLConverter.java
License:Open Source License
public static javax.xml.namespace.QName toJavaxQName(org.dom4j.QName dom4jQName) { javax.xml.namespace.QName javaxQName = new javax.xml.namespace.QName(dom4jQName.getNamespaceURI(), dom4jQName.getName(), dom4jQName.getNamespacePrefix()); return javaxQName; }
From source file:com.rdvmedecin.proprietes.Properties.java
public Properties() throws DocumentException { File fichier = new File("configuration.xml"); SAXReader reader = new SAXReader(); Document doc = reader.read(fichier); Element root = doc.getRootElement(); List attributes = root.attributes(); List elements = root.elements(); QName qName = root.getQName(); String nom = qName.getName(); // lecture du nom de l'espace de noms String nomEspaceDeNoms = qName.getNamespaceURI(); // lecture du prfixe utilis pour cet espace de nom String nomPrefix = qName.getNamespacePrefix(); String texte = root.getText(); Attribute attribute = (Attribute) attributes.iterator().next(); QName attributeQName = attribute.getQName(); String value = attribute.getValue(); String nomAttribut = attribute.getName(); }
From source file:org.orbeon.oxf.processor.ProcessorUtils.java
License:Open Source License
public static Processor createProcessorWithInputs(Element testNode, boolean saxDebug) { // Create processor QName processorName = XMLProcessorRegistry.extractProcessorQName(testNode); ProcessorFactory processorFactory = ProcessorFactoryRegistry.lookup(processorName); if (processorFactory == null) throw new OXFException("Cannot find processor factory with name '" + processorName.getNamespacePrefix() + ":" + processorName.getName() + "'"); Processor processor = processorFactory.createInstance(); // Connect inputs for (Iterator j = XPathUtils.selectIterator(testNode, "input"); j.hasNext();) { Element inputElement = (Element) j.next(); String name = XPathUtils.selectStringValue(inputElement, "@name"); if (XPathUtils.selectStringValue(inputElement, "@href") == null) { // Case of embedded XML Element originalElement = (Element) ((Element) inputElement).elementIterator().next(); if (originalElement == null) throw new OXFException("Input content is mandatory"); Element copiedElement = Dom4jUtils.copyElementCopyParentNamespaces(originalElement); final String sid = Dom4jUtils.makeSystemId(originalElement); final DOMGenerator domGenerator = new DOMGenerator(copiedElement, "input from pipeline utils", DOMGenerator.ZeroValidity, sid); if (saxDebug) { final SAXLoggerProcessor loggerProcessor = new SAXLoggerProcessor(); PipelineUtils.connect(domGenerator, "data", loggerProcessor, "data"); PipelineUtils.connect(loggerProcessor, "data", processor, name); } else { PipelineUtils.connect(domGenerator, "data", processor, name); }// www . ja va 2 s . com } else { // Href LocationData locationData = (LocationData) inputElement.getData(); URL fullURL = createRelativeURL(locationData, XPathUtils.selectStringValue(inputElement, "@href")); URLGenerator urlGenerator = new URLGenerator(fullURL); urlGenerator.setLocationData(locationData); PipelineUtils.connect(urlGenerator, "data", processor, name); } } return processor; }
From source file:org.orbeon.oxf.xforms.action.actions.XFormsMessageAction.java
License:Open Source License
public void execute(XFormsActionInterpreter actionInterpreter, Element actionElement, Scope actionScope, boolean hasOverriddenContext, Item overriddenContext) { final XFormsContainingDocument containingDocument = actionInterpreter.containingDocument(); {//w ww . j a v a 2 s . c o m final String levelAttribute; final QName levelQName; { final String tempLevelAttribute = actionElement.attributeValue(XFormsConstants.LEVEL_QNAME); if (tempLevelAttribute == null) { // "The default is "modal" if the attribute is not specified." levelQName = XFormsConstants.XFORMS_MODAL_LEVEL_QNAME; levelAttribute = levelQName.getName(); } else { levelAttribute = tempLevelAttribute; levelQName = Dom4jUtils.extractAttributeValueQName(actionElement, XFormsConstants.LEVEL_QNAME); } } // Get message value final String messageValue; { final String elementValue = XFormsUtils.getElementValue(actionInterpreter.container(), actionInterpreter.actionXPathContext(), actionInterpreter.getSourceEffectiveId(actionElement), actionElement, false, false, null); // If we got a null consider the message to be an empty string messageValue = elementValue != null ? elementValue : ""; } if (LOG_APPEARANCES.get(levelQName) != null) { // Special log appearance final IndentedLogger indentedLogger = containingDocument.indentedLogger(); if (XFormsConstants.XXFORMS_LOG_DEBUG_LEVEL_QNAME.equals(levelQName)) { indentedLogger.logDebug("xf:message", messageValue); } else if (XFormsConstants.XXFORMS_LOG_INFO_DEBUG_LEVEL_QNAME.equals(levelQName)) { indentedLogger.logInfo("xf:message", messageValue); } else if (XFormsConstants.XXFORMS_LOG_WARN_DEBUG_LEVEL_QNAME.equals(levelQName)) { indentedLogger.logWarning("xf:message", messageValue); } else if (XFormsConstants.XXFORMS_LOG_ERROR_DEBUG_LEVEL_QNAME.equals(levelQName)) { indentedLogger.logError("xf:message", messageValue); } } else if (SUPPORTED_APPEARANCES.get(levelQName) != null) { // Any other supported appearance are sent to the client final String level; if (levelQName.getNamespacePrefix().equals("")) { level = levelAttribute; } else { level = "{" + levelQName.getNamespaceURI() + "}" + levelQName.getName(); } // Store message for sending to client containingDocument.addMessageToRun(messageValue, level); // NOTE: In the future, we *may* want to save and resume the event state before and after // displaying a message, in order to possibly provide a behavior which is more consistent with what // users may expect regarding actions executed after xf:message. } else { // Unsupported appearance throw new OXFException( "xf:message element's 'level' attribute must have value: 'ephemeral'|'modeless'|'modal'|'xxf:log-debug'|'xxf:log-info'|'xxf:log-warn'|'xxf:log-error'."); } } }
From source file:org.orbeon.oxf.xforms.control.controls.XMLCleaner.java
License:Open Source License
public static org.dom4j.Document cleanXML(org.dom4j.Document doc, String stylesheetURL) { try {/* w ww . j av a 2 s . co m*/ final org.dom4j.Element element = doc.getRootElement(); final String systemId = Dom4jUtils.makeSystemId(element); // The date to clean final DOMGenerator dataToClean = new DOMGenerator(doc, "clean xml", DOMGenerator.ZeroValidity, systemId); // The stylesheet final URLGenerator stylesheetGenerator = new URLGenerator(stylesheetURL); // The transformation // 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 xsltProcessor = processorFactory.createInstance(); // Where the result goes final DOMSerializer transformationOutput = new DOMSerializer(); // Connect PipelineUtils.connect(stylesheetGenerator, "data", xsltProcessor, "config"); PipelineUtils.connect(dataToClean, "data", xsltProcessor, "data"); PipelineUtils.connect(xsltProcessor, "data", transformationOutput, "data"); // Run the pipeline // Candidate for Scala withPipelineContext final PipelineContext pipelineContext = new PipelineContext(); boolean success = false; try { final org.dom4j.Document result = transformationOutput.runGetDocument(pipelineContext); success = true; return result; } finally { pipelineContext.destroy(success); } } catch (Exception e) { throw new OXFException(e); } }
From source file:org.orbeon.oxf.xforms.XFormsModelBinds.java
License:Open Source License
public Item evaluateBindByType(RuntimeBind bind, int position, QName mipType) throws XPathException { if (mipType.equals(XFormsConstants.RELEVANT_QNAME)) { // Relevant final Boolean relevant = evaluateRelevantMIP(bind, position); return (relevant != null) ? BooleanValue.get(relevant) : null; } else if (mipType.equals(XFormsConstants.READONLY_QNAME)) { // Readonly final Boolean readonly = evaluateReadonlyMIP(bind, position); return (readonly != null) ? BooleanValue.get(readonly) : null; } else if (mipType.equals(XFormsConstants.REQUIRED_QNAME)) { // Required final Boolean required = evaluateRequiredMIP(bind, position); return (required != null) ? BooleanValue.get(required) : null; } else if (mipType.equals(XFormsConstants.TYPE_QNAME)) { // Type//from w w w .j a va 2 s .co m final NamespaceMapping namespaceMapping = bind.staticBind.namespaceMapping(); final QName type = bind.evaluateTypeQName(namespaceMapping.mapping); return (type != null) ? new QNameValue(type.getNamespacePrefix(), type.getNamespaceURI(), type.getName(), null) : null; } else if (mipType.equals(XFormsConstants.CONSTRAINT_QNAME)) { // Constraint // TODO: Add support for other constraint levels. if (bind.staticBind.constraintsByLevel().nonEmpty()) return BooleanValue.get(failedConstraintMIPs(StaticBind.jErrorLevel(), bind, position).isEmpty()); else return null; } else if (mipType.equals(XFormsConstants.CALCULATE_QNAME)) { // Calculate final String result = evaluateCalculateBind(bind, position); return (result != null) ? new StringValue(result) : null; } else if (mipType.equals(XFormsConstants.XXFORMS_DEFAULT_QNAME)) { // xxf:default final String result = evaluateXXFormsDefaultBind(bind, position); return (result != null) ? new StringValue(result) : null; } else { // Try custom MIPs final String result = evaluateCustomMIP(bind, Model.buildCustomMIPName(mipType.getQualifiedName()), position); return (result != null) ? new StringValue(result) : null; } }
From source file:org.orbeon.oxf.xml.XMLUtils.java
License:Open Source License
public static org.dom4j.Document cleanXML(org.dom4j.Document doc, String stylesheetURL) { try {/* w w w . j a v a 2 s .c o m*/ final org.dom4j.Element element = doc.getRootElement(); final String systemId = Dom4jUtils.makeSystemId(element); // The date to clean final DOMGenerator dataToClean = new DOMGenerator(doc, "clean xml", DOMGenerator.ZeroValidity, systemId); // The stylesheet URLGenerator stylesheetGenerator = new URLGenerator(stylesheetURL); // The transformation // 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 xsltProcessor = processorFactory.createInstance(); // Where the result goes DOMSerializer transformationOutput = new DOMSerializer(); // Connect PipelineUtils.connect(stylesheetGenerator, "data", xsltProcessor, "config"); PipelineUtils.connect(dataToClean, "data", xsltProcessor, "data"); PipelineUtils.connect(xsltProcessor, "data", transformationOutput, "data"); // Run the pipeline // Candidate for Scala withPipelineContext final PipelineContext pipelineContext = new PipelineContext(); boolean success = false; try { final org.dom4j.Document result = transformationOutput.runGetDocument(pipelineContext); success = true; return result; } finally { pipelineContext.destroy(success); } } catch (Exception e) { throw new OXFException(e); } }