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.cladonia.xngreditor.grammar.GrammarProperties.java

License:Open Source License

/**
 * Constructor for the grammar properties.
 *
 * @param element the element that contains the properties,
 *        for the editor.// w ww  .j  a  v  a  2s.c  om
 */
public GrammarProperties(ConfigurationProperties props, ExchangerDocument document) {
    super(new XElement(GRAMMAR_PROPERTIES));

    this.properties = props;

    if (document != null) {

        String name = document.getName();
        int dotPos = name.lastIndexOf('.');

        if (dotPos != -1) {
            setExtensions(name.substring(dotPos + 1, name.length()));
        }

        if (!document.isError()) {
            XElement root = document.getRoot();

            if (root != null) {
                setRootElementName(root.getName());
                setNamespace(root.getNamespaceURI());
                setNamespacePrefix(root.getNamespacePrefix());
            }

            List namespaces = root.additionalNamespaces();

            for (int i = 0; i < namespaces.size(); i++) {
                Namespace namespace = (Namespace) namespaces.get(i);
                addNamespace(new NamespaceProperties(namespace.getURI(), namespace.getPrefix()));
            }

            DocumentType docType = document.getDocument().getDocType();

            if (docType != null) {

                setPublicID(docType.getPublicID());
                setSystemID(docType.getSystemID());
                setValidationLocation(docType.getSystemID());
                setUseXMLValidationLocation(true);

                addTagCompletion(new TagCompletionProperties(docType.getSystemID(), XMLGrammar.TYPE_DTD));

                //               setTemplateLocation( docType.getSystemID());
                //               setTemplateGrammar( XMLGrammar.TYPE_DTD);

                setValidationGrammar(XMLGrammar.TYPE_DTD);
            } else {
                String location = root.getAttribute("schemaLocation");

                if (location == null) {
                    location = root.getAttribute("noNamespaceSchemaLocation");
                }

                if (location != null) {
                    StringTokenizer tokenizer = new StringTokenizer(location, " \t\n\r\f");
                    String targetURI = null;

                    // if there is only one token than use this as the uri
                    if (tokenizer.hasMoreTokens()) {
                        targetURI = tokenizer.nextToken();
                    }

                    // there is more than one token, use this token as the uri
                    if (tokenizer.hasMoreTokens()) {
                        targetURI = tokenizer.nextToken();
                    }

                    setValidationLocation(targetURI);

                    addTagCompletion(new TagCompletionProperties(targetURI, XMLGrammar.TYPE_XSD));

                    setUseXMLValidationLocation(true);
                    setValidationGrammar(XMLGrammar.TYPE_XSD);
                }
            }

            setDescription(getRootElementName());
        } else {
            setDescription(getExtensions());
        }
    }
}

From source file:com.cladonia.xngreditor.SchemaLocationDialog.java

License:Open Source License

/**
 * Sets the original values displayed by the dialog, plus what should be enabled\disabled
 *//*from  www.j  av a 2  s . c  o  m*/
private void setCurrentValues() {
    XDocument xdoc = document.getDocument();
    Element ele = xdoc.getRootElement();

    Attribute attr = ele.attribute(SCHEMALOCATION);

    if (attr == null) {
        // check for no namespace schema
        Attribute attr2 = ele.attribute(NOSCHEMALOCATION);
        if (attr2 == null) {
            // set the defaults
            schemaButton.setSelected(true);
            Namespace ns = ele.getNamespace();
            if (ns != Namespace.NO_NAMESPACE) {
                namespaceField.setText(ns.getURI());
            } else {
                namespaceField.setText("");
            }

            urlField.setText("");
        } else {
            // we have a "no namespace schema"
            schemaNoNSButton.setSelected(true);
            namespaceField.setText("");
            namespaceField.setEnabled(false);
            namespaceLabel.setEnabled(false);
            urlField.setText(attr2.getValue());
        }
    } else {
        // we hava a namepace schema

        schemaButton.setSelected(true);

        // we have namespace schema, set the namespace and the URL
        String attrValue = attr.getValue();

        // break up all the namespace and url pairs
        ArrayList stringValues = new ArrayList();

        StringTokenizer st = new StringTokenizer(attrValue);
        while (st.hasMoreTokens()) {
            stringValues.add(st.nextToken());
        }

        String namespaceValue = (String) stringValues.get(0);
        if (namespaceValue != null) {
            namespaceField.setText(namespaceValue);
        } else {
            namespaceField.setText("");
        }

        String urlValue = (String) stringValues.get(1);
        if (urlValue != null) {
            urlField.setText(urlValue);
        } else {
            urlField.setText("");
        }
    }
}

From source file:com.cladonia.xngreditor.ToolsAddNodeDialog.java

License:Open Source License

private void fillNamespaceCombo(Vector namespaces) {
    namespaceCombo.removeAllItems();/*from  w ww.j a v  a2 s  . c om*/
    namespaceCombo.addItem("None");

    for (int cnt = 0; cnt < namespaces.size(); ++cnt) {
        Namespace ns = (Namespace) namespaces.get(cnt);
        //String toAdd = ns.getPrefix()+":"+ns.getURI();
        namespaceCombo.addItem(ns.getURI());

    }
    namespaceCombo.setSelectedIndex(0);

}

