List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:com.arc.xml.AbstractBuilder.java
License:Open Source License
/** * Check that attributes of element are valid and that all required attributes are there Apply attributes that are * valid to the builder via reflection by calling <code>"set<i>Property</i>"</code>. *///from www.j ava2 s . co m protected void doAttributes(Element e, IBinding binding) throws SAXException { List<Attribute> attrs = Cast.toType(e.attributes()); for (Attribute a : attrs) { IAttributeDef adef = binding.getAttribute(a.getName()); if (adef == null) unknownAttribute(e, binding, a); else try { setAttribute(e, a.getName(), adef, a.getValue()); } catch (NoSuchMethodException x) { error(e, "Can't set attribute " + adef.getName()); } } /* * Look for missing required attributes */ for (IAttributeDef a : binding.getAttributes().values()) { if (a.isRequired() && e.attributeValue(a.getName()) == null && !accessedByAlias(e, binding, a)) error(e, "Required attribute \"" + a.getName() + "\" for tag \"" + binding.getTagName() + "\" is missing"); } }
From source file:com.arc.xml.XmlProcessor.java
License:Open Source License
/** * Extract attribute from element. Return null if attribute isn't defined. Complain if it is required, but is * missing./*from w w w . j a va 2s. c o m*/ */ private String getAttribute(Element element, String name, boolean required) throws BadXmlException { String attribute = element.attributeValue(name); if (attribute == null || attribute.length() == 0) { if (required) metaError(element, "Required attribute " + name + " is missing."); attribute = null; } return attribute; }
From source file:com.atlassian.jira.plugin.aboutpagepanel.AboutPagePanelModuleDescriptorImpl.java
License:LGPL
private String assertModuleKeyPresent(final Element introduction, String field) { String location = introduction.attributeValue(MODULE_KEY); if (StringUtils.isEmpty(location)) throw new PluginParseException(field + " module key must be specified"); return location; }
From source file:com.atlassian.jira.plugin.aboutpagepanel.AboutPagePanelModuleDescriptorImpl.java
License:LGPL
private String assertLocationPresent(final Element introduction, String field) { String location = introduction.attributeValue(LOCATION_KEY); if (StringUtils.isEmpty(location)) throw new PluginParseException(field + " license file must be specified"); return location; }
From source file:com.atlassian.jira.plugin.aboutpagepanel.AboutPagePanelModuleDescriptorImpl.java
License:LGPL
private String assertFunctionPresent(final Element introduction, String field) { String location = introduction.attributeValue(FUNCTION_KEY); if (StringUtils.isEmpty(location)) throw new PluginParseException(field + " function must be specified"); return location; }
From source file:com.autoupdater.client.xml.parsers.FileCacheParser.java
License:Apache License
@Override Map<String, String> parseDocument(Document document) throws ParserException { logger.trace("Parsing file cache's data file's document"); try {/*from www.ja v a 2s.co m*/ Map<String, String> files = new HashMap<String, String>(); for (Node fileNode : document.selectNodes("./" + FileCacheSchema.Files.file_)) { Element file = (Element) fileNode; String path = file.attributeValue(FileCacheSchema.Files.File.path); String hash = file.attributeValue(FileCacheSchema.Files.File.hash); files.put(path, hash); } return files; } catch (Exception e) { logger.error( "Cannot parse file cache's data file's document: " + e.getMessage() + " (exception thrown)", e); throw new ParserException("Error occured while parsing file cache's data file").addSuppresed(e, ParserException.class); } }
From source file:com.bay12games.df.rawedit.xml.RawsDescriptionLoader.java
License:Open Source License
/** * Parse the XML element containing token definition. * /*from w w w. j av a 2 s .com*/ * @param e XML DOM element * @return Parsed token. If the token existed before, returns the same (possibly * altered) instance. */ private Token parseToken(Element e) { String name = e.attributeValue("name"); if (name == null) { return null; } Token token; if (tokens.containsKey(name)) { token = tokens.get(name); } else { token = new Token(name); tokens.put(name, token); } boolean clean = false; for (Element ce : e.elements()) { // add the attribute if ("a".equals(ce.getName())) { Argument a = parseArgument(ce, name); if (a != null) { if (!clean) { token.getArguments().clear(); clean = true; } token.addArgument(a); } } else if ("d".equals(ce.getName())) { token.setDescription(ce.getText()); } } return token; }
From source file:com.bay12games.df.rawedit.xml.RawsDescriptionLoader.java
License:Open Source License
/** * Parse the XML element containing token definition. * * @param e XML DOM element/*from w w w . j ava 2 s. c o m*/ * @param parentName Name of the parent element (currently unused - 20100905) * @return Parsed token. If the token existed before, returns the same (possibly * altered) instance. */ private Argument parseArgument(Element e, String parentName) { String type = e.attributeValue("type"); if (type == null) { return null; } boolean required = Boolean.parseBoolean(e.attributeValue("required")); Argument argument = null; if ("enum".equals(type)) { Set<String> items = new HashSet<String>(); for (Element ee : e.elements()) { if ("e".equals(ee.getName())) { items.add(ee.attributeValue("name")); } } argument = new Argument(type, items); } else if ("range".equals(type)) { int min = 0; int max = 0; try { min = Integer.parseInt(e.attributeValue("min")); max = Integer.parseInt(e.attributeValue("max")); argument = new Argument(type, min, max); } catch (NumberFormatException ex) { return null; } } else if ("int".equals(type)) { argument = new Argument(type); } else if ("string".equals(type)) { String id = e.attributeValue("id"); String ref = e.attributeValue("ref"); if (id != null) { // [NOTE] inline "default" id can only be a flat list. if (!ids.containsKey(id)) { Id idObject = new Id(id); ids.put(id, idObject); // we might load a description later... } } argument = new Argument(type, id, ref); } String desc = e.elementText("d"); if (desc != null && argument != null) { argument.setDescription(desc); } argument.setLabel(e.attributeValue(Constants.XML_ARGUMENT_LABLE)); return argument; }
From source file:com.bay12games.df.rawedit.xml.RawsDescriptionLoader.java
License:Open Source License
/** * Parse the XML element containing container definition. * * @param e XML DOM element// w ww . j ava 2 s.co m * @return Parsed container. If the container existed before, returns the same (possibly * altered) instance. */ private Container parseContainer(Element e) { String name = e.attributeValue("name"); if (name == null) { return null; } Container container; if (containers.containsKey(name)) { container = containers.get(name); } else { container = new Container(name); containers.put(name, container); } boolean clean = false; for (Element ce : e.elements()) { // add the attribute if ("a".equals(ce.getName())) { Argument a = parseArgument(ce, name); if (a != null) { if (!clean) { container.getArguments().clear(); clean = true; } container.addArgument(a); } } else if ("c".equals(ce.getName())) { Container cc = parseContainer(ce); if (cc != null) { if (!container.getContainers().containsKey(cc.getName())) { container.addContainer(cc); } } } else if ("t".equals(ce.getName())) { Token ct = parseToken(ce); if (ct != null) { if (!container.getTokens().containsKey(ct.getName())) { container.addToken(ct); } } } else if ("d".equals(ce.getName())) { container.setDescription(ce.getText()); } } return container; }
From source file:com.bay12games.df.rawedit.xml.RawsDescriptionLoader.java
License:Open Source License
/** * Parse the XML element containing id definition. * * @param e XML DOM element/*from w w w . ja va 2 s.c o m*/ * @return Parsed id. If the id existed before, returns the same (possibly * altered) instance. */ private Id parseId(Element e) { String name = e.attributeValue("name"); if (name == null) { return null; } Id id; if (ids.containsKey(name)) { id = ids.get(name); } else { id = new Id(name); ids.put(name, id); } String description = e.elementText("d"); String from = e.attributeValue("from"); String to = e.attributeValue("to"); String superidName = e.attributeValue("id"); id.setDescription(description); if (from != null && to != null) { if (id.getFromToMap() != null && id.getFromToMap().containsKey(from)) { log.warn("From-to map on id " + id.getName() + " already contains key " + from); } id.addFromTo(from, to); } // else... // If from or to are null, the list is flat, so we don't have to set anything if (superidName != null) { Id superid; if (ids.containsKey(superidName)) { superid = ids.get(superidName); } else { superid = new Id(superidName); ids.put(superidName, superid); } // [NOTE] supercategory is always flat!! superid.addItem(to); id.setParentName(superidName); } return id; }