Example usage for org.dom4j Namespace getURI

List of usage examples for org.dom4j Namespace getURI

Introduction

In this page you can find the example usage for org.dom4j Namespace getURI.

Prototype

public String getURI() 

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.FaultExtractor.java

License:Open Source License

FaultExtractor(String expr, Namespace ns) {
    this.expr = expr;
    this.ns = ns;
    namespaceContext = new SimpleNamespaceContext();
    namespaceContext.addNamespace(ns.getPrefix(), ns.getURI());
}

From source file:com.webslingerz.jpt.PageTemplateImpl.java

License:Open Source License

private void processElement(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler,
        Interpreter beanShell, Stack<Map<String, Slot>> slotStack)
        throws SAXException, PageTemplateException, IOException {
    // Get attributes
    Expressions expressions = new Expressions();
    AttributesImpl attributes = getAttributes(element, expressions);

    // Skip macro definitions
    if (expressions.macro) {
        return;/*  w w w.j  a  v a  2s .c o  m*/
    }

    // Process instructions
    // 1. define
    if (expressions.define != null) {
        processDefine(expressions.define, beanShell);
    }

    // 2. condition
    if (expressions.condition != null && !Expression.evaluateBoolean(expressions.condition, beanShell)) {
        // Skip this element (and children)
        return;
    }

    // 3. repeat
    Loop loop = new Loop(expressions.repeat, beanShell);
    while (loop.repeat(beanShell)) {
        // expand macro
        if (expressions.useMacro != null) {
            processMacro(expressions.useMacro, element, contentHandler, lexicalHandler, beanShell, slotStack);
            continue;
        }

        // 4. content or replace
        Object jptContent = null;
        if (expressions.content != null) {
            jptContent = processContent(expressions.content, beanShell);
        } else
        // fill slots
        if (expressions.defineSlot != null) {
            // System.err.println( "fill slot: " + expressions.defineSlot );
            if (!slotStack.isEmpty()) {
                Map<String, Slot> slots = slotStack.pop();
                Slot slot = slots.get(expressions.defineSlot);
                // System.err.println( "slot: " + slot );
                if (slot != null) {
                    slot.process(contentHandler, lexicalHandler, beanShell, slotStack);
                    slotStack.push(slots);
                    return;
                }
                // else { use content in macro }
                slotStack.push(slots);
            } else {
                throw new PageTemplateException("slot definition not allowed outside of macro");
            }
        }

        // 5. attributes
        if (expressions.attributes != null) {
            processAttributes(attributes, expressions.attributes, beanShell);
        }

        // 6. omit-tag
        boolean jptOmitTag = false;
        if (expressions.omitTag != null) {
            if (expressions.omitTag.equals("")) {
                jptOmitTag = true;
            } else {
                jptOmitTag = Expression.evaluateBoolean(expressions.omitTag, beanShell);
            }
        }

        // Output

        // Declare element
        Namespace namespace = element.getNamespace();
        if (!jptOmitTag) {
            for (int i = 0; i < attributes.getLength(); i++) {
                String processedValue = Expression.evaluateText(attributes.getValue(i), beanShell);
                attributes.setValue(i, processedValue);
            }
            contentHandler.startElement(namespace.getURI(), element.getName(), element.getQualifiedName(),
                    attributes);
        }

        // Process content
        if (jptContent != null) {
            // Content for this element has been generated dynamically
            if (jptContent instanceof HTMLFragment) {
                HTMLFragment html = (HTMLFragment) jptContent;
                html.toXhtml(contentHandler, lexicalHandler);
            }

            // plain text
            else {
                char[] text = ((String) jptContent).toCharArray();
                contentHandler.characters(text, 0, text.length);
            }
        } else {
            defaultContent(element, contentHandler, lexicalHandler, beanShell, slotStack);
        }

        // End element
        if (!jptOmitTag) {
            contentHandler.endElement(namespace.getURI(), element.getName(), element.getQualifiedName());
        }
    }
}

From source file:com.webslingerz.jpt.PageTemplateImpl.java

License:Open Source License

