Example usage for org.dom4j Namespace get

List of usage examples for org.dom4j Namespace get

Introduction

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

Prototype

public static Namespace get(String prefix, String uri) 

Source Link

Document

A helper method to return the Namespace instance for the given prefix and URI

Usage

From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JInputStreamInterpreter.java

License:Open Source License

private void initialize(String parserName) {
    // The method to retrieve the SAX XMLReader (parser) is delegated to DOM4J in the method doInterpret().
    // This method is not the preferred one, but due to a bug in WebLogic 6.1 this work around has been
    // implemented. The "good" version can be retrieved from revision 1.10
    this.parserName = parserName;
    // Create the internal ino namespace instance.
    this.inoNamespace = Namespace.get(TInoNamespace.getInstance().getPrefix(),
            TInoNamespace.getInstance().getUri());
    // Create the internal xql namespace instance. Hardcoding will be replaced later :-)
    this.xqlNamespace = Namespace.get(TXQLNamespace.getInstance().getPrefix(),
            TXQLNamespace.getInstance().getUri());
    // Create the internal xq namespace instance. Hardcoding will be replaced later :-)
    this.xqNamespace = Namespace.get(TXQNamespace.getInstance().getPrefix(),
            TXQNamespace.getInstance().getUri());
    // Obtain the response content item factory singleton.
    this.responseContentItemFactory = TResponseContentItemFactory.getInstance();
}

From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JXMLOutputter.java

License:Open Source License

/**
* <p>/*from   w  w  w  . j  a v  a 2 s .  c  om*/
* Print out an <code>{@link Element}</code>, including
*   its <code>{@link Attribute}</code>s, and its value, and all
*   contained (child) elements etc.
* </p>
*
* @param element <code>Element</code> to output.
* @param out <code>Writer</code> to write to.
**/
public void output(Element element, Writer out) throws IOException {
    /****** Original Source *******/
    // If this is the root element we could pre-initialize the
    // namespace stack with the namespaces
    //printElement(element, out, indentLevel, new TDOM4JNamespaceStack());
    /******************************/
    TDOM4JNamespaceStack namespaces = new TDOM4JNamespaceStack();
    Document document = element.getDocument();
    Element rootElement = (document != null) ? document.getRootElement() : null;
    // If element is not root element or prefix of root element is not "ino" then add ino namespace to stack
    if (element != rootElement || !rootElement.getNamespacePrefix().equals(TInoNamespace.PREFIX)) {
        //System.err.println( "Adding ino namespace!" );
        Namespace inoNamespace = Namespace.get(TInoNamespace.getInstance().getPrefix(),
                TInoNamespace.getInstance().getUri());
        namespaces.push(inoNamespace);
    }
    //System.out.println( "Getting Parent Namespaces!" );
    namespaces = getParentNamespaces(element.getParent(), namespaces);
    printElement(element, out, indentLevel, namespaces);
}

From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java

License:Open Source License

