Example usage for org.dom4j Namespace Namespace

List of usage examples for org.dom4j Namespace Namespace

Introduction

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

Prototype

public Namespace(String prefix, String uri) 

Source Link

Document

DOCUMENT ME!

Usage

From source file:org.olat.ims.cp.objects.CPManifest.java

License:Apache License

/**
 * This constructor is used when creating a new CP
 * //from w ww.  j a va2  s . co m
 * @param cp the cpcore to which this manifest belongs
 * @param identifier the identifier of the manifest
 */
public CPManifest(final CPCore cp, final String identifier) {
    super(CPCore.MANIFEST);
    log = Logger.getLogger(CPManifest.class);
    this.identifier = identifier;
    schemaLocation = CPManifest.DEFAULT_SCHEMALOC;
    setNamespace(new Namespace("imsmd", DEFAULT_NMS));
    organizations = new CPOrganizations();
    resources = new CPResources();
    errors = new Vector<String>();
    this.cp = cp;
}

From source file:org.onosproject.yms.app.ych.defaultcodecs.xml.DefaultXmlCodec.java

License:Apache License

/**
 * Returns the xml string from YDT./*from   ww w  .j a  va  2s.  c om*/
 *
 * @param ydtBuilder YDT builder
 * @return the xml string from YDT
 */
private String buildXmlForYdt(YdtBuilder ydtBuilder) {

    YdtExtendedBuilder extBuilder = (YdtExtendedBuilder) ydtBuilder;
    YdtExtendedContext rootNode = extBuilder.getRootNode();

    if (rootNode == null) {
        throw new YchException(E_YDT_ROOT_NODE);
    }

    // Creating the root element for xml.
    Element rootElement = DocumentHelper.createDocument().addElement(rootNode.getName());

    // Adding the name space if exist for root name.
    if (rootNode.getNamespace() != null) {
        rootElement.add(Namespace.get(rootNode.getNamespace()));
    }

    if (rootElement.getName().equals("config")) {
        rootElement.add(new Namespace("nc", "urn:ietf:params:xml:ns:netconf:base:1.0"));
    }

    // Adding the attribute if exist
    Map<String, String> tagAttrMap = extBuilder.getRootTagAttributeMap();
    if (tagAttrMap != null && !tagAttrMap.isEmpty()) {
        for (Map.Entry<String, String> attr : tagAttrMap.entrySet()) {
            rootElement.addAttribute(attr.getKey(), attr.getValue());
        }
    }

    XmlCodecYdtListener listener = new XmlCodecYdtListener(XML, rootNode);
    listener.getElementStack().push(rootElement);

    // Walk through YDT and build the xml.
    YdtExtendedWalker extWalker = new DefaultYdtWalker();
    extWalker.walk(listener, rootNode);

    return rootElement.asXML();
}

From source file:org.openbravo.dal.xml.XMLUtil.java

License:Open Source License

/**
 * Creates a standard Openbravo root element for a xml document and set ths namespace. Ads the new
 * root element to the Dom4j document./* w  w  w . j  av a 2 s .co m*/
 * 
 * @param doc
 *          the Dom4j document to set the root element
 * @param elementName
 *          the name of the root element
 * @return the new root element
 */
public Element addRootElement(Document doc, String elementName) {
    final Namespace ns = new Namespace("ob", "http://www.openbravo.com");
    final QName qName = new QName(elementName, ns);
    final Element root = doc.addElement(qName);
    root.addNamespace("ob", "http://www.openbravo.com");
    return root;
}

From source file:org.opensha.commons.geo.RegionUtils.java

License:Apache License

