Example usage for org.w3c.dom Element getNamespaceURI

List of usage examples for org.w3c.dom Element getNamespaceURI

Introduction

In this page you can find the example usage for org.w3c.dom Element getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:org.alfresco.web.forms.xforms.Schema2XForms.java

/**
 * method to set an Id to this element and to all XForms descendants of this element
 *//*from  w w  w  .  j  a  v a  2 s .  co m*/
private void resetXFormIds(final Element newControl) {
    if (newControl.getNamespaceURI() != null
            && newControl.getNamespaceURI().equals(NamespaceConstants.XFORMS_NS)) {
        this.setXFormsId(newControl);
    }

    //recursive call
    final NodeList children = newControl.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        final Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            this.resetXFormIds((Element) child);
        }
    }
}

From source file:org.alfresco.web.forms.XSLTRenderingEngine.java

/**
 * Adds the specified parameters to the xsl template as variables within the 
 * alfresco namespace.//ww w .ja v a  2 s. c o m
 *
 * @param model the variables to place within the xsl template
 * @param xslTemplate the xsl template
 */
protected void addParameters(final Map<QName, Object> model, final Document xslTemplate) {
    final Element docEl = xslTemplate.getDocumentElement();
    final String XSL_NS = docEl.getNamespaceURI();
    final String XSL_NS_PREFIX = docEl.getPrefix();

    for (Map.Entry<QName, Object> e : model.entrySet()) {
        if (RenderingEngine.ROOT_NAMESPACE.equals(e.getKey())) {
            continue;
        }
        final Element el = xslTemplate.createElementNS(XSL_NS, XSL_NS_PREFIX + ":variable");
        el.setAttribute("name", e.getKey().toPrefixString());
        final Object o = e.getValue();
        if (o instanceof String || o instanceof Number || o instanceof Boolean) {
            el.appendChild(xslTemplate.createTextNode(o.toString()));
            docEl.insertBefore(el, docEl.getFirstChild());
        }
    }
}

From source file:org.apache.axis.AxisFault.java

/**
 * turn the fault and details into a string, with XML escaping.
 * subclassers: for security (cross-site-scripting) reasons,
 * escape everything that could contain caller-supplied data.
 * @return stringified fault details//  ww  w .  j av  a2 s .  c om
 */
public String dumpToString() {
    StringBuffer buf = new StringBuffer("AxisFault");
    buf.append(JavaUtils.LS);
    buf.append(" faultCode: ");
    buf.append(XMLUtils.xmlEncodeString(faultCode.toString()));
    buf.append(JavaUtils.LS);
    buf.append(" faultSubcode: ");
    if (faultSubCode != null) {
        for (int i = 0; i < faultSubCode.size(); i++) {
            buf.append(JavaUtils.LS);
            buf.append(faultSubCode.elementAt(i).toString());
        }
    }
    buf.append(JavaUtils.LS);
    buf.append(" faultString: ");
    try {
        buf.append(XMLUtils.xmlEncodeString(faultString));
    } catch (RuntimeException re) {
        buf.append(re.getMessage());
    }
    buf.append(JavaUtils.LS);
    buf.append(" faultActor: ");
    buf.append(XMLUtils.xmlEncodeString(faultActor));
    buf.append(JavaUtils.LS);
    buf.append(" faultNode: ");
    buf.append(XMLUtils.xmlEncodeString(faultNode));
    buf.append(JavaUtils.LS);
    buf.append(" faultDetail: ");
    if (faultDetails != null) {
        for (int i = 0; i < faultDetails.size(); i++) {
            Element e = (Element) faultDetails.get(i);
            buf.append(JavaUtils.LS);
            buf.append("\t{");
            buf.append(null == e.getNamespaceURI() ? "" : e.getNamespaceURI());
            buf.append("}");
            buf.append(null == e.getLocalName() ? "" : e.getLocalName());
            buf.append(":");
            buf.append(XMLUtils.getInnerXMLString(e));
        }
    }
    buf.append(JavaUtils.LS);
    return buf.toString();
}

From source file:org.apache.axis.AxisFault.java

/**
 * Find a fault detail element by its qname.
 * @param qname name of the node to look for
 * @return the matching element or null//from  w w w  .  ja  v a 2  s . com
 * @since axis1.1
 */
