Example usage for org.jdom2.filter ElementFilter ElementFilter

List of usage examples for org.jdom2.filter ElementFilter ElementFilter

Introduction

In this page you can find the example usage for org.jdom2.filter ElementFilter ElementFilter.

Prototype

public ElementFilter(Namespace namespace) 

Source Link

Document

Select only the Elements with the supplied Namespace.

Usage

From source file:appmain.AppMain.java

private List<String> readXMLData(File xml) {
    try {//from  ww  w .j  a  va2  s.  c  om
        List<String> transactions = new ArrayList<>();

        Document xmlDoc = jdomBuilder.build(xml);
        Element report = xmlDoc.getRootElement();

        ElementFilter filter = new ElementFilter("G_TR");
        Iterator<Element> c = report.getDescendants(filter);
        while (c.hasNext()) {
            Element e = c.next();
            transactions.add(processTransactionElement(e));
        }
        return transactions;
    } catch (JDOMException | IOException ex) {
        JOptionPane.showMessageDialog(null, "Hiba az XML fjl feldolgozsa kzben!\n"
                + ExceptionUtils.getStackTrace(ex) + "Fjl: " + xml.getAbsolutePath(), "Hiba",
                JOptionPane.ERROR_MESSAGE);
    }
    return null;
}

From source file:com.musala.cron.RefreshDbTask.java

License:Apache License

@Scheduled(fixedRate = 300000)
@Transactional/* www . java 2  s .  co m*/
public void printMe() {
    logger.info("Cron task is started");

    for (Site rssFeedSite : siteService.findAll()) {
        logger.info("--------------> Reading information for site: " + rssFeedSite.getRssLink());
        SAXBuilder builder = new SAXBuilder();
        Document doc = null;

        try {
            doc = builder.build(new URL(rssFeedSite.getRssLink()));
            if (rssFeedSite.getLastVisitDateTag() != null) {
                Element root = doc.getRootElement();
                ElementFilter filter = new ElementFilter(rssFeedSite.getLastVisitDateTag());

                String currentLastVisitedDate = null;

                for (Element c : root.getDescendants(filter)) {
                    currentLastVisitedDate = c.getTextNormalize();
                }

                if (currentLastVisitedDate != null
                        && currentLastVisitedDate.equals(rssFeedSite.getLastVisitDate())) {
                    logger.info("--------------> Rss {} is not changed", rssFeedSite.getRssLink());
                } else {
                    logger.info("--------------> Rss {} is changed", rssFeedSite.getRssLink());
                    rssFeedSite.setLastVisitDate(currentLastVisitedDate);
                    subject.processRss(rssFeedSite);
                }
            }
        } catch (JDOMException | IOException e) {
            logger.warn("Error occurred during reading of rss", e);
        }
    }
}

From source file:com.novell.ldapchai.impl.edir.NmasResponseSet.java

License:Open Source License

static List<Challenge> parseNmasPolicyXML(final String str, final Locale locale)
        throws IOException, JDOMException {
    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 boolean required = doc.getRootElement().getName().equals("RequiredQuestions");

    for (Iterator qIter = doc.getDescendants(new ElementFilter("Question")); qIter.hasNext();) {
        final Element loopQ = (Element) qIter.next();
        final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255);
        final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 1);

        final String challengeText = readDisplayString(loopQ, locale);

        final Challenge challenge = new ChaiChallenge(required, challengeText, minLength, maxLength, true, 0,
                false);/*www .j  a va  2s .  c o  m*/
        returnList.add(challenge);
    }

    for (Iterator iter = doc.getDescendants(new ElementFilter("UserDefined")); 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"), 1);
        final Challenge challenge = new ChaiChallenge(required, null, minLength, maxLength, false, 0, false);
        returnList.add(challenge);
    }

    return returnList;
}

From source file:com.novell.ldapchai.impl.edir.NmasResponseSet.java

License:Open Source License

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;
    {//from  w  ww.ja  va  2  s  .  c o m
        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 = defineStrValue.equalsIgnoreCase("Admin");
        final String typeStrValue = loopQ.getAttributeValue("Type");
        final boolean required = typeStrValue.equalsIgnoreCase("Required");
        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);
}

From source file:com.seleniumtests.util.squashta.TaScriptGenerator.java

License:Apache License

/**
 * Read a test element in an XML testNG file
 * @param test         the test element to read
 * @param testDefs      list of test definitions to update
 * @param testngFile   testNgFile read/* w ww.  ja  va2 s  .  c o  m*/
 */
