Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 /**
  * {@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());
     }
   }
 }
Exemplo n.º 3
0
 /** {@inheritDoc} */
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof Namespace) {
     Namespace other = (Namespace) obj;
     return uri.equals(other.getUri());
   }
   return super.equals(obj);
 }
Exemplo n.º 4
0
 /**
  * {@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);
     }
   }
 }
Exemplo n.º 5
0
  /** 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);
      }
    }
  }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
 /** {@inheritDoc} */
 public int compareTo(final Namespace other) {
   return Infra.compare(getUri(), other.getUri());
 }
Exemplo n.º 8
0
 /** @deprecated Use getNamespace() */
 String getUri() {
   return namespace.getUri();
 }
Exemplo n.º 9
0
 void setAttribute(org.w3c.dom.Element element, String value) {
   if (namespace.getPrefix() == null) lookupPrefix(element);
   element.setAttributeNS(namespace.getUri(), qualify(namespace.getPrefix(), localName), value);
 }
Exemplo n.º 10
0
 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());
 }
Exemplo n.º 11
0
 private String getExistingPrefixFor(Namespace namespace) {
   if (getDefaultNamespace().getUri().equals(namespace.getUri())) {
     return "";
   }
   return dom.lookupPrefix(namespace.getUri());
 }