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);
}
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;
}
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;
}
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 !";
}
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();
}
Aggregations