org.jdom2.filter.ElementFilter Java Examples

The following examples show how to use org.jdom2.filter.ElementFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoConfigMigrationIntegrationTest.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRemoveAllLuauConfigurationFromConfig() throws Exception {
    String configString =
            "<cruise schemaVersion='66'>"
                    + "<server siteUrl='https://hostname'>"
                    + "<security>"
                    + "      <luau url='https://luau.url.com' clientKey='0d010cf97ec505ee3788a9b5b8cf71d482c394ae88d32f0333' authState='authorized' />"
                    + "      <ldap uri='ldap' managerDn='managerDn' encryptedManagerPassword='+XhtUNvVAxJdHGF4qQGnWw==' searchFilter='(sAMAccountName={0})'>"
                    + "        <bases>"
                    + "          <base value='ou=Enterprise,ou=Principal,dc=corporate,dc=thoughtworks,dc=com' />"
                    + "        </bases>"
                    + "      </ldap>"
                    + "      <roles>"
                    + "         <role name='luau-role'><groups><luauGroup>luau-group</luauGroup></groups></role>"
                    + "         <role name='ldap-role'><users><user>some-user</user></users></role>"
                    + "</roles>"
                    + "</security>"
                    + "</server>"
                    + "</cruise>";

    String migratedContent = migrateXmlString(configString, 66);
    Document document = new SAXBuilder().build(new StringReader(migratedContent));

    assertThat(document.getDescendants(new ElementFilter("luau")).hasNext()).isFalse();
    assertThat(document.getDescendants(new ElementFilter("groups")).hasNext()).isFalse();
}
 
Example #2
Source File: MCRWCMSDefaultSectionProvider.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
public JsonArray toJSON(Element rootElement) {
    JsonArray sectionArray = new JsonArray();
    for (Element section : rootElement.getChildren(MyCoReWebPageProvider.XML_SECTION)) {
        // get infos of element
        String title = section.getAttributeValue(MyCoReWebPageProvider.XML_TITLE);
        String lang = section.getAttributeValue(MyCoReWebPageProvider.XML_LANG, Namespace.XML_NAMESPACE);
        String data = null;
        if (section.getContent(new ElementFilter()).size() > 1) {
            Element div = new Element("div");
            while (section.getChildren().size() > 0) {
                div.addContent(section.getChildren().get(0).detach());
            }
            section.addContent(div);
        }
        try {
            data = getContent(section);
        } catch (IOException ioExc) {
            LOGGER.error("while reading section data.", ioExc);
            continue;
        }

        // create json object
        JsonObject jsonObject = new JsonObject();
        if (title != null && !title.equals("")) {
            jsonObject.addProperty(JSON_TITLE, title);
        }
        if (lang != null && !lang.equals("")) {
            jsonObject.addProperty(JSON_LANG, lang);
        }
        String invalidElementName = validateElement(section);
        if (invalidElementName != null) {
            jsonObject.addProperty("hidden", "true");
            jsonObject.addProperty("invalidElement", invalidElementName);
        }
        jsonObject.addProperty(JSON_DATA, data);
        // add to array
        sectionArray.add(jsonObject);
    }
    return sectionArray;
}
 
Example #3
Source File: NmasResponseSet.java    From ldapchai with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ChallengeSet parseNmasUserResponseXML( final String str )
        throws IOException, JDOMException, ChaiValidationException
{
    final List<Challenge> returnList = new ArrayList<Challenge>();

    final Reader xmlreader = new StringReader( str );
    final SAXBuilder builder = new SAXBuilder();
    final Document doc = builder.build( xmlreader );

    final Element rootElement = doc.getRootElement();
    final int minRandom = StringHelper.convertStrToInt( rootElement.getAttributeValue( "RandomQuestions" ), 0 );

    final String guidValue;
    {
        final Attribute guidAttribute = rootElement.getAttribute( "GUID" );
        guidValue = guidAttribute == null ? null : guidAttribute.getValue();
    }

    for ( Iterator iter = doc.getDescendants( new ElementFilter( "Challenge" ) ); iter.hasNext(); )
    {
        final Element loopQ = ( Element ) iter.next();
        final int maxLength = StringHelper.convertStrToInt( loopQ.getAttributeValue( "MaxLength" ), 255 );
        final int minLength = StringHelper.convertStrToInt( loopQ.getAttributeValue( "MinLength" ), 2 );
        final String defineStrValue = loopQ.getAttributeValue( "Define" );
        final boolean adminDefined = "Admin".equalsIgnoreCase( defineStrValue );
        final String typeStrValue = loopQ.getAttributeValue( "Type" );
        final boolean required = "Required".equalsIgnoreCase( typeStrValue );
        final String challengeText = loopQ.getText();

        final Challenge challenge = new ChaiChallenge( required, challengeText, minLength, maxLength, adminDefined, 0, false );
        returnList.add( challenge );
    }

    return new ChaiChallengeSet( returnList, minRandom, null, guidValue );
}
 
Example #4
Source File: MCRIncludeHandler.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
private Optional<Element> findDescendant(Element container, String id) {
    IteratorIterable<Element> descendants = container.getDescendants(new ElementFilter());
    return StreamSupport.stream(descendants.spliterator(), false)
        .filter(e -> hasOrIncludesID(e, id)).findFirst();
}
 
Example #5
Source File: MCRRSSFeedImporter.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
/** If mods:genre was not mapped by conversion/import function, ignore this publication and do not import */
private static boolean shouldIgnore(Element publication) {
    return !publication.getDescendants(new ElementFilter("genre", MCRConstants.MODS_NAMESPACE)).hasNext();
}
 
Example #6
Source File: MCRQLSearchUtils.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Build MCRQuery from editor XML input
 */
public static MCRQuery buildFormQuery(Element root) {
    Element conditions = root.getChild("conditions");

    if (conditions.getAttributeValue("format", "xml").equals("xml")) {
        Element condition = conditions.getChildren().get(0);
        renameElements(condition);

        // Remove conditions without values
        List<Element> empty = new ArrayList<>();
        for (Iterator<Element> it = conditions.getDescendants(new ElementFilter("condition")); it.hasNext();) {
            Element cond = it.next();
            if (cond.getAttribute("value") == null) {
                empty.add(cond);
            }
        }

        // Remove empty sort conditions
        Element sortBy = root.getChild("sortBy");
        if (sortBy != null) {
            for (Element field : sortBy.getChildren("field")) {
                if (field.getAttributeValue("name", "").length() == 0) {
                    empty.add(field);
                }
            }
        }

        for (int i = empty.size() - 1; i >= 0; i--) {
            empty.get(i).detach();
        }

        if (sortBy != null && sortBy.getChildren().size() == 0) {
            sortBy.detach();
        }

        // Remove empty returnFields
        Element returnFields = root.getChild("returnFields");
        if (returnFields != null && returnFields.getText().length() == 0) {
            returnFields.detach();
        }
    }

    return MCRQuery.parseXML(root.getDocument());
}