public static void regionToKML(Region region, String filename, Color c) {
    String kmlFileName = filename + ".kml";
    Document doc = DocumentHelper.createDocument();
    Element root = new DefaultElement("kml", new Namespace("", "http://www.opengis.net/kml/2.2"));
    doc.add(root);//from  w  ww. ja  v a2s.com

    Element e_doc = root.addElement("Document");
    Element e_doc_name = e_doc.addElement("name");
    e_doc_name.addText(kmlFileName);

    addBorderStyle(e_doc, c);
    addBorderVertexStyle(e_doc);
    addGridNodeStyle(e_doc, c);

    Element e_folder = e_doc.addElement("Folder");
    Element e_folder_name = e_folder.addElement("name");
    e_folder_name.addText("region");
    Element e_open = e_folder.addElement("open");
    e_open.addText("1");

    addBorder(e_folder, region);
    addPoints(e_folder, "Border Nodes", region.getBorder(), Style.BORDER_VERTEX);
    if (region.getInteriors() != null) {
        for (LocationList interior : region.getInteriors()) {
            addPoints(e_folder, "Interior Nodes", interior, Style.BORDER_VERTEX);
        }
    }

    if (region instanceof GriddedRegion) {
        addPoints(e_folder, "Grid Nodes", ((GriddedRegion) region).getNodeList(), Style.GRID_NODE);
    }

    // TODO absolutely need to create seom platform specific output directory
    // that is not in project space (e.g. desktop, Decs and Settings);

    String outDirName = "sha_kml/";
    File outDir = new File(outDirName);
    outDir.mkdirs();
    String tmpFile = outDirName + kmlFileName;

    try {
        //XMLUtils.writeDocumentToFile(tmpFile, doc);
        XMLWriter writer;
        OutputFormat format = new OutputFormat("\t", true);
        writer = new XMLWriter(new FileWriter(tmpFile), format);
        writer.write(doc);
        writer.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    //Element e = new Elem
}

From source file:org.opensha.commons.geo.RegionUtils.java

License:Apache License

public static void locListToKML(LocationList locs, String filename, Color c) {
    String kmlFileName = filename + ".kml";
    Document doc = DocumentHelper.createDocument();
    Element root = new DefaultElement("kml", new Namespace("", "http://www.opengis.net/kml/2.2"));
    doc.add(root);/*w ww.  j  a  va 2  s .c  om*/

    Element e_doc = root.addElement("Document");
    Element e_doc_name = e_doc.addElement("name");
    e_doc_name.addText(kmlFileName);

    addBorderStyle(e_doc, c);
    addBorderVertexStyle(e_doc);
    addGridNodeStyle(e_doc, c);

    Element e_folder = e_doc.addElement("Folder");
    Element e_folder_name = e_folder.addElement("name");
    e_folder_name.addText("region");
    Element e_open = e_folder.addElement("open");
    e_open.addText("1");

    //      addLocationPoly(e_folder, locs);
    addLocationLine(e_folder, locs);
    addPoints(e_folder, "Border Nodes", locs, Style.BORDER_VERTEX);

    // TODO absolutely need to create seom platform specific output directory
    // that is not in project space (e.g. desktop, Decs and Settings);

    String outDirName = "sha_kml/";
    File outDir = new File(outDirName);
    outDir.mkdirs();
    String tmpFile = outDirName + kmlFileName;

    try {
        //XMLUtils.writeDocumentToFile(tmpFile, doc);
        XMLWriter writer;
        OutputFormat format = new OutputFormat("\t", true);
        writer = new XMLWriter(new FileWriter(tmpFile), format);
        writer.write(doc);
        writer.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    //Element e = new Elem
}

From source file:org.orbeon.oxf.processor.serializer.BinaryTextXMLReceiver.java

License:Open Source License

public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) {
    if (elementLevel++ == 0) {
        // This is the root element

        // Get xsi:type attribute and determine whether the input is binary or text
        String xsiType = attributes.getValue(XMLConstants.XSI_TYPE_QNAME.getNamespaceURI(),
                XMLConstants.XSI_TYPE_QNAME.getName());

        if (xsiType == null)
            throw new OXFException("Root element must contain an xsi:type attribute");

        int colonIndex = xsiType.indexOf(':');
        if (colonIndex == -1)
            throw new OXFException("Type xs:string or xs:base64Binary must be specified");

        String typePrefix = xsiType.substring(0, colonIndex);
        String typeLocalName = xsiType.substring(colonIndex + 1);

        if (prefixMappings == null)
            throw new OXFException("Undeclared prefix in xsi:type: " + typePrefix);

        String typeNamespaceURI = prefixMappings.get(typePrefix);
        if (typeNamespaceURI == null)
            throw new OXFException("Undeclared prefix in xsi:type: " + typePrefix);

        QName typeQName = new QName(typeLocalName, new Namespace(typePrefix, typeNamespaceURI));
        boolean isBinaryInput;
        if (typeQName.equals(XMLConstants.XS_BASE64BINARY_QNAME)) {
            isBinaryInput = true;//from  ww w. ja v a 2  s  .  c o  m
        } else if (typeQName.equals(XMLConstants.XS_STRING_QNAME)) {
            isBinaryInput = false;
        } else
            throw new OXFException("Type xs:string or xs:base64Binary must be specified");

        // Set last-modified if available
        final String validityAttribute = attributes.getValue("last-modified");
        if (StringUtils.isNotBlank(validityAttribute)) {
            // Override caching settings which may have taken place before
            if (response != null)
                response.setPageCaching(DateUtils.parseRFC1123(validityAttribute));
        }

        // Set filename if available
        final String fileName = attributes.getValue("filename");
        if (StringUtils.isNotBlank(fileName)) {
            if (response != null)
                response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        }

        // Set status code if available
        final String statusCode = attributes.getValue("status-code");
        if (StringUtils.isNotBlank(statusCode)) {
            if (response != null)
                response.setStatus(Integer.parseInt(statusCode));
        }

        // Set ContentHandler and headers depending on input type
        final String contentTypeAttribute = attributes.getValue("content-type");
        if (isBinaryInput) {
            // Get content-type
            final String contentType = getContentType(contentTypeAttribute, DEFAULT_BINARY_CONTENT_TYPE);

            if (response != null)
                response.setContentType(contentType);

            outputContentHandler = new Base64XMLReceiver(outputStream);
        } else {
            // Get content-type and encoding
            final String contentType = getContentType(contentTypeAttribute, DEFAULT_TEXT_CONTENT_TYPE);
            final String encoding = getEncoding(contentTypeAttribute, CachedSerializer.DEFAULT_ENCODING);

            // Always set the content type with a charset attribute
            if (response != null)
                response.setContentType(contentType + "; charset=" + encoding);

            try {
                writer = new OutputStreamWriter(outputStream, encoding);
            } catch (UnsupportedEncodingException e) {
                throw new OXFException(e);
            }
            outputContentHandler = new TextXMLReceiver(writer);
        }
    }
}

From source file:org.orbeon.oxf.processor.sql.interpreters.AttributeInterpreter.java

License:Open Source License

private static QName getQName(Locator locator, String qNameString, Map prefixesMap) {

    final int colonIndex = qNameString.indexOf(':');
    if (colonIndex == -1)
        return new QName(qNameString);
    if (colonIndex == 0)
        throw new ValidationException("Invalid QName:" + qNameString, new LocationData(locator));

    final String prefix = qNameString.substring(0, colonIndex);
    final String localName = qNameString.substring(colonIndex + 1);

    if (prefixesMap.get(prefix) == null) {
        throw new ValidationException("Undeclared prefix for QName:" + qNameString, new LocationData(locator));
    } else {/*from   w ww . j av  a  2s. co m*/
        return new QName(localName, new Namespace(prefix, (String) prefixesMap.get(prefix)));
    }
}

From source file:org.orbeon.oxf.transformer.xupdate.VariableContextImpl.java

License:Open Source License

public Object getVariableValue(String namespaceURI, String prefix, String localName)
        throws UnresolvableException {
    if (this.qname == null) {
        throw new UnresolvableException(
                "Variable '" + Utils.qualifiedName(prefix, localName) + "' is not defined");
    } else {/*from   w w w  . j  a  v  a 2  s.  c  o  m*/
        QName qname = new QName(localName, new Namespace(prefix, namespaceURI));
        return this.qname.equals(qname) ? value
                : parentContext.getVariableValue(namespaceURI, prefix, localName);
    }
}

From source file:org.orbeon.oxf.xforms.function.XFormsFunction.java

License:Open Source License

private QName createQName(String qNameString, String qNameURI, int colonIndex, String prefix) {
    if (colonIndex == -1) {
        // NCName
        // NOTE: This assumes that if there is no prefix, the QName is in no namespace
        return new QName(qNameString);
    } else {/* ww  w. j  a  v a2 s  .c  o  m*/
        // QName-but-not-NCName
        return new QName(qNameString.substring(colonIndex + 1), new Namespace(prefix, qNameURI));
    }
}

From source file:org.orbeon.oxf.xforms.RuntimeBind.java

License:Open Source License

public QName evaluateTypeQName(Map<String, String> namespaceMap) {
    final String typeQNameString = staticBind.dataTypeOrNull();
    if (typeQNameString != null) {
        final String typeNamespacePrefix;
        final String typeNamespaceURI;
        final String typeLocalname;

        final int prefixPosition = typeQNameString.indexOf(':');
        if (prefixPosition > 0) {
            typeNamespacePrefix = typeQNameString.substring(0, prefixPosition);
            typeNamespaceURI = namespaceMap.get(typeNamespacePrefix);
            if (typeNamespaceURI == null)
                throw new ValidationException("Namespace not declared for prefix '" + typeNamespacePrefix + "'",
                        staticBind.locationData());

            // TODO: xxx check what XForms event must be dispatched

            typeLocalname = typeQNameString.substring(prefixPosition + 1);
        } else {//from  ww  w .  ja  v a  2 s .  co  m
            typeNamespacePrefix = "";
            typeNamespaceURI = "";
            typeLocalname = typeQNameString;
        }

        return QName.get(typeLocalname, new Namespace(typeNamespacePrefix, typeNamespaceURI));
    } else {
        return null;
    }
}