private void handleSpringXml(String targetFilePath, ProcessItem processItem, InputStream springInput,
        ExportFileResource osgiResource, boolean convertToBP, boolean convertImports) {

    File targetFile = new File(getTmpFolder() + PATH_SEPARATOR + targetFilePath);
    try {/*w w w.  j av  a  2 s  .co m*/
        SAXReader saxReader = new SAXReader();
        saxReader.setStripWhitespaceText(false);
        Document document = saxReader.read(springInput);
        Element root = document.getRootElement();

        if (convertToBP) {
            if ("blueprint".equals(root.getName())) {
                formatSchemaLocation(root, false, false);
                InputStream inputStream = new ByteArrayInputStream(root.asXML().getBytes());
                FilesUtils.copyFile(inputStream, targetFile);
                osgiResource.addResource(FileConstants.BLUEPRINT_FOLDER_NAME, targetFile.toURI().toURL());
                return;
            }

            String bpPrefix = "bp";
            int cnt = 0;
            while (root.getNamespaceForPrefix(bpPrefix) != null) {
                bpPrefix = "bp" + (++cnt);
            }
            root.setQName(QName.get("blueprint", bpPrefix, BLUEPRINT_NSURI));
        }

        Namespace springCamelNsp = Namespace.get("camel", CAMEL_SPRING_NSURI);
        boolean addCamel = springCamelNsp.equals(root.getNamespaceForPrefix("camel"));
        formatSchemaLocation(root, convertToBP, addCamel);

        for (Iterator<?> i = root.elementIterator("import"); i.hasNext();) {
            Element ip = (Element) i.next();
            Attribute resource = ip.attribute("resource");
            URL path = dummyURL(resource.getValue());
            for (ResourceDependencyModel resourceModel : RouteResourceUtil
                    .getResourceDependencies(processItem)) {
                if (matches(path, resourceModel)) {
                    IFile resourceFile = RouteResourceUtil.getSourceFile(resourceModel.getItem());
                    String cpUrl = adaptedClassPathUrl(resourceModel, convertImports);
                    handleSpringXml(cpUrl, processItem, resourceFile.getContents(), osgiResource,
                            convertImports, convertImports);
                    resource.setValue(IMPORT_RESOURCE_PREFIX + cpUrl);
                }
            }
            if (convertImports) {
                i.remove();
            }
        }

        if (CONVERT_CAMEL_CONTEXT) {
            if (CONVERT_CAMEL_CONTEXT_ALL) {
                moveNamespace(root, CAMEL_SPRING_NSURI, CAMEL_BLUEPRINT_NSURI);
            } else {
                Namespace blueprintCamelNsp = Namespace.get("camel", CAMEL_BLUEPRINT_NSURI);
                moveNamespace(root, springCamelNsp, blueprintCamelNsp);
                if (springCamelNsp.equals(root.getNamespaceForPrefix("camel"))) {
                    root.remove(springCamelNsp);
                    root.add(blueprintCamelNsp);
                }
                Namespace springCamelDefNsp = Namespace.get(CAMEL_SPRING_NSURI);
                Namespace blueprintCamelDefNsp = Namespace.get(CAMEL_BLUEPRINT_NSURI);
                for (Iterator<?> i = root.elementIterator("camelContext"); i.hasNext();) {
                    Element cc = (Element) i.next();
                    if (springCamelDefNsp.equals(cc.getNamespace())) {
                        moveNamespace(cc, springCamelDefNsp, blueprintCamelDefNsp);
                    }
                }
            }
        }

        InputStream inputStream = new ByteArrayInputStream(root.asXML().getBytes());
        FilesUtils.copyFile(inputStream, targetFile);
        osgiResource.addResource(adaptedResourceFolderName(targetFilePath, convertToBP),
                targetFile.toURI().toURL());
    } catch (Exception e) {
        Logger.getAnonymousLogger().log(Level.WARNING, "Custom Spring to OSGi conversion failed. ", e);
    } finally {
        try {
            springInput.close();
        } catch (IOException e) {
            Logger.getAnonymousLogger().log(Level.WARNING, "Unexpected File closing failure. ", e);
        }
    }
}

From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java

License:Open Source License

private static void moveNamespace(Element treeRoot, String oldNspURI, String newNspURI) {
    Namespace oldNsp = treeRoot.getNamespace();
    if (oldNspURI.equals(oldNsp.getURI())) {
        Namespace newNsp = Namespace.get(oldNsp.getPrefix(), newNspURI);
        treeRoot.setQName(QName.get(treeRoot.getName(), newNsp));
        treeRoot.remove(oldNsp);/*  w  ww . j a  v a 2  s. c  o m*/
    }
    moveNamespaceInChildren(treeRoot, oldNspURI, newNspURI);
}

From source file:org.talend.camel.designer.ui.wizards.export.RouteJavaScriptOSGIForESBManager.java

License:Open Source License

