Search in sources :

Example 21 with Content

use of org.jdom2.Content in project jspwiki by apache.

the class AtomFeed method getItems.

private Collection getItems() {
    ArrayList<Element> list = new ArrayList<Element>();
    WikiEngine engine = m_wikiContext.getEngine();
    ServletContext servletContext = null;
    if (m_wikiContext.getHttpRequest() != null)
        servletContext = m_wikiContext.getHttpRequest().getSession().getServletContext();
    for (Iterator i = m_entries.iterator(); i.hasNext(); ) {
        Entry e = (Entry) i.next();
        WikiPage p = e.getPage();
        Element entryEl = getElement("entry");
        // 
        // Mandatory elements
        // 
        entryEl.addContent(getElement("id").setText(getEntryID(e)));
        entryEl.addContent(getElement("title").setAttribute("type", "html").setText(e.getTitle()));
        entryEl.addContent(getElement("updated").setText(DateFormatUtils.formatUTC(p.getLastModified(), RFC3339FORMAT)));
        // 
        // Optional elements
        // 
        entryEl.addContent(getElement("author").addContent(getElement("name").setText(e.getAuthor())));
        entryEl.addContent(getElement("link").setAttribute("rel", "alternate").setAttribute("href", e.getURL()));
        entryEl.addContent(getElement("content").setAttribute("type", "html").setText(e.getContent()));
        if (engine.getAttachmentManager().hasAttachments(p) && servletContext != null) {
            try {
                Collection c = engine.getAttachmentManager().listAttachments(p);
                for (Iterator a = c.iterator(); a.hasNext(); ) {
                    Attachment att = (Attachment) a.next();
                    Element attEl = getElement("link");
                    attEl.setAttribute("rel", "enclosure");
                    attEl.setAttribute("href", engine.getURL(WikiContext.ATTACH, att.getName(), null, true));
                    attEl.setAttribute("length", Long.toString(att.getSize()));
                    attEl.setAttribute("type", getMimeType(servletContext, att.getFileName()));
                    entryEl.addContent(attEl);
                }
            } catch (ProviderException ex) {
            // FIXME: log.info("Can't get attachment data",ex);
            }
        }
        list.add(entryEl);
    }
    return list;
}
Also used : ProviderException(org.apache.wiki.api.exceptions.ProviderException) Element(org.jdom2.Element) WikiPage(org.apache.wiki.WikiPage) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ServletContext(javax.servlet.ServletContext) Collection(java.util.Collection) Attachment(org.apache.wiki.attachment.Attachment) WikiEngine(org.apache.wiki.WikiEngine)

Example 22 with Content

use of org.jdom2.Content in project pom-manipulation-ext by release-engineering.

the class PomIO method write.

private void write(final Project project, final File pom, final Model model) throws ManipulationException {
    try {
        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());
    }
}
Also used : Comment(org.jdom2.Comment) IOException(java.io.IOException) MavenJDOMWriter(org.apache.maven.model.io.jdom.MavenJDOMWriter) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) LineSeparator(org.jdom2.output.LineSeparator) ContentFilter(org.jdom2.filter.ContentFilter) DocumentModifier(org.apache.maven.io.util.DocumentModifier) Content(org.jdom2.Content) Iterator(java.util.Iterator) ManipulationException(org.commonjava.maven.ext.common.ManipulationException)

Example 23 with Content

use of org.jdom2.Content in project qpp-conversion-tool by CMSgov.

the class Converter method transform.

/**
 * Transform the content in a given input stream
 *
 * @param inStream source content
 * @return a transformed representation of the source content
 * @throws XmlException during transform
 */
private JsonWrapper transform(InputStream inStream) {
    Element doc = XmlUtils.parseXmlStream(inStream);
    decoded = XmlDecoderEngine.decodeXml(context, doc);
    JsonWrapper qpp = null;
    if (null != decoded) {
        DEV_LOG.info("Decoded template ID {}", decoded.getType());
        if (!context.isDoDefaults()) {
            DefaultDecoder.removeDefaultNode(decoded.getChildNodes());
        }
        if (context.isDoValidation()) {
            QrdaValidator validator = new QrdaValidator(context);
            details.addAll(validator.validate(decoded));
        }
        if (details.isEmpty()) {
            qpp = encode();
        }
    } else {
        Detail detail = Detail.forErrorCode(ErrorCode.NOT_VALID_QRDA_DOCUMENT.format(Context.REPORTING_YEAR, Context.IG_URL));
        details.add(detail);
    }
    return qpp;
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) QrdaValidator(gov.cms.qpp.conversion.validate.QrdaValidator) Element(org.jdom2.Element) Detail(gov.cms.qpp.conversion.model.error.Detail)

