Example usage for org.dom4j.io OutputFormat createPrettyPrint

List of usage examples for org.dom4j.io OutputFormat createPrettyPrint

Introduction

In this page you can find the example usage for org.dom4j.io OutputFormat createPrettyPrint.

Prototype

public static OutputFormat createPrettyPrint() 

Source Link

Document

A static helper method to create the default pretty printing format.

Usage

From source file:org.jetbrains.kotlin.projectsextensions.j2se.buildextender.KotlinBuildExtender.java

License:Apache License

private void addKotlinLibProperty(FileObject buildImpl)
        throws DocumentException, UnsupportedEncodingException, IOException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(buildImpl.toURL());

    List<Element> elements = document.getRootElement().elements("property");

    for (Element el : elements) {
        if (el.attribute("name").getValue().equals("kotlin.lib")) {
            return;
        }//from  w  w w  .  j a  v a  2 s  . c  om
    }

    DefaultElement prop = new DefaultElement("property");
    prop.addAttribute("name", "kotlin.lib");
    prop.addAttribute("value", ProjectUtils.KT_HOME + "lib");

    List content = document.getRootElement().content();
    if (content != null) {
        content.add(0, prop);
    }

    OutputFormat format = OutputFormat.createPrettyPrint();
    FileWriter out = new FileWriter(buildImpl.getPath());
    XMLWriter writer;
    writer = new XMLWriter(out, format);
    writer.write(document);
    writer.close();
    out.close();
}

From source file:org.jetbrains.kotlin.projectsextensions.j2se.buildextender.KotlinBuildExtender.java

License:Apache License

private void addKotlinAnt(FileObject buildImpl)
        throws DocumentException, UnsupportedEncodingException, IOException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(buildImpl.toURL());

    List<Element> elements = document.getRootElement().elements("typedef");
    for (Element el : elements) {
        if (el.attribute("classpath").getValue().equals("${kotlin.lib}/kotlin-ant.jar")) {
            return;
        }//from w w  w.  ja  v  a2s. c  o  m
    }

    DefaultElement typedef = new DefaultElement("typedef");
    typedef.addAttribute("classpath", "${kotlin.lib}/kotlin-ant.jar");
    typedef.addAttribute("resource", "org/jetbrains/kotlin/ant/antlib.xml");

    List content = document.getRootElement().content();
    if (content != null) {
        content.add(0, typedef);
    }

    OutputFormat format = OutputFormat.createPrettyPrint();
    FileWriter out = new FileWriter(buildImpl.getPath());
    XMLWriter writer;
    writer = new XMLWriter(out, format);
    writer.write(document);
    writer.close();
    out.close();
}

From source file:org.jetbrains.kotlin.projectsextensions.j2se.buildextender.KotlinBuildExtender.java

License:Apache License

private void insertWithKotlin(FileObject buildImpl) throws DocumentException, IOException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(buildImpl.toURL());
    Element target = null;//  w ww.ja  v  a 2  s .  c o  m

    List<Element> elements = document.getRootElement().elements("target");
    for (Element el : elements) {
        if (el.attribute("name").getValue().equals("-init-macrodef-javac-with-processors")) {
            target = el;
        }
    }

    if (target == null) {
        return;
    }

    Element macrodef = target.element("macrodef");
    if (macrodef == null) {
        return;
    }

    Element sequential = macrodef.element("sequential");
    if (sequential == null) {
        return;
    }

    Element javac = sequential.element("javac");
    if (javac == null) {
        return;
    }

    if (javac.element("withKotlin") != null) {
        return;
    }

    DefaultElement withKotlin = new DefaultElement("withKotlin");

    List content = javac.content();
    if (content != null) {
        content.add(3, withKotlin);
    }

    OutputFormat format = OutputFormat.createPrettyPrint();
    FileWriter out = new FileWriter(buildImpl.getPath());
    XMLWriter writer;
    writer = new XMLWriter(out, format);
    writer.write(document);
    writer.close();
    out.close();
}

From source file:org.jetbrains.kotlin.projectsextensions.maven.buildextender.PomXmlModifier.java

License:Apache License

