Example usage for org.jdom2 Comment Comment

List of usage examples for org.jdom2 Comment Comment

Introduction

In this page you can find the example usage for org.jdom2 Comment Comment.

Prototype

public Comment(String text) 

Source Link

Document

This creates the comment with the supplied text.

Usage

From source file:org.commonjava.maven.ext.io.PomIO.java

License:Apache License

private void write(final Project project, final File pom, final Model model) throws ManipulationException {
    try {/*from   www  .j  a v  a2 s.  c om*/
        final String manifestInformation = project.isInheritanceRoot() ? ManifestUtils.getManifestInformation()
                : null;

        MavenJDOMWriter mjw = new MavenJDOMWriter(model);

        // We possibly could store the EOL type in the Project when we first read
        // the file but we would then have to do a dual read, then write as opposed
        // to a read, then read + write now.
        LineSeparator ls = determineEOL(pom);
        mjw.setLineSeparator(ls);

        mjw.write(model, pom, new DocumentModifier() {
            @Override
            public void postProcess(final Document doc) {
                // Only add the modified by to the top level pom.
                if (project.isExecutionRoot()) {
                    final Iterator<Content> it = doc.getContent(new ContentFilter(ContentFilter.COMMENT))
                            .iterator();
                    while (it.hasNext()) {
                        final Comment c = (Comment) it.next();

                        if (c.toString().contains(MODIFIED_BY)) {
                            it.remove();
                        }
                    }

                    doc.addContent(Collections.<Content>singletonList(
                            new Comment("\nModified by POM Manipulation Extension for Maven "
                                    + manifestInformation + "\n")));
                }
            }
        });
    } catch (final IOException e) {
        throw new ManipulationException("Failed to read POM for rewrite: %s. Reason: %s", e, pom,
                e.getMessage());
    } catch (final JDOMException e) {
        throw new ManipulationException("Failed to parse POM for rewrite: %s. Reason: %s", e, pom,
                e.getMessage());
    }
}

From source file:org.fnppl.opensdx.xml.Element.java

License:Open Source License

public void addComment(String comment) {
    base.addContent(new Comment(comment));
}

From source file:org.fnppl.opensdx.xml.Element.java

License:Open Source License

public void addCommentFirst(String comment) {
    base.addContent(0, new Comment(comment));
}

From source file:org.fnppl.opensdx.xml.Element.java

License:Open Source License

public void addCommentAfter(String name, String comment) {
    int ind = base.indexOf(base.getChild(name));
    base.addContent(ind + 1, new Comment(comment));
}

From source file:org.isima.carsharing.launcher.Launcher.java

public static void addConfigComment(SettingsDelegate settingsDelegate, File out) {
    try {/*  w ww  .j  a v  a  2s  . co m*/
        SAXBuilder builder = new SAXBuilder();

        Document doc = (Document) builder.build(out);
        Element rootNode = doc.getRootElement();
        Element rootNodeCopy = rootNode.clone();

        doc.removeContent(rootNode);
        rootNodeCopy.detach();

        Comment comment = new Comment(settingsDelegate.usedConfigsToXMLComment());
        doc.addContent(comment);
        doc.addContent(rootNodeCopy);

        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, new FileWriter(out));
    } catch (JDOMException | IOException ex) {
        Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.mycore.restapi.v1.utils.MCRRestAPIObjectsHelper.java

License:Open Source License

public static Response showMCRObject(String pathParamId, String queryParamStyle, UriInfo info) {
    try {/*from  w ww  .  j  av  a2  s .co  m*/
        MCRObject mcrObj = retrieveMCRObject(pathParamId);
        Document doc = mcrObj.createXML();
        Element eStructure = doc.getRootElement().getChild("structure");
        if (queryParamStyle != null && !MCRRestAPIObjects.STYLE_DERIVATEDETAILS.equals(queryParamStyle)) {
            throw new MCRRestAPIException(MCRRestAPIError.create(Response.Status.BAD_REQUEST,
                    "The value of parameter {style} is not allowed.",
                    "Allowed values for {style} parameter are: " + MCRRestAPIObjects.STYLE_DERIVATEDETAILS));
        }

        if (MCRRestAPIObjects.STYLE_DERIVATEDETAILS.equals(queryParamStyle) && eStructure != null) {
            Element eDerObjects = eStructure.getChild("derobjects");
            if (eDerObjects != null) {
                for (Element eDer : (List<Element>) eDerObjects.getChildren("derobject")) {
                    String derID = eDer.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
                    try {
                        MCRDerivate der = MCRMetadataManager
                                .retrieveMCRDerivate(MCRObjectID.getInstance(derID));
                        eDer.addContent(der.createXML().getRootElement().detach());

                        //<mycorederivate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:noNamespaceSchemaLocation="datamodel-derivate.xsd" ID="cpr_derivate_00003760" label="display_image" version="1.3">
                        //  <derivate display="true">

                        eDer = eDer.getChild("mycorederivate").getChild("derivate");
                        eDer.addContent(listDerivateContent(mcrObj,
                                MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derID)), info));
                    } catch (MCRException e) {
                        eDer.addContent(new Comment("Error: Derivate not found."));
                    } catch (IOException e) {
                        eDer.addContent(
                                new Comment("Error: Derivate content could not be listed: " + e.getMessage()));
                    }
                }
            }
        }

        StringWriter sw = new StringWriter();
        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
        try {
            outputter.output(doc, sw);
        } catch (IOException e) {
            throw new MCRRestAPIException(MCRRestAPIError.create(Response.Status.INTERNAL_SERVER_ERROR,
                    "Unable to retrieve MyCoRe object", e.getMessage()));
        }
        return Response.ok(sw.toString()).type("application/xml").build();
    }

    catch (MCRRestAPIException rae) {
        return rae.getError().createHttpResponse();
    }

}