Example 24 with Content

use of org.jdom2.Content in project aws-doc-sdk-examples by awsdocs.

the class SendNotifications method handleVoiceMessage.

public String handleVoiceMessage(String myDom) throws JDOMException, IOException {
    String mobileNum = "";
    List<String> listVal = new ArrayList<>();
    listVal.add("application/json");
    Map<String, List<String>> values = new HashMap<>();
    values.put("Content-Type", listVal);
    ClientOverrideConfiguration config2 = ClientOverrideConfiguration.builder().headers(values).build();
    PinpointSmsVoiceClient client = PinpointSmsVoiceClient.builder().overrideConfiguration(config2).region(Region.US_EAST_1).build();
    SAXBuilder builder = new SAXBuilder();
    Document jdomDocument = builder.build(new InputSource(new StringReader(myDom)));
    org.jdom2.Element root = jdomDocument.getRootElement();
    // get a list of children elements.
    List<org.jdom2.Element> students = root.getChildren("Student");
    for (org.jdom2.Element element : students) {
        mobileNum = element.getChildText("Phone");
        sendVoiceMsg(client, mobileNum);
    }
    client.close();
    return mobileNum;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputSource(org.xml.sax.InputSource) HashMap(java.util.HashMap) ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) PinpointSmsVoiceClient(software.amazon.awssdk.services.pinpointsmsvoice.PinpointSmsVoiceClient)

Example 25 with Content

use of org.jdom2.Content in project jena by apache.

the class GMLWriter method buildPolygon.

private static Element buildPolygon(final Polygon polygon, final String srsName) {
    Element gmlRoot = new Element(polygon.getGeometryType(), GML_NAMESPACE);
    gmlRoot.setAttribute("srsName", srsName);
    if (!polygon.isEmpty()) {
        LineString lineString = polygon.getExteriorRing();
        CustomCoordinateSequence coordSequence = (CustomCoordinateSequence) lineString.getCoordinateSequence();
        // Find exterior shell
        Element exterior = new Element("exterior", GML_NAMESPACE);
        Element exteriorLinearRing = new Element("LinearRing", GML_NAMESPACE);
        Element exteriorPosList = new Element("posList", GML_NAMESPACE);
        exteriorPosList.addContent(convertToGMLText(coordSequence));
        exteriorLinearRing.addContent(exteriorPosList);
        exterior.addContent(exteriorLinearRing);
        gmlRoot.addContent(exterior);
        // Find inner holes
        int interiorRings = polygon.getNumInteriorRing();
        for (int i = 0; i < interiorRings; i++) {
            // flush all content
            Element interior = new Element("interior", GML_NAMESPACE);
            Element interiorLinearRing = new Element("LinearRing", GML_NAMESPACE);
            Element innerPosList = new Element("posList", GML_NAMESPACE);
            LineString innerLineString = polygon.getInteriorRingN(i);
            CustomCoordinateSequence innerCoordSequence = (CustomCoordinateSequence) innerLineString.getCoordinateSequence();
            innerPosList.addContent(convertToGMLText(innerCoordSequence));
            interiorLinearRing.addContent(innerPosList);
            interior.addContent(interiorLinearRing);
            gmlRoot.addContent(interior);
        }
    } else {
    // Do nothing to the GML
    }
    return gmlRoot;
}
Also used : Element(org.jdom2.Element) CustomCoordinateSequence(org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)

Aggregations

Element (org.jdom2.Element)77 Document (org.jdom2.Document)27 IOException (java.io.IOException)18 JDOMException (org.jdom2.JDOMException)16 File (java.io.File)11 MCRException (org.mycore.common.MCRException)11 Content (org.jdom2.Content)10 MCRContent (org.mycore.common.content.MCRContent)10 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)10 XMLOutputter (org.jdom2.output.XMLOutputter)9 SAXBuilder (org.jdom2.input.SAXBuilder)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Attribute (org.jdom2.Attribute)6 MCRPath (org.mycore.datamodel.niofs.MCRPath)6 SAXException (org.xml.sax.SAXException)6 JsonElement (com.google.gson.JsonElement)5 Color (java.awt.Color)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 MCRObject (org.mycore.datamodel.metadata.MCRObject)4