Example usage for org.jdom2 Element getContentSize

List of usage examples for org.jdom2 Element getContentSize

Introduction

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

Prototype

@Override
    public int getContentSize() 

Source Link

Usage

From source file:org.artifactory.version.converter.v167.TrashcanConfigConverter.java

License:Open Source License

private void addDefaultConfig(Element rootElement, Namespace namespace) {
    TrashcanConfigDescriptor descriptor = new TrashcanConfigDescriptor();
    Element trashcan = new Element("trashcanConfig", namespace);
    Namespace trashcanConfigNs = trashcan.getNamespace();
    ArrayList<Element> elements = Lists.newArrayList();
    elements.add(new Element("enabled", trashcanConfigNs).setText(String.valueOf(descriptor.isEnabled())));
    elements.add(new Element("retentionPeriodDays", trashcanConfigNs)
            .setText(String.valueOf(descriptor.getRetentionPeriodDays())));
    trashcan.addContent(elements);//from  ww  w . j  ava  2 s. c  o m
    rootElement.addContent(rootElement.getContentSize(), trashcan);
}

From source file:org.artifactory.version.converter.v167.UserLockConfigConverter.java

License:Open Source License

private void addDefaultConfig(Element rootElement, Namespace namespace) {

    Element securityConfigElement = rootElement.getChild("security", namespace);
    if (securityConfigElement == null || securityConfigElement.getChild("userLockPolicy", namespace) != null) {
        return;/*  ww w .j  a  v a  2  s  .  c  o  m*/
    }

    Element userLockPolicyElement = securityConfigElement.getChild("userLockPolicy", namespace);
    if (userLockPolicyElement == null) {
        UserLockPolicy userLockPolicy = new UserLockPolicy();
        userLockPolicyElement = new Element("userLockPolicy", namespace);

        Namespace passwordConfigNs = userLockPolicyElement.getNamespace();
        ArrayList<Element> elements = Lists.newArrayList();
        elements.add(
                new Element("enabled", passwordConfigNs).setText(String.valueOf(userLockPolicy.isEnabled())));
        elements.add(new Element("loginAttempts", passwordConfigNs)
                .setText(String.valueOf(userLockPolicy.getLoginAttempts())));

        userLockPolicyElement.addContent(userLockPolicyElement.getContentSize(), elements);
        securityConfigElement.addContent(securityConfigElement.getContentSize(), userLockPolicyElement);
    }
}

From source file:org.artifactory.version.converter.v168.PasswordPolicyConverter.java

License:Open Source License

@Override
public void convert(Document doc) {
    log.info("Starting user PasswordPolicyConverter conversion");
    Element rootElement = doc.getRootElement();
    Namespace namespace = rootElement.getNamespace();

    Element securityConfigElement = rootElement.getChild("security", namespace);
    if (securityConfigElement == null) {
        securityConfigElement = new Element("security", namespace);
    }/*from  ww  w .j  a  v a 2  s.  c  o m*/

    Element passwordSettings = securityConfigElement.getChild("passwordSettings", namespace);
    if (passwordSettings == null) {
        return;
    }

    Element expirationPolicy = passwordSettings.getChild("expirationPolicy", passwordSettings.getNamespace());
    if (expirationPolicy == null) {
        expirationPolicy = new Element("expirationPolicy", passwordSettings.getNamespace());

        Namespace expirationPolicyNs = expirationPolicy.getNamespace();

        PasswordExpirationPolicy passwordExpirationPolicy = new PasswordExpirationPolicy();

        ArrayList<Element> elements = Lists.newArrayList();
        elements.add(new Element("enabled", expirationPolicyNs)
                .setText(String.valueOf(passwordExpirationPolicy.isEnabled())));
        elements.add(new Element("passwordMaxAge", expirationPolicyNs)
                .setText(String.valueOf(passwordExpirationPolicy.getPasswordMaxAge())));
        elements.add(new Element("notifyByEmail", expirationPolicyNs)
                .setText(String.valueOf(passwordExpirationPolicy.isNotifyByEmail())));

        expirationPolicy.addContent(expirationPolicy.getContentSize(), elements);
        passwordSettings.addContent(passwordSettings.getContentSize(), expirationPolicy);
    }
    log.info("Finished PasswordPolicyConverter conversion");
}

