Example usage for org.jdom2 Content getCType

List of usage examples for org.jdom2 Content getCType

Introduction

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

Prototype

public final CType getCType() 

Source Link

Document

All content has an enumerated type expressing the type of content.

Usage

From source file:org.esa.s2tbx.dataio.s2.gml.GmlFilter.java

License:Open Source License

public Pair<String, List<EopPolygon>> parse(InputStream stream) {
    SAXBuilder builder = new SAXBuilder();
    Document jdomDoc = null;// www .jav a  2 s . c  o  m

    try {
        jdomDoc = builder.build(stream);

        //get the root element
        Element web_app = jdomDoc.getRootElement();
        String maskEpsg = "";

        Namespace gml = Namespace.getNamespace("http://www.opengis.net/gml/3.2");
        Namespace eop = Namespace.getNamespace("http://www.opengis.net/eop/2.0");

        List<Element> targeted = web_app.getChildren("boundedBy", gml);
        if (!targeted.isEmpty()) {
            Element aEnvelope = targeted.get(0).getChild("Envelope", gml);
            if (aEnvelope != null) {
                maskEpsg = aEnvelope.getAttribute("srsName").getValue();
            }
        }

        List<EopPolygon> recoveredGeometries = new ArrayList<>();

        IteratorIterable<Content> contents = web_app.getDescendants();
        while (contents.hasNext()) {
            Content web_app_content = contents.next();
            if (!web_app_content.getCType().equals(CType.Text)
                    && !web_app_content.getCType().equals(CType.Comment)) {
                boolean withGml = (web_app_content.getNamespacesInScope().get(0).getPrefix().contains("gml"));
                if (withGml) {
                    boolean parentNotGml = !(web_app_content.getParentElement().getNamespace().getPrefix()
                            .contains("gml"));
                    if (parentNotGml) {
                        Element capturedElement = (Element) web_app_content;
                        Attribute attr = null;
                        String polygonId = "";
                        String typeId = "";
                        if (capturedElement.getName().contains("Polygon")) {
                            attr = capturedElement.getAttribute("id", gml);
                            if (attr != null) {
                                polygonId = attr.getValue();
                                if (polygonId.indexOf('.') != -1) {
                                    typeId = polygonId.substring(0, polygonId.indexOf('.'));
                                }
                            }
                        }

                        Document newDoc = new Document(capturedElement.clone().detach());

                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        xmlOutput.output(newDoc, baos);
                        String replacedContent = baos.toString().replace("/www.opengis.net/gml/3.2",
                                "/www.opengis.net/gml");

                        InputStream ois = new ByteArrayInputStream(replacedContent.getBytes());

                        List<Polygon> pols = streamParseGML3(ois);
                        for (Polygon pol : pols) {
                            recoveredGeometries.add(new EopPolygon(polygonId, typeId, pol));
                        }
                    }
                }

            }
        }

        return new Pair<String, List<EopPolygon>>(maskEpsg, recoveredGeometries);
    } catch (JDOMException e) {
        // {@report "parse xml problem !"}
    } catch (IOException e) {
        // {@report "IO problem !"}
    }

    return new Pair<String, List<EopPolygon>>("", new ArrayList<>());
}

From source file:org.kdp.word.transformer.ListParagraphTransformer.java

License:Apache License

private void normalizeListItemText(Element el) {
    for (Content co : el.getContent()) {
        if (co.getCType() == CType.Text) {
            Text tco = (Text) co;
            String text = tco.getText().trim();
            tco.setText(text + " ");
        }//from   w w  w . j av a2  s.c  o  m
    }
}

From source file:org.kdp.word.transformer.ListParagraphTransformer.java

License:Apache License

private boolean processItemMarker(Element liItem) {
    String first = "";
    int cosize = liItem.getContentSize();
    Content co = liItem.getContent(0);
    if (co.getCType() == CType.Text) {
        Text text = (Text) co;
        String value = text.getText();
        int index = value.indexOf(" ");
        first = value.substring(0, index);
        value = value.substring(index + 1);
        text.setText(value);/*from w  w  w  .  ja  v a2 s  . co  m*/
    } else if (cosize > 1 && co.getCType() == CType.Element) {
        Element el = (Element) co;
        first = el.getText();
        el.getParent().removeContent(co);
    }
    return first.endsWith(".");
}

From source file:ru.iteco.xmldoc.Config.java

License:Open Source License

/**
 *    ? element.// ww w.  j  a v  a 2 s  . c o m
 * ? ? ,  null.
 *
 * @param element
 * @return
 */
protected static String getPreviousComment(Element element) {
    //? ?    
    Element parent = element.getParentElement();
    //?  ?  
    int index = parent.indexOf(element);

    // ""   ?,   ?-
    for (int i = index - 1; i > 0; i--) {
        //? 
        Content prev = parent.getContent(i);
        //? ?  ? - ?, , ? /??
        if (prev.getCType().equals(Content.CType.Text))
            continue;
        //? ?  -  ,  ?,  
        else if (prev.getCType().equals(Content.CType.Comment))
            return prev.getValue();
        // ?,  ?  ,   ?  ? ?. .
        else
            return "";
    }
    //   ?    .
    return "";
}