private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler,
        Interpreter beanShell, Stack<Map<String, Slot>> slotStack)
        throws SAXException, PageTemplateException, IOException {
    // Use default template content
    for (Iterator i = element.nodeIterator(); i.hasNext();) {
        Node node = (Node) i.next();
        switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            processElement((Element) node, contentHandler, lexicalHandler, beanShell, slotStack);
            break;

        case Node.TEXT_NODE:
            char[] text = Expression.evaluateText(node.getText().toString(), beanShell).toCharArray();
            contentHandler.characters(text, 0, text.length);
            break;

        case Node.COMMENT_NODE:
            char[] comment = node.getText().toCharArray();
            lexicalHandler.comment(comment, 0, comment.length);
            break;

        case Node.CDATA_SECTION_NODE:
            lexicalHandler.startCDATA();
            char[] cdata = node.getText().toCharArray();
            contentHandler.characters(cdata, 0, cdata.length);
            lexicalHandler.endCDATA();/*  w  w w  .j  av a 2  s.  c o m*/
            break;

        case Node.NAMESPACE_NODE:
            Namespace declared = (Namespace) node;
            // System.err.println( "Declared namespace: " +
            // declared.getPrefix() + ":" + declared.getURI() );
            namespaces.put(declared.getPrefix(), declared.getURI());
            // if ( declared.getURI().equals( TAL_NAMESPACE_URI ) ) {
            // this.talNamespacePrefix = declared.getPrefix();
            // }
            // else if (declared.getURI().equals( METAL_NAMESPACE_URI ) ) {
            // this.metalNamespacePrefix = declared.getPrefix();
            // }
            break;

        case Node.ATTRIBUTE_NODE:
            // Already handled
            break;

        case Node.DOCUMENT_TYPE_NODE:
        case Node.ENTITY_REFERENCE_NODE:
        case Node.PROCESSING_INSTRUCTION_NODE:
        default:
            // System.err.println( "WARNING: Node type not supported: " +
            // node.getNodeTypeName() );
        }
    }
}

From source file:com.webslingerz.jpt.PageTemplateImpl.java

License:Open Source License

AttributesImpl getAttributes(Element element, Expressions expressions) throws PageTemplateException {
    AttributesImpl attributes = new AttributesImpl();
    for (Iterator i = element.attributeIterator(); i.hasNext();) {
        Attribute attribute = (Attribute) i.next();
        Namespace namespace = attribute.getNamespace();
        Namespace elementNamespace = element.getNamespace();
        if (!namespace.hasContent() && elementNamespace.hasContent())
            namespace = elementNamespace;
        // String prefix = namespace.getPrefix();
        // System.err.println( "attribute: name=" + attribute.getName() +
        // "\t" +
        // "qualified name=" + attribute.getQualifiedName() + "\t" +
        // "ns prefix=" + namespace.getPrefix() + "\t" +
        // "ns uri=" + namespace.getURI() );
        // String qualifiedName = attribute.getName();
        // String name = qualifiedName;
        // if ( qualifiedName.startsWith( prefix + ":" ) ) {
        // name = qualifiedName.substring( prefix.length() + 1 );
        // }/*  w  w  w.j  av a  2  s .  co  m*/
        String name = attribute.getName();

        // Handle JPT attributes
        // if ( prefix.equals( talNamespacePrefix ) ) {
        if (TAL_NAMESPACE_URI.equals(namespace.getURI())
                || (!strict && TAL_NAMESPACE_PREFIX.equals(namespace.getPrefix()))) {

            // tal:define
            if (name.equals("define")) {
                expressions.define = attribute.getValue();
            }

            // tal:condition
            else if (name.equals("condition")) {
                expressions.condition = attribute.getValue();
            }

            // tal:repeat
            else if (name.equals("repeat")) {
                expressions.repeat = attribute.getValue();
            }

            // tal:content
            else if (name.equals("content")) {
                expressions.content = attribute.getValue();
            }

            // tal:replace
            else if (name.equals("replace")) {
                if (expressions.omitTag == null) {
                    expressions.omitTag = "";
                }
                expressions.content = attribute.getValue();
            }

            // tal:attributes
            else if (name.equals("attributes")) {
                expressions.attributes = attribute.getValue();
            }

            // tal:omit-tag
            else if (name.equals("omit-tag")) {
                expressions.omitTag = attribute.getValue();
            }

            // error
            else {
                throw new PageTemplateException("unknown tal attribute: " + name);
            }
        }
        // else if ( prefix.equals( metalNamespacePrefix ) )
        else if (METAL_NAMESPACE_URI.equals(namespace.getURI())
                || (!strict && METAL_NAMESPACE_PREFIX.equals(namespace.getPrefix()))) {

            // metal:use-macro
            if (name.equals("use-macro")) {
                expressions.useMacro = attribute.getValue();
            }

            // metal:define-slot
            else if (name.equals("define-slot")) {
                expressions.defineSlot = attribute.getValue();
            }

            // metal:define-macro
            else if (name.equals("define-macro")) {
                //System.out.println("Defining macro: " + attribute.getValue());
                Element el = element.createCopy();
                el.remove(attribute);
                macros.put(attribute.getValue(), new MacroImpl(el));
                expressions.macro = true;
            }

            // metal:fill-slot
            else if (name.equals("fill-slot")) {
                // these are ignored here, as they don't affect processing
                // of current template, but are called from other templates
            }

            // error
            else {
                throw new PageTemplateException("unknown metal attribute: " + name);
            }
        }

        // Pass on all other attributes
        else {
            String nsURI = namespace.getURI();
            // String qualifiedName = namespace.getPrefix() + ":" + name;
            attributes.addAttribute(nsURI, name, attribute.getQualifiedName(), "CDATA", attribute.getValue());
            if (nsURI != "" && namespace != elementNamespace) {
                String prefix = namespace.getPrefix();
                String qName = "xmlns:" + prefix;
                if (attributes.getIndex(qName) == -1) {
                    // add xmlns for this attribute
                    attributes.addAttribute("", prefix, qName, "CDATA", nsURI);
                }
            }
            // attributes.addAttribute( getNamespaceURIFromPrefix(prefix),
            // name, qualifiedName, "CDATA", attribute.getValue() );
        }
    }
    return attributes;
}

