Example usage for org.dom4j DocumentFactory getInstance

List of usage examples for org.dom4j DocumentFactory getInstance

Introduction

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

Prototype

public static synchronized DocumentFactory getInstance() 

Source Link

Document

Access to singleton implementation of DocumentFactory which is used if no DocumentFactory is specified when building using the standard builders.

Usage

From source file:org.nuxeo.automation.scripting.blockly.converter.XMLSerializer.java

License:Open Source License

public static Element createChainElement(String name) {
    Element e = DocumentFactory.getInstance().createElement(chainTag);
    e.addAttribute("name", name);
    return e;//from w  w  w .j  av a2  s  . c o m
}

From source file:org.nuxeo.automation.scripting.blockly.converter.XMLSerializer.java

License:Open Source License

public static Element createBlock(String type) {
    Element block = DocumentFactory.getInstance().createElement(blockTag);

    block.addAttribute("type", type);
    block.addAttribute("id", counter.incrementAndGet() + "");
    block.addAttribute("inline", "false");

    return block;
}

From source file:org.nuxeo.automation.scripting.blockly.converter.XMLSerializer.java

License:Open Source License

public static Element createLoopBlock(Element list, Element statement) {
    Element block = DocumentFactory.getInstance().createElement(blockTag);

    block.addAttribute("type", "controls_forEach");
    block.addAttribute("id", counter.incrementAndGet() + "");
    Element field = createFieldElement(block, "VAR");
    String varName = "doc" + varCounter.incrementAndGet();
    field.setText(varName);/*from w w  w .j  av a2s  .c  o  m*/

    Element listTag = createValueElement(block, "LIST");
    listTag.add(list);

    // swallow result ?

    String lastOpName = statement.attributeValue("type");
    try {
        OperationType type = Framework.getService(AutomationService.class).getOperation(lastOpName);
        if (new BlocklyOperationWrapper(type).hasOutput()) {
            statement = createSwallowBlock(statement);
        }
    } catch (Exception e) {
        throw new UnsupportedOperationException("Can not resolve " + lastOpName);
    }

    // pipe variable as input
    Element inputSlot = BlockHelper.getInputElementRecursive(statement);
    Element inputVar = createBlock("variables_get");
    Element inputValue = createFieldElement(inputVar, "VAR");
    inputValue.setText(varName);
    inputSlot.add(inputVar);

    Element statementTag = createStatementElement(block, "DO");
    statementTag.add(statement);

    return block;
}

From source file:org.nuxeo.automation.scripting.blockly.converter.XMLSerializer.java

License:Open Source License

public static Element createPlaceHolder(String target, String parameters, boolean loop, boolean allowPipe) {
    Element block = DocumentFactory.getInstance().createElement(placeHolderTag);
    block.addAttribute("target", target);
    block.addAttribute("id", counter.incrementAndGet() + "");
    if (parameters != null) {
        block.addAttribute("parameters", parameters);
    }/* w  w  w.  j  a va 2s  . c o m*/
    block.addAttribute("allowPipe", Boolean.toString(allowPipe));
    block.addAttribute("loop", Boolean.toString(loop));
    return block;
}

From source file:org.nuxeo.ecm.core.io.impl.ExportedDocumentImpl.java

License:Apache License

protected void readDocument(DocumentModel doc, boolean inlineBlobs) throws IOException {
    document = DocumentFactory.getInstance().createDocument();
    document.setName(doc.getName());//from   w w  w  . ja va 2  s  . co  m
    Element rootElement = document.addElement(ExportConstants.DOCUMENT_TAG);
    rootElement.addAttribute(ExportConstants.REP_NAME, doc.getRepositoryName());
    rootElement.addAttribute(ExportConstants.ID_ATTR, doc.getRef().toString());
    Element systemElement = rootElement.addElement(ExportConstants.SYSTEM_TAG);
    systemElement.addElement(ExportConstants.TYPE_TAG).addText(doc.getType());
    systemElement.addElement(ExportConstants.PATH_TAG).addText(path.toString());
    // lifecycle
    readLifeCycleInfo(systemElement, doc);

    // facets
    readFacets(systemElement, doc);
    // write security
    Element acpElement = systemElement.addElement(ExportConstants.ACCESS_CONTROL_TAG);
    ACP acp = doc.getACP();
    if (acp != null) {
        readACP(acpElement, acp);
    }
    // write schemas
    readDocumentSchemas(rootElement, doc, inlineBlobs);
}

