Example usage for org.dom4j Document processingInstructions

List of usage examples for org.dom4j Document processingInstructions

Introduction

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

Prototype

List<ProcessingInstruction> processingInstructions();

Source Link

Document

Returns a list of all the processing instructions in this branch.

Usage

From source file:org.codehaus.mojo.hibernate2.MappingsAggregatorMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    try {//from ww w . ja va2  s . com
        String version = null;

        if (getBasedir() == null) {
            throw new MojoExecutionException("Required configuration missing: basedir");
        }

        File files[] = getIncludeFiles();
        if (files == null || files.length <= 0) {
            return;
        }
        File f = new File(getOutputFile());
        if (!f.exists()) {
            f.getParentFile().mkdirs();
            f.createNewFile();
        }
        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(new FileWriter(f), format);
        writer.setEntityResolver(new HibernateEntityResolver());
        //writer.setResolveEntityRefs(false);
        Document finalDoc = DocumentHelper.createDocument();
        Element rootHM = null;
        for (int i = 0; i < files.length; i++) {
            print("Parsing: " + files[i].getAbsolutePath());
            SAXReader reader = new SAXReader(false);
            reader.setEntityResolver(new HibernateEntityResolver());
            //reader.setIncludeExternalDTDDeclarations(false);
            //reader.setIncludeExternalDTDDeclarations(false);
            Document current = reader.read(files[i]);
            String currentVersion = getVersion(current);
            if (version == null) {
                version = currentVersion;
                finalDoc.setProcessingInstructions(current.processingInstructions());
                finalDoc.setDocType(current.getDocType());
                rootHM = finalDoc.addElement("hibernate-mapping");
            } else if (!version.equals(currentVersion)) {
                //LOG.warn("Mapping in " + files[i].getName() + " is not of the same mapping version as " + files[0].getName() + " mapping, so merge is impossible. Skipping");
                continue;
            }
            for (Iterator iter = current.selectSingleNode("hibernate-mapping").selectNodes("class")
                    .iterator(); iter.hasNext(); rootHM.add((Element) ((Element) iter.next()).clone())) {
            }
        }

        print("Writing aggregate file: " + f.getAbsolutePath());
        writer.write(finalDoc);
        writer.close();
    } catch (Exception ex) {
        throw new MojoExecutionException("Error in executing MappingsAgrregatorBean", ex);
    }
}

From source file:org.openxml4j.opc.signature.RelationshipTransform.java

License:Apache License

@SuppressWarnings("unchecked")
private static void RemoveProcessingInstructions(Document doc) {
    List<String> processingInstructions = doc.processingInstructions();
    for (String s : processingInstructions) {
        System.out.println("removing processing instruction : " + s);
        doc.removeProcessingInstruction(s);
    }/*  w w  w.  jav  a2 s.  c o m*/
}