From source file:org.esa.snap.datamodel.metadata.AbstractMetadataIO.java

License:Open Source License

private static void findAbstractedMetadata(final List domChildren, final MetadataElement metadataElem) {
    for (Object aChild : domChildren) {
        if (aChild instanceof Element) {
            final Element child = (Element) aChild;
            final String childName = child.getName();
            if (child.getContentSize() > 0) {
                MetadataElement subElem = metadataElem.getElement(childName);
                if (subElem == null) {
                    subElem = new MetadataElement(childName);
                    metadataElem.addElement(subElem);
                }/*from   w  w  w. ja va  2 s . co  m*/
                findAbstractedMetadata(child.getContent(), subElem);
            } else if (childName.equals(ATTRIB)) {
                loadAttribute(child, metadataElem);
            }
        }
    }
}

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);/*from  ww  w.  j a v a 2  s .  c  om*/
    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);
    } 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.knoxcraft.database.xml.XmlDatabase.java

License:Open Source License

/**
 * Performs a field-by-field comparison for the two given Contents.
 * First they must be of type Element and then the fields are checked against each other.
 * If the number of equal fields does not match the number of child elements ot Content a,
 * this method will return false, true otherwise
 *
 * @param a//from   w  w w.j a v  a 2s . c o  m
 * @param b
 *
 * @return
 */
private boolean elementEquals(Content a, Content b) {
    if (!(b instanceof Element)) {
        return false;
    }
    if (!(a instanceof Element)) {
        return false;
    }
    if (a == b) {
        return true;
    }

    Element elB = (Element) b;
    Element elA = (Element) a;

    if (elA.getContentSize() != elB.getContentSize()) {
        return false;
    }
    int equalHits = 0;

    for (Element el : elA.getChildren()) {
        for (Element other : elB.getChildren()) {
            if (el.getName().equals(other.getName())) {
                if (el.getText().equalsIgnoreCase(other.getText())) {
                    equalHits++;
                }
            }
        }
    }
    return equalHits == elA.getChildren().size();
}

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--;//from w  w  w .  j  av a2  s. c  o m
        }
    }
}

From source file:org.mycore.frontend.editor.MCREditorDefReader.java

License:Open Source License

/**
 * Recursively resolves references by the @ref attribute and
 * replaces them with the referenced component.
 *///from w w  w.j  av a  2 s  .  c o m
