Example usage for org.dom4j Visitor Visitor

List of usage examples for org.dom4j Visitor Visitor

Introduction

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

Prototype

Visitor

Source Link

Usage

From source file:org.nuxeo.template.importer.ModelImporter.java

License:Open Source License

protected int importSamples(File root, DocumentRef modelRef, DocumentModel rootDoc) throws Exception {

    int nbImportedDocs = 0;
    for (File exampleDir : root.listFiles()) {
        if (!exampleDir.isDirectory()) {
            continue;
        }/*from  ww  w  .  j  av a2 s.  c  om*/

        // import
        DocumentReader reader = new XMLModelReader(exampleDir, exampleDir.getName());
        DocumentWriter writer = new DocumentModelWriter(session, rootDoc.getPathAsString());

        DocumentPipe pipe = new DocumentPipeImpl(10);

        final String targetUUID = modelRef.toString();

        pipe.addTransformer(new DocumentTransformer() {

            @Override
            public boolean transform(ExportedDocument xdoc) throws IOException {
                xdoc.getDocument().accept(new Visitor() {

                    @Override
                    public void visit(Text node) {
                    }

                    @Override
                    public void visit(ProcessingInstruction node) {
                    }

                    @Override
                    public void visit(Namespace namespace) {
                    }

                    @Override
                    public void visit(Entity node) {
                    }

                    @Override
                    public void visit(Comment node) {
                    }

                    @Override
                    public void visit(CDATA node) {
                    }

                    @Override
                    public void visit(Attribute node) {
                    }

                    @Override
                    public void visit(Element node) {
                        if ("templateId".equalsIgnoreCase(node.getName())
                                && "templateEntry".equalsIgnoreCase(node.getParent().getName())) {
                            log.debug("Translating uuid to " + targetUUID);
                            node.setText(targetUUID);
                        }
                    }

                    @Override
                    public void visit(DocumentType documentType) {
                    }

                    @Override
                    public void visit(Document document) {
                    }
                });
                return true;
            }
        });
        pipe.setReader(reader);
        pipe.setWriter(writer);
        pipe.run();
        nbImportedDocs++;

    }
    session.save();
    return nbImportedDocs;
}

From source file:org.nuxeo.template.samples.importer.ModelImporter.java

License:Apache License

protected int importSamples(File root, DocumentRef modelRef, DocumentModel rootDoc) throws IOException {

    int nbImportedDocs = 0;
    for (File exampleDir : root.listFiles()) {
        if (!exampleDir.isDirectory()) {
            continue;
        }//  w w  w .j a  v  a 2  s.  c  om

        // import
        DocumentReader reader = new XMLModelReader(exampleDir, exampleDir.getName());
        DocumentWriter writer = new DocumentModelWriter(session, rootDoc.getPathAsString());

        DocumentPipe pipe = new DocumentPipeImpl(10);

        final String targetUUID = modelRef.toString();

        pipe.addTransformer(new DocumentTransformer() {

            @Override
            public boolean transform(ExportedDocument xdoc) throws IOException {
                xdoc.getDocument().accept(new Visitor() {

                    @Override
                    public void visit(Text node) {
                    }

                    @Override
                    public void visit(ProcessingInstruction node) {
                    }

                    @Override
                    public void visit(Namespace namespace) {
                    }

                    @Override
                    public void visit(Entity node) {
                    }

                    @Override
                    public void visit(Comment node) {
                    }

                    @Override
                    public void visit(CDATA node) {
                    }

                    @Override
                    public void visit(Attribute node) {
                    }

                    @Override
                    public void visit(Element node) {
                        if ("templateId".equalsIgnoreCase(node.getName())
                                && "templateEntry".equalsIgnoreCase(node.getParent().getName())) {
                            log.debug("Translating uuid to " + targetUUID);
                            node.setText(targetUUID);
                        }
                    }

                    @Override
                    public void visit(DocumentType documentType) {
                    }

                    @Override
                    public void visit(Document document) {
                    }
                });
                return true;
            }
        });
        pipe.setReader(reader);
        pipe.setWriter(writer);
        pipe.run();
        nbImportedDocs++;

    }
    session.save();
    return nbImportedDocs;
}