protected final org.jdom.Element findTypeContent(final String type, org.jdom.Element docRoot) { @SuppressWarnings("unchecked") List<org.jdom.Element> lst = docRoot.getContent(new Filter() { @Override public boolean matches(Object match) { if (match instanceof org.jdom.Element) { org.jdom.Element el = (org.jdom.Element)match; if ("complexType".equals(el.getName()) && type.equals(el.getAttributeValue("name"))) { //NOI18N return true; } } return false; } }); if (lst.size() > 0) { org.jdom.Element typeEl = lst.get(0); return typeEl.getChild("all", docRoot.getNamespace()); //NOI18N } return null; }
/** * Extracts the contents of the named XML element from a parent * * @param parentElement The parent element * @param theElement Name of the XML element to be extracted * @return * @throws IOException * @throws JDOMException */ public static Element extractXMLelement(Element parentElement, String theElement) throws JDOMException, IOException { Filter elementFilter = new ElementFilter(); List<Element> children = parentElement.getContent(elementFilter); for (Element element : children) { if (element.getName().equalsIgnoreCase(theElement)) { return element; } Element child = extractXMLelement(element, theElement); if (child != null) { return child; } } return null; }
private static void cleanTaggedValues(StringBuffer xmiContents) throws IOException { // filter for <UML:TaggedValue ../> Filter taggedValueFilter = new Filter() { public boolean matches(Object obj) { if (obj instanceof Element) { Element elem = (Element) obj; if (elem.getName().equals("TaggedValue")) { return elem.getAttribute("value") == null; } } return false; } }; int removed = removeElementsByFilter(xmiContents, taggedValueFilter); log.debug("Removed " + removed + " TaggedValue elements"); }
public boolean hasDocumentation() { Filter filter = new DocumentationFilter(); Iterator docIt = element.getDescendants(filter); if ( docIt.hasNext() ) { return true; } else { return false; } }
public Documentation getDocumentation () { Filter filter = new DocumentationFilter(); Iterator docIt = element.getDescendants(filter); Element documentation = (Element) docIt.next(); if ( documentation != null ) { return new Documentation(documentation); } return null; }
public Element findProperty(Element group, String name) throws LASException { Filter propertyFilter = new FindPropertyFilter(name); Iterator propsIt = group.getDescendants(propertyFilter); Element property=null; if ( propsIt.hasNext() ) { property = (Element) propsIt.next(); } if ( propsIt.hasNext()) { throw new LASException("More than one property with same name."); } return property; }
public Element findPropertyGroup(Element properties, String group) throws LASException { // Finds properties below a particular element. Filter propertyGroupFilter = new FindPropertyGroupFilter(group); Iterator pgIt = properties.getDescendants(propertyGroupFilter); Element propGroup = null; if (pgIt.hasNext()) { propGroup = (Element) pgIt.next(); } // if ( pgIt.hasNext() ) { // throw new LASException("More than one property group with name = "+group); // } // Just return the first... return propGroup; }
public ArrayList<Element> findPropertyGroupList(Element element, String group) { ArrayList<Element> groups = new ArrayList<Element>(); Filter propertyGroupFilter = new FindPropertyGroupFilter(group); for (Iterator pgIt = element.getDescendants(propertyGroupFilter); pgIt.hasNext(); ) { groups.add((Element)pgIt.next()); } return groups; }
private List<CDATA> getCDATAExceptionStackTracesUnder(Element rootElement) { Iterator it = rootElement.getDescendants(new Filter() { public boolean matches(Object arg0) { return arg0 instanceof CDATA; } }); List<CDATA> stackTraceElements = new ArrayList<CDATA>(); while (it.hasNext()) { CDATA next = (CDATA) it.next(); stackTraceElements.add(next); } return stackTraceElements; }
private static void cleanUmlDiagrams(StringBuffer xmiContents) throws IOException { // filter for <UML:Diagram ../> Filter diagramFilter = new Filter() { public boolean matches(Object obj) { if (obj instanceof Element) { Element elem = (Element) obj; return elem.getName().equals("Diagram"); } return false; } }; int removed = removeElementsByFilter(xmiContents, diagramFilter); log.debug("Removed " + removed + " Diagram elements"); }
public static CQLQuery checkDefaultPredicates(CQLQuery original) throws Exception { LOG.debug("Checking query for Attributes with no predicate defined"); StringWriter originalWriter = new StringWriter(); Utils.serializeObject(original, DataServiceConstants.CQL_QUERY_QNAME, originalWriter); Element root = XMLUtilities.stringToDocument(originalWriter.getBuffer().toString()).getRootElement(); Filter attributeNoPredicateFilter = new Filter() { public boolean matches(Object o) { if (o instanceof Element) { Element e = (Element) o; if (e.getName().equals("Attribute") && e.getAttribute("predicate") == null) { return true; } } return false; } }; List<?> attributesWithNoPredicate = root.getContent(attributeNoPredicateFilter); Iterator<?> attribIter = attributesWithNoPredicate.iterator(); while (attribIter.hasNext()) { LOG.debug("Adding default predicate to an attribute"); Element elem = (Element) attribIter.next(); elem.setAttribute("predicate", "EQUAL_TO"); } String xml = XMLUtilities.elementToString(root); CQLQuery edited = Utils.deserializeObject(new StringReader(xml), CQLQuery.class); return edited; }
@Override public <T extends Content> List<T> getContent(final Filter<T> filter) { return (List<T>)ContainerUtil.filter(myContent, new Condition<Content>() { @Override public boolean value(Content content) { return filter.matches(content); } }); }
@SuppressWarnings({ "unchecked", "serial", "rawtypes" }) private void addHttpsConnector(String keyStorePassword, File keyStoreLocation, Element serverElement) throws IOException, ContainerException { Iterator httpsConnectorElements = serverElement.getDescendants(new Filter() { public boolean matches(Object o) { if (o instanceof Element) { Element e = (Element) o; if (e.getName().equals("Connector")) { if(e.getAttribute("schema")!=null && "https".equals(e.getAttribute("schema").getValue())){ return true; } } } return false; } }); // verify there is only one connector if (!httpsConnectorElements.hasNext()) { Element service=(Element)serverElement.getChildren("Service").get(0); Element connector = new Element("Connector"); connector.setAttribute(new Attribute("acceptCount", "100")); connector.setAttribute(new Attribute("clientAuth", "false")); connector.setAttribute(new Attribute("debug", "0")); connector.setAttribute(new Attribute("disableUploadTimeout", "true")); connector.setAttribute(new Attribute("enableLookups", "false")); connector.setAttribute(new Attribute("keystoreFile", keyStoreLocation.getCanonicalPath())); connector.setAttribute(new Attribute("keystorePass", keyStorePassword)); connector.setAttribute(new Attribute("maxHttpHeaderSize", "8192")); connector.setAttribute(new Attribute("maxSpareThreads", "75")); connector.setAttribute(new Attribute("maxThreads", "150")); connector.setAttribute(new Attribute("minSpareThreads", "25")); connector.setAttribute(new Attribute("port", ""+httpsPortNumber)); connector.setAttribute(new Attribute("schema", "https")); connector.setAttribute(new Attribute("secure", "true")); connector.setAttribute(new Attribute("sslProtocol", "TLS")); service.getChildren().add(connector); }else{ throw new ContainerException("More than one HTTPS connector was found in the server configuration!"); } }
public void startFixing() { List<File> classpathFiles = recursiveListFiles(new File(baseSearchDir), new FileFilter() { public boolean accept(File pathname) { return pathname.getName().equals(".classpath"); } }); for (File f : classpathFiles) { if (f.isFile()) { System.out.println("Working on " + f.getAbsolutePath()); try { Document doc = fileToDocument(f); List libElements = doc.getRootElement().getContent(new Filter() { public boolean matches(Object o) { if (o instanceof Element) { Element e = (Element) o; if (e.getName().equals("classpathentry") && "lib".equals(e.getAttributeValue("kind"))) { return true; } } return false; } }); Iterator libElemIter = libElements.iterator(); while (libElemIter.hasNext()) { Element entryElem = (Element) libElemIter.next(); File projectBase = f.getParentFile(); String libPath = entryElem.getAttributeValue("path"); File libFile = new File(projectBase, libPath); String libName = libFile.getName(); if (libName.startsWith("caGrid-") && libName.endsWith("-1.6-dev.jar")) { System.out.println("Found a library to fix up (" + libPath + ")"); int endIndex = libPath.lastIndexOf("-1.6-dev.jar"); libPath = libPath.substring(0, endIndex); libPath += "-1.4.jar"; System.out.println("\tFixed up to " + libPath); entryElem.setAttribute("path", libPath); } } saveDocument(doc, f); } catch (Exception ex) { ex.printStackTrace(); } } } }
@Override public <T extends Content> Iterator<T> getDescendants(Filter<T> filter) { throw immutableError(this); }
@Override public <T extends Content> List<T> removeContent(Filter<T> filter) { throw immutableError(this); }
/** * Returns as a {@link java.util.List} the content of * this parent that matches the supplied filter. The returned list is * <b>"live"</b> and in document order. Any modifications to it affect * the element's actual contents. Modifications are checked for * conformance to XML 1.0 rules. * <p> * Sequential traversal through the List is best done with an Iterator * since the underlying implement of {@link java.util.List#size} may * require walking the entire list and indexed lookups may require * starting at the beginning each time. * * @param filter filter to apply * @return a list of the content of the parent matching the filter * @throws IllegalStateException if parent is a Document * and the root element is not set */ List getContent(Filter filter);
/** * Removes from this parent all child content matching the given filter * and returns a list of the detached children. * * @param filter filter to apply * @return list of the detached children matching the filter */ List removeContent(Filter filter);
/** * Returns an {@link java.util.Iterator} that walks over all descendants * in document order applying the Filter to return only elements that * match the filter rule. With filters you can match only Elements, * only Comments, Elements or Comments, only Elements with a given name * and/or prefix, and so on. * * @param filter filter to select which descendants to see * @return an iterator to walk descendants that match a filter */ Iterator getDescendants(Filter filter);