From source file:com.xebialabs.overthere.cifs.winrm.ResponseExtractor.java

License:Open Source License

ResponseExtractor(String expr, Namespace ns) {
    this.expr = expr;
    this.ns = ns;
    namespaceContext = new SimpleNamespaceContext();
    namespaceContext.addNamespace(ns.getPrefix(), ns.getURI());
}

From source file:com.zimbra.soap.JaxbUtil.java

License:Open Source License

/**
 * Use namespace inheritance in preference to prefixes
 * @param elem// w w  w  .j  a va 2s .c o  m
 * @param defaultNs
 */
private static void removeNamespacePrefixes(org.dom4j.Element elem) {
    Namespace elemNs = elem.getNamespace();
    if (elemNs != null) {
        if (!Strings.isNullOrEmpty(elemNs.getPrefix())) {
            Namespace newNs = Namespace.get(elemNs.getURI());
            org.dom4j.QName newQName = new org.dom4j.QName(elem.getName(), newNs);
            elem.setQName(newQName);
        }
    }
    Iterator<?> elemIter = elem.elementIterator();
    while (elemIter.hasNext()) {
        JaxbUtil.removeNamespacePrefixes((org.dom4j.Element) elemIter.next());
    }
}

From source file:cz.fi.muni.xkremser.editor.server.newObject.Namespaces.java

License:Open Source License

private static Map<String, String> initPrefixUriMap(Map<String, Namespace> prefixNamespaceMap) {
    Map<String, String> prefixUriMap = new HashMap<String, String>();
    for (Namespace ns : prefixNamespaceMap.values()) {
        prefixUriMap.put(ns.getPrefix(), ns.getURI());
    }// w  w w.  j a  v a  2  s .  c  o  m
    return Collections.unmodifiableMap(prefixUriMap);
}

From source file:de.fct.companian.analyze.mvn.helper.PomHelper.java

License:Apache License

public PomHelper(File pomFile) throws DocumentException {
    this.pomFile = pomFile;
    this.document = null;

    SAXReader reader = new SAXReader();
    reader.setEncoding("ISO-8859-1");
    reader.setIgnoreComments(true);//from   w ww.j av a2  s  .co  m
    reader.setValidation(false);

    try {
        this.document = reader.read(this.pomFile);
    } catch (Throwable t) {
        t.printStackTrace();
    }

    if (this.document != null) {
        Element projectElement = this.document.getRootElement();
        Namespace defaultNS = projectElement.getNamespace();
        if (logger.isDebugEnabled()) {
            logger.debug("extractPomInfo() using default namespace " + defaultNS.getURI());
        }

        Map<String, String> nsMap = new HashMap<String, String>();
        nsMap.put("mvn", defaultNS.getURI());

        this.nsContext = new SimpleNamespaceContext(nsMap);
    } else {
        throw new DocumentException("Could not create document.");
    }
}

From source file:de.interactive_instruments.etf.bsxm.SecondaryGeometryElementValidationHandler.java

License:Apache License