private static void moveNamespaceInChildren(Element treeRoot, String oldNspURI, String newNspURI) {
    for (Iterator<?> i = treeRoot.elementIterator(); i.hasNext();) {
        Element e = (Element) i.next();
        Namespace oldNsp = e.getNamespace();
        if (oldNspURI.equals(oldNsp.getURI())) {
            Namespace newNsp = Namespace.get(oldNsp.getPrefix(), newNspURI);
            e.setQName(QName.get(e.getName(), newNsp));
            e.remove(oldNsp);/*from   www  . j a  v a 2s. c  o m*/
        }
        moveNamespaceInChildren(e, oldNspURI, newNspURI);
    }
}

From source file:org.ualberta.xsl.ECCJIXSLTitleExtractor.java

License:Creative Commons License

private void convertFile(File file) {
    try {/*w w w.  ja  v  a2s .  c o  m*/
        System.out.println("Reading File: " + file.getName());
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();

        Document doc = builder.newDocument();

        Namespace namespace = Namespace.get("xsi", "http://www.w3.org/2001/XMLSchema-instance");

        Element root = doc.createElement("modsCollectionDefinition");
        doc.appendChild(root);

        Workbook book;
        book = new XSSFWorkbook(new FileInputStream(file));
        Sheet sheet = book.getSheetAt(0);

        for (int i = 1; i <= sheet.getLastRowNum(); ++i) {
            Row row = sheet.getRow(i);

            String JNL = row.getCell(0) == null ? null : row.getCell(0).toString();
            String NDX = row.getCell(1) == null ? null : getCellStringAsInt(row.getCell(1));
            String SNAME = convertToTitleCase(row.getCell(2) == null ? null : row.getCell(2).toString());
            String FNAME = convertToTitleCase(row.getCell(3) == null ? null : row.getCell(3).toString());
            String TI = convertToTitleCase(row.getCell(4) == null ? "---" : row.getCell(4).toString());
            String MAG = row.getCell(5) == null ? null : convertToTitleCase(row.getCell(5).toString());
            String VOL = row.getCell(6) == null ? null : getCellStringAsInt(row.getCell(6));
            String NUM = row.getCell(7) == null ? null : getCellStringAsInt(row.getCell(7));
            String MO = row.getCell(8) == null ? null : row.getCell(8).toString();
            String YR = row.getCell(9) == null ? null : getCellStringAsInt(row.getCell(9));
            String PG = row.getCell(10) == null ? null : row.getCell(10).toString();
            String S1 = row.getCell(11) == null ? null : convertToTitleCase(row.getCell(11).toString());
            String S2 = row.getCell(12) == null ? null : convertToTitleCase(row.getCell(12).toString());
            String GEN = row.getCell(13) == null ? null : row.getCell(13).toString();
            String ORG = row.getCell(14) == null ? null : row.getCell(14).toString();
            String FLINE = row.getCell(15) == null ? null
                    : row.getCell(15).toString().toLowerCase() + "[First line of poetry.]";
            String SP = row.getCell(16) == null ? null : row.getCell(16).toString();

            String id = JNL + NDX;

            //TODO: Check if entry exists;
            root.appendChild(createTitle(doc, GEN, TI, FNAME, SNAME, FLINE, S1, S2, MAG, ORG, VOL, NUM, PG, MO,
                    YR, id, SP));
        }

        File output = new File(
                "./title_build/" + file.getName().substring(0, file.getName().length() - 5) + ".mgxml");
        System.out.println("Writing File: " + output.getName());
        transformDocument(doc, output);
    } catch (IOException ex) {
        System.err.println("Error reading file: " + ex.getMessage());
    } catch (ParserConfigurationException ex) {
        System.err.println("Error creating xml document: " + ex.getMessage());
    } catch (TransformerConfigurationException ex) {
        System.err.println("Error writing xml document: " + ex.getMessage());
    } catch (TransformerException ex) {
        System.err.println("Error writing xml document: " + ex.getMessage());
    }
}