From source file:org.rascalmpl.library.lang.xml.DOM.java

License:Open Source License

private Content nodeToContent(IConstructor n) {
    if (n.getConstructorType() == Factory.Node_element) {
        return nodeToElement(n);
    }/*from  ww w.  j  a v a 2s .  co m*/
    if (n.getConstructorType() == Factory.Node_pi) {
        IString target = (IString) n.get(0);
        IString data = (IString) n.get(1);
        return new ProcessingInstruction(target.getValue(), data.getValue());

    }
    if (n.getConstructorType() == Factory.Node_charRef) {
        IInteger code = (IInteger) n.get(0);
        int c = java.lang.Integer.parseInt(code.getStringRepresentation());
        return new Text(new java.lang.String(Character.toChars(c)));
    }
    if (n.getConstructorType() == Factory.Node_entityRef) {
        return new EntityRef(((IString) n.get(0)).getValue());
    }

    java.lang.String text = ((IString) n.get(0)).getValue();
    if (n.getConstructorType() == Factory.Node_cdata) {
        return new CDATA(text);
    }
    if (n.getConstructorType() == Factory.Node_charData) {
        return new Text(text);
    }
    if (n.getConstructorType() == Factory.Node_comment) {
        return new Comment(text);
    }

    wellformednessError();
    return null;
}

From source file:org.shaman.rpg.editor.project.impl.ModuleBuildFileGenerator.java

private Document generateDoc() {
    Element root = new Element("project");
    root.setAttribute("name", "build-impl-engine");
    root.setAttribute("basedir", "..");
    root.addContent(new Comment("these ant tasks are called from the modules"));

    //add properties
    addProperties(root);/*ww  w  .  ja va 2  s.  c o  m*/
    root.addContent("\n");

    //add custom contents
    root.addContent(customContents);
    root.addContent("\n");

    //add main target
    addMainTarget(root);
    root.addContent("\n");

    //add property init target
    addPropertyInitTarget(root);
    root.addContent("\n");

    //add ant-contrib initializing target
    addTaskefTarget(root);
    root.addContent("\n");

    //add groovy-compile target
    addGroovyCTarget(root);
    root.addContent("\n");

    //add targets
    addTargets(root);

    //create document
    return new Document(root);
}

From source file:par5e.ModuleXML.java

public ModuleXML() {
    Comment comment = new Comment("Generated by PAR5E - Fantasy Grounds Module Parser - Zeus Copyright 2014");

    root = new Element("root");
    root.setAttribute("version", "3.0");
    doc = new Document(root);
    doc.addContent(0, comment);//w w w . java  2s.c o  m

    //doc.setRootElement(root);
}

From source file:password.pwm.config.stored.StoredConfigurationImpl.java

License:Open Source License

public void resetAllPasswordValues(final String comment) {
    for (final Iterator<SettingValueRecord> settingValueRecordIterator = new StoredValueIterator(
            false); settingValueRecordIterator.hasNext();) {
        final SettingValueRecord settingValueRecord = settingValueRecordIterator.next();
        if (settingValueRecord.getSetting().getSyntax() == PwmSettingSyntax.PASSWORD) {
            this.resetSetting(settingValueRecord.getSetting(), settingValueRecord.getProfile(), null);
            if (comment != null && !comment.isEmpty()) {
                final XPathExpression xp = XPathBuilder.xpathForSetting(settingValueRecord.getSetting(),
                        settingValueRecord.getProfile());
                final Element settingElement = (Element) xp.evaluateFirst(document);
                if (settingElement != null) {
                    settingElement.addContent(new Comment(comment));
                }//w  ww .  j a  va 2  s .  co  m
            }
        }
    }

    final String pwdHash = this.readConfigProperty(ConfigurationProperty.PASSWORD_HASH);
    if (pwdHash != null && !pwdHash.isEmpty()) {
        this.writeConfigProperty(ConfigurationProperty.PASSWORD_HASH, comment);
    }
}