public Element lookupFaultDetail(QName qname) {
    if (faultDetails != null) {
        //extract details from the qname. the empty namespace is represented
        //by the empty string
        String searchNamespace = qname.getNamespaceURI();
        String searchLocalpart = qname.getLocalPart();
        //now spin through the elements, seeking a match
        Iterator it = faultDetails.iterator();
        while (it.hasNext()) {
            Element e = (Element) it.next();
            String localpart = e.getLocalName();
            if (localpart == null) {
                localpart = e.getNodeName();
            }
            String namespace = e.getNamespaceURI();
            if (namespace == null) {
                namespace = "";
            }
            //we match on matching namespace and local part; empty namespace
            //in an element may be null, which matches QName's ""
            if (searchNamespace.equals(namespace) && searchLocalpart.equals(localpart)) {
                return e;
            }
        }
    }
    return null;
}

From source file:org.apache.axis.encoding.SerializationContext.java

/**
 * Output a DOM representation to a SerializationContext
 * @param el is a DOM Element//from  ww  w . j a  v a  2  s.c  o m
 */
public void writeDOMElement(Element el) throws IOException {
    if (startOfDocument && sendXMLDecl) {
        writeXMLDeclaration();
    }

    // If el is a Text element, write the text and exit
    if (el instanceof org.apache.axis.message.Text) {
        writeSafeString(((Text) el).getData());
        return;
    }

    AttributesImpl attributes = null;
    NamedNodeMap attrMap = el.getAttributes();

    if (attrMap.getLength() > 0) {
        attributes = new AttributesImpl();
        for (int i = 0; i < attrMap.getLength(); i++) {
            Attr attr = (Attr) attrMap.item(i);
            String tmp = attr.getNamespaceURI();
            if (tmp != null && tmp.equals(Constants.NS_URI_XMLNS)) {
                String prefix = attr.getLocalName();
                if (prefix != null) {
                    if (prefix.equals("xmlns"))
                        prefix = "";
                    String nsURI = attr.getValue();
                    registerPrefixForURI(prefix, nsURI);
                }
                continue;
            }

            attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA",
                    attr.getValue());
        }
    }

    String namespaceURI = el.getNamespaceURI();
    String localPart = el.getLocalName();
    if (namespaceURI == null || namespaceURI.length() == 0)
        localPart = el.getNodeName();
    QName qName = new QName(namespaceURI, localPart);

    startElement(qName, attributes);

    NodeList children = el.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            writeDOMElement((Element) child);
        } else if (child instanceof CDATASection) {
            writeString("<![CDATA[");
            writeString(((Text) child).getData());
            writeString("]]>");
        } else if (child instanceof Comment) {
            writeString("<!--");
            writeString(((CharacterData) child).getData());
            writeString("-->");
        } else if (child instanceof Text) {
            writeSafeString(((Text) child).getData());
        }
    }

    endElement();
}

From source file:org.apache.axis.encoding.SerializationContextImpl.java

/**
 * Output a DOM representation to a SerializationContext
 * @param el is a DOM Element// w  w  w  . j  a  v  a2s . c  o m
 */
public void writeDOMElement(Element el)
    throws IOException
{
    AttributesImpl attributes = null;
    NamedNodeMap attrMap = el.getAttributes();

    if (attrMap.getLength() > 0) {
        attributes = new AttributesImpl();
        for (int i = 0; i < attrMap.getLength(); i++) {
            Attr attr = (Attr)attrMap.item(i);
            String tmp = attr.getNamespaceURI();
            if ( tmp != null && tmp.equals(Constants.NS_URI_XMLNS) ) {
                String prefix = attr.getLocalName();
                if (prefix != null) {
                    if (prefix.equals("xmlns"))
                        prefix = "";
                    String nsURI = attr.getValue();
                    registerPrefixForURI(prefix, nsURI);
                }
                continue;
            }

            attributes.addAttribute(attr.getNamespaceURI(),
                                    attr.getLocalName(),
                                    attr.getName(),
                                    "CDATA", attr.getValue());
        }
    }

    String namespaceURI = el.getNamespaceURI();
    String localPart = el.getLocalName();
    if(namespaceURI == null || namespaceURI.length()==0)
        localPart = el.getNodeName();
    QName qName = new QName(namespaceURI, localPart);

    startElement(qName, attributes);

    NodeList children = el.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            writeDOMElement((Element)child);
        } else if (child instanceof CDATASection) {
            writeString("<![CDATA[");
            writeString(((Text)child).getData());
            writeString("]]>");
        } else if (child instanceof Comment) {
            writeString("<!--");
            writeString(((CharacterData)child).getData());
            writeString("-->");
        } else if (child instanceof Text) {
            writeSafeString(((Text)child).getData());
        }
    }

    endElement();
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * create a node through a deep copy of the passed in element.
 * @param elem name to copy from/*  w w  w  .ja va 2s . c o m*/
 */
