List of usage examples for org.dom4j QName getName
public String getName()
From source file:org.orbeon.oxf.xforms.XFormsModelSchemaValidator.java
License:Open Source License
/** * Validate an element following the XML Schema "lax" mode. * * @param element element to validate/* ww w . j a va2 s .c o m*/ */ private boolean validateElementLax(final Element element) { final String elementURI; final String elementName; // NOTE: We do some special processing for xsi:type to find if there is a type declared for it. If not, we do // lax processing. However, it is not clear whether we should apply lax processing in this case or not. Maybe if // an xsi:type is specified and not found, the element should just be invalid. // TODO: should pass true? final QName xsiType = Dom4jUtils.extractAttributeValueQName(element, XMLConstants.XSI_TYPE_QNAME, false); if (xsiType != null) { // Honor xsi:type elementURI = xsiType.getNamespaceURI(); elementName = xsiType.getName(); } else { // Use element name elementURI = element.getNamespaceURI(); elementName = element.getName(); } boolean isValid = true; { // Find expression for element type final Expression expression; { // Find schema for type namespace final XMLSchemaSchema schema = ((XMLSchemaGrammar) schemaGrammar).getByNamespace(elementURI); if (schema != null) { // Try to find the expression in the schema final ElementDeclExp elementDeclExp = schema.elementDecls.get(elementName); if (elementDeclExp != null) { // Found element type expression = elementDeclExp; } else if (xsiType != null) { // Try also complex type expression = schema.complexTypes.get(elementName); } else { // No type found expression = null; } } else { // No schema so no expression expression = null; } } if (expression != null) { // Found type for element, so validate element final Acceptor acceptor = documentDeclaration.createAcceptor(); isValid &= validateElement(element, acceptor, null, true); } else { // Element does not have type, so try to validate attributes and children elements // Attributes if (false) { // TODO: find out way of validating an attribute only // TODO: should we also look at schema.attributeGroups? final List attributesList = element.attributes(); for (final Iterator iterator = attributesList.iterator(); iterator.hasNext();) { final Attribute attribute = (Attribute) iterator.next(); final String attributeURI = attribute.getNamespaceURI(); final String attributeName = attribute.getName(); // final String attributeQName = attribute.getQualifiedName(); // final String attributeValue = attribute.getValue(); // Find expression for element type final Expression attributeExpression; { // Find schema for type namespace final XMLSchemaSchema schema = ((XMLSchemaGrammar) schemaGrammar) .getByNamespace(attributeURI); if (schema != null) { attributeExpression = schema.attributeDecls.get(attributeName); } else { attributeExpression = null; } } if (attributeExpression != null) { // final ExpressionAcceptor expressionAcceptor = new SimpleAcceptor(documentDeclaration, attributeExpression, null, null); // // Validate attribute value // final StringRef errorStringRef = new StringRef(); // final DatatypeRef datatypeRef = new DatatypeRef(); // // if (!expressionAcceptor.onAttribute2(attributeURI, attributeName, attributeQName, attributeValue, validationContext, errorStringRef, datatypeRef)) { // if (errorStringRef.str == null) // not sure if this can happen // errorStringRef.str = "Error validating attribute"; // addSchemaError(attribute, errorStringRef.str); // } // if (!expressionAcceptor.onText2(attributeValue, validationContext, errorStringRef, datatypeRef)) { // if (errorStringRef.str == null) // not sure if this can happen // errorStringRef.str = "Error validating attribute"; // addSchemaError(attribute, errorStringRef.str); // } // // // Check final acceptor state // if (!expressionAcceptor.isAcceptState(errorStringRef)) { // if (errorStringRef.str == null) // not sure if this can happen // errorStringRef.str = "Error validating attribute"; // addSchemaError(attribute, errorStringRef.str); // } } } } // Validate children elements for (final Iterator iterator = element.elementIterator(); iterator.hasNext();) { final Element childElement = (Element) iterator.next(); isValid &= validateElementLax(childElement); } } } return isValid; }
From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java
License:Open Source License
/** * Encode a QName to an exploded QName (also known as a "Clark name") String. *//*w w w . ja v a2 s . c o m*/ public static String qNameToExplodedQName(QName qName) { return (qName == null) ? null : XMLUtils.buildExplodedQName(qName.getNamespaceURI(), qName.getName()); }
From source file:org.orbeon.oxf.xml.XMLUtils.java
License:Open Source License
public static String buildExplodedQName(QName qName) { return buildExplodedQName(qName.getNamespaceURI(), qName.getName()); }
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 {//from w w w . j a va 2s .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); } }
From source file:org.orbeon.saxon.dom4j.TypedNodeWrapper.java
License:Open Source License
@Override public int getTypeAnnotation() { final QName nodeType = InstanceData.getType((Node) node); if (nodeType == null) { return getUntypedType(); } else {/*from w w w . jav a2 s . co m*/ // Extract QName String uri = nodeType.getNamespaceURI(); final String localname = nodeType.getName(); // For type annotation purposes, xforms:integer is translated into xs:integer. This is because XPath has no // knowledge of the XForms union types. if (uri.equals(XFormsConstants.XFORMS_NAMESPACE_URI) && Model.jXFormsVariationTypeNames().contains(localname)) uri = XMLConstants.XSD_URI; final int requestedTypeFingerprint = StandardNames.getFingerprint(uri, localname); if (requestedTypeFingerprint == -1) { // Back to default case return getUntypedType(); } else { // Return identified type return requestedTypeFingerprint; } } }