private void validate(ValidatorContext validatorContext, Element element)
        throws XMLParsingException, UnknownCRSException {

    Namespace namespace = element.getNamespace();
    String namespaceURI = namespace == null ? null : namespace.getURI();

    if (namespace == null
            || (!geoutils.isGML32Namespace(namespaceURI) && !geoutils.isGML31Namespace(namespaceURI))) {

        LOGGER.error("Unable to determine GML version. Namespace= {}", namespaceURI);

        String errMessage = ValidatorMessageBundle.getMessage("validator.core.validation.geometry.no-gml",
                namespaceURI);/*  w w w.ja  v  a2s  . c  om*/

        validatorContext.addError(errMessage);
        return;
    }

    if (!isGMLVersionReported) {
        if (geoutils.isGML32Namespace(namespaceURI)) {
            validatorContext.addNotice(
                    ValidatorMessageBundle.getMessage("validator.core.validation.geometry.gmlversion", "3.2"));
        } else if (geoutils.isGML31Namespace(namespaceURI)) {
            validatorContext.addNotice(
                    ValidatorMessageBundle.getMessage("validator.core.validation.geometry.gmlversion", "3.1"));
        }
        isGMLVersionReported = true;
    }

    try {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(element.asXML().getBytes());

        XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(byteArrayInputStream);

        GMLVersion gmlVersion = null;
        if (geoutils.isGML32Namespace(namespaceURI)) {
            // GML 3.2
            gmlVersion = GMLVersion.GML_32;
        } else if (geoutils.isGML31Namespace(namespaceURI)) {
            gmlVersion = GMLVersion.GML_31;
        } else {
            throw new Exception("Cannot determine GML version");
        }

        GMLStreamReader gmlStream = GMLInputFactory.createGMLStreamReader(gmlVersion, xmlStream);

        Geometry geom = gmlStream.readGeometry();

        // ================
        // Test: polygon patches of a surface are connected
        if (isTestPolygonPatchConnectivity) {
            boolean isValid = checkConnectivityOfPolygonPatches(geom);
            if (!isValid) {
                polygonPatchesAreConnected = false;
            }
        }

        // ================
        // Test: point repetition in curve segment
        if (isTestRepetitionInCurveSegments) {
            boolean isValid = checkNoRepetitionInCurveSegment(geom);
            if (!isValid) {
                noRepetitionInCurveSegments = false;
            }
        }

    } catch (XMLStreamException e) {

        String currentGmlId = Dom4JHelper.findGmlId(element);

        String message = getLocationDescription(element, currentGmlId) + ": " + e.getMessage();

        validatorContext.addError(message, new IdErrorLocation(currentGmlId));

        LOGGER.error(e.getMessage(), e);

    } catch (FactoryConfigurationError e) {

        LOGGER.error(e.getMessage(), e);
        validatorContext.addError(
                ValidatorMessageBundle.getMessage("validator.core.validation.geometry.unknown-exception"));

    } catch (Exception e) {
        String currentGmlId = Dom4JHelper.findGmlId(element);

        String message = getLocationDescription(element, currentGmlId) + ": " + e.getMessage();

        validatorContext.addError(message, new IdErrorLocation(currentGmlId));

        LOGGER.error(e.getMessage(), e);
    }

    // finally {
    // // Only permitted if this is a main geometry....
    // if (isMainGeometry(element)) {
    // element.detach();
    // }
    // }
}

From source file:dk.netarkivet.common.utils.SimpleXml.java

License:Open Source License

/**
 * Get an XPath version of the given dotted path. A dotted path foo.bar.baz corresponds to the XML node
 * &lt;foo&gt;&lt;bar&gt;&lt;baz&gt; &lt;/baz&gt;&lt;/bar&gt;&lt;/foo&gt;
 * <p>/*  w ww. j  a  va  2s  . c o m*/
 * Implementation note: If needed, this could be optimized by keeping a HashMap cache of the XPaths, since they
 * don't change.
 *
 * @param path A dotted path
 * @return An XPath that matches the dotted path equivalent, using "dk:" as namespace prefix for all but the first
 * element.
 */
private XPath getXPath(String path) {
    String[] pathParts = path.split("\\.");
    StringBuilder result = new StringBuilder();
    result.append("/");
    result.append(pathParts[0]);
    for (int i = 1; i < pathParts.length; i++) {
        result.append("/dk:");
        result.append(pathParts[i]);
    }
    XPath xpath = xmlDoc.createXPath(result.toString());
    Namespace nameSpace = xmlDoc.getRootElement().getNamespace();
    Map<String, String> namespaceURIs = new HashMap<String, String>(1);
    namespaceURIs.put("dk", nameSpace.getURI());
    xpath.setNamespaceURIs(namespaceURIs);
    return xpath;
}