Example usage for org.dom4j.io XMLWriter writeOpen

List of usage examples for org.dom4j.io XMLWriter writeOpen

Introduction

In this page you can find the example usage for org.dom4j.io XMLWriter writeOpen.

Prototype

public void writeOpen(Element element) throws IOException 

Source Link

Document

Writes the opening tag of an Element , including its Attribute s but without its content.

Usage

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

private static void addIssueAttachments(XMLWriter writer, List<IssueAttachment> entities) throws IOException {
    if (entities.size() > 0) {
        Element elTmp;/*  w w w .  j  a va 2 s  .c o m*/
        final DocumentFactory factory = getDocumentFactory();
        final Element el = factory.createElement(TAG_ISSUE_ATTACHMENTS);
        writer.writeOpen(el);
        for (IssueAttachment c : entities) {
            elTmp = factory.createElement(TAG_ISSUE_ATTACHMENT);
            writer.writeOpen(elTmp);
            Properties pTmp = new Properties();
            pTmp.setProperty(TAG_ISSUE_ATTACHMENT_DESCRIPTION,
                    ITrackerResources.escapeUnicodeString(c.getDescription(), false));
            pTmp.setProperty(TAG_ISSUE_ATTACHMENT_FILENAME,
                    ITrackerResources.escapeUnicodeString(c.getFileName(), false));
            pTmp.setProperty(TAG_ISSUE_ATTACHMENT_ORIGFILE,
                    ITrackerResources.escapeUnicodeString(c.getOriginalFileName(), false));
            addCdataPropertyTags(writer, pTmp);
            pTmp.clear();

            pTmp.setProperty(TAG_ISSUE_ATTACHMENT_SIZE, String.valueOf(c.getSize()));
            pTmp.setProperty(TAG_ISSUE_ATTACHMENT_TYPE,
                    StringUtils.defaultString(c.getType(), "application/octet-stream"));
            pTmp.setProperty(TAG_ISSUE_ATTACHMENT_CREATOR, TAG_USER + c.getUser().getId());
            addPropertyTags(writer, pTmp);
            writer.writeClose(elTmp);
        }
        writer.writeClose(el);
    }
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

private static void addIssueHistory(XMLWriter writer, List<IssueHistory> entities) throws IOException {
    if (entities.size() > 0) {
        Element elTmp;/*  ww  w. jav a2s . c o m*/
        final DocumentFactory factory = getDocumentFactory();
        final Element el = factory.createElement(TAG_ISSUE_HISTORY);
        writer.writeOpen(el);
        for (IssueHistory c : entities) {
            elTmp = factory.createElement(TAG_HISTORY_ENTRY);
            elTmp.addAttribute(ATTR_CREATOR_ID, TAG_USER + c.getUser().getId());
            elTmp.addAttribute(ATTR_DATE, DATE_FORMATTER.format(c.getCreateDate()));
            elTmp.addAttribute(ATTR_STATUS, String.valueOf(c.getStatus()));

            writer.writeOpen(elTmp);
            writer.write(factory.createCDATA(ITrackerResources.escapeUnicodeString(c.getDescription(), false)));
            writer.writeClose(elTmp);
        }
        writer.writeClose(el);
    }
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

public static void getIssueXML(XMLWriter writer, Issue issue) throws IOException {
    Element elIssue = getDocumentFactory().createElement(TAG_ISSUE);
    elIssue.addAttribute(ATTR_ID, TAG_ISSUE + issue.getId());
    elIssue.addAttribute(ATTR_SYSTEMID, String.valueOf(issue.getId()));

    writer.writeOpen(elIssue);

    final Properties tags = new Properties();
    final Properties ctags = new Properties();

    tags.setProperty(TAG_ISSUE_PROJECT, TAG_PROJECT + issue.getProject().getId());
    ctags.setProperty(TAG_ISSUE_DESCRIPTION,
            ITrackerResources.escapeUnicodeString(issue.getDescription(), false));
    tags.setProperty(TAG_ISSUE_SEVERITY, String.valueOf(issue.getSeverity()));
    tags.setProperty(TAG_ISSUE_STATUS, String.valueOf(issue.getStatus()));
    tags.setProperty(TAG_ISSUE_RESOLUTION, StringUtils.defaultString(issue.getResolution()));
    if (issue.getTargetVersion() != null) {
        tags.setProperty(TAG_TARGET_VERSION_ID, TAG_VERSION + issue.getTargetVersion().getId());
    }//from  w  w  w. ja  v  a2 s .  c  o  m
    tags.setProperty(TAG_CREATE_DATE, DATE_FORMATTER.format(issue.getCreateDate()));
    tags.setProperty(TAG_LAST_MODIFIED, DATE_FORMATTER.format(issue.getLastModifiedDate()));
    tags.setProperty(TAG_CREATOR, TAG_USER + issue.getCreator().getId());
    if (issue.getOwner() != null) {
        tags.setProperty(TAG_OWNER, TAG_USER + issue.getOwner().getId());
    }

    addPropertyTags(writer, tags);
    addCdataPropertyTags(writer, ctags);

    addIdCollection(writer, issue.getComponents(), TAG_ISSUE_COMPONENTS, TAG_COMPONENT_ID, TAG_COMPONENT);
    addIdCollection(writer, issue.getVersions(), TAG_ISSUE_VERSIONS, TAG_VERSION_ID, TAG_VERSION);

    addIssueFields(writer, issue.getFields());
    addIssueAttachments(writer, issue.getAttachments());
    addIssueHistory(writer, issue.getHistory());

    writer.writeClose(elIssue);
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

private static void addProjectComponents(XMLWriter writer, List<Component> entities) throws IOException {
    if (entities.size() > 0) {
        Element elTmp;//from w  w  w  . j  a va2s.co  m
        final DocumentFactory factory = getDocumentFactory();
        final Element el = factory.createElement(TAG_COMPONENTS);
        writer.writeOpen(el);
        for (Component c : entities) {
            elTmp = factory.createElement(TAG_COMPONENT);

            elTmp.addAttribute(ATTR_ID, TAG_CUSTOM_FIELD + c.getId());
            elTmp.addAttribute(ATTR_SYSTEMID, String.valueOf(c.getId()));

            writer.writeOpen(elTmp);
            Properties tags = new Properties();
            tags.setProperty(TAG_COMPONENT_NAME, ITrackerResources.escapeUnicodeString(c.getName(), false));
            tags.setProperty(TAG_COMPONENT_DESCRIPTION,
                    ITrackerResources.escapeUnicodeString(c.getDescription(), false));
            addCdataPropertyTags(writer, tags);
            writer.writeClose(elTmp);
        }
        writer.writeClose(el);
    }
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

private static void addProjectVersions(XMLWriter writer, List<Version> entities) throws IOException {
    if (entities.size() > 0) {
        Element elTmp;//w  w  w . ja v  a 2s .co m
        final DocumentFactory factory = getDocumentFactory();
        final Element el = factory.createElement(TAG_VERSIONS);
        writer.writeOpen(el);
        for (Version c : entities) {
            elTmp = factory.createElement(TAG_VERSION);

            elTmp.addAttribute(ATTR_ID, TAG_VERSION + c.getId());
            elTmp.addAttribute(ATTR_SYSTEMID, String.valueOf(c.getId()));

            writer.writeOpen(elTmp);
            Properties tags = new Properties();
            tags.setProperty(TAG_VERSION_NUMBER, ITrackerResources.escapeUnicodeString(c.getNumber(), false));
            tags.setProperty(TAG_VERSION_DESCRIPTION,
                    ITrackerResources.escapeUnicodeString(c.getDescription(), false));
            addCdataPropertyTags(writer, tags);
            writer.writeClose(elTmp);
        }
        writer.writeClose(el);
    }
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

private static void getProjectXML(XMLWriter writer, Project project) throws IOException {
    Element elProject = getDocumentFactory().createElement(TAG_PROJECT);
    elProject.addAttribute(ATTR_ID, TAG_PROJECT + project.getId());
    elProject.addAttribute(ATTR_SYSTEMID, String.valueOf(project.getId()));

    writer.writeOpen(elProject);
    Properties tags = new Properties();
    tags.setProperty(TAG_PROJECT_NAME, ITrackerResources.escapeUnicodeString(project.getName(), false));
    tags.setProperty(TAG_PROJECT_DESCRIPTION,
            ITrackerResources.escapeUnicodeString(project.getDescription(), false));
    addCdataPropertyTags(writer, tags);// w  w w . j av a  2 s .c  o m
    tags.clear();
    tags.setProperty(TAG_PROJECT_STATUS, ProjectUtilities.getStatusName(project.getStatus(), EXPORT_LOCALE));
    tags.setProperty(TAG_PROJECT_OPTIONS, String.valueOf(project.getOptions()));
    addPropertyTags(writer, tags);

    addIdCollection(writer, project.getCustomFields(), TAG_PROJECT_FIELDS, TAG_PROJECT_FIELD_ID,
            TAG_CUSTOM_FIELD);
    addIdCollection(writer, project.getOwners(), TAG_PROJECT_OWNERS, TAG_PROJECT_OWNER_ID, TAG_USER);

    addProjectComponents(writer, project.getComponents());
    addProjectVersions(writer, project.getVersions());

    writer.writeClose(elProject);

}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

public static void getUserXML(XMLWriter writer, User user) throws IOException {
    Element elUser = getDocumentFactory().createElement(TAG_USER);
    elUser.addAttribute(ATTR_ID, TAG_USER + user.getId());
    elUser.addAttribute(ATTR_SYSTEMID, String.valueOf(user.getId()));

    writer.writeOpen(elUser);
    Properties tags = new Properties();
    tags.setProperty(TAG_LOGIN, ITrackerResources.escapeUnicodeString(user.getLogin(), false));
    tags.setProperty(TAG_FIRST_NAME, ITrackerResources.escapeUnicodeString(user.getFirstName(), false));
    tags.setProperty(TAG_LAST_NAME, ITrackerResources.escapeUnicodeString(user.getLastName(), false));
    tags.setProperty(TAG_EMAIL, ITrackerResources.escapeUnicodeString(user.getEmail(), false));
    addCdataPropertyTags(writer, tags);//from   w  w w.  j ava  2 s .c o m
    tags.clear();

    tags.setProperty(TAG_USER_STATUS, String.valueOf(user.getStatus()));
    tags.setProperty(TAG_SUPER_USER, String.valueOf(user.isSuperUser()));
    addPropertyTags(writer, tags);

    writer.writeClose(elUser);
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

private static void getConfigurationXML(XMLWriter writer, List<Configuration> cs, String elName, String itName)
        throws IOException {
    Element el = getDocumentFactory().createElement(elName);
    writer.writeOpen(el);
    for (Configuration c : cs) {
        Element elIt = getDocumentFactory().createElement(itName);
        elIt.addAttribute(ATTR_VALUE, c.getValue());
        elIt.addAttribute(ATTR_ORDER, String.valueOf(c.getOrder()));
        writer.writeOpen(elIt);/*w  ww .j av  a 2 s  .  c o  m*/
        writer.write(
                getDocumentFactory().createCDATA(ITrackerResources.escapeUnicodeString(c.getName(), false)));
        writer.writeClose(elIt);
    }
    writer.writeClose(el);
}

From source file:org.itracker.web.util.ImportExportUtilities.java

License:Open Source License

private static void getCustomFieldsXML(XMLWriter writer, SystemConfiguration config) throws IOException {
    Properties tags = new Properties();
    Element elCustomField = getDocumentFactory().createElement(TAG_CUSTOM_FIELDS);
    Element elTmp;/*w  ww  . ja va  2 s  .  c om*/
    writer.writeOpen(elCustomField);
    for (CustomField c : config.getCustomFields()) {
        tags.clear();
        tags.setProperty(TAG_CUSTOM_FIELD_LABEL, ITrackerResources
                .escapeUnicodeString(CustomFieldUtilities.getCustomFieldName(c.getId()), false));
        tags.setProperty(TAG_CUSTOM_FIELD_TYPE, String.valueOf(c.getFieldType().name()));
        tags.setProperty(TAG_CUSTOM_FIELD_REQUIRED, String.valueOf(c.isRequired()));
        tags.setProperty(TAG_CUSTOM_FIELD_DATEFORMAT,
                ITrackerResources.escapeUnicodeString(c.getDateFormat(), false));
        tags.setProperty(TAG_CUSTOM_FIELD_SORTOPTIONS, String.valueOf(c.isSortOptionsByName()));
        tags.setProperty(TAG_CUSTOM_FIELD_LABEL, ITrackerResources
                .escapeUnicodeString(CustomFieldUtilities.getCustomFieldName(c.getId()), false));
        elTmp = getDocumentFactory().createElement(TAG_CUSTOM_FIELD);

        elTmp.addAttribute(ATTR_ID, TAG_CUSTOM_FIELD + c.getId());
        elTmp.addAttribute(ATTR_SYSTEMID, String.valueOf(c.getId()));
        writer.writeOpen(elTmp);
        addCdataPropertyTags(writer, tags);
        if (c.getFieldType() == CustomField.Type.LIST) {
            Element elOption;
            for (CustomFieldValue o : c.getOptions()) {
                elOption = getDocumentFactory().createElement(TAG_CUSTOM_FIELD_OPTION);
                elOption.addAttribute(ATTR_VALUE, ITrackerResources.escapeUnicodeString(o.getValue(), false));
                elOption.add(getDocumentFactory().createCDATA(ITrackerResources
                        .escapeUnicodeString(CustomFieldUtilities.getCustomFieldOptionName(o, null), false)));
                writer.write(elOption);
            }
        }
        writer.writeClose(elTmp);
    }

    writer.writeClose(elCustomField);
}

From source file:org.snipsnap.snip.XMLSnipExport.java

License:Open Source License

public static void store(OutputStream out, List snips, List users, String filter, List ignoreElements,
        File fileStore) {//w  w  w  .j  ava  2  s .  c o m
    try {
        OutputFormat outputFormat = new OutputFormat();
        outputFormat.setEncoding("UTF-8");
        outputFormat.setNewlines(true);
        XMLWriter xmlWriter = new XMLWriter(out, outputFormat);
        Element root = DocumentHelper.createElement("snipspace");
        xmlWriter.writeOpen(root);
        storeUsers(xmlWriter, users);
        storeSnips(xmlWriter, snips, filter, ignoreElements, fileStore);
        xmlWriter.writeClose(root);
        xmlWriter.flush();
    } catch (Exception e) {
        e.printStackTrace();
    }
}