List of usage examples for org.dom4j QName getQualifiedName
public String getQualifiedName()
From source file:org.orbeon.oxf.processor.ProcessorUtils.java
License:Open Source License
private static void outputStartDocument(ContentHandler output, String contentType, Long lastModified, int statusCode, String fileName, QName type, String documentElement) { try {/*from ww w . j a v a2s .c o m*/ // Create attributes for root element: xsi:type, and optional content-type final AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute(XMLConstants.XSI_URI, "type", "xsi:type", "CDATA", type.getQualifiedName()); if (contentType != null) attributes.addAttribute("", "content-type", "content-type", "CDATA", contentType); if (fileName != null) attributes.addAttribute("", "filename", "filename", "CDATA", fileName); if (lastModified != null) attributes.addAttribute("", "last-modified", "last-modified", "CDATA", DateUtils.RFC1123Date().print(lastModified)); if (statusCode > 0) attributes.addAttribute("", "status-code", "status-code", "CDATA", Integer.toString(statusCode)); // Write document output.startDocument(); output.startPrefixMapping(XMLConstants.XSI_PREFIX, XMLConstants.XSI_URI); output.startPrefixMapping(XMLConstants.XSD_PREFIX, XMLConstants.XSD_URI); output.startElement("", documentElement, documentElement, attributes); } catch (Exception e) { throw new OXFException(e); } }
From source file:org.orbeon.oxf.properties.PropertySet.java
License:Open Source License
/** * Get a property./* w w w .j av a2 s . com*/ * * @param name property name * @param type property type to check against, or null * @return property object if found */ private Property getProperty(String name, final QName type) { // Try first from exact properties Property property = exactProperties.get(name); if (property == null) { // If not found try traversing tree which contains properties with wildcards // Parse name and put into array final String[] tokensArray; { final List<String> tokensList = new ArrayList<String>(); for (StringTokenizer nameTokenizer = new StringTokenizer(name, "."); nameTokenizer.hasMoreTokens();) tokensList.add(nameTokenizer.nextToken()); tokensArray = tokensList.toArray(new String[tokensList.size()]); } // Call recursive worker property = getPropertyWorker(wildcardProperties, tokensArray, 0); if (property == null) return null; } // Found a value, check type if (type != null && !type.equals(property.type)) throw new OXFException("Invalid attribute type requested for property '" + name + "': expected " + type.getQualifiedName() + ", found " + property.type.getQualifiedName()); // Return value return property; }
From source file:org.orbeon.oxf.properties.PropertyStore.java
License:Open Source License
/** * Construct a new property store./*from www . j ava2s. c o m*/ * * @param propertiesDocument Document containing the properties definitions */ public PropertyStore(final Document propertiesDocument) { // NOTE: the use of "attributes" and "attribute" is for special use of the property store by certain processors for (final Iterator i = XPathUtils.selectIterator(propertiesDocument, "/properties//property | /attributes//attribute"); i.hasNext();) { final Element propertyElement = (Element) i.next(); // Extract attributes final String processorName = propertyElement.attributeValue("processor-name"); final String as = propertyElement.attributeValue("as"); final String name = propertyElement.attributeValue("name"); final String value = propertyElement.attributeValue("value"); if (as != null) { // Read QName final QName typeQName = Dom4jUtils.extractAttributeValueQName(propertyElement, "as"); if (SUPPORTED_TYPES.get(typeQName) == null) throw new ValidationException("Invalid as attribute: " + typeQName.getQualifiedName(), (LocationData) propertyElement.getData()); if (processorName != null) { // Processor-specific property final QName processorQName = Dom4jUtils.extractAttributeValueQName(propertyElement, "processor-name"); getProcessorPropertySet(processorQName).setProperty(propertyElement, name, typeQName, value); } else { // Global property getGlobalPropertySet().setProperty(propertyElement, name, typeQName, value); } } } }
From source file:org.orbeon.oxf.transformer.xupdate.VariableContextImpl.java
License:Open Source License
public void assign(QName qname, Object value) throws UnresolvableException { if (this.qname == null) { throw new UnresolvableException("Variable '" + qname.getQualifiedName() + "' is not defined"); } else {/*from w w w. j a v a2 s . c o m*/ if (this.qname.equals(qname)) this.value = value; else parentContext.assign(qname, value); } }
From source file:org.orbeon.oxf.xforms.action.XFormsActionInterpreter.java
License:Open Source License
private void runSingleIteration(ElementAnalysis actionAnalysis, QName actionQName, String ifConditionAttribute, String whileIterationAttribute, boolean hasOverriddenContext, Item contextItem) { // The context is now the overridden context int whileIteration = 1; while (true) { // Check if the conditionAttribute attribute exists and stop if false if (ifConditionAttribute != null) { boolean result = evaluateCondition(actionAnalysis.element(), actionQName.getQualifiedName(), ifConditionAttribute, "if", contextItem); if (!result) break; }//from w w w.j a v a 2 s . c o m // Check if the iterationAttribute attribute exists and stop if false if (whileIterationAttribute != null) { boolean result = evaluateCondition(actionAnalysis.element(), actionQName.getQualifiedName(), whileIterationAttribute, "while", contextItem); if (!result) break; } // We are executing the action if (_indentedLogger.isDebugEnabled()) { _indentedLogger.startHandleOperation("interpreter", "executing", "action name", actionQName.getQualifiedName(), "while iteration", (whileIterationAttribute != null) ? Integer.toString(whileIteration) : null); } // Get action and execute it final DynamicActionContext dynamicActionContext = new DynamicActionContext(this, actionAnalysis, hasOverriddenContext ? Option.apply(contextItem) : Option.apply((Item) null)); // Push binding excluding excluding @context and @model // NOTE: If we repeat, re-evaluate the action binding. // For example: // // <xf:delete ref="/*/foo[1]" while="/*/foo"/> // // In this case, in the second iteration, xf:repeat must find an up-to-date nodeset! // TODO: function context _actionXPathContext.pushBinding(actionAnalysis.refJava(), null, null, null, actionAnalysis.bindJava(), actionAnalysis.element(), actionAnalysis.namespaceMapping(), getSourceEffectiveId(actionAnalysis.element()), actionAnalysis.scope(), false); XFormsActions.getAction(actionQName).execute(dynamicActionContext); _actionXPathContext.popBinding(); if (_indentedLogger.isDebugEnabled()) { _indentedLogger.endHandleOperation("action name", actionQName.getQualifiedName(), "while iteration", (whileIterationAttribute != null) ? Integer.toString(whileIteration) : null); } // Stop if there is no iteration if (whileIterationAttribute == null) break; whileIteration++; } }
From source file:org.orbeon.oxf.xforms.processor.handlers.xhtml.XFormsGroupDefaultHandler.java
License:Open Source License
@Override public void init(String uri, String localname, String qName, Attributes attributes, Object matched) throws SAXException { super.init(uri, localname, qName, attributes, matched); // Use explicit container element name if present, otherwise use default final QName explicitQName = ((ContainerControl) containingDocument.getStaticOps() .getControlAnalysis(getPrefixedId())).elementQName(); if (explicitQName != null) { elementName = explicitQName.getName(); elementQName = explicitQName.getQualifiedName(); } else {/*from w w w . ja v a 2 s . c o m*/ elementName = super.getContainingElementName(); elementQName = super.getContainingElementQName();// NOTE: this calls back getContainingElementName() } }
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 ww w . ja va 2s . c om 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.xforms.XFormsModelBinds.java
License:Open Source License
private boolean validateType(RuntimeBind bind, NodeInfo currentNodeInfo, boolean required) { final boolean typeValid; {//from w ww.ja v a 2 s .c o m // NOTE: xf:bind/@type is a literal type value, and it is the same that applies to all nodes pointed to by xf:bind/@ref final QName typeQName = bind.typeQName; final String typeNamespaceURI = typeQName.getNamespaceURI(); final String typeLocalname = typeQName.getName(); // Get value to validate if not already computed above final String nodeValue = DataModel.getValue(currentNodeInfo); // TODO: "[...] these datatypes can be used in the type model item property without the addition of the // XForms namespace qualifier if the namespace context has the XForms namespace as the default // namespace." final boolean isBuiltInSchemaType = XMLConstants.XSD_URI.equals(typeNamespaceURI); final boolean isBuiltInXFormsType = XFormsConstants.XFORMS_NAMESPACE_URI.equals(typeNamespaceURI); final boolean isBuiltInXXFormsType = XFormsConstants.XXFORMS_NAMESPACE_URI.equals(typeNamespaceURI); if (isBuiltInXFormsType && Model.jXFormsSchemaTypeNames().contains(typeLocalname)) { // xf:dayTimeDuration, xf:yearMonthDuration, xf:email, xf:card-number if (xformsValidator == null) { xformsValidator = new XFormsModelSchemaValidator("oxf:/org/orbeon/oxf/xforms/xforms-types.xsd"); xformsValidator.loadSchemas(containingDocument); } final String validationError = xformsValidator.validateDatatype(nodeValue, typeNamespaceURI, typeLocalname, typeQName.getQualifiedName(), bind.staticBind.locationData()); typeValid = validationError == null; } else if (isBuiltInXFormsType && nodeValue.length() == 0) { // Don't consider the node invalid if the string is empty with xf:* types typeValid = true; } else if (isBuiltInSchemaType || isBuiltInXFormsType) { // Built-in schema or XForms type // Use XML Schema namespace URI as Saxon doesn't know anything about XForms types final String newTypeNamespaceURI = XMLConstants.XSD_URI; // Get type information final int requiredTypeFingerprint = StandardNames.getFingerprint(newTypeNamespaceURI, typeLocalname); if (requiredTypeFingerprint == -1) { throw new ValidationException("Invalid schema type '" + bind.staticBind.dataTypeOrNull() + "'", bind.staticBind.locationData()); // TODO: xxx check what XForms event must be dispatched } // Need an evaluator to check and convert type below final XPathEvaluator xpathEvaluator; try { xpathEvaluator = new XPathEvaluator(); // NOTE: Not sure declaring namespaces here is necessary just to perform the cast final IndependentContext context = (IndependentContext) xpathEvaluator.getStaticContext(); for (final Map.Entry<String, String> entry : bind.staticBind.namespaceMapping().mapping .entrySet()) { context.declareNamespace(entry.getKey(), entry.getValue()); } } catch (Exception e) { throw OrbeonLocationException.wrapException(e, bind.staticBind.locationData()); // TODO: xxx check what XForms event must be dispatched } // Try to perform casting // TODO: Should we actually perform casting? This for example removes leading and trailing space around tokens. Is that expected? final StringValue stringValue = new StringValue(nodeValue); final XPathContext xpContext = new XPathContextMajor(stringValue, xpathEvaluator.getExecutable()); final ConversionResult result = stringValue.convertPrimitive( (BuiltInAtomicType) BuiltInType.getSchemaType(requiredTypeFingerprint), true, xpContext); // Set error on node if necessary typeValid = !(result instanceof ValidationFailure); } else if (isBuiltInXXFormsType) { // Built-in extension types final boolean isOptionalAndEmpty = !required && "".equals(nodeValue); if (typeLocalname.equals("xml")) { // xxf:xml type typeValid = isOptionalAndEmpty || XMLUtils.isWellFormedXML(nodeValue); } else if (typeLocalname.equals("xpath2")) { // xxf:xpath2 type // Find element which scopes namespaces final NodeInfo namespaceNodeInfo; if (currentNodeInfo.getNodeKind() == Node.ELEMENT_NODE) namespaceNodeInfo = currentNodeInfo; else namespaceNodeInfo = currentNodeInfo.getParent(); if (namespaceNodeInfo != null && namespaceNodeInfo.getNodeKind() == Node.ELEMENT_NODE) { // ASSUMPTION: Binding to dom4j-backed node (which InstanceData assumes too) final Element namespaceElement = XML.unwrapElement(namespaceNodeInfo); final NamespaceMapping namespaceMapping = new NamespaceMapping( Dom4jUtils.getNamespaceContextNoDefault(namespaceElement)); typeValid = isOptionalAndEmpty || XPath.isXPath2Expression(nodeValue, namespaceMapping, bind.staticBind.locationData(), indentedLogger); } else { // This means that we are bound to a node which is not an element and which does not have a // parent element. This could be a detached attribute, or an element node, etc. Unsure if we // would have made it this far anyway! We can't validate the expression so we only consider // the "optional-and-empty" case. typeValid = isOptionalAndEmpty; } } else { throw new ValidationException("Invalid schema type '" + bind.staticBind.dataTypeOrNull() + "'", bind.staticBind.locationData()); // TODO: xxx check what XForms event must be dispatched } } else if (model.hasSchema()) { // Other type and there is a schema // There are possibly types defined in the schema final String validationError = model.getSchemaValidator().validateDatatype(nodeValue, typeNamespaceURI, typeLocalname, typeQName.getQualifiedName(), bind.staticBind.locationData()); typeValid = validationError == null; } else { throw new ValidationException("Invalid schema type '" + bind.staticBind.dataTypeOrNull() + "'", bind.staticBind.locationData()); // TODO: xxx check what XForms event must be dispatched } } return typeValid; }