private void resolveReferences() {
    for (Iterator<Element> it = referencing2ref.keySet().iterator(); it.hasNext();) {
        Element referencing = it.next();
        String id = referencing2ref.get(referencing);
        LOGGER.debug("Resolving reference to " + id);

        Element found = id2component.get(id);
        if (found == null) {
            String msg = "Reference to component " + id + " could not be resolved";
            throw new MCRConfigurationException(msg);
        }

        String name = referencing.getName();
        referencing.removeAttribute("ref");
        it.remove();

        if (name.equals("cell") || name.equals("repeater")) {
            if (found.getParentElement().getName().equals("components")) {
                referencing.addContent(0, found.detach());
            } else {
                referencing.addContent(0, (Element) found.clone());
            }
        } else if (name.equals("panel")) {
            if (referencing2ref.containsValue(id)) {
                referencing.addContent(0, found.cloneContent());
            } else {
                found.detach();
                List<Content> content = found.getContent();
                for (int i = 0; !content.isEmpty(); i++) {
                    Content child = content.remove(0);
                    referencing.addContent(i, child);
                }
            }
        } else if (name.equals("include")) {
            Element parent = referencing.getParentElement();
            int pos = parent.indexOf(referencing);
            referencing.detach();

            if (referencing2ref.containsValue(id)) {
                parent.addContent(pos, found.cloneContent());
            } else {
                found.detach();
                List<Content> content = found.getContent();
                for (int i = pos; !content.isEmpty(); i++) {
                    Content child = content.remove(0);
                    parent.addContent(i, child);
                }
            }
        }
    }

    Element components = editor.getChild("components");
    String root = components.getAttributeValue("root");

    for (int i = 0; i < components.getContentSize(); i++) {
        Content child = components.getContent(i);
        if (!(child instanceof Element)) {
            continue;
        }
        if (((Element) child).getName().equals("headline")) {
            continue;
        }
        if (!root.equals(((Element) child).getAttributeValue("id"))) {
            components.removeContent(i--);
        }
    }
}

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));
    }/*from w  w  w  .  j  av  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.elements.YTask.java

License:Open Source License

public synchronized boolean t_complete(YPersistenceManager pmgr, YIdentifier childID,
        Document decompositionOutputData)
        throws YDataStateException, YStateException, YQueryException, YPersistenceException {
    if (t_isBusy()) {
        YSpecification spec = _net.getSpecification();
        YDataValidator validator = spec.getDataValidator();
        validateOutputs(validator, decompositionOutputData);

        for (String query : getQueriesForTaskCompletion()) {
            if (ExternalDBGatewayFactory.isExternalDBMappingExpression(query)) {
                AbstractExternalDBGateway gateway = ExternalDBGatewayFactory.getInstance(query);
                updateExternalFromTaskCompletion(gateway, query, decompositionOutputData);
                continue;
            }/*from w w w  . ja  va2s. c om*/

            String localVarThatQueryResultGetsAppliedTo = getMIOutputAssignmentVar(query);
            Element queryResultElement = evaluateTreeQuery(query, decompositionOutputData);

            //debugging method call
            generateCompletingReport1(query, decompositionOutputData, queryResultElement);

            if (queryResultElement == null) {
                throw new YDataQueryException(query, queryResultElement, null,
                        "The result of the output query (" + query + ") is null");
            }

            // handle empty complex type flag elements
            if (queryResultElement.getContentSize() == 0) {
                handleEmptyComplexTypeFlagOutput(decompositionOutputData, queryResultElement, query,
                        localVarThatQueryResultGetsAppliedTo);
            }

            if (query.equals(getPreJoiningMIQuery())) {
                _groupedMultiInstanceOutputData.getRootElement().addContent(queryResultElement.clone());
            } else {
                _localVariableNameToReplaceableOutputData.put(localVarThatQueryResultGetsAppliedTo,
                        queryResultElement);
            }

            //Now we check that the resulting transformation produced data according
            //to the net variable's type.
            if (spec.getSchemaVersion().isSchemaValidating() && (!query.equals(getPreJoiningMIQuery()))) {
                YVariable var = _net.getLocalOrInputVariable(localVarThatQueryResultGetsAppliedTo);
                try {
                    Element tempRoot = new Element(_decompositionPrototype.getID());
                    tempRoot.addContent(queryResultElement.clone());
                    /**
                     * MF: Skip schema checking if we have an empty XQuery result to allow us to effectively blank-out
                     * a net variable.
                     */
                    if ((queryResultElement.getChildren().size() != 0
                            || (queryResultElement.getContent().size() != 0))) {
                        validator.validate(var, tempRoot, getID());
                    }
                } catch (YDataValidationException e) {
                    YDataStateException f = new YDataStateException(query,
                            decompositionOutputData.getRootElement(), validator.getSchema(), queryResultElement,
                            e.getErrors(), getID(),
                            "BAD PROCESS DEFINITION. Data extraction failed schema validation at task completion.");
                    f.setStackTrace(e.getStackTrace());
                    throw f;
                }
                generateCompletingReport2(queryResultElement, localVarThatQueryResultGetsAppliedTo, query,
                        decompositionOutputData);
            }
        }
        _mi_executing.removeOne(pmgr, childID);
        _mi_complete.add(pmgr, childID);
        if (t_isExitEnabled()) {
            t_exit(pmgr);
            return true;
        }
        return false;
    } else {
        throw new RuntimeException("This task [" + (getName() != null ? getName() : getID())
                + "] is not active, and therefore cannot be completed.");
    }
}