private void checkKotlinStdLibDependency() throws DocumentException, IOException {
    File pom = getPOMFile(project);
    if (pom == null) {
        return;//from w  w  w  . j  av a 2  s  .  co m
    }
    SAXReader reader = new SAXReader();
    Document pomDocument = reader.read(pom);

    Element root = pomDocument.getRootElement();
    Element dependencies = root.element("dependencies");
    if (dependencies == null) {
        dependencies = createDependenciesElement(root);
    }

    Element stdlibDependency = null;
    for (Object el : dependencies.elements("dependency")) {
        Element dep = (Element) el;
        Element groupId = dep.element("groupId");
        Element artifactId = dep.element("artifactId");
        if (groupId == null || artifactId == null) {
            continue;
        }
        if (groupId.getText().equals(groupIdName) && artifactId.getText().equals("kotlin-stdlib")) {
            stdlibDependency = dep;
            break;
        }
    }

    if (stdlibDependency == null) {
        createStdlibDependency(dependencies);
    }

    OutputFormat format = OutputFormat.createPrettyPrint();
    FileWriter out = new FileWriter(pom);
    XMLWriter writer;
    writer = new XMLWriter(out, format);
    writer.write(pomDocument);
    out.close();
}

From source file:org.jetbrains.kotlin.projectsextensions.maven.buildextender.PomXmlModifier.java

License:Apache License

private void checkKotlinPlugin() throws DocumentException, IOException {
    File pom = getPOMFile(project);
    if (pom == null) {
        return;/*from   w  ww.ja va 2s  .c  om*/
    }
    SAXReader reader = new SAXReader();
    Document pomDocument = reader.read(pom);

    Element root = pomDocument.getRootElement();
    Element build = root.element("build");
    if (build == null) {
        build = createBuildElement(root);
    }

    Element plugins = build.element("plugins");
    if (plugins == null) {
        plugins = createPluginsElement(build);
    }

    Element plugin = null;
    for (Object el : plugins.elements("plugin")) {
        Element plug = (Element) el;
        Element groupId = plug.element("groupId");
        Element artifactId = plug.element("artifactId");
        if (groupId == null || artifactId == null) {
            continue;
        }
        if (groupId.getText().equals(groupIdName) && artifactId.getText().equals("kotlin-maven-plugin")) {
            plugin = plug;
            break;
        }
    }

    if (plugin != null) {
        return;
    }

    createPluginElement(plugins);

    OutputFormat format = OutputFormat.createPrettyPrint();
    FileWriter out = new FileWriter(pom);
    XMLWriter writer;
    writer = new XMLWriter(out, format);
    writer.write(pomDocument);
    out.close();
}

From source file:org.jfrog.jade.plugins.idea.IdeaXmlWriter.java

License:Apache License

/**
 * Default constructor.//from  w  w  w .j  a va2s.c  o m
 *
 * @param file output file to be written
 */
public IdeaXmlWriter(File file) throws IOException {
    super(new FileWriter(file), OutputFormat.createPrettyPrint());
}

From source file:org.jivesoftware.admin.LdapUserProfile.java

License:Open Source License

/**
 * Saves current configuration as XML/DB properties.
 *//*w  ww .  j  a  v  a2  s  . c  om*/