From source file:org.nuxeo.ecm.platform.audit.io.IOLogEntryBase.java

License:Open Source License

private static Document writeDocument(List<LogEntry> logEntries) {
    Document document = DocumentFactory.getInstance().createDocument();
    document.setName("logEntries");

    Element rootElement = document.addElement(DOCUMENT_TAG);
    for (LogEntry logEntry : logEntries) {
        Element logEntryElement = rootElement.addElement(LOGENTRY_TAG);
        writeLogEntry(logEntryElement, logEntry);
    }//from www . j  a  v a2s . co m

    return document;
}

From source file:org.nuxeo.ecm.platform.jbpm.syndication.serializer.SimpleXMLSerializer.java

License:Open Source License

@Override
public void serialize(ResultSummary summary, List<DashBoardItem> workItems, String columnsDefinition,
        List<String> labels, String lang, Response res, HttpServletRequest req) {
    if (workItems == null) {
        return;//w  w w.j a v  a  2 s .  c  o  m
    }

    QName tasksTag = DocumentFactory.getInstance().createQName(rootTaskNodeName, taskNSPrefix, taskNS);
    QName taskTag = DocumentFactory.getInstance().createQName(taskNodeName, taskNSPrefix, taskNS);
    QName taskCategoryTag = DocumentFactory.getInstance().createQName(taskCategoryNodeName, taskNSPrefix,
            taskNS);

    org.dom4j.Element rootElem = DocumentFactory.getInstance().createElement(tasksTag);
    rootElem.addNamespace(taskNSPrefix, taskNS);
    org.dom4j.Document rootDoc = DocumentFactory.getInstance().createDocument(rootElem);

    Map<String, List<DashBoardItem>> sortedDashBoardItem = new HashMap<String, List<DashBoardItem>>();
    for (DashBoardItem item : workItems) {
        String category = item.getDirective();
        if (category == null) {
            category = "None";
        }

        if (!sortedDashBoardItem.containsKey(category)) {
            sortedDashBoardItem.put(category, new ArrayList<DashBoardItem>());
        }
        sortedDashBoardItem.get(category).add(item);
    }

    for (String category : sortedDashBoardItem.keySet()) {
        org.dom4j.Element categoryElem = rootElem.addElement(taskCategoryTag);
        categoryElem.addAttribute("category", category);

        for (DashBoardItem item : sortedDashBoardItem.get(category)) {
            org.dom4j.Element taskElem = categoryElem.addElement(taskTag);
            taskElem.addAttribute("name", item.getName());
            taskElem.addAttribute("directive", item.getDirective());
            taskElem.addAttribute("description", item.getDescription());
            taskElem.addAttribute("id", item.getId().toString());
            taskElem.addAttribute("link", item.getDocumentLink());
            if (item.getDueDate() != null) {
                taskElem.addAttribute("dueDate", DateFormat.getDateInstance().format(item.getDueDate()));
            }
            if (item.getStartDate() != null) {
                taskElem.addAttribute("startDate", DateFormat.getDateInstance().format(item.getStartDate()));
            }
            String currentLifeCycle = "";

            try {
                currentLifeCycle = item.getDocument().getCurrentLifeCycleState();
            } catch (ClientException e) {
                log.debug("No LifeCycle found");
            }

            taskElem.addAttribute("currentDocumentLifeCycle", currentLifeCycle);

            // not thread-safe so don't use a static instance
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (item.getDueDate() != null) {
                taskElem.addAttribute("dueDate", dateFormat.format(item.getDueDate()));
            }
            if (item.getStartDate() != null) {
                taskElem.addAttribute("startDate", dateFormat.format(item.getStartDate()));
            }
            if (item.getComment() != null) {
                taskElem.setText(item.getComment());
            }
        }
    }
    QName translationTag = DocumentFactory.getInstance().createQName(translationNodeName, taskNSPrefix, taskNS);
    org.dom4j.Element translationElem = rootElem.addElement(translationTag);

    Map<String, String> translatedWords = getTranslationsForWorkflow("en");
    for (String key : translatedWords.keySet()) {
        translationElem.addAttribute(key, translatedWords.get(key));
    }

    res.setEntity(rootDoc.asXML(), MediaType.TEXT_XML);
    res.getEntity().setCharacterSet(CharacterSet.UTF_8);
}

