void lookupPrefix(org.w3c.dom.Node node) { if (node == null) throw new IllegalArgumentException("node must not be null"); String prefix = node.lookupPrefix(namespace.getUri()); if (prefix == null) { // check to see if we match the default namespace String defaultNamespace = node.lookupNamespaceURI(null); if (defaultNamespace == null) defaultNamespace = ""; String nodeNamespace = namespace.getUri(); if (nodeNamespace.equals(defaultNamespace)) { prefix = ""; } } int i = 0; while (prefix == null) { String generatedPrefix = "e4x_" + i++; String generatedUri = node.lookupNamespaceURI(generatedPrefix); if (generatedUri == null) { prefix = generatedPrefix; org.w3c.dom.Node top = node; while (top.getParentNode() != null && top.getParentNode() instanceof org.w3c.dom.Element) { top = top.getParentNode(); } ((org.w3c.dom.Element) top) .setAttributeNS( "http://www.w3.org/2000/xmlns/", "xmlns:" + prefix, namespace.getUri()); } } namespace.setPrefix(prefix); }
/** * {@inheritDoc} * * @see * org.jboss.as.controller.Extension#initializeParsers(org.jboss.as.controller.parsing.ExtensionParsingContext) */ @Override public void initializeParsers(ExtensionParsingContext context) { for (Namespace namespace : Namespace.values()) { if (namespace != Namespace.UNKNOWN) { context.setSubsystemXmlMapping(SUBSYSTEM_NAME, namespace.getUri(), namespace.getReader()); } } }
/** {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj instanceof Namespace) { Namespace other = (Namespace) obj; return uri.equals(other.getUri()); } return super.equals(obj); }
/** * {@inheritDoc} * * @see * org.jboss.as.controller.Extension#initializeParsers(org.jboss.as.controller.parsing.ExtensionParsingContext) */ @Override public void initializeParsers(ExtensionParsingContext context) { for (Namespace namespace : Namespace.values()) { XMLElementReader<List<ModelNode>> reader = namespace.getXMLReader(); if (reader != null) { context.setSubsystemXmlMapping(SUBSYSTEM_NAME, namespace.getUri(), reader); } } }
/** property url should be src attribute with url as value */ @Override public void transform(WidgetTransformerContext context, Property property) throws CoreException { String domainAttributValue = property .getWidget() .getPropertyValue(PropertyTypeConstants.DOMAIN_ATTRIBUTE_WITHOUT_VALIDATOR); if (domainAttributValue != null && domainAttributValue.length() > 0) { Property beanNameProperty = BeanPropertyUtils.findBeanNameProperty(context, property.getWidget()); String beanNamePropertyValue = beanNameProperty.getValue(); // Create the element <xsp:attribute name="src">...</xsp:attribute> Namespace ns = context.getTransformModel().findNamespace(XSP_NAMESPACE_URI); Element valElmt = context .getDocument() .createElementNS(ns.getUri(), TransformerConstants.ATTRIBUTE_ELEMENT_NAME); valElmt.setPrefix(ns.getPrefix()); TransformUtils.appendChild(context, valElmt); // Create the attribute name="src" Attr a = context.getDocument().createAttribute(TransformerConstants.NAME_ATTRIBUTE_NAME); a.setValue("src"); valElmt.setAttributeNode(a); // create the <bean:get-property bean="..." property="..."/> Namespace beanNamespace = context.getTransformModel().findNamespace(BEAN_URI); Element defElmt = context.getDocument().createElementNS(beanNamespace.getUri(), BEAN_GET_PROPERTY_ELEMENT); defElmt.setPrefix(beanNamespace.getPrefix()); addAttribute(context, defElmt, BEAN_BEAN_ATTRIBUTE, beanNamePropertyValue); addAttribute(context, defElmt, BEAN_PROPERTY_ATTRIBUTE, domainAttributValue); valElmt.appendChild(defElmt); } else { String url = property.getValue(); if (url != null && url.length() != 0) { addAttribute(context, "src", url); } } }
String qualify(org.w3c.dom.Node node) { if (namespace.getPrefix() == null) { if (node != null) { lookupPrefix(node); } else { if (namespace.getUri().equals("")) { namespace.setPrefix(""); } else { // TODO I am not sure this is right, but if we are creating a standalone node, I // think we can set the // default namespace on the node itself and not worry about setting a prefix // for that namespace. namespace.setPrefix(""); } } } return qualify(namespace.getPrefix(), localName); }
/** {@inheritDoc} */ public int compareTo(final Namespace other) { return Infra.compare(getUri(), other.getUri()); }
/** @deprecated Use getNamespace() */ String getUri() { return namespace.getUri(); }
void setAttribute(org.w3c.dom.Element element, String value) { if (namespace.getPrefix() == null) lookupPrefix(element); element.setAttributeNS(namespace.getUri(), qualify(namespace.getPrefix(), localName), value); }
private boolean namespacesEqual(Namespace one, Namespace two) { if (one == null && two == null) return true; if (one == null || two == null) return false; return equals(one.getUri(), two.getUri()); }
private String getExistingPrefixFor(Namespace namespace) { if (getDefaultNamespace().getUri().equals(namespace.getUri())) { return ""; } return dom.lookupPrefix(namespace.getUri()); }