List of usage examples for org.jdom2 Attribute getValue
public String getValue()
Attribute
. From source file:org.kdp.word.transformer.TOCTransformer.java
License:Apache License
private String getAnchorName(Element el) { String result = null;/*ww w. ja va 2 s . c o m*/ Attribute att = el.getAttribute("name"); if ("a".equals(el.getName()) && att != null) { result = att.getValue(); } else { for (Element ch : el.getChildren()) { result = getAnchorName(ch); if (result != null) { break; } } } return result; }
From source file:org.kdp.word.utils.JDOMUtils.java
License:Apache License
public static boolean isElement(Element el, String name, String attname, String attvalue) { if (el != null && el.getName().equals(name)) { if (attname != null && attvalue != null) { Attribute att = el.getAttribute(attname); return att != null && attvalue.equals(att.getValue()); } else {//from w w w . j a v a2s.com return true; } } return false; }
From source file:org.kisst.cordys.caas.util.XmlNode.java
License:Open Source License
public Map<String, String> getAttributes() { Map<String, String> retVal = new LinkedHashMap<String, String>(); List<Attribute> tmp = element.getAttributes(); for (Attribute a : tmp) { retVal.put(a.getName(), a.getValue()); }/*from w w w . j a va 2 s . co m*/ return retVal; }
From source file:org.kisst.cordys.caas.util.XmlNode.java
License:Open Source License
public String getAttribute(String name, String defaultValue) { Attribute attr = element.getAttribute(name); if (attr == null) return defaultValue; else//from www . jav a 2s .c o m return attr.getValue(); }
From source file:org.mule.tools.apikit.input.parsers.APIKitConfigParser.java
License:Open Source License
@Override public Map<String, APIKitConfig> parse(Document document) { Map<String, APIKitConfig> apikitConfigs = new HashMap<String, APIKitConfig>(); XPathExpression<Element> xp = XPathFactory.instance().compile( "//*/*[local-name()='" + APIKitConfig.ELEMENT_NAME + "']", Filters.element(APIKitTools.API_KIT_NAMESPACE.getNamespace())); List<Element> elements = xp.evaluate(document); for (Element element : elements) { Attribute name = element.getAttribute(APIKitConfig.NAME_ATTRIBUTE); Attribute raml = element.getAttribute(APIKitConfig.RAML_ATTRIBUTE); Attribute consoleEnabled = element.getAttribute(APIKitConfig.CONSOLE_ENABLED_ATTRIBUTE); Attribute consolePath = element.getAttribute(APIKitConfig.CONSOLE_PATH_ATTRIBUTE); if (raml == null) { throw new IllegalArgumentException(APIKitConfig.RAML_ATTRIBUTE + " attribute is required"); }//w ww .j ava 2 s .c o m APIKitConfig.Builder configBuilder = new APIKitConfig.Builder(raml.getValue()); if (name != null) { configBuilder.setName(name.getValue()); } if (consoleEnabled != null) { configBuilder.setConsoleEnabled(Boolean.valueOf(consoleEnabled.getValue())); } if (consolePath != null) { configBuilder.setConsolePath(consolePath.getValue()); } APIKitConfig config = configBuilder.build(); String configId = config.getName() != null ? config.getName() : APIKitFlow.UNNAMED_CONFIG_NAME; apikitConfigs.put(configId, config); } return apikitConfigs; }
From source file:org.mule.tools.apikit.input.parsers.APIKitRoutersParser.java
License:Open Source License
@Override public Map<String, API> parse(Document document) { Map<String, API> includedApis = new HashMap<String, API>(); XPathExpression<Element> xp = XPathFactory.instance().compile("//*/*[local-name()='router']", Filters.element(APIKitTools.API_KIT_NAMESPACE.getNamespace())); List<Element> elements = xp.evaluate(document); for (Element element : elements) { Attribute configRef = element.getAttribute("config-ref"); String configId = configRef != null ? configRef.getValue() : APIKitFlow.UNNAMED_CONFIG_NAME; APIKitConfig config = apikitConfigs.get(configId); if (config == null) { throw new IllegalStateException("An Apikit configuration is mandatory."); }/* w ww . java 2s .com*/ for (File yamlPath : yamlPaths) { if (yamlPath.getName().equals(config.getRaml())) { Element listener = element.getParentElement().getChildren().get(0); Attribute httpListenerConfigRef = listener.getAttribute("config-ref"); String httpListenerConfigId = httpListenerConfigRef != null ? httpListenerConfigRef.getValue() : HttpListenerConfig.DEFAULT_CONFIG_NAME; HttpListenerConfig httpListenerConfig = httpListenerConfigs.get(httpListenerConfigId); if (httpListenerConfig == null) { throw new IllegalStateException("An HTTP Listener configuration is mandatory."); } // TODO Unhack, it is assuming that the router will always be in a flow // where the first element is going to be an http listener if (!"listener".equals(listener.getName())) { throw new IllegalStateException("The first element of the main flow must be a listener"); } String path = getPathFromListener(listener); includedApis.put(configId, apiFactory.createAPIBinding(yamlPath, file, config, httpListenerConfig, path)); } } } return includedApis; }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
private void setVariablesFromXML(String prefix, Element element, Hashtable predecessors) { String key = getNamespacePrefix(element.getNamespace()) + element.getName(); setVariablesFromXML(prefix, key, element, predecessors); List attributes = element.getAttributes(); for (Object attribute1 : attributes) { Attribute attribute = (Attribute) attribute1; String name = getNamespacePrefix(attribute.getNamespace()) + attribute.getName(); String value = attribute.getValue().replace(BLANK, BLANK_ESCAPED).replace(SLASH, SLASH_ESCAPED); if (value == null || value.length() == 0) { continue; }/* w w w. j av a2s .c om*/ key = getNamespacePrefix(element.getNamespace()) + element.getName() + ATTR_SEP + name + ATTR_SEP + value; if (predicates.containsKey(key)) { setVariablesFromXML(prefix, key, element, predecessors); } } }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
private void setVariablesFromXML(String prefix, String key, Element element, Hashtable predecessors) { int pos = 1;//ww w . j a v a2s . com if (predecessors.containsKey(key)) { pos = (Integer) predecessors.get(key) + 1; } predecessors.put(key, pos); String path = prefix + "/" + key; if (pos > 1) { path = path + "[" + pos + "]"; } // Add element text addVariable(path, element.getText()); // Add value of all attributes List attributes = element.getAttributes(); for (Object attribute1 : attributes) { Attribute attribute = (Attribute) attribute1; String value = attribute.getValue(); if (value != null && value.length() > 0) { addVariable(path + "/@" + getNamespacePrefix(attribute.getNamespace()) + attribute.getName(), value); } } // Add values of all children predecessors = new Hashtable(); List children = element.getChildren(); for (Object aChildren : children) { Element child = (Element) aChildren; setVariablesFromXML(path, child, predecessors); } }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
private void setValidatorProperties(MCRValidator validator, Element condition) { for (Attribute attribute : (List<Attribute>) (condition.getAttributes())) { if (!attribute.getValue().isEmpty()) validator.setProperty(attribute.getName(), attribute.getValue()); }/*from w ww . jav a2 s . c o m*/ }
From source file:org.mycore.mir.wizard.command.MIRWizardMCRCommand.java
License:Open Source License
@Override public void doExecute() { Session currentSession = MCRHIBConnection.instance().getSession(); try {/* w w w. ja v a2 s . c o m*/ for (Element command : getInputXML().getChildren()) { String cmd = command.getTextTrim(); cmd = cmd.replaceAll("\n", "").replaceAll("\r", "").replaceAll(" ", " "); cmd = cmd.replaceAll(" ", " "); for (Attribute attr : command.getAttributes()) { if (attr.getValue().startsWith("resource:")) { File tmpFile = File.createTempFile("resfile", ".xml"); MCRContent source = new MCRJDOMContent(MCRURIResolver.instance().resolve(attr.getValue())); source.sendTo(tmpFile); cmd = cmd.replace("{" + attr.getName() + "}", tmpFile.getAbsolutePath()); } else { cmd = cmd.replace("{" + attr.getName() + "}", attr.getValue()); } } MCRCommandManager mcrCmdMgr = new MCRCommandManager(); Transaction tx = currentSession.beginTransaction(); try { mcrCmdMgr.invokeCommand(cmd); tx.commit(); } catch (HibernateException e) { tx.rollback(); this.result.setResult(result + e.toString()); this.result.setSuccess(false); return; } catch (InvocationTargetException e) { e.printStackTrace(); this.result.setResult(result + e.toString()); this.result.setSuccess(false); return; } } this.result.setSuccess(true); } catch (Exception ex) { ex.printStackTrace(); this.result.setResult(ex.toString()); this.result.setSuccess(false); } }