Example usage for org.jdom2 Element getContent

List of usage examples for org.jdom2 Element getContent

Introduction

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

Prototype

@Override
    public Content getContent(final int index) 

Source Link

Usage

From source file:org.gemoc.xdsmlframework.ide.ui.builder.pde.PluginXMLHelper.java

License:Open Source License

public Element updateXDSMLDefinitionInExtensionPoint(Element extensionPoint, String xDSMLName) {
    Element result;//www  .j  a v a 2  s  .c  o  m
    List<Element> elements = extensionPoint.getContent(
            new ElementFilter(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF));
    if (elements.size() == 0) {
        // create extension point
        result = new Element(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF);
        extensionPoint.addContent(result);
    } else {
        result = elements.get(0);
    }
    result.setAttribute("name", xDSMLName);
    return result;
}

From source file:org.gemoc.xdsmlframework.ide.ui.builder.pde.PluginXMLHelper.java

License:Open Source License

public Element updateXDSMLDefinitionAttributeInExtensionPoint(Element extensionPoint, String atributeName,
        String value) {//from  w ww  . j ava 2s . c  om
    Element result;
    List<Element> elements = extensionPoint.getContent(
            new ElementFilter(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF));
    if (elements.size() == 0) {
        // create extension point
        result = new Element(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF);
        extensionPoint.addContent(result);
    } else {
        result = elements.get(0);
    }
    result.setAttribute(atributeName, value);
    return result;
}

From source file:org.gemoc.xdsmlframework.ide.ui.builder.pde.PluginXMLHelper.java

License:Open Source License

public String getXDSMLDefinitionAttributeInExtensionPointValue(Element extensionPoint, String atributeName) {
    Element result;//from  w w  w.j a  va2  s  .c om
    List<Element> elements = extensionPoint.getContent(
            new ElementFilter(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF));
    if (elements.size() == 0) {
        // create extension point
        result = new Element(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF);
        extensionPoint.addContent(result);
    } else {
        result = elements.get(0);
    }
    return result.getAttributeValue(atributeName);
}

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 . j a  va  2 s  . c om
    } 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:org.mycore.frontend.editor.MCREditorDefReader.java

License:Open Source License

private void resolveChildren(Element parent) {
    for (int i = 0; i < parent.getContentSize(); i++) {
        Content child = parent.getContent(i);
        if (child instanceof Element && resolveIncludes((Element) child)) {
            i--;// w w  w.  j a v  a2 s  .c  o m
        }
    }
}

From source file:org.openconcerto.xml.JDOM2Utils.java

License:Open Source License

/**
 * Get the filtered content of an element, optionnaly merging adjacent {@link Text}. Adjacent
 * text can only happen programmatically.
 * //from   w  w w.j a  v  a  2 s  . c  o m
 * @param elem the parent.
 * @param pred which content to return.
 * @param mergeText <code>true</code> if adjacent Text should be merged into one,
 *        <code>false</code> to leave the list as it is.
 * @return the filtered content (not supportting {@link Iterator#remove()}).
 */
