Search in sources :

Example 86 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project ldapchai by ldapchai.

the class NmasResponseSet method parseNmasUserResponseXML.

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);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) Document(org.jdom2.Document) Challenge(com.novell.ldapchai.cr.Challenge) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge) ElementFilter(org.jdom2.filter.ElementFilter) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ChaiChallengeSet(com.novell.ldapchai.cr.ChaiChallengeSet) ChaiChallenge(com.novell.ldapchai.cr.ChaiChallenge)

Example 87 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project ldapchai by ldapchai.

the class DirXMLEntitlementRef method convertStrToDoc.

private static Document convertStrToDoc(final String str) {
    final Reader xmlreader = new StringReader(str);
    final SAXBuilder builder = new SAXBuilder();
    Document doc = null;
    try {
        doc = builder.build(xmlreader);
    } catch (JDOMException | IOException e) {
        // @todo
        e.printStackTrace();
    }
    return doc;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 88 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project ldapchai by ldapchai.

the class NspmComplexityRules method readComplexityPoliciesFromXML.

private static List<Policy> readComplexityPoliciesFromXML(final String input) {
    final List<Policy> returnList = new ArrayList<>();
    try {
        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<>();
            for (final Object ruleSetObjects : policyElement.getChildren("RuleSet")) {
                final Element loopRuleSet = (Element) ruleSetObjects;
                final Map<Rule, String> returnRules = new HashMap<>();
                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;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) HashMap(java.util.HashMap) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 89 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project ParadoxosModManager by ThibautSF.

the class MyXML method importList.

public String importList(String xml, Map<String, Mod> availableMods) throws Exception {
    SAXBuilder sxb = new SAXBuilder();
    Document importDocument = sxb.build(xml);
    Element importRoot = importDocument.getRootElement();
    if (importRoot.getAttribute(GAME_ID).getValue().equals(ModManager.STEAM_ID.toString())) {
        List<Element> modLists = importRoot.getChildren(LIST);
        Iterator<Element> i = modLists.iterator();
        while (i.hasNext()) {
            ArrayList<Mod> listMods = new ArrayList<Mod>();
            Element oneListElement = (Element) i.next();
            String listName = oneListElement.getAttribute(NAME).getValue();
            String listDescr = oneListElement.getChild(DESCR).getText();
            String listLang = oneListElement.getChild(LANG).getText();
            List<Element> modsElements = oneListElement.getChildren(MOD);
            for (Element modElement : modsElements) {
                List<Attribute> modElementAttr = modElement.getAttributes();
                String fileName = "", modName = "", remoteFileId = null;
                for (Attribute attribute : modElementAttr) {
                    switch(attribute.getName()) {
                        case ID:
                        case FILE_NAME:
                            fileName = attribute.getValue();
                            break;
                        case MOD_NAME:
                            modName = attribute.getValue();
                            break;
                        case REMOTE_ID:
                            remoteFileId = attribute.getValue();
                            break;
                        default:
                            break;
                    }
                }
                Mod oneMod = availableMods.get(fileName);
                if (oneMod == null) {
                    oneMod = new Mod(modName, fileName, remoteFileId);
                    if (remoteFileId != null && !"".equals(remoteFileId)) {
                        for (Mod mod : availableMods.values()) {
                            if (mod.getRemoteFileID().equals(remoteFileId)) {
                                oneMod = mod;
                            }
                        }
                    }
                }
                if (!listMods.contains(oneMod)) {
                    listMods.add(oneMod);
                }
            }
            ModList oneList = new ModList("[Imported]" + listName + "_" + System.currentTimeMillis(), listDescr, Languages.getLanguage(listLang), listMods);
            modifyList(oneList);
        }
        return "Import done.";
    }
    return "Import procedure aborted, this list is not for the current game !";
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Mod(mod.Mod) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) ModList(mod.ModList)

Example 90 with SAXBuilder

use of org.jdom2.input.SAXBuilder in project iaf by ibissource.

the class XmlBuilder method buildElement.

private Element buildElement(String value) throws JDOMException, IOException {
    StringReader stringReader = new StringReader(value);
    SAXBuilder saxBuilder = new SAXBuilder();
    Document document;
    document = saxBuilder.build(stringReader);
    Element element = document.getRootElement();
    return element.detach();
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) StringReader(java.io.StringReader) Document(org.jdom2.Document)

Aggregations

SAXBuilder (org.jdom2.input.SAXBuilder)134 Document (org.jdom2.Document)94 Element (org.jdom2.Element)55 IOException (java.io.IOException)33 JDOMException (org.jdom2.JDOMException)27 File (java.io.File)20 StringReader (java.io.StringReader)20 Test (org.junit.jupiter.api.Test)18 InputStream (java.io.InputStream)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)11 URL (java.net.URL)9 XMLOutputter (org.jdom2.output.XMLOutputter)8 Modification (com.thoughtworks.go.domain.materials.Modification)7 List (java.util.List)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputSource (org.xml.sax.InputSource)6 ParseException (java.text.ParseException)5 MCRPath (org.mycore.datamodel.niofs.MCRPath)5 BufferedInputStream (java.io.BufferedInputStream)4