private void readTestTag(Element test, List<SquashTaTestDef> testDefs, File testngFile) {
    boolean cucumberTest = false;
    String cucumberNamedTest = "";
    boolean exclude = false;

    // search cucumber parameters among test parameters
    // does test specifies precise cucumber properties (cucumberTests / cucumberTags)
    for (Element param : test.getChildren("parameter")) {
        if ("cucumberTests".equals(param.getAttributeValue("name"))
                || "cucumberTags".equals(param.getAttributeValue("name"))) {
            cucumberTest = true;
            cucumberNamedTest = param.getAttributeValue("value");

            if (!cucumberNamedTest.isEmpty()) {
                break;
            }
        }
    }

    for (Element param : test.getChildren("parameter")) {
        if (XML_EXCLUDE.equals(param.getAttributeValue("name"))) {
            exclude = true;
        }
    }

    // is this test a cucumber test ? (calling specific runner)
    for (Element pack : test.getDescendants(new ElementFilter("package"))) {
        if (pack.getAttributeValue("name").contains("com.seleniumtests.core.runner")) {
            cucumberTest = true;
        }
    }

    if (!exclude) {
        if (cucumberTest) {
            testDefs.add(
                    new SquashTaTestDef(testngFile, test.getAttributeValue("name"), true, cucumberNamedTest));
        } else {
            testDefs.add(new SquashTaTestDef(testngFile, test.getAttributeValue("name"), false, ""));
        }
    }
}

From source file:com.tactfactory.harmony.platform.winphone.updater.XmlProjectWinphone.java

License:Open Source License

private void removeIfExists(Element element, String type, String file) {
    Filter<Element> filter = new ElementFilter(type);
    List<Element> content = element.getContent(filter);
    List<Element> elementToDelete = new ArrayList<>();

    for (Element node : content) {
        if (node.getAttribute("Include").getValue().equals(file)) {
            elementToDelete.add(node);/* w w w  . j  a v  a2  s.com*/
        }
    }

    for (Element node : elementToDelete) {
        element.removeContent(node);
    }
}

From source file:com.tactfactory.harmony.platform.winphone.updater.XmlProjectWinphone.java

License:Open Source License

private Element findFirstItemGroup(String groupType) {
    Element result = null;/* w  ww  . j  a  v  a 2 s  .co  m*/

    Filter<Element> filter = new ElementFilter(XML_ELEMENT_ITEM);
    List<Element> content = this.rootNode.getContent(filter);

    filter = new ElementFilter(groupType);

    for (Element element : content) {
        content = element.getContent(filter);

        if (!content.isEmpty()) {
            result = element;
            break;
        }
    }

    if (result == null) {
        result = new Element(XML_ELEMENT_ITEM);
        filter = new ElementFilter("Import");
        content = this.rootNode.getContent(filter);
        rootNode.addContent(rootNode.indexOf(content.get(0)), result);
    }

    return result;
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.MfencedReplacer.java

License:Apache License

@Override
public void execute(final Document doc) {
    if (doc == null) {
        throw new NullPointerException("doc");
    }/*  www  . j a v a 2  s .c o  m*/
    final List<Element> toReplace = new ArrayList<Element>();
    for (Element mfenced : doc.getDescendants(new ElementFilter(FENCED))) {
        toReplace.add(mfenced);
    }
    if (toReplace.isEmpty()) {
        LOGGER.fine("No mfenced elements found");
        return;
    }
    for (Element mfenced : toReplace) {
        replaceMfenced(mfenced);
    }
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.OperatorNormalizer.java

License:Apache License

private void replaceOperators(final Element element, final Map<String, String> replacements) {
    assert element != null && replacements != null;
    List<Element> operatorsToReplace = new ArrayList<Element>();
    for (Element operator : element.getDescendants(new ElementFilter(OPERATOR))) {
        if (replacements.containsKey(operator.getTextTrim())) {
            operatorsToReplace.add(operator);
        }// ww w .j ava 2 s.  co  m
    }
    for (Element operator : operatorsToReplace) {
        final String oldOperator = operator.getTextTrim();
        final String newOperator = replacements.get(oldOperator);
        operator.setText(newOperator);
        LOGGER.log(Level.FINE, "Operator ''{0}'' was replaced by ''{1}''",
                new Object[] { oldOperator, newOperator });
    }
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.OperatorNormalizer.java

License:Apache License

private void replaceIdentifiers(final Element ancestor, final Set<String> operators) {
    assert ancestor != null && operators != null;
    final List<Element> toReplace = new ArrayList<Element>();
    for (Element element : ancestor.getDescendants(new ElementFilter(IDENTIFIER))) {
        // TODO: control whole ranges of symbols rather than listed ones
        if (operators.contains(element.getTextTrim())) {
            toReplace.add(element);/*from  w w  w.  j  a  va2 s  .co m*/
        }
    }
    for (Element element : toReplace) {
        LOGGER.log(Level.FINE, "Creating an operator from {0}", element.getText());
        replaceElement(element, OPERATOR);
    }
}