public MessageElement(Element elem) {
    namespaceURI = elem.getNamespaceURI();
    name = elem.getLocalName();
    copyNode(elem);
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * helper method for recusively getting the element that has namespace URI and localname
 * @param parentElement parent element/*  ww  w .j  a  va  2  s  .c  o m*/
 * @param namespace namespace
 * @param localName local name of element
 * @return (potentially empty) list of elements that match the (namespace,localname) tuple
 */
protected NodeList getElementsNS(org.w3c.dom.Element parentElement, String namespace, String localName) {
    NodeList children = parentElement.getChildNodes();
    NodeListImpl matches = new NodeListImpl();

    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i) instanceof Text) {
            continue;
        }
        Element child = (Element) children.item(i);
        if (namespace.equals(child.getNamespaceURI()) && localName.equals(child.getLocalName())) {
            matches.addNode(child);
        }
        // search the grand-children.
        matches.addNodeList(child.getElementsByTagNameNS(namespace, localName));
    }
    return matches;
}

From source file:org.apache.axis.utils.Admin.java

/**
 * The meat of the Admin service.  Process an xML document rooted with
 * a "deploy", "undeploy", "list", or "quit" element.
 *
 * @param msgContext the MessageContext we're processing
 * @param root the root Element of the XML
 * @return an XML Document indicating the results.
 *///from   w ww  .j  a v a  2  s .  com
public Document process(MessageContext msgContext, Element root) throws Exception {
    // Check security FIRST.

    /** Might do something like this once security is a little more
     * integrated.
    if (!engine.hasSafePassword() &&
    !action.equals("passwd"))
    throw new AxisFault("Server.MustSetPassword",
      "You must change the admin password before administering Axis!",
                         null, null);
     */

    verifyHostAllowed(msgContext);

    String rootNS = root.getNamespaceURI();
    AxisEngine engine = msgContext.getAxisEngine();

    // If this is WSDD, process it correctly.
    if (rootNS != null && rootNS.equals(WSDDConstants.URI_WSDD)) {
        return processWSDD(msgContext, engine, root);
    }

    // Else fault
    // TODO: Better handling here
    throw new Exception(Messages.getMessage("adminServiceNoWSDD"));
}

From source file:org.apache.axis.wsdl.fromJava.Types.java

/**
 * Loads the types from the input schema file.
 *
 * @param inputSchema file or URL//w w  w  .j a  v  a2s  . co  m
 * @throws IOException
 * @throws WSDLException
 * @throws SAXException
 * @throws ParserConfigurationException
 */
public void loadInputSchema(String inputSchema)
        throws IOException, WSDLException, SAXException, ParserConfigurationException {

    // Read the input wsdl file into a Document
    Document doc = XMLUtils.newDocument(inputSchema);

    // Ensure that the root element is xsd:schema
    Element root = doc.getDocumentElement();

    if (root.getLocalName().equals("schema") && Constants.isSchemaXSD(root.getNamespaceURI())) {
        Node schema = docHolder.importNode(root, true);

        if (null == wsdlTypesElem) {
            writeWsdlTypesElement();
        }

        wsdlTypesElem.appendChild(schema);

        // Create a symbol table and populate it with the input types
        BaseTypeMapping btm = new BaseTypeMapping() {

            public String getBaseName(QName qNameIn) {

                QName qName = new QName(qNameIn.getNamespaceURI(), qNameIn.getLocalPart());
                Class cls = defaultTM.getClassForQName(qName);

                if (cls == null) {
                    return null;
                } else {
                    return JavaUtils.getTextClassName(cls.getName());
                }
            }
        };
        SymbolTable symbolTable = new SymbolTable(btm, true, false, false);

        symbolTable.populateTypes(new URL(inputSchema), doc);
        processSymTabEntries(symbolTable);
    } else {

        // If not, we'll just bail out... perhaps we should log a warning
        // or throw an exception?
        ;
    }
}