public void saveProperties() {
    Element vCard = DocumentHelper.createElement(QName.get("vCard", "vcard-temp"));
    Element subelement;

    // Add name
    if (name != null && name.trim().length() > 0) {
        subelement = vCard.addElement("N");
        subelement.addElement("GIVEN").setText(name.trim());
    }
    // Add email
    if (email != null && email.trim().length() > 0) {
        subelement = vCard.addElement("EMAIL");
        subelement.addElement("INTERNET");
        subelement.addElement("USERID").setText(email.trim());
    }
    // Add Full Name
    vCard.addElement("FN").setText(fullName.trim());
    // Add nickname
    if (nickname != null && nickname.trim().length() > 0) {
        vCard.addElement("NICKNAME").setText(nickname.trim());
    }
    // Add birthday
    if (birthday != null && birthday.trim().length() > 0) {
        vCard.addElement("BDAY").setText(birthday.trim());
    }
    // Add photo/avatar
    if (photo != null && photo.trim().length() > 0) {
        Element element = vCard.addElement("PHOTO");
        element.addElement("TYPE").setText("image/jpeg");
        element.addElement("BINVAL").setText(photo.trim());
    }
    // Add home address
    subelement = vCard.addElement("ADR");
    subelement.addElement("HOME");
    if (homeStreet != null && homeStreet.trim().length() > 0) {
        subelement.addElement("STREET").setText(homeStreet.trim());
    }
    if (homeCity != null && homeCity.trim().length() > 0) {
        subelement.addElement("LOCALITY").setText(homeCity.trim());
    }
    if (homeState != null && homeState.trim().length() > 0) {
        subelement.addElement("REGION").setText(homeState.trim());
    }
    if (homeZip != null && homeZip.trim().length() > 0) {
        subelement.addElement("PCODE").setText(homeZip.trim());
    }
    if (homeCountry != null && homeCountry.trim().length() > 0) {
        subelement.addElement("CTRY").setText(homeCountry.trim());
    }
    // Add business address
    subelement = vCard.addElement("ADR");
    subelement.addElement("WORK");
    if (businessStreet != null && businessStreet.trim().length() > 0) {
        subelement.addElement("STREET").setText(businessStreet.trim());
    }
    if (businessCity != null && businessCity.trim().length() > 0) {
        subelement.addElement("LOCALITY").setText(businessCity.trim());
    }
    if (businessState != null && businessState.trim().length() > 0) {
        subelement.addElement("REGION").setText(businessState.trim());
    }
    if (businessZip != null && businessZip.trim().length() > 0) {
        subelement.addElement("PCODE").setText(businessZip.trim());
    }
    if (businessCountry != null && businessCountry.trim().length() > 0) {
        subelement.addElement("CTRY").setText(businessCountry.trim());
    }
    // Add home phone
    if (homePhone != null && homePhone.trim().length() > 0) {
        subelement = vCard.addElement("TEL");
        subelement.addElement("HOME");
        subelement.addElement("VOICE");
        subelement.addElement("NUMBER").setText(homePhone.trim());
    }
    // Add home mobile
    if (homeMobile != null && homeMobile.trim().length() > 0) {
        subelement = vCard.addElement("TEL");
        subelement.addElement("HOME");
        subelement.addElement("CELL");
        subelement.addElement("NUMBER").setText(homeMobile.trim());
    }
    // Add home fax
    if (homeFax != null && homeFax.trim().length() > 0) {
        subelement = vCard.addElement("TEL");
        subelement.addElement("HOME");
        subelement.addElement("FAX");
        subelement.addElement("NUMBER").setText(homeFax.trim());
    }
    // Add home pager
    if (homePager != null && homePager.trim().length() > 0) {
        subelement = vCard.addElement("TEL");
        subelement.addElement("HOME");
        subelement.addElement("PAGER");
        subelement.addElement("NUMBER").setText(homePager.trim());
    }
    // Add business phone
    if (businessPhone != null && businessPhone.trim().length() > 0) {
        subelement = vCard.addElement("TEL");
        subelement.addElement("WORK");
        subelement.addElement("VOICE");
        subelement.addElement("NUMBER").setText(businessPhone.trim());
    }
    // Add business mobile
    if (businessMobile != null && businessMobile.trim().length() > 0) {
        subelement = vCard.addElement("TEL");
        subelement.addElement("WORK");
        subelement.addElement("CELL");
        subelement.addElement("NUMBER").setText(businessMobile.trim());
    }
    // Add business fax
    if (businessFax != null && businessFax.trim().length() > 0) {
        subelement = vCard.addElement("TEL");
        subelement.addElement("WORK");
        subelement.addElement("FAX");
        subelement.addElement("NUMBER").setText(businessFax.trim());
    }
    // Add business pager
    if (businessPager != null && businessPager.trim().length() > 0) {
        subelement = vCard.addElement("TEL");
        subelement.addElement("WORK");
        subelement.addElement("PAGER");
        subelement.addElement("NUMBER").setText(businessPager.trim());
    }
    // Add job title
    if (businessJobTitle != null && businessJobTitle.trim().length() > 0) {
        vCard.addElement("TITLE").setText(businessJobTitle.trim());
    }
    // Add job department
    if (businessDepartment != null && businessDepartment.trim().length() > 0) {
        vCard.addElement("ORG").addElement("ORGUNIT").setText(businessDepartment.trim());
    }
    // Generate content to store in property
    String vcardXML;
    StringWriter writer = new StringWriter();
    OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();
    XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);
    try {
        xmlWriter.write(vCard);
        vcardXML = writer.toString();
    } catch (IOException e) {
        Log.error("Error pretty formating XML", e);
        vcardXML = vCard.asXML();
    }

    StringBuilder sb = new StringBuilder(vcardXML.length());
    sb.append("<![CDATA[").append(vcardXML).append("]]>");
    // Save mapping as an XML property
    JiveGlobals.setProperty("ldap.vcard-mapping", sb.toString());

    // Set that the vcard provider is LdapVCardProvider
    JiveGlobals.setProperty("provider.vcard.className", LdapVCardProvider.class.getName());

    // Save duplicated fields in LdapManager (should be removed in the future)
    LdapManager.getInstance().setNameField(name.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2"));
    LdapManager.getInstance().setEmailField(email.replaceAll("(\\{)([\\d\\D&&[^}]]+)(})", "$2"));

    // Store the DB storage variable in the actual database.
    JiveGlobals.setProperty("ldap.override.avatar", avatarStoredInDB.toString());
}

