List of usage examples for org.dom4j QName getName
public String getName()
From source file:org.orbeon.oxf.xforms.control.XFormsSingleNodeControl.java
License:Open Source License
/** * Convenience method to return the local name of a built-in XML Schema or XForms type. * * @return the local name of the built-in type, or null if not found *//*ww w . j a v a2 s . c o m*/ public String getBuiltinTypeName() { final QName type = getType(); if (type != null) { final boolean isBuiltInSchemaType = type.getNamespaceURI().equals(XMLConstants.XSD_URI); final boolean isBuiltInXFormsType = type.getNamespaceURI().equals(XFormsConstants.XFORMS_NAMESPACE_URI); if (isBuiltInSchemaType || isBuiltInXFormsType) { return type.getName(); } else { return null; } } else { return null; } }
From source file:org.orbeon.oxf.xforms.control.XFormsSingleNodeControl.java
License:Open Source License
/** * Convenience method to return the local name of the XML Schema type. * * @return the local name of the type, or null if not found *///from ww w. j ava 2s .c o m public String getTypeLocalName() { final QName type = getType(); if (type != null) { return type.getName(); } else { return null; } }
From source file:org.orbeon.oxf.xforms.function.Property.java
License:Open Source License
@Override public Item evaluateItem(XPathContext xpathContext) throws XPathException { final String propertyNameString = argument[0].evaluateAsString(xpathContext).toString(); final QName propertyNameQName = Dom4jUtils.extractTextValueQName(namespaceMappings, propertyNameString, false);/*from w w w .j a va 2s .com*/ // Never return any property containing the string "password" as a first line of defense if (propertyNameString.toLowerCase().contains("password")) { return null; } if (VERSION_PROPERTY.equals(propertyNameString)) { // Standard "version" property return VERSION; } else if (CONFORMANCE_LEVEL_PROPERTY.equals(propertyNameString)) { // Standard "conformance-level" property return CONFORMANCE_LEVEL; } else if (XFormsConstants.XXFORMS_NAMESPACE_URI.equals(propertyNameQName.getNamespaceURI())) { // Property in the xxforms namespace: return our properties // Retrieve property final Object value = XFormsProperties.getProperty(getContainingDocument(xpathContext), propertyNameQName.getName()); if (value == null) return null; // Convert Java object to Saxon object before returning it return (Item) XFormsUtils.convertJavaObjectToSaxonObject(value); } else { throw new XPathException("Invalid property() function parameter: " + propertyNameString); } }
From source file:org.orbeon.oxf.xforms.function.xxforms.XXFormsType.java
License:Open Source License
@Override public Item evaluateItem(XPathContext xpathContext) throws XPathException { final Expression nodesetExpression = argument[0]; // "If the argument is omitted, it defaults to a node-set with the context node as its only // member."//from w w w. jav a2 s .c om final Item item; if (nodesetExpression == null) item = xpathContext.getContextItem(); else item = nodesetExpression.iterate(xpathContext).next(); if (item instanceof AtomicValue) { // Atomic type final ItemType type = ((Value) item).getItemType(null); if (type instanceof BuiltInAtomicType) { final BuiltInAtomicType atomicType = (BuiltInAtomicType) type; final int fingerprint = atomicType.getFingerprint(); return new QNameValue(StandardNames.getPrefix(fingerprint), StandardNames.getURI(fingerprint), StandardNames.getLocalName(fingerprint), null); } else { return null; } } else if (item instanceof NodeInfo) { // Get type from node final QName typeQName = InstanceData.getType((NodeInfo) item); if (typeQName == null) return null; // Create Saxon QName return new QNameValue("", typeQName.getNamespaceURI(), typeQName.getName(), null); } else { // Return () if we can't access the node or if it is not an atomic value or a node return null; } }
From source file:org.orbeon.oxf.xforms.itemset.Itemset.java
License:Open Source License
public static String getAttributeName(QName key) { final String attributeName; if (key.getNamespace().equals(Namespace.NO_NAMESPACE)) { attributeName = key.getName(); } else if (key.getNamespace().equals(XFormsConstants.XXFORMS_NAMESPACE)) { attributeName = "xxforms-" + key.getName(); } else {//from www . j a v a 2s . c o m // Other namespaces are not allowed in the first place throw new IllegalStateException("Invalid attribute on item: " + key.getName()); } return attributeName; }
From source file:org.orbeon.oxf.xforms.processor.handlers.xhtml.XFormsBaseHandlerXHTML.java
License:Open Source License
protected static void appendAppearances(ElementAnalysis elementAnalysis, StringBuilder sb) { for (final QName appearance : XFormsControl.appearances(elementAnalysis)) { if (sb.length() > 0) sb.append(' '); sb.append("xforms-"); sb.append(elementAnalysis.element().getName()); sb.append("-appearance-"); // Allow xxforms:* and * if (XFormsConstants.XXFORMS_NAMESPACE_URI.equals(appearance.getNamespace().getURI())) sb.append("xxforms-"); else if (!"".equals(appearance.getNamespace().getURI())) throw new ValidationException( "Invalid appearance namespace URI: " + appearance.getNamespace().getURI(), elementAnalysis.locationData()); sb.append(appearance.getName()); }/* ww w .ja v a2 s. c om*/ }
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 . j a 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.processor.handlers.xhtml.XHTMLBodyHandler.java
License:Open Source License
public static void registerHandlers(final ElementHandlerController controller, final XFormsContainingDocument containingDocument) { // xf:input// ww w. j a v a2 s . c o m controller.registerHandler(XFormsInputHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "input", ANY_MATCHER); // xf:output controller.registerHandler(XFormsOutputTextHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "output", new AppearanceMatcher(XFormsConstants.XXFORMS_TEXT_APPEARANCE_QNAME)); controller.registerHandler(XFormsOutputDownloadHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "output", new AppearanceMatcher(XFormsConstants.XXFORMS_DOWNLOAD_APPEARANCE_QNAME)); controller.registerHandler(XFormsOutputImageHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "output", new Matcher() { public Object match(Attributes attributes, Object handlerContext) { final ElementAnalysis elementAnalysis = getElementAnalysis(attributes, handlerContext); // TODO: aks ElementAnalysis for its mediatype final String mediatypeValue = attributes.getValue("mediatype"); return mediatypeValue != null && mediatypeValue.startsWith("image/") ? elementAnalysis : null; } }); controller.registerHandler(XFormsOutputHTMLHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "output", new Matcher() { public Object match(Attributes attributes, Object handlerContext) { final ElementAnalysis elementAnalysis = getElementAnalysis(attributes, handlerContext); // TODO: aks ElementAnalysis for its mediatype final String mediatypeValue = attributes.getValue("mediatype"); return mediatypeValue != null && mediatypeValue.equals("text/html") ? elementAnalysis : null; } }); controller.registerHandler(XFormsOutputDefaultHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "output", ANY_MATCHER); // xf:trigger final Matcher triggerSubmitMinimalMatcher = new Matcher() { public ElementAnalysis match(Attributes attributes, Object handlerContext) { final ElementAnalysis elementAnalysis = getElementAnalysis(attributes, handlerContext); return elementAnalysis != null && !containingDocument.getStaticState().isNoscript() // in noscript mode, use the full appearance && hasAppearance(elementAnalysis, XFormsConstants.XFORMS_MINIMAL_APPEARANCE_QNAME) // minimal appearance ? elementAnalysis : null; } }; controller.registerHandler(XFormsTriggerMinimalHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "trigger", triggerSubmitMinimalMatcher); controller.registerHandler(XFormsTriggerFullHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "trigger", ANY_MATCHER); // xf:submit controller.registerHandler(XFormsTriggerMinimalHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "submit", triggerSubmitMinimalMatcher); controller.registerHandler(XFormsTriggerFullHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "submit", ANY_MATCHER); // xf:group controller.registerHandler(XFormsGroupInternalHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "group", new AppearanceMatcher(XFormsConstants.XXFORMS_INTERNAL_APPEARANCE_QNAME)); controller.registerHandler(XFormsGroupFieldsetHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "group", new AppearanceMatcher(XFormsConstants.XXFORMS_FIELDSET_APPEARANCE_QNAME)); controller.registerHandler(XFormsGroupSeparatorHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "group", new Matcher() { public Object match(Attributes attributes, Object handlerContext) { final ElementAnalysis elementAnalysis = getElementAnalysis(attributes, handlerContext); // XFormsAnnotatorContentHandler adds this appearance if needed // See: https://github.com/orbeon/orbeon-forms/issues/418 final String appearanceAttributeValue = attributes .getValue(XFormsConstants.APPEARANCE_QNAME.getName()); return XFormsConstants.XXFORMS_SEPARATOR_APPEARANCE_QNAME.getQualifiedName() .equals(appearanceAttributeValue) ? elementAnalysis : null; } }); controller.registerHandler(XFormsGroupDefaultHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "group", ANY_MATCHER); // xf:switch // NOTE: We use the same handlers for switch as we do for group controller.registerHandler(XFormsGroupSeparatorHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "switch", new Matcher() { public Object match(Attributes attributes, Object handlerContext) { final ElementAnalysis elementAnalysis = getElementAnalysis(attributes, handlerContext); // XFormsAnnotatorContentHandler adds this appearance if needed // See: https://github.com/orbeon/orbeon-forms/issues/418 final String appearanceAttributeValue = attributes .getValue(XFormsConstants.APPEARANCE_QNAME.getName()); return XFormsConstants.XXFORMS_SEPARATOR_APPEARANCE_QNAME.getQualifiedName() .equals(appearanceAttributeValue) ? elementAnalysis : null; } }); controller.registerHandler(XFormsGroupDefaultHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "switch", ANY_MATCHER); controller.registerHandler(XFormsCaseHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "case", ANY_MATCHER); // xf:repeat controller.registerHandler(XFormsRepeatHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "repeat", ANY_MATCHER); controller.registerHandler(NullElementHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "repeat-iteration", ANY_MATCHER); // xf:secret controller.registerHandler(XFormsSecretHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "secret", ANY_MATCHER); // xf:upload controller.registerHandler(XFormsUploadHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "upload", ANY_MATCHER); // xf:range controller.registerHandler(XFormsRangeHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "range", ANY_MATCHER); // Other controls controller.registerHandler(XFormsTextareaHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "textarea", ANY_MATCHER); if (!containingDocument.getStaticState().isNoscript()) controller.registerHandler(XXFormsDialogHandler.class.getName(), XFormsConstants.XXFORMS_NAMESPACE_URI, "dialog", ANY_MATCHER); else controller.registerHandler(NullHandler.class.getName(), XFormsConstants.XXFORMS_NAMESPACE_URI, "dialog", ANY_MATCHER); // xf:select and xf:select1 controller.registerHandler(XFormsSelect1InternalHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "select", new AppearanceMatcher(XFormsConstants.XXFORMS_INTERNAL_APPEARANCE_QNAME)); controller.registerHandler(XFormsSelect1InternalHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "select1", new AppearanceMatcher(XFormsConstants.XXFORMS_INTERNAL_APPEARANCE_QNAME)); controller.registerHandler(XFormsSelectHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "select", ANY_MATCHER); controller.registerHandler(XFormsSelect1Handler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "select1", ANY_MATCHER); // Add handlers for LHHA elements controller.registerHandler(XFormsLHHAHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "label", ANY_MATCHER); controller.registerHandler(XFormsLHHAHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "help", ANY_MATCHER); controller.registerHandler(XFormsLHHAHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "hint", ANY_MATCHER); controller.registerHandler(XFormsLHHAHandler.class.getName(), XFormsConstants.XFORMS_NAMESPACE_URI, "alert", ANY_MATCHER); // Add handlers for custom components final Seq<QName> componentBindings = containingDocument.getStaticOps().jBindingQNames(); for (final scala.collection.Iterator<QName> i = componentBindings.iterator(); i.hasNext();) { final QName currentQName = i.next(); controller.registerHandler(XXFormsComponentHandler.class.getName(), currentQName.getNamespaceURI(), currentQName.getName(), ANY_MATCHER); } // xxf:dynamic controller.registerHandler(XXFormsDynamicHandler.class.getName(), XFormsConstants.XXFORMS_NAMESPACE_URI, "dynamic", ANY_MATCHER); }
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// w ww . j a v a2 s. c o 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.xforms.XFormsModelBinds.java
License:Open Source License
private boolean validateType(RuntimeBind bind, NodeInfo currentNodeInfo, boolean required) { final boolean typeValid; {// w w w. j av a2 s . c om // 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; }