From source file:org.nuxeo.ecm.platform.layout.service.LayoutAutomaticGeneration.java

License:Open Source License

public static Document generateLayoutOutput(SchemaManager sm, String schemaName, boolean generateLabels) {
    String layoutName = String.format("%s", schemaName);

    Document document = DocumentFactory.getInstance().createDocument();
    document.setName(layoutName);/*from  w  ww . j a  va  2  s  .  c om*/

    Element component = document.addElement("component");
    component.addAttribute("name", String.format("myproject.%s.generatedContrib", layoutName));

    Element extension = component.addElement("extension");
    extension.addAttribute("target", "org.nuxeo.ecm.platform.forms.layout.WebLayoutManager");
    extension.addAttribute("point", "layouts");

    Element layout = extension.addElement("layout");
    layout.addAttribute("name", layoutName);
    Element rows = layout.addElement("rows");

    Schema schema = sm.getSchema(schemaName);
    String schemaPrefix = schema.getNamespace().prefix;

    List<Field> fields = new ArrayList<Field>();
    fields.addAll(schema.getFields());
    Collections.sort(fields, new Comparator<Field>() {
        public int compare(Field f1, Field f2) {
            return f1.getName().getLocalName().compareTo(f2.getName().getLocalName());
        }
    });

    for (Field field : fields) {
        // add row element
        Element row = rows.addElement("row");
        Element rowWidget = row.addElement("widget");
        String fieldName = field.getName().getLocalName();
        rowWidget.setText(fieldName);

        // add widget element
        boolean widgetResolved = false;
        if (field.getType().isSimpleType()) {
            boolean needsInputStyleClass = false;
            boolean needsDateFormat = false;
            Type fieldType = field.getType();
            String widgetType = null;
            if (fieldType == StringType.INSTANCE) {
                widgetType = "text";
                needsInputStyleClass = true;
            } else if (fieldType == LongType.INSTANCE || fieldType == IntegerType.INSTANCE
                    || fieldType == DoubleType.INSTANCE) {
                widgetType = "int";
                needsInputStyleClass = true;
            } else if (fieldType == DateType.INSTANCE) {
                widgetType = "datetime";
                needsDateFormat = true;
            } else {
                break;
            }

            widgetResolved = true;

            Element widget = layout.addElement("widget");
            widget.addAttribute("name", fieldName);
            widget.addAttribute("type", widgetType);

            if (generateLabels) {
                Element labels = widget.addElement("labels");
                Element label = labels.addElement("label");
                label.addAttribute("mode", BuiltinModes.ANY);
                label.setText(String.format("label.widget.%s.%s", layoutName, fieldName));
            }

            Element fieldsElement = widget.addElement("fields");
            Element fieldElement = fieldsElement.addElement("field");
            if (schemaPrefix != null) {
                fieldElement.setText(field.getName().getPrefixedName());
            } else {
                fieldElement.addAttribute("schema", schemaName);
                fieldElement.setText(fieldName);
            }

            // FIXME: this condition is always true. What's the point?
            if (needsDateFormat || needsInputStyleClass) {
                Element properties = widget.addElement("properties");
                if (needsDateFormat) {
                    properties.addAttribute("mode", BuiltinModes.ANY);
                    String defaultDatePattern = "#{nxu:basicDateFormater()}";
                    Element patternProp = properties.addElement("property");
                    patternProp.addAttribute("name", "pattern");
                    patternProp.setText(defaultDatePattern);
                    Element formatProp = properties.addElement("property");
                    formatProp.addAttribute("name", "format");
                    formatProp.setText(defaultDatePattern);
                }
                if (needsInputStyleClass) {
                    properties.addAttribute("mode", BuiltinModes.EDIT);
                    String defaultStyleClass = "dataInputText";
                    Element styleClassProp = properties.addElement("property");
                    styleClassProp.addAttribute("name", "styleClass");
                    styleClassProp.setText(defaultStyleClass);
                }
            }
        }

        if (!widgetResolved) {
            // widget needs to be done by hand for now
            layout.addComment(String.format("TODO: %s", fieldName));
        }

    }

    return document;
}