From source file:org.jivesoftware.openfire.archive.ArchiveIndexer.java

License:Open Source License

/**
 * Loads a property manager for search properties if it isn't already
 * loaded. If an XML file for the search properties isn't already
 * created, it will attempt to make a file with default values.
 *//* w  w w.java  2s .com*/
private void loadPropertiesFile(File searchDir) throws IOException {
    File indexPropertiesFile = new File(searchDir, "indexprops.xml");

    // Make sure the file actually exists. If it doesn't, a new file
    // will be created.
    // If it doesn't exists we have to create it.
    if (!indexPropertiesFile.exists()) {
        org.dom4j.Document doc = DocumentFactory.getInstance()
                .createDocument(DocumentFactory.getInstance().createElement("search"));
        // Now, write out to the file.
        Writer out = null;
        try {
            // Use JDOM's XMLOutputter to do the writing and formatting.
            out = new FileWriter(indexPropertiesFile);
            XMLWriter outputter = new XMLWriter(out, OutputFormat.createPrettyPrint());
            outputter.write(doc);
            outputter.flush();
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch (Exception e) {
                // Ignore.
            }
        }
    }
    indexProperties = new XMLProperties(indexPropertiesFile);
}

From source file:org.jivesoftware.openfire.update.UpdateManager.java

License:Open Source License

/**
 * Saves to conf/server-update.xml information about the latest Openfire release that is
 * available for download./*from  w  ww .  j  a  va  2s  . co m*/
 */
private void saveLatestServerInfo() {
    Element xmlResponse = docFactory.createDocument().addElement("version");
    if (serverUpdate != null) {
        Element component = xmlResponse.addElement("openfire");
        component.addAttribute("latest", serverUpdate.getLatestVersion());
        component.addAttribute("changelog", serverUpdate.getChangelog());
        component.addAttribute("url", serverUpdate.getURL());
    }
    // Write data out to conf/server-update.xml file.
    Writer writer = null;
    try {
        // Create the conf folder if required
        File file = new File(JiveGlobals.getHomeDirectory(), "conf");
        if (!file.exists()) {
            file.mkdir();
        }
        file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf", "server-update.xml");
        // Delete the old server-update.xml file if it exists
        if (file.exists()) {
            file.delete();
        }
        // Create new version.xml with returned data
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
        OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();
        XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);
        xmlWriter.write(xmlResponse);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e1) {
                Log.error(e1.getMessage(), e1);
            }
        }
    }
}

From source file:org.jivesoftware.openfire.update.UpdateManager.java

License:Open Source License

/**
 * Saves to conf/available-plugins.xml the list of plugins that are available
 * at igniterealtime.org./*from  w w  w .j a v a 2 s .  co m*/
 */
private void saveAvailablePluginsInfo() {
    //  XML to store in the file
    Element xml = docFactory.createDocument().addElement("available");
    for (AvailablePlugin plugin : availablePlugins.values()) {
        Element component = xml.addElement("plugin");
        component.addAttribute("name", plugin.getName());
        component.addAttribute("latest", plugin.getLatestVersion());
        component.addAttribute("changelog", plugin.getChangelog());
        component.addAttribute("url", plugin.getURL());
        component.addAttribute("author", plugin.getAuthor());
        component.addAttribute("description", plugin.getDescription());
        component.addAttribute("icon", plugin.getIcon());
        component.addAttribute("minServerVersion", plugin.getMinServerVersion());
        component.addAttribute("readme", plugin.getReadme());
        component.addAttribute("licenseType", plugin.getLicenseType());
        component.addAttribute("fileSize", Long.toString(plugin.getFileSize()));
    }
    // Write data out to conf/available-plugins.xml file.
    Writer writer = null;
    try {
        // Create the conf folder if required
        File file = new File(JiveGlobals.getHomeDirectory(), "conf");
        if (!file.exists()) {
            file.mkdir();
        }
        file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf", "available-plugins.xml");
        // Delete the old version.xml file if it exists
        if (file.exists()) {
            file.delete();
        }
        // Create new version.xml with returned data
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
        OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();
        XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);
        xmlWriter.write(xml);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e1) {
                Log.error(e1.getMessage(), e1);
            }
        }
    }
}