Example usage for org.jdom2.input SAXBuilder SAXBuilder

List of usage examples for org.jdom2.input SAXBuilder SAXBuilder

Introduction

In this page you can find the example usage for org.jdom2.input SAXBuilder SAXBuilder.

Prototype

public SAXBuilder() 

Source Link

Document

Creates a new JAXP-based SAXBuilder.

Usage

From source file:com.move.in.nantes.cars.ParkingParser.java

private static List<Parking> parseXml() {
    List<Parking> listPakings = new ArrayList<Parking>();

    try {//from  w  w w.  j  a  va  2s. c o m
        SAXBuilder saxb = new SAXBuilder();
        File file = new File("WEB-INF/json/Parking.xml");

        Document doc = saxb.build(file);
        Element root = doc.getRootElement();
        List<Element> locations = root.getChildren("data").get(0).getChildren("element");

        for (int i = 0; i < locations.size(); i++) {
            Element elem = locations.get(i);

            if (elem.getChildText("CATEGORIE").equalsIgnoreCase("1001")) {

                String name = elem.getChild("geo").getChildText("name");

                Coordinates coordinates = getCoordinates(elem.getChildText("_l"));

                String postalCode = elem.getChildText("CODE_POSTAL");
                String city = elem.getChildText("COMMUNE");
                String address = elem.getChildText("ADRESSE");

                listPakings.add(new Parking(name, coordinates, postalCode, city, address));
            }
        }
    } catch (JDOMException ex) {
        Logger.getLogger(ParkingParser.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ParkingParser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return listPakings;
}

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

License:Apache License

@Scheduled(fixedRate = 300000)
@Transactional/*w w  w  . j  a v  a2  s.  c o  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);/*from ww  w. j  av  a 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  .j a v  a  2  s . c  om*/
        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.novell.ldapchai.impl.edir.value.DirXML_EntitlementRef.java

License:Open Source License

private static Document convertStrToDoc(final String str) {
    final Reader xmlreader = new StringReader(str);
    final SAXBuilder builder = new SAXBuilder();
    Document doc = null;//  w  ww  .jav  a2  s . co m
    try {
        doc = builder.build(xmlreader);
    } catch (JDOMException e) {
        e.printStackTrace(); //@todo
    } catch (IOException e) {
        e.printStackTrace(); //@todo
    }
    return doc;
}

From source file:com.novell.ldapchai.impl.edir.value.nspmComplexityRules.java

License:Open Source License

private static List<Policy> readComplexityPoliciesFromXML(final String input) {
    final List<Policy> returnList = new ArrayList<Policy>();
    try {/*  w ww .j a  v  a2s .  c  o m*/
        final SAXBuilder builder = new SAXBuilder();
        final Document doc = builder.build(new StringReader(input));
        final Element rootElement = doc.getRootElement();

        final List policyElements = rootElement.getChildren("Policy");
        for (final Object policyNode : policyElements) {
            final Element policyElement = (Element) policyNode;
            final List<RuleSet> returnRuleSets = new ArrayList<RuleSet>();
            for (final Object ruleSetObjects : policyElement.getChildren("RuleSet")) {
                final Element loopRuleSet = (Element) ruleSetObjects;
                final Map<Rule, String> returnRules = new HashMap<Rule, String>();
                int violationsAllowed = 0;

                final org.jdom2.Attribute violationsAttribute = loopRuleSet.getAttribute("ViolationsAllowed");
                if (violationsAttribute != null && violationsAttribute.getValue().length() > 0) {
                    violationsAllowed = Integer.parseInt(violationsAttribute.getValue());
                }

                for (final Object ruleObject : loopRuleSet.getChildren("Rule")) {
                    final Element loopRuleElement = (Element) ruleObject;

                    final List ruleAttributes = loopRuleElement.getAttributes();
                    for (final Object attributeObject : ruleAttributes) {
                        final org.jdom2.Attribute loopAttribute = (org.jdom2.Attribute) attributeObject;

                        final Rule rule = Rule.valueOf(loopAttribute.getName());
                        final String value = loopAttribute.getValue();
                        returnRules.put(rule, value);
                    }
                }
                returnRuleSets.add(new RuleSet(violationsAllowed, returnRules));
            }
            returnList.add(new Policy(returnRuleSets));
        }
    } catch (JDOMException e) {
        LOGGER.debug("error parsing stored response record: " + e.getMessage());
    } catch (IOException e) {
        LOGGER.debug("error parsing stored response record: " + e.getMessage());
    } catch (NullPointerException e) {
        LOGGER.debug("error parsing stored response record: " + e.getMessage());
    } catch (IllegalArgumentException e) {
        LOGGER.debug("error parsing stored response record: " + e.getMessage());
    }
    return returnList;
}

From source file:com.oagsoft.grafo.util.XMLLoader.java

public static Grafo leerArchivoXml(String nomArch) {
    SAXBuilder builder = new SAXBuilder();
    Grafo g = null;//w w  w.j  av  a 2 s  .co m
    try {
        Document document = (Document) builder.build(new File(nomArch));
        Element rootNode = document.getRootElement();
        Element nV = rootNode.getChild("numero-vertices");
        int numVertices = Integer.parseInt(nV.getValue().trim());
        g = new Grafo(numVertices);
        Element ad = rootNode.getChild("adyacencias");
        List<Element> hijos = ad.getChildren("adyacencia");
        for (Element hijo : hijos) {
            int nIni = Integer.parseInt(hijo.getChildTextTrim("nodo-inicial"));
            int nFin = Integer.parseInt(hijo.getChildTextTrim("nodo-final"));
            g.adyacencia(nIni, nFin);
        }
        //            System.out.println("Hay " + hijos.size()+ " adyacencias");
    } catch (JDOMException | IOException ex) {
        System.out.println(ex.getMessage());
    }
    return g;
}

From source file:com.oagsoft.wazgle.tools.XMLLoader.java

public static Grafo<GraphicNode> leerArchivoXml(String nomArch) {
    SAXBuilder builder = new SAXBuilder();
    Grafo<GraphicNode> g = null;/*from   w w w  .ja v a2s.  c  om*/
    try {
        Document document = (Document) builder.build(new File(nomArch));
        Element rootNode = document.getRootElement();
        Element nV = rootNode.getChild("numero-vertices");
        int numVertices = Integer.parseInt(nV.getValue().trim());
        g = new Grafo(numVertices);
        Element nodos = rootNode.getChild("nodos");
        List<Element> hijos = nodos.getChildren("nodo");
        for (Element hijo : hijos) {
            int id = Integer.parseInt(hijo.getChildTextTrim("id"));
            int coorX = Integer.parseInt(hijo.getChildTextTrim("coor-x"));
            int coorY = Integer.parseInt(hijo.getChildTextTrim("coor-y"));
            GraphicNode nodo = new GraphicNode(id, new Point(coorX, coorY), 10, false);
            g.adVertice(nodo);
        }
        Element adyacencias = rootNode.getChild("adyacencias");
        List<Element> ad = adyacencias.getChildren("adyacencia");
        for (Element hijo : ad) {
            int vIni = Integer.parseInt(hijo.getChildTextTrim("nodo-inicial"));
            int vFinal = Integer.parseInt(hijo.getChildTextTrim("nodo-final"));
            GraphicNode nIni = g.getVertice(vIni);
            GraphicNode nFin = g.getVertice(vFinal);

            g.adyacencia(nIni, nFin);

        }
        //            System.out.println("Hay " + hijos.size()+ " adyacencias");
    } catch (JDOMException | IOException ex) {
        System.out.println(ex.getMessage());
    }
    return g;
}

From source file:com.offbytwo.jenkins.JenkinsServer.java

License:MIT License

public List<String> getJobsOnView(String viewName) throws IOException, JDOMException {
    String result = client.get("view/" + encode(viewName) + "/config.xml");
    return JOB_NAMES.evaluate(new SAXBuilder().build(new StringReader(result))).stream().map(c -> c.getValue())
            .collect(Collectors.toList());
}

From source file:com.ohnosequences.xml.model.go.GoTermXML.java

License:Open Source License

public static GoTermXML getGoTerm(String id) throws Exception {

    GoTermXML temp = new GoTermXML();

    URL url = new URL(GO_TERM_SERVICE_URL + id);
    // Connect// www  .  j  a v  a 2  s.c  o  m
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    // Get data
    SAXBuilder saxBuilder = new SAXBuilder();
    Document doc = saxBuilder.build(urlConnection.getInputStream());

    Element termElement = doc.getRootElement().getChild("term");

    String idString, nameString, defString;
    idString = termElement.getChildText("id");
    nameString = termElement.getChildText("name");
    defString = termElement.getChild("def").getChildText("defstr");

    if (!id.equals(idString)) {
        throw new Exception(
                "El id proporcionado y el encontrado en el xml proporcionado por el servicio no son el mismo");
    } else {
        temp.setId(idString);
        temp.setGoName(nameString);
        temp.setDefinition(defString);
    }

    return temp;
}