Example usage for org.jdom2 Element removeChild

List of usage examples for org.jdom2 Element removeChild

Introduction

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

Prototype

public boolean removeChild(final String cname, final Namespace ns) 

Source Link

Document

This removes the first child element (one level deep) with the given local name and belonging to the given namespace.

Usage

From source file:org.artifactory.version.converter.v169.PasswordMaxAgeConverter.java

License:Open Source License

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

    Element securityConfigElement = rootElement.getChild("security", namespace);
    if (securityConfigElement != null) {
        Element passwordSettings = securityConfigElement.getChild("passwordSettings", namespace);
        if (passwordSettings != null) {
            Element expirationPolicy = passwordSettings.getChild("expirationPolicy", namespace);
            if (expirationPolicy != null) {
                String passwordMaxAge = String.valueOf(new PasswordExpirationPolicy().getPasswordMaxAge());
                if (expirationPolicy.getChild("expiresIn", namespace) != null) {
                    passwordMaxAge = expirationPolicy.getChildText("expiresIn", namespace);
                    expirationPolicy.removeChild("expiresIn", namespace);
                }//from   w  w w . ja  va2 s.  c  o  m
                if (expirationPolicy.getChild("passwordMaxAge", namespace) == null) {
                    expirationPolicy.addContent(3,
                            new Element("passwordMaxAge", namespace).setText(passwordMaxAge));
                }
            }
        }
    }
    log.info("Finished PasswordMaxAgeConverter conversion");
}

From source file:org.yawlfoundation.yawl.unmarshal.YMarshal.java

License:Open Source License

/**
 * Builds a list of specification objects from a XML string.
 * @param specStr the XML string describing the specification set
 * @param schemaValidate when true, will cause the specifications to be
 * validated against schema while being parsed
 * @return a list of YSpecification objects taken from the XML string.
 * @throws YSyntaxException if a parsed specification doesn't validate against
 * schema//  w w w  .  ja v  a  2 s  . c  o m
 */
public static List<YSpecification> unmarshalSpecifications(String specStr, boolean schemaValidate)
        throws YSyntaxException {

    List<YSpecification> result = null;

    // first check if the xml string is well formed and build a document
    Document document = JDOMUtil.stringToDocument(specStr);
    if (document != null) {
        Element specificationSetEl = document.getRootElement();
        YSchemaVersion version = getVersion(specificationSetEl);
        Namespace ns = specificationSetEl.getNamespace();

        // strip layout element, if any (the engine doesn't use it)
        specificationSetEl.removeChild("layout", ns);

        // now check the specification file against its respective schema
        if (schemaValidate) {
            SchemaHandler validator = new SchemaHandler(version.getSchemaURL());
            if (!validator.compileAndValidate(specStr)) {
                throw new YSyntaxException(" The specification file failed to verify against YAWL's Schema:\n"
                        + validator.getConcatenatedMessage());
            }
        }

        // now build a set of specifications - verification has not yet occurred.
        result = buildSpecifications(specificationSetEl, ns, version);
    } else {
        throw new YSyntaxException("Invalid XML specification.");
    }
    return result;
}