From source file:org.nuxeo.ecm.platform.pictures.tiles.serializer.XMLPictureTilesSerializer.java

License:Open Source License

public String serialize(PictureTiles tiles) {
    org.dom4j.Element rootElem = DocumentFactory.getInstance().createElement(rootTag);
    rootElem.addNamespace(picturetilesNSPrefix, picturetilesNS);
    org.dom4j.Document rootDoc = DocumentFactory.getInstance().createDocument(rootElem);

    // tile info//from w ww  .  jav  a  2s .  c o m
    org.dom4j.Element tileInfo = rootElem.addElement("tileInfo");
    tileInfo.addElement("zoom").setText(tiles.getZoomfactor() + "");
    tileInfo.addElement("maxTiles").setText(tiles.getMaxTiles() + "");
    tileInfo.addElement("tileWidth").setText(tiles.getTilesWidth() + "");
    tileInfo.addElement("tileHeight").setText(tiles.getTilesHeight() + "");
    tileInfo.addElement("xTiles").setText(tiles.getXTiles() + "");
    tileInfo.addElement("yTiles").setText(tiles.getYTiles() + "");

    // original img info
    org.dom4j.Element originalInfo = rootElem.addElement("originalImage");
    ImageInfo oInfo = tiles.getOriginalImageInfo();
    dumpImageInfo(oInfo, originalInfo);

    // source img info
    org.dom4j.Element srcInfo = rootElem.addElement("srcImage");
    ImageInfo sInfo = tiles.getSourceImageInfo();
    dumpImageInfo(sInfo, srcInfo);

    // dump misc info returned by the tiler
    org.dom4j.Element addInfo = rootElem.addElement("additionalInfo");
    for (String k : tiles.getInfo().keySet()) {
        org.dom4j.Element propElem = addInfo.addElement(k);
        propElem.setText(tiles.getInfo().get(k));
    }

    // debug info
    org.dom4j.Element debugInfo = rootElem.addElement("debug");
    debugInfo.addElement("cacheKey").setText(tiles.getCacheKey());
    debugInfo.addElement("formatKey").setText(tiles.getTileFormatCacheKey());
    debugInfo.addElement("tilePath").setText(tiles.getTilesPath());

    return rootDoc.asXML();
}

From source file:org.nuxeo.ecm.platform.publisher.remoting.marshaling.DefaultDocumentLocationMarshaler.java

License:Open Source License

public String marshalDocumentLocation(DocumentLocation docLoc) throws PublishingMarshalingException {
    org.dom4j.Element rootElem = DocumentFactory.getInstance().createElement(rootTag);
    rootElem.addNamespace(publisherSerializerNSPrefix, publisherSerializerNS);
    org.dom4j.Document rootDoc = DocumentFactory.getInstance().createDocument(rootElem);

    rootElem.addAttribute("repository", docLoc.getServerName());
    rootElem.addAttribute("ref", docLoc.getDocRef().toString());

    if (sourceServer != null) {
        rootElem.addAttribute("originalServer", sourceServer);
    }/*from ww  w .j  a  v a  2s .  c  o m*/

    String data = rootDoc.asXML();

    return cleanUpXml(data);
}