List of usage examples for org.jdom2 Element getAttribute
public Attribute getAttribute(final String attname)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
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 {/* w w w. j a v a2 s .co m*/ return true; } } return false; }
From source file:org.kisst.cordys.caas.util.XmlNode.java
License:Open Source License
public Object get(String path) { String[] parts = path.split("/"); Element e = element; for (String part : parts) { if (part.equals("..")) e = e.getParentElement();//from www . j av a2s . c o m else if (part.equals("text()")) return e.getText(); else if (part.startsWith("@")) return e.getAttribute(part.substring(1)).getValue(); else e = e.getChild(part, null); if (e == null) return null; } return new XmlNode(e); }
From source file:org.kisst.cordys.caas.util.XmlNode.java
License:Open Source License
public Object getWithCreate(String path) { String[] parts = path.split("/"); Element e = element; for (String part : parts) { if (part.equals("..")) e = e.getParentElement();/* w ww.j ava2 s . co m*/ else if (part.equals("text()")) return e.getText(); else if (part.startsWith("@")) return e.getAttribute(part.substring(1)).getValue(); else { Element child = e.getChild(part, null); if (child == null) { child = new Element(part, e.getNamespace()); e.addContent(child); } e = child; } } return new XmlNode(e); }
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"); }/*from w w w .ja v a 2 s . c om*/ 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."); }/*from www . jav a 2s .c o m*/ 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.mule.tools.apikit.output.MuleConfigGenerator.java
License:Open Source License
private void generateAPIKitConfig(API api, Document doc) { XPathExpression muleExp = XPathFactory.instance().compile("//*[local-name()='mule']"); List<Element> mules = muleExp.evaluate(doc); Element mule = mules.get(0);//from w w w . j a v a2 s . c om if (api.getHttpListenerConfig() == null) { api.setHttpListenerConfig( new HttpListenerConfig(HttpListenerConfig.DEFAULT_CONFIG_NAME, HttpListenerConfig.DEFAULT_HOST, HttpListenerConfig.DEFAULT_PORT, HttpListenerConfig.DEFAULT_BASE_PATH)); } new HttpListenerConfigScope(api, mule).generate(); new APIKitConfigScope(api.getConfig(), mule).generate(); Element exceptionStrategy = new ExceptionStrategyScope(mule, api.getId()).generate(); String configRef = api.getConfig() != null ? api.getConfig().getName() : null; String listenerConfigRef = api.getHttpListenerConfig().getName(); new FlowScope(mule, exceptionStrategy.getAttribute("name").getValue(), api, configRef, listenerConfigRef) .generate(); }
From source file:org.mycore.datamodel.ifs.MCRSimpleFCTDetector.java
License:Open Source License
/** * Adds a detection rule from the file content type definition XML file. The * detector parses the <rules> element provided with each content type * in the file content types XML definition. * // ww w. java 2s . co m * @param type * the file content type the rule is for * @param xRules * the rules XML element containing the rules for detecting that * type */ public void addRule(MCRFileContentType type, Element xRules) { Vector rules = new Vector(); rulesTable.put(type, rules); typesList.add(type); try { List extensions = xRules.getChildren("extension"); for (Object extension : extensions) { Element elem = (Element) extension; double score = elem.getAttribute("score").getDoubleValue(); String ext = elem.getTextTrim(); rules.addElement(new MCRExtensionRule(ext, score)); } List patterns = xRules.getChildren("pattern"); for (Object pattern1 : patterns) { Element elem = (Element) pattern1; double score = elem.getAttribute("score").getDoubleValue(); int offset = elem.getAttribute("offset").getIntValue(); String format = elem.getAttributeValue("format"); String pattern = elem.getTextTrim(); rules.addElement(new MCRPatternRule(pattern, format, offset, score)); } List doctypes = xRules.getChildren("doctype"); for (Object doctype1 : doctypes) { Element elem = (Element) doctype1; double score = elem.getAttribute("score").getDoubleValue(); String doctype = elem.getTextTrim(); rules.addElement(new MCRDoctypeRule(doctype, score)); } List strings = xRules.getChildren("string"); for (Object string1 : strings) { Element elem = (Element) string1; double score = elem.getAttribute("score").getDoubleValue(); String string = elem.getTextTrim(); rules.addElement(new MCRStringRule(string, score)); } } catch (Exception exc) { String msg = "Error parsing detection rules for file content type " + type.getLabel(); throw new MCRConfigurationException(msg, exc); } }
From source file:org.mycore.datamodel.metadata.MCRObjectMetadata.java
License:Open Source License
/** * This method adds MCRMetaElement's from a given MCRObjectMetadata to * this data set if there are any differences between the data sets. * /*from w ww . j a va 2 s. c om*/ * @param input * the MCRObjectMetadata, that should merged into this data set * * @deprecated use {@link MCRObjectMerger#mergeMetadata(MCRObject, boolean)} instead */ public final void mergeMetadata(MCRObjectMetadata input) { for (MCRMetaElement metaElement : input) { int pos = -1; for (int j = 0; j < size(); j++) { if (meta_list.get(j).getTag().equals(metaElement.getTag())) { pos = j; } } if (pos != -1) { for (int j = 0; j < metaElement.size(); j++) { boolean found = false; for (MCRMetaInterface mcrMetaInterface : meta_list.get(pos)) { Element xml = mcrMetaInterface.createXML(); Element xmlNEW = metaElement.getElement(j).createXML(); List<Element> childrenXML = xml.getChildren(); if (childrenXML.size() > 0 && xmlNEW.getChildren().size() > 0) { int i = 0; for (Element element : childrenXML) { Element elementNew = xmlNEW.getChild(element.getName()); if (elementNew != null && element != null) { if (element.getText().equals(elementNew.getText())) { i++; } } } if (i == childrenXML.size()) { found = true; } } else { if (xml.getText().equals(xmlNEW.getText())) { found = true; } else if (!found) { int i = 0; List<Attribute> attributes = xml.getAttributes(); for (Attribute attribute : attributes) { Attribute attr = xmlNEW.getAttribute(attribute.getName()); if ((attr != null) && attr.equals(attribute)) { i++; } } if (i == attributes.size()) { found = true; } } } } MCRMetaInterface obj = metaElement.getElement(j); if (!found) { meta_list.get(pos).addMetaObject(obj); } else if (LOGGER.isDebugEnabled()) { LOGGER.debug("Found equal tags: \n\r" + new XMLOutputter(Format.getPrettyFormat()).outputString(obj.createXML())); } } } else { meta_list.add(metaElement); } } }
From source file:org.mycore.datamodel.metadata.validator.MCREditorOutValidator.java
License:Open Source License
public static String checkMetaObjectWithLang(Element datasubtag, Class<? extends MCRMetaInterface> metaClass) { if (datasubtag.getAttribute("lang") != null) { datasubtag.getAttribute("lang").setNamespace(XML_NAMESPACE); LOGGER.warn("namespace add for xml:lang attribute in " + datasubtag.getName()); }/*from w w w. j a v a 2s. com*/ return checkMetaObject(datasubtag, metaClass, true); }
From source file:org.mycore.datamodel.metadata.validator.MCREditorOutValidator.java
License:Open Source License
public static String checkMetaObjectWithLinks(Element datasubtag, Class<? extends MCRMetaInterface> metaClass) { if (datasubtag.getAttributeValue("href") == null && datasubtag.getAttributeValue("href", XLINK_NAMESPACE) == null) { return datasubtag.getName() + " has no href attribute defined"; }// www . j a va2s . c om if (datasubtag.getAttribute("xtype") != null) { datasubtag.getAttribute("xtype").setNamespace(XLINK_NAMESPACE).setName("type"); } else if (datasubtag.getAttribute("type") != null && datasubtag.getAttribute("type", XLINK_NAMESPACE) == null) { datasubtag.getAttribute("type").setNamespace(XLINK_NAMESPACE); LOGGER.warn("namespace add for xlink:type attribute in " + datasubtag.getName()); } if (datasubtag.getAttribute("href") != null) { datasubtag.getAttribute("href").setNamespace(XLINK_NAMESPACE); LOGGER.warn("namespace add for xlink:href attribute in " + datasubtag.getName()); } if (datasubtag.getAttribute("title") != null) { datasubtag.getAttribute("title").setNamespace(XLINK_NAMESPACE); LOGGER.warn("namespace add for xlink:title attribute in " + datasubtag.getName()); } if (datasubtag.getAttribute("label") != null) { datasubtag.getAttribute("label").setNamespace(XLINK_NAMESPACE); LOGGER.warn("namespace add for xlink:label attribute in " + datasubtag.getName()); } return checkMetaObject(datasubtag, metaClass, false); }