List of usage examples for org.jdom2.filter Filters element
public static final Filter<Element> element(Namespace ns)
From source file:AIR.Common.xml.XmlHelper.java
License:Open Source License
public static List<Element> getElements(Parent doc, final String name) { IteratorIterable<Element> matches = doc.<Element>getDescendants(Filters.element(name)); List<Element> returnList = new ArrayList<Element>(); while (matches.hasNext()) returnList.add(matches.next());/*from ww w.j a v a 2 s. c o m*/ return returnList; }
From source file:edu.unc.lib.dl.xml.DepartmentOntologyUtil.java
License:Apache License
public DepartmentOntologyUtil() { addressPattern = Pattern.compile("([^,]+,)+\\s*[a-zA-Z ]*\\d+[a-zA-Z]*\\s*[^\\n]*"); addressTrailingPattern = Pattern.compile("([^,]+,){2,}\\s*([a-zA-Z]+ ?){1,2}\\s*"); addressSplit = Pattern.compile( "(,? *(and *)?(?=dep(t\\.?|artment(s)?)|school|division|section(s)?|program in|center for|university)(?= of)?)", Pattern.CASE_INSENSITIVE); trimLeading = Pattern.compile("^([.?;:*&^%$#@!\\-]|the |at |and |\\s)+"); trimTrailing = Pattern.compile("([.?;:*&^%$#@!\\-]|the |at |\\s)+$"); deptSplitPlural = Pattern.compile( "(and the |and (the )?(dep(t\\.?|artment(s)?)|school|division|section(s)?|program in|center for)( of)?|and )"); trimSuffix = Pattern.compile("\\s*(department|doctoral|masters)$"); trimUNC = Pattern.compile("\\b(unc|carolina)\\s+"); splitSimple = Pattern.compile("(\\s*[:()]\\s*)+"); try {/*from w w w. j av a2s .co m*/ XPathFactory xFactory = XPathFactory.instance(); namePath = xFactory.compile("mods:name", Filters.element(MODS_V3_NS), null, MODS_V3_NS); } catch (Exception e) { log.error("Failed to construct xpath", 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"); }//w w w .j a v a2 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.APIKitFlowsParser.java
License:Open Source License
@Override public Set<ResourceActionMimeTypeTriplet> parse(Document document) { Set<ResourceActionMimeTypeTriplet> entries = new HashSet<ResourceActionMimeTypeTriplet>(); XPathExpression<Element> xp = XPathFactory.instance().compile("//*/*[local-name()='flow']", Filters.element(XMLNS_NAMESPACE.getNamespace())); List<Element> elements = xp.evaluate(document); for (Element element : elements) { String name = element.getAttributeValue("name"); APIKitFlow flow;/* w w w . j a v a 2s . c o m*/ try { flow = APIKitFlow.buildFromName(name, includedApis.keySet()); } catch (IllegalArgumentException iae) { LOGGER.info("Flow named '" + name + "' is not an APIKit Flow because it does not follow APIKit naming convention."); continue; } API api = includedApis.get(flow.getConfigRef()); String resource = flow.getResource(); if (api != null) { if (!resource.startsWith("/")) { resource = "/" + resource; } if (api.getPath() == null) { throw new IllegalStateException("Api path is invalid"); } String path = APIKitTools.getCompletePathFromBasePathAndPath( api.getHttpListenerConfig().getBasePath(), api.getPath()); entries.add(new ResourceActionMimeTypeTriplet(api, path + resource, flow.getAction(), flow.getMimeType())); } else { throw new IllegalStateException("No APIKit entries found in Mule config"); } } return entries; }
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 w w w .j a va 2 s . 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.input.parsers.HttpListenerConfigParser.java
License:Open Source License
public Map<String, HttpListenerConfig> parse(Document document) { Map<String, HttpListenerConfig> httpListenerConfigMap = new HashMap<String, HttpListenerConfig>(); XPathExpression<Element> xp = XPathFactory.instance().compile( "//*/*[local-name()='" + HttpListenerConfig.ELEMENT_NAME + "']", Filters.element(HTTP_NAMESPACE.getNamespace())); List<Element> elements = xp.evaluate(document); for (Element element : elements) { String name = element.getAttributeValue("name"); if (name == null) { throw new IllegalStateException("Cannot retrieve name."); }// w w w . j av a 2 s. c o m String host = element.getAttributeValue("host"); if (host == null) { throw new IllegalStateException("Cannot retrieve host."); } String port = element.getAttributeValue("port"); if (port == null) { port = HttpListenerConfig.DEFAULT_PORT; } String basePath = element.getAttributeValue("basePath"); if (basePath == null) { basePath = "/"; } else if (!basePath.startsWith("/")) { basePath = "/" + basePath; } httpListenerConfigMap.put(name, new HttpListenerConfig(name, host, port, basePath)); } return httpListenerConfigMap; }