From source file:com.cladonia.xngreditor.ToolsAddNodeDialog.java

License:Open Source License

private String getPrefixForURI(String uri) {

    for (int cnt = 0; cnt < namespaces.size(); ++cnt) {
        Namespace ns = (Namespace) namespaces.get(cnt);
        if (ns.getURI().equalsIgnoreCase(uri)) {
            return (ns.getPrefix());
        }/*  w  ww.j  a v  a 2s  .  c om*/
    }
    return (null);
}

From source file:com.cladonia.xngreditor.ToolsAddNodeToNamespaceDialog.java

License:Open Source License

private void fillNamespaceCombo(Vector namespaces) {
    nsURICombo.removeAllItems();/*ww w  .jav a 2s.  com*/
    nsURICombo.addItem("None");

    for (int cnt = 0; cnt < namespaces.size(); ++cnt) {
        Namespace ns = (Namespace) namespaces.get(cnt);
        //String toAdd = ns.getPrefix()+":"+ns.getURI();
        nsURICombo.addItem(ns.getURI());

    }
    nsURICombo.setSelectedIndex(0);

}

From source file:com.cladonia.xngreditor.ToolsChangeNSPrefixDialog.java

License:Open Source License

public void show(Vector ns) {
    this.namespaces = ns;
    listModel.removeAllElements();//  ww  w .j a v a 2  s . co m
    for (int cnt = 0; cnt < namespaces.size(); ++cnt) {
        Namespace newNs = (Namespace) namespaces.get(cnt);
        listModel.addElement(newNs.getPrefix() + ":" + newNs.getURI());
    }
    //pack();
    super.show();
}

From source file:com.cladonia.xngreditor.ToolsChangeNSPrefixDialog.java

License:Open Source License

public void updateMainDialog(Vector prefixes) {

    this.namespaces = prefixes;
    listModel.removeAllElements();//from   ww w .ja v  a 2 s.co  m
    for (int cnt = 0; cnt < namespaces.size(); ++cnt) {
        Namespace newNs = (Namespace) namespaces.get(cnt);
        listModel.addElement(newNs.getPrefix() + ":" + newNs.getURI());
    }
}

From source file:com.panet.imeta.trans.steps.getxmldata.GetXMLData.java

License:Open Source License

@SuppressWarnings("unchecked")
public void prepareNSMap(Element l) {
    for (Namespace ns : (List<Namespace>) l.declaredNamespaces()) {
        if (ns.getPrefix().trim().length() == 0) {
            data.NAMESPACE.put("pre" + data.NSPath.size(), ns.getURI());
            String path = "";
            Element element = l;/* w w w .  j  av  a2 s  .  c o m*/
            while (element != null) {
                if (element.getNamespacePrefix() != null && element.getNamespacePrefix().length() > 0) {
                    path = "/" + element.getNamespacePrefix() + ":" + element.getName() + path;
                } else {
                    path = "/" + element.getName() + path;
                }
                element = element.getParent();
            }
            data.NSPath.add(path);
        } else {
            data.NAMESPACE.put(ns.getPrefix(), ns.getURI());
        }
    }
    for (Element e : (List<Element>) l.elements()) {
        prepareNSMap(e);
    }
}

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

License:Open Source License

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

    // Process instructions

    // use macro//from  w  w  w  .  j ava2  s .  c  o  m
    if (expressions.useMacro != null) {
        processMacro(expressions.useMacro, element, contentHandler, lexicalHandler, beanShell, slotStack);
        return;
    }

    // fill slot
    if (expressions.defineSlot != null) {
        //System.err.println( "fill slot: " + expressions.defineSlot );
        if (!slotStack.isEmpty()) {
            Map slots = (Map) slotStack.pop();
            Slot 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");
        }
    }

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

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

    // repeat
    Loop loop = new Loop(expressions.repeat, beanShell);
    while (loop.repeat(beanShell)) {
        // content or replace
        Object jptContent = null;
        if (expressions.content != null) {
            jptContent = processContent(expressions.content, beanShell);
        }

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

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

        // Declare element
        Namespace namespace = element.getNamespace();
        if (!jptOmitTag) {
            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.shopximity.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();
        //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 );
        //}/*ww  w.  j  a va  2s.co  m*/
        String name = attribute.getName();

        // Handle JPT attributes
        //if ( prefix.equals( talNamespacePrefix ) ) {
        if (TAL_NAMESPACE_URI.equals(namespace.getURI())) {
            // 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())) {
            // 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
            // metal:fill-slot
            else if (name.equals("define-macro") || 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 qualifiedName = namespace.getPrefix() + ":" + name;
            attributes.addAttribute(namespace.getURI(), name, attribute.getQualifiedName(), "CDATA",
                    attribute.getValue());
            //attributes.addAttribute( getNamespaceURIFromPrefix(prefix), name, qualifiedName, "CDATA", attribute.getValue() );
        }
    }
    return attributes;
}