List of usage examples for org.jdom2 Attribute getValue
public String getValue()
Attribute
. From source file:com.novell.ldapchai.impl.edir.NmasResponseSet.java
License:Open Source License
private static String readDisplayString(final Element questionElement, final Locale locale) { final Namespace XML_NAMESPACE = Namespace.getNamespace("xml", "http://www.w3.org/XML/1998/namespace"); // someday ResoureBundle won't suck and this will be a 5 line method. // see if the node has any localized displays. final List displayChildren = questionElement.getChildren("display"); // if no locale specified, or if no localized text is available, just use the default. if (locale == null || displayChildren == null || displayChildren.size() < 1) { return questionElement.getText(); }//w ww . ja v a2 s. com // convert the xml 'display' elements to a map of locales/strings final Map<Locale, String> localizedStringMap = new HashMap<Locale, String>(); for (final Object aDisplayChildren : displayChildren) { final Element loopDisplay = (Element) aDisplayChildren; final Attribute localeAttr = loopDisplay.getAttribute("lang", XML_NAMESPACE); if (localeAttr != null) { final String localeStr = localeAttr.getValue(); final String displayStr = loopDisplay.getText(); final Locale localeKey = parseLocaleString(localeStr); localizedStringMap.put(localeKey, displayStr); } } final Locale matchedLocale = localeResolver(locale, localizedStringMap.keySet()); if (matchedLocale != null) { return localizedStringMap.get(matchedLocale); } // none found, so just return the default string. return questionElement.getText(); }
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; {/* ww w .ja va 2s.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.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 w w . ja v a 2 s . c om 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.rhythm.louie.server.LouieProperties.java
License:Apache License
private static void processServers(Element servers) { List<Server> serverList = new ArrayList<>(); if (servers == null) { List<Server> empty = Collections.emptyList(); Server.processServers(empty);//from w ww . j ava 2 s.c om return; } for (Element server : servers.getChildren()) { if (!SERVER.equals(server.getName().toLowerCase())) continue; String name = null; for (Attribute attr : server.getAttributes()) { if (NAME.equals(attr.getName().toLowerCase())) name = attr.getValue(); } if (name == null) { LoggerFactory.getLogger(LouieProperties.class) .error("A server was missing it's 'name' attribute and will be skipped!"); continue; } Server prop = new Server(name); for (Element serverProp : server.getChildren()) { String propName = serverProp.getName().toLowerCase(); String propValue = serverProp.getTextTrim(); if (null != propName) switch (propName) { case HOST: prop.setHost(propValue); break; case DISPLAY: prop.setDisplay(propValue); break; case LOCATION: prop.setLocation(propValue); break; case GATEWAY: prop.setGateway(propValue); break; case IP: prop.setIp(propValue); break; case EXTERNAL_IP: prop.setExternalIp(propValue); break; case CENTRAL_AUTH: prop.setCentralAuth(Boolean.parseBoolean(propValue)); break; case PORT: prop.setPort(Integer.parseInt(propValue)); break; case SECURE: prop.setSecure(Boolean.parseBoolean(propValue)); break; case TIMEZONE: prop.setTimezone(propValue); break; case CUSTOM: for (Element child : serverProp.getChildren()) { prop.addCustomProperty(child.getName(), child.getTextTrim()); } break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected server property {}:{}", propName, propValue); break; } } serverList.add(prop); } Server.processServers(serverList); }
From source file:com.rhythm.louie.server.LouieProperties.java
License:Apache License
private static void processServices(Element services, boolean internal) { if (services == null) return;//from w ww . j a v a 2 s. com for (Element elem : services.getChildren()) { if (DEFAULT.equalsIgnoreCase(elem.getName())) { processServiceDefaults(elem); break; } } List<ServiceProperties> servicesList = new ArrayList<>(); for (Element service : services.getChildren()) { String elementName = service.getName(); if (!SERVICE.equalsIgnoreCase(elementName)) { if (!DEFAULT.equalsIgnoreCase(elementName)) { LoggerFactory.getLogger(LouieProperties.class).warn("Unknown {} element: {}", SERVICE_PARENT, elementName); } continue; } String serviceName = null; Boolean enable = null; for (Attribute attr : service.getAttributes()) { String propName = attr.getName().toLowerCase(); String propValue = attr.getValue(); if (null != propName) switch (propName) { case NAME: serviceName = propValue; break; case ENABLE: enable = Boolean.valueOf(propValue); break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected service attribute {}:{}", propName, propValue); break; } } if (serviceName == null) { LoggerFactory.getLogger(LouieProperties.class) .error("A service was missing it's 'name' attribute and will be skipped"); continue; } ServiceProperties prop = new ServiceProperties(serviceName); if (enable != null) { prop.setEnable(enable); } for (Element serviceProp : service.getChildren()) { String propName = serviceProp.getName().toLowerCase(); String propValue = serviceProp.getTextTrim(); if (null != propName) switch (propName) { case CACHING: prop.setCaching(Boolean.valueOf(propValue)); break; case READ_ONLY: prop.setReadOnly(Boolean.valueOf(propValue)); break; case PROVIDER_CL: prop.setProviderClass(propValue); break; case RESPECTED_GROUPS: AccessManager.loadServiceAccess(serviceName, serviceProp); break; case RESERVED: if (internal) prop.setReserved(Boolean.valueOf(propValue)); break; case LAYERS: processServiceLayers(serviceProp, prop); break; case CUSTOM: for (Element child : serviceProp.getChildren()) { prop.addCustomProp(child.getName(), child.getTextTrim()); } break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected server property {}:{}", propName, propValue); } } servicesList.add(prop); } ServiceProperties.processServices(servicesList); }
From source file:com.rometools.modules.atom.io.AtomModuleParser.java
License:Apache License
protected String getAttributeValue(final Element e, final String attributeName) { Attribute attr = e.getAttribute(attributeName); if (attr == null) { attr = e.getAttribute(attributeName, NS); }//from ww w .jav a 2 s . c om if (attr != null) { return attr.getValue(); } else { return null; } }
From source file:com.rometools.modules.content.io.ContentModuleParser.java
License:Open Source License
@Override public com.rometools.rome.feed.module.Module parse(final Element element, final Locale locale) { boolean foundSomething = false; final ContentModule cm = new ContentModuleImpl(); final List<Element> encodeds = element.getChildren("encoded", CONTENT_NS); final ArrayList<String> contentStrings = new ArrayList<String>(); final ArrayList<String> encodedStrings = new ArrayList<String>(); if (!encodeds.isEmpty()) { foundSomething = true;//from w w w .j a v a 2s . c o m for (int i = 0; i < encodeds.size(); i++) { final Element encodedElement = encodeds.get(i); encodedStrings.add(encodedElement.getText()); contentStrings.add(encodedElement.getText()); } } final ArrayList<ContentItem> contentItems = new ArrayList<ContentItem>(); final List<Element> items = element.getChildren("items", CONTENT_NS); for (int i = 0; i < items.size(); i++) { foundSomething = true; final List<Element> lis = items.get(i).getChild("Bag", RDF_NS).getChildren("li", RDF_NS); for (int j = 0; j < lis.size(); j++) { final ContentItem ci = new ContentItem(); final Element li = lis.get(j); final Element item = li.getChild("item", CONTENT_NS); final Element format = item.getChild("format", CONTENT_NS); final Element encoding = item.getChild("encoding", CONTENT_NS); final Element value = item.getChild("value", RDF_NS); if (value != null) { if (value.getAttributeValue("parseType", RDF_NS) != null) { ci.setContentValueParseType(value.getAttributeValue("parseType", RDF_NS)); } if (ci.getContentValueParseType() != null && ci.getContentValueParseType().equals("Literal")) { ci.setContentValue(getXmlInnerText(value)); contentStrings.add(getXmlInnerText(value)); ci.setContentValueNamespaces(value.getAdditionalNamespaces()); } else { ci.setContentValue(value.getText()); contentStrings.add(value.getText()); } ci.setContentValueDOM(value.clone().getContent()); } if (format != null) { ci.setContentFormat(format.getAttribute("resource", RDF_NS).getValue()); } if (encoding != null) { ci.setContentEncoding(encoding.getAttribute("resource", RDF_NS).getValue()); } if (item != null) { final Attribute about = item.getAttribute("about", RDF_NS); if (about != null) { ci.setContentAbout(about.getValue()); } } contentItems.add(ci); } } cm.setEncodeds(encodedStrings); cm.setContentItems(contentItems); cm.setContents(contentStrings); return foundSomething ? cm : null; }
From source file:com.rometools.modules.opensearch.impl.OpenSearchModuleParser.java
License:Apache License
/** * Use xml:base attributes at feed and entry level to resolve relative links *///from ww w .j a v a2s .c o m private static String resolveURI(final URL baseURI, final Parent parent, String url) { url = url.equals(".") || url.equals("./") ? "" : url; if (isRelativeURI(url) && parent != null && parent instanceof Element) { final Attribute baseAtt = ((Element) parent).getAttribute("base", Namespace.XML_NAMESPACE); String xmlBase = baseAtt == null ? "" : baseAtt.getValue(); if (!isRelativeURI(xmlBase) && !xmlBase.endsWith("/")) { xmlBase = xmlBase.substring(0, xmlBase.lastIndexOf("/") + 1); } return resolveURI(baseURI, parent.getParent(), xmlBase + url); } else if (isRelativeURI(url) && parent == null) { return baseURI + url; } else if (baseURI != null && url.startsWith("/")) { String hostURI = baseURI.getProtocol() + "://" + baseURI.getHost(); if (baseURI.getPort() != baseURI.getDefaultPort()) { hostURI = hostURI + ":" + baseURI.getPort(); } return hostURI + url; } return url; }
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
/** * Return URL string of Atom link element under parent element. Link with no rel attribute is * considered to be rel="alternate"/*from w w w . jav a2 s .com*/ * * @param parent Consider only children of this parent element * @param rel Consider only links with this relationship */ private String findAtomLink(final Element parent, final String rel) { String ret = null; final List<Element> linksList = parent.getChildren("link", ATOM_10_NS); if (linksList != null) { for (final Element element : linksList) { final Element link = element; final Attribute relAtt = getAttribute(link, "rel"); final Attribute hrefAtt = getAttribute(link, "href"); if (relAtt == null && "alternate".equals(rel) || relAtt != null && relAtt.getValue().equals(rel)) { ret = hrefAtt.getValue(); break; } } } return ret; }
From source file:com.rometools.rome.io.impl.DCModuleParser.java
License:Open Source License
/** * Utility method to parse a taxonomy from an element. * <p>//from w ww.j ava 2s . c o m * * @param desc the taxonomy description element. * @return the string contained in the resource of the element. */ protected final String getTaxonomy(final Element desc) { String taxonomy = null; final Element topic = desc.getChild("topic", getTaxonomyNamespace()); if (topic != null) { final Attribute resource = topic.getAttribute("resource", getRDFNamespace()); if (resource != null) { taxonomy = resource.getValue(); } } return taxonomy; }