public static Iterator<Content> getContent(final Element elem, final IPredicate<? super Content> pred,
        final boolean mergeText) {
    final Iterator<Content> iter = (Iterator<Content>) elem.getContent(new AbstractFilter<Content>() {
        @Override
        public Content filter(Object obj) {
            final Content c = (Content) obj;
            return pred.evaluateChecked(c) ? c : null;
        }
    }).iterator();
    if (!mergeText)
        return iter;

    return new Iterator<Content>() {

        private Content next = null;

        @Override
        public boolean hasNext() {
            return this.next != null || iter.hasNext();
        }

        @Override
        public Content next() {
            if (this.next != null) {
                final Content res = this.next;
                this.next = null;
                return res;
            }

            Content res = iter.next();
            assert res != null;
            if (res instanceof Text && iter.hasNext()) {
                this.next = iter.next();
                Text concatText = null;
                while (this.next instanceof Text) {
                    if (concatText == null) {
                        concatText = new Text(res.getValue());
                    }
                    concatText.append((Text) this.next);
                    this.next = iter.hasNext() ? iter.next() : null;
                }
                assert this.next != null;
                if (concatText != null)
                    res = concatText;
            }

            return res;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}

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

License:Open Source License

private IConstructor convertElement(Element e, boolean trim) {
    IListWriter kids = vf.listWriter(Factory.Node);
    for (Object o : e.getAttributes()) {
        Attribute attr = (Attribute) o;
        IString key = vf.string(attr.getName());
        IString val = vf.string(attr.getValue());

        kids.insert(vf.constructor(Factory.Node_attribute, convertNamespace(attr.getNamespace()), key, val));
    }//www .  j a  v  a  2 s.c  o  m

    int len = e.getContentSize();
    for (int i = 0; i < len; i++) {
        try {
            kids.append(convertContent(e.getContent(i), trim));
        } catch (Skip c) { // Ugh, terrible, but I'm in hurry
            continue;
        }
    }

    IString name = vf.string(e.getName());
    return vf.constructor(Factory.Node_element, convertNamespace(e.getNamespace()), name, kids.done());
}

From source file:org.yawlfoundation.yawl.engine.interfce.Marshaller.java

License:Open Source License

public static WorkItemRecord unmarshalWorkItem(Element workItemElement) {
    if (workItemElement == null)
        return null;

    WorkItemRecord wir;/*from www .ja  v a 2  s .c o m*/
    String status = workItemElement.getChildText("status");
    String caseID = workItemElement.getChildText("caseid");
    String taskID = workItemElement.getChildText("taskid");
    String specURI = workItemElement.getChildText("specuri");
    String enablementTime = workItemElement.getChildText("enablementTime");
    if (caseID != null && taskID != null && specURI != null && enablementTime != null && status != null) {

        wir = new WorkItemRecord(caseID, taskID, specURI, enablementTime, status);

        wir.setExtendedAttributes(unmarshalWorkItemAttributes(workItemElement));
        wir.setUniqueID(workItemElement.getChildText("uniqueid"));
        wir.setTaskName(workItemElement.getChildText("taskname"));
        wir.setDocumentation(workItemElement.getChildText("documentation"));
        wir.setAllowsDynamicCreation(workItemElement.getChildText("allowsdynamiccreation"));
        wir.setRequiresManualResourcing(workItemElement.getChildText("requiresmanualresourcing"));
        wir.setCodelet(workItemElement.getChildText("codelet"));
        wir.setDeferredChoiceGroupID(workItemElement.getChildText("deferredChoiceGroupID"));
        wir.setSpecVersion(workItemElement.getChildText("specversion"));
        wir.setFiringTime(workItemElement.getChildText("firingTime"));
        wir.setStartTime(workItemElement.getChildText("startTime"));
        wir.setCompletionTimeMs(workItemElement.getChildText("completionTime"));
        wir.setEnablementTimeMs(workItemElement.getChildText("enablementTimeMs"));
        wir.setFiringTimeMs(workItemElement.getChildText("firingTimeMs"));
        wir.setStartTimeMs(workItemElement.getChildText("startTimeMs"));
        wir.setCompletionTimeMs(workItemElement.getChildText("completionTimeMs"));
        wir.setTimerTrigger(workItemElement.getChildText("timertrigger"));
        wir.setTimerExpiry(workItemElement.getChildText("timerexpiry"));
        wir.setStartedBy(workItemElement.getChildText("startedBy"));
        wir.setTag(workItemElement.getChildText("tag"));
        wir.setCustomFormURL(workItemElement.getChildText("customform"));

        String specid = workItemElement.getChildText("specidentifier");
        if (specid != null)
            wir.setSpecIdentifier(specid);

        String resStatus = workItemElement.getChildText("resourceStatus");
        if (resStatus != null)
            wir.setResourceStatus(resStatus);

        Element data = workItemElement.getChild("data");
        if ((null != data) && (data.getContentSize() > 0))
            wir.setDataList((Element) data.getContent(0));

        Element updateddata = workItemElement.getChild("updateddata");
        if ((null != updateddata) && (updateddata.getContentSize() > 0))
            wir.setUpdatedData((Element) updateddata.getContent(0));

        Element logPredicate = workItemElement.getChild("logPredicate");
        if (logPredicate != null) {
            wir.setLogPredicateStarted(logPredicate.getChildText("start"));
            wir.setLogPredicateCompletion(logPredicate.getChildText("completion"));
        }

        return wir;
    }
    throw new IllegalArgumentException("Input element could not be parsed.");
}

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

License:Open Source License

/**
 *    ? element./*from ww  w . j av a2s  .  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 "";
}