Java 类org.jdom.filter.ElementFilter 实例源码

项目:DocIT    文件:Cut.java   
public static void cut(Document doc) {

    // Iterate over all salary elements
    Iterator<?> iterator = doc.getDescendants(new ElementFilter("salary"));

    // Snapshot these elements before modification
    List<Element> elems = new LinkedList<Element>();
    while (iterator.hasNext())
        elems.add((Element)iterator.next());

    // Iterate over salary elements and cut salaries
    for (Element elem : elems) {
        Double salary = Double.valueOf(elem.getText());
        elem.setText(Double.toString(salary/2));
    }
}
项目:OSCAR-ConCert    文件:OntarioMD.java   
private Hashtable parseReturn(InputStream is){
    Hashtable h = null;
    try {


        SAXBuilder parser = new SAXBuilder();
        Document doc = parser.build(is);
        Element root = doc.getRootElement();
         h  = new Hashtable();
        String jsessionID =g(root.getDescendants(new ElementFilter("jsessionID")));
        String ptLoginToken =g(root.getDescendants(new ElementFilter("ptLoginToken")));
        String returnCode =g(root.getDescendants(new ElementFilter("returnCode")));

        h.put("returnCode",returnCode);
        h.put("ptLoginToken",ptLoginToken);
        h.put("jsessionID",jsessionID);

    }catch(Exception e){
        MiscUtils.getLogger().error("Error", e);
    }
    return h;
}
项目:LAS    文件:IsoMetadata.java   
public void init() {
    Iterator extentIt = getDescendants(new ElementFilter("extent", gmd));
    Element extent;
    if ( extentIt.hasNext() ) {
        extent = (Element) extentIt.next();
        geographic = extent.getChild("EX_Extent", gmd).getChild("geographicElement", gmd).getChild("EX_GeographicBoundingBox", gmd);
        Element verticalParent = extent.getChild("EX_Extent", gmd).getChild("verticalElement", gmd);
        if ( verticalParent != null ) {
            vertical = verticalParent.getChild("EX_VerticalExtent", gmd);
        }
        Element timeouter = extent.getChild("EX_Extent", gmd).getChild("temporalElement", gmd);
        if ( timeouter != null ) {
            time = timeouter.getChild("EX_TemporalExtent", gmd);
        }
    }
}
项目:LAS    文件:ESGFSearchDocument.java   
private List<String> getStringValues(String elementName, String name) {
    List<String> values = new ArrayList<String>();
    Element root = getRootElement();
    Iterator elements = root.getDescendants(new ElementFilter(elementName));
    if ( root == null ) {
        return values;
    }
    while ( elements.hasNext() ) {
        Element e = (Element) elements.next();
        String ename = e.getAttributeValue("name");
        if (ename != null && ename.equals(name) ) {
            List<Element> strs = e.getChildren("str");
            for ( Iterator strIt = strs.iterator(); strIt.hasNext(); ) {
                Element str = (Element) strIt.next();     
                String value = str.getTextTrim();
                if ( value != null ) {
                    values.add(value);
                }
            }
        }
    }
    return values;
}
项目:sakai    文件:PrintHandler.java   
public void setResourceMetadataXml(Element the_md) {
    // version 1 and higher are different formats, hence a slightly weird test
    Iterator mdroles = the_md.getDescendants(new ElementFilter("intendedEndUserRole", ns.lom_ns()));
    if (mdroles != null) {
    while (mdroles.hasNext()) {
 Element role = (Element)mdroles.next();
     Iterator values = role.getDescendants(new ElementFilter("value", ns.lom_ns()));
     if (values != null) {
  while (values.hasNext()) {
 if (roles == null)
     roles = new HashSet<String>();
      Element value = (Element)values.next();
      String roleName = value.getTextTrim();
      roles.add(roleName);
  }
     }
 }
    }

    if (log.isDebugEnabled())
 log.debug("resource md xml: "+the_md); 
}
项目:incubator-taverna-workbench    文件:IterationStrategyContextualView.java   
private static void stripEmptyElements(Element asXML) {
    int childCount = asXML.getContent().size();
    int index = 0;
    while (index < childCount) {
        Content child = asXML.getContent(index);
        if (child instanceof Element) {
            Element childElement = (Element) child;
            if (childElement.getName().equals("port")) {
                index++;
            } else if (childElement.getDescendants(new ElementFilter("port")).hasNext()) {
                stripEmptyElements(childElement);
                index++;
            } else {
                asXML.removeContent(childElement);
                childCount--;
            }
        }
    }
}
项目:jhove2    文件:PronomWebService.java   
/**
 * 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;
}
项目:sakai    文件:PrintHandler.java   
public void setResourceMetadataXml(Element the_md) {
    // version 1 and higher are different formats, hence a slightly weird test
    Iterator mdroles = the_md.getDescendants(new ElementFilter("intendedEndUserRole", ns.lom_ns()));
    if (mdroles != null) {
    while (mdroles.hasNext()) {
 Element role = (Element)mdroles.next();
     Iterator values = role.getDescendants(new ElementFilter("value", ns.lom_ns()));
     if (values != null) {
  while (values.hasNext()) {
 if (roles == null)
     roles = new HashSet<String>();
      Element value = (Element)values.next();
      String roleName = value.getTextTrim();
      roles.add(roleName);
  }
     }
 }
    }

    if (log.isDebugEnabled())
 log.debug("resource md xml: "+the_md); 
}
项目:olfs    文件:Dap4Error.java   
private Document ingestError(Document error){
        Iterator i = error.getDescendants(new ElementFilter(DAP4.ERROR,DAP4.NS));

        if(i.hasNext()){
            Element e = (Element)i.next();
            e.detach();
//            error.detachRootElement();
//            error.setRootElement(e);
            ingestError(e);
            return error;
        }
        else
            return null;


    }
项目:olfs    文件:CoverageDescription.java   
/**
 * Gets the wcs:Identifier of each wcs:Field in this wcs:Coverage.
 * @return An array of strings containing the values of each wcs:Identifier of each wcs:Field in this wcs:Coverage.
 */
public String[] getFieldIDs(){
    Vector<String> fIDs = new Vector<String>();
    Element field, identifier;
    String id;

    Iterator i =  myCD.getDescendants(new ElementFilter("Field",WCS.WCS_NS));
    while(i.hasNext()){
        field = (Element) i.next();
        identifier = field.getChild("Identifier",WCS.WCS_NS);
        if(identifier!=null){
            id = identifier.getTextTrim();
            fIDs.add(id);
        }
    }

    String[] fieldIDs = new String[fIDs.size()];

    return fIDs.toArray(fieldIDs);
}
项目:olfs    文件:CoverageDescription.java   
public Vector<Field> getFields() throws WcsException {

        Element rangeType;
        rangeType = _myCD.getChild("rangeType",WCS.GMLCOV_NS);
        if(rangeType==null)
            throw new WcsException("wcs:CoverageDescription is missing a gmlcov:rangeType: ",
                WcsException.MISSING_PARAMETER_VALUE,"gmlcov:rangeType");

        Vector<Field> fields = new Vector<>();
        ElementFilter filter = new ElementFilter("field",WCS.SWE_NS);
        Iterator i = rangeType.getDescendants(filter);
        while(i.hasNext()){
            Element fieldElement = (Element) i.next();
            Field field = new Field(fieldElement);
            fields.add(field);
        }
        return fields;
    }
项目:olfs    文件:NcmlManager.java   
public static  Vector<Element> getNcmlDatasetElements(Element catalog){

        Vector<Element> ncmlDatasets = new Vector<Element>();

        Iterator alldatasets = catalog.getDescendants(new ElementFilter(THREDDS.DATASET, THREDDS.NS));

        Iterator ncmlContent;
        Element dataset;
        while(alldatasets.hasNext()){
            dataset = (Element) alldatasets.next();
            ncmlContent = dataset.getDescendants(new ElementFilter(NCML.NS));

            if(ncmlContent.hasNext())
                ncmlDatasets.add(dataset);
        }

        return ncmlDatasets;
    }
项目:olfs    文件:BESError.java   
public BESError(Document error, MediaType mt) {
    this();
    setResponseMediaType(mt);

    Iterator i = error.getDescendants(new ElementFilter(BES_ERROR));

    if(i.hasNext()){
        Element e = (Element)i.next();
        e.detach();
        error.detachRootElement();
        error.setRootElement(e);
    }

    besErrorDoc = processError(error);


}
项目:olfs    文件:BESError.java   
private Document processError(Document error){
    Iterator i = error.getDescendants(new ElementFilter(BES_ERROR));

    if(i.hasNext()){
        Element e = (Element)i.next();
        e.detach();
        error.detachRootElement();
        error.setRootElement(e);
        processError(e);
        return error;
    }
    else
        return null;


}
项目:olfs    文件:DatasetScan.java   
private Vector<Element> getDatasetScanServiceElements() throws JDOMException, SaxonApiException, IOException {

        Vector<Element> services = new Vector<>();

        Iterator<Element> i = _sourceDatasetScanElement.getDescendants(new ElementFilter(THREDDS.SERVICE_NAME, THREDDS.NS));


        while(i.hasNext()){
            Element serviceNameElement = i.next();
            String serviceName = serviceNameElement.getTextTrim();

            Element service = getServiceByName(serviceName);

            if (service == null ) {
                _log.error("getDatasetScanServiceElements() - Unable to locate service named '{}'. Skipping.",serviceName);
            }
            else {
                services.add(service);
            }
        }

        return services;
    }
项目:oscar-old    文件:OntarioMD.java   
private Hashtable parseReturn(InputStream is){
    Hashtable h = null;
    try {


        SAXBuilder parser = new SAXBuilder();
        Document doc = parser.build(is);
        Element root = doc.getRootElement();
         h  = new Hashtable();
        String jsessionID =g(root.getDescendants(new ElementFilter("jsessionID")));
        String ptLoginToken =g(root.getDescendants(new ElementFilter("ptLoginToken")));
        String returnCode =g(root.getDescendants(new ElementFilter("returnCode")));

        h.put("returnCode",returnCode);
        h.put("ptLoginToken",ptLoginToken);
        h.put("jsessionID",jsessionID);

    }catch(Exception e){
        MiscUtils.getLogger().error("Error", e);
    }
    return h;
}
项目:enhanced-basiclti-b2    文件:Utils.java   
public static Element getXmlChild(Element root, String name) {

    Element child = null;
    List<Element> elements = null;
    if (name != null) {
      ElementFilter elementFilter = new ElementFilter(name);
      Iterator<Element> iter = (Iterator<Element>)root.getDescendants(elementFilter);
      if (iter.hasNext()) {
        child = iter.next();
      }
    } else {
      elements = (List<Element>)root.getChildren();
      if (elements.size() >= 1) {
        child = elements.get(0);
      }
    }

    return child;

  }
项目:proactive-component-monitoring    文件:HierarchicalBarChart.java   
@SuppressWarnings("unchecked")
public void generateChart(Element eTimit, BenchmarkStatistics bstats, ConfigChart cChart) {
    Element eTimitClone = (Element) eTimit.clone();

    // Apply filter on elements
    Iterator<Element> itTimers = eTimitClone.getDescendants(new ElementFilter("timers"));

    while (itTimers.hasNext()) {
        XMLHelper.tagFiltering(itTimers.next(), cChart.get("filter").split(","));
    }

    // Get values from XML tree (Element)
    List<Element> fstats = eTimitClone.getChildren();
    this.timers = new Element[fstats.size()];
    this.categories = new Comparable[fstats.size()];

    for (int i = 0; i < fstats.size(); i++) {
        Element fstat = (Element) fstats.get(i);
        fstat.removeChild("events");
        this.timers[i] = fstat.getChild("timers");
        this.categories[i] = fstat.getAttributeValue("name");
    }

    this.buildFinalChart(cChart);
}
项目:proactive-component-monitoring    文件:SerieResultWriter.java   
/**
 * Add a new result to write to the file. Output file is updated every time
 * you invoke this method.
 *
 * @param bResults
 *            the root Element of XML benchmark result file
 * @param name
 *            the name of the current serie execution
 * @param runs
 *            the number of runs for this benchmark statistics result
 * @param totalTimeoutErrors
 *            the total number of timeout errors which occured
 *            during the serie run
 */
public void addResult(Element bResults, String name, int runs, int totalTimeoutErrors) {
    Element benchResult = new Element("FinalStatistics");
    this.eTimit.addContent(benchResult);
    benchResult.setAttribute(new Attribute("name", name));
    benchResult.setAttribute(new Attribute("runs", "" + runs));
    benchResult.setAttribute(new Attribute("timeoutErrors", "" + totalTimeoutErrors));
    benchResult.setAttribute(new Attribute("date", "" +
        (new java.sql.Timestamp(System.currentTimeMillis()))));

    // Timer statistics
    this.fillTimersResults(benchResult, bResults.getDescendants(new ElementFilter("timers")));

    // Event statistics
    this.fillEventsResults(benchResult, bResults.getDescendants(new ElementFilter("events")));

    // Informations
    this.fillInformations(benchResult);

    // Save modification into file
    XMLHelper.writeFile(this.document, this.filename);
}
项目:LAS    文件:TestGFDL.java   
@Test
  public final void testGFDL() {
    // Test to make sure variables with names that start with u or v but aren't vectors don't get included.  There should only be one composite.
    String url = DODSNetcdfFile.canonicalURL("http://data1.gfdl.noaa.gov:8080/thredds/dodsC/CM2.1U_CDFef_v1.0_r1ocean");
String[] name = new String[]{"Vector of "};
String[] units = new String[]{"m s-1"};
NetcdfDataset ncds;
try {
    ADDXMLProcessor addxml = new ADDXMLProcessor();
    HashMap<String, String> options= new HashMap<String, String>();
    addxml.setOptions(options);
    ncds = ucar.nc2.dataset.NetcdfDataset.openDataset(url);
    // Test from COADS, which tests the new vectors capability
    Document leetmaa = addxml.createXMLfromNetcdfDataset(ncds , url);
    Iterator compIt = leetmaa.getRootElement().getDescendants(new ElementFilter("composite"));
    assertTrue(compIt.hasNext());
    int index = 0;
    while ( compIt.hasNext() ) {
        Element composite = (Element) compIt.next();
        List children = composite.getChildren();                
        assertTrue(children.size() == 1);
        Element variable = (Element) children.get(0);
        assertTrue(variable != null);
        String vname = variable.getAttributeValue("name");
        String vunits = variable.getAttributeValue("units");
        assertTrue(vname.contains(name[index]));
        assertTrue(vunits.equals(units[index]));
        index++;
    }
    assertTrue(index == 1);
} catch (IOException e) {
    fail("Unable to connect to OPeNDAP server.");
}
  }
项目:LAS    文件:TestNGDC.java   
@Test
  public final void testNGDC() {
    // The sole purpose of this test it to check the starting hour of the time axis.
    // The time axis is regular with an interval of 1 day, but for some strange reason the times are recorded at 17:00
    // so the hour needs to be included in the start string.
    String url = DODSNetcdfFile.canonicalURL("http://www.ngdc.noaa.gov/thredds/dodsC/sst-100km-aggregation");
NetcdfDataset ncds;
try {
    ADDXMLProcessor addxml = new ADDXMLProcessor();
    HashMap<String, String> options= new HashMap<String, String>();
    options.put("force","t");
    addxml.setOptions(options);
    ncds = ucar.nc2.dataset.NetcdfDataset.openDataset(url);
    Document ngdc = addxml.createXMLfromNetcdfDataset(ncds , url);
    Iterator<Element> arangeIt = ngdc.getDescendants(new ElementFilter("arange"));
    assertTrue(arangeIt.hasNext());
    while ( arangeIt.hasNext() ) {
        Element arange = (Element) arangeIt.next();
        String start = arange.getAttributeValue("start");
        if ( start.length() > 6) {
            Pattern pattern = Pattern.compile(".*[0-9][0-9]:[0-9][0-9]:[0-9][0-9]");
            Matcher matcher = pattern.matcher(start);
            assertTrue(matcher.matches());
        }
    }
} catch (IOException e) {
    fail("Unable to connect to OPeNDAP server.");
}
  }
项目:LAS    文件:ESGFSearchDocument.java   
private List<FacetMember> getFacetValues(String elementName, String name ) {
    List<FacetMember> members = new ArrayList<FacetMember>();
    Element root = getRootElement();
    Iterator elements = root.getDescendants(new ElementFilter(elementName));
    if ( root == null ) {
        return members;
    }
    while ( elements.hasNext() ) {
        Element e = (Element) elements.next();
        String ename = e.getAttributeValue("name");
        if (ename != null && ename.equals(name) ) {
            List<Element> strs = e.getChildren("int");
            for ( Iterator strIt = strs.iterator(); strIt.hasNext(); ) {
                Element str = (Element) strIt.next();
                String fname = str.getAttributeValue("name");
                String count = str.getTextTrim();
                int c = 0;
                try {
                    c = Integer.valueOf(count);
                } catch ( NumberFormatException e1 ) {
                   // Ok, must be 0;
                }
                if ( count != null ) {
                    members.add(new FacetMember(fname, c));
                }
            }
        }
    }
    Collections.sort(members, new Comparator<FacetMember>() {

        @Override
        public int compare(FacetMember o1, FacetMember o2) {
            if ( o1 == null ) return -1;
            if ( o2 == null ) return 1;
            return o1.getName().compareToIgnoreCase(o2.getName());
        }

    });
    return members;
}
项目:LAS    文件:ESGFSearchDocument.java   
private String getValue(Element element, String elementName, String name ) {
    if ( element == null ) {
        return null;
    }
    Iterator elements = element.getDescendants(new ElementFilter(elementName));
    while ( elements.hasNext() ) {
        Element e = (Element) elements.next();
        String ename = e.getAttributeValue("name");
        if (ename != null && ename.equals(name) ) {
            return e.getTextTrim();
        }
    }
    return null;
}
项目:intellij-ce-playground    文件:JDOMUtil.java   
@SuppressWarnings("unused")
@Nullable
@Deprecated
public static Element cloneElement(@NotNull Element element, @NotNull ElementFilter elementFilter) {
  Element result = new Element(element.getName(), element.getNamespace());
  List<Attribute> attributes = element.getAttributes();
  if (!attributes.isEmpty()) {
    ArrayList<Attribute> list = new ArrayList<Attribute>(attributes.size());
    for (Attribute attribute : attributes) {
      list.add(attribute.clone());
    }
    result.setAttributes(list);
  }

  for (Namespace namespace : element.getAdditionalNamespaces()) {
    result.addNamespaceDeclaration(namespace);
  }

  boolean hasContent = false;
  for (Content content : element.getContent()) {
    if (content instanceof Element) {
      if (elementFilter.matches(content)) {
        hasContent = true;
      }
      else {
        continue;
      }
    }
    result.addContent(content.clone());
  }
  return hasContent ? result : null;
}
项目:olfs    文件:NcmlManager.java   
private static HashMap<String, Element> collectServices(Element threddsCatalog)  throws InterruptedException {
    HashMap<String, Element> services = new HashMap<String, Element>();

    Iterator i = threddsCatalog.getDescendants(new ElementFilter(
            THREDDS.SERVICE, THREDDS.NS));

    Element srvcElem;
    while (i.hasNext()) {
        srvcElem = (Element) i.next();
        services.put(srvcElem.getAttributeValue(THREDDS.NAME), srvcElem);
    }

    return services;

}
项目:olfs    文件:ThreddsCatalogUtil.java   
/**
 * Returns all of the THREDDS catalog URLs in the passed catalog element.
 * 
 * @param catalogUrlString
 *            The URL from where the catalog was retrieved.
 * @param catalog
 *            The root element (the catalog element) in a THREDDS catalog
 *            document.
 * @param recurse
 *            If true the code will recursively descend into all of the
 *            child catalogs and return all the contained catalog URLs. Be
 *            Careful!
 * @return A vector of fully qualified URL Strings each of which points to a
 *         THREDDS catalog document.
 */
private Vector<String> getCatalogRefURLs(String catalogUrlString,
        Element catalog, boolean recurse) throws InterruptedException, IOException, JDOMException {

    Vector<String> catalogURLs = new Vector<String>();

    try {

        String href;
        String newCatalogURL;
        Element catalogRef;
        Iterator i = catalog.getDescendants(new ElementFilter("catalogRef",
                THREDDS.NS));
        while (i.hasNext()) {
            catalogRef = (Element) i.next();
            href = catalogRef.getAttributeValue("href", XLINK.NS);

            newCatalogURL = getCatalogURL(catalogUrlString, href);

            catalogURLs.add(newCatalogURL);

            if (recurse)
                catalogURLs
                        .addAll(getCatalogRefURLs(newCatalogURL, recurse));

        }

    }
    catch (MalformedURLException e) {
        log.error("Malformed URL Exception: " + catalogUrlString + " msg: "
                + e.getMessage());
    }

    return catalogURLs;

}
项目:olfs    文件:ThreddsCatalogUtil.java   
private HashMap<String, Element> collectServices(Element threddsCatalog)  throws InterruptedException {
    HashMap<String, Element> services = new HashMap<String, Element>();

    Iterator i = threddsCatalog.getDescendants(new ElementFilter(
            THREDDS.SERVICE, THREDDS.NS));

    Element srvcElem;
    while (i.hasNext()) {
        srvcElem = (Element) i.next();
        services.put(srvcElem.getAttributeValue("name"), srvcElem);
    }

    return services;

}
项目:olfs    文件:ThreddsUtil.java   
/**
 * Returns all of the THREDDS catalog URLs in the passed catalog element.
 * 
 * @param catalogUrlString
 *            The URL from where the catalog was retrieved.
 * @param catalog
 *            The root element (the catalog element) in a THREDDS catalog
 *            document.
 * @return A vector of fully qualified URL Strings each of which points to a
 *         THREDDS catalog document.
 */
private Vector<String> getCatalogRefURLs(String catalogUrlString, Element catalog) {

    Vector<String> catalogURLs = new Vector<String>();

    try {
        String href;
        String newCatalogURL;
        Element catalogRef;

        @SuppressWarnings("rawtypes")
        Iterator i = catalog.getDescendants(new ElementFilter("catalogRef", THREDDS.NS));
        while (i.hasNext()) {
            catalogRef = (Element) i.next();
            href = catalogRef.getAttributeValue("href", XLINK.NS);

            newCatalogURL = getCatalogURL(catalogUrlString, href);

            catalogURLs.add(newCatalogURL);
        }

    }
    catch (MalformedURLException e) {
        log.error("Malformed URL Exception: " + catalogUrlString + " msg: "
                + e.getMessage());
    }

    return catalogURLs;

}
项目:olfs    文件:ThreddsUtil.java   
private HashMap<String, Element> collectServices(Element threddsCatalog) {
    HashMap<String, Element> services = new HashMap<String, Element>();

    @SuppressWarnings("rawtypes")
    Iterator i = threddsCatalog.getDescendants(new ElementFilter(THREDDS.SERVICE, THREDDS.NS));

    Element srvcElem;
    while (i.hasNext()) {
        srvcElem = (Element) i.next();
        services.put(srvcElem.getAttributeValue("name"), srvcElem);
    }

    return services;

}
项目:olfs    文件:ThreddsCatalogUtil.java   
/**
 * Returns all of the THREDDS catalog URLs in the passed catalog element.
 * 
 * @param catalogUrlString
 *            The URL from where the catalog was retrieved.
 * @param catalog
 *            The root element (the catalog element) in a THREDDS catalog
 *            document.
 * @return A vector of fully qualified URL Strings each of which points to a
 *         THREDDS catalog document.
 */
private Vector<String> getCatalogRefURLs(String catalogUrlString, Element catalog) {

    Vector<String> catalogURLs = new Vector<String>();

    try {
        String href;
        String newCatalogURL;
        Element catalogRef;

        @SuppressWarnings("rawtypes")
        Iterator i = catalog.getDescendants(new ElementFilter("catalogRef", THREDDS.NS));
        while (i.hasNext()) {
            catalogRef = (Element) i.next();
            href = catalogRef.getAttributeValue("href", XLINK.NS);

            newCatalogURL = getCatalogURL(catalogUrlString, href);

            catalogURLs.add(newCatalogURL);
        }

    }
    catch (MalformedURLException e) {
        log.error("Malformed URL Exception: " + catalogUrlString + " msg: "
                + e.getMessage());
    }

    return catalogURLs;

}
项目:olfs    文件:ThreddsCatalogUtil.java   
private HashMap<String, Element> collectServices(Element threddsCatalog) {
    HashMap<String, Element> services = new HashMap<String, Element>();

    @SuppressWarnings("rawtypes")
    Iterator i = threddsCatalog.getDescendants(new ElementFilter(THREDDS.SERVICE, THREDDS.NS));

    Element srvcElem;
    while (i.hasNext()) {
        srvcElem = (Element) i.next();
        services.put(srvcElem.getAttributeValue("name"), srvcElem);
    }

    return services;

}
项目:geowave    文件:JDOMUtils.java   
public static Element findFirstChild(
        final Element parentEl,
        final String childName ) {
    final ElementFilter filter = new ElementFilter(
            childName);
    final Iterator<Element> childrenIter = parentEl.getDescendants(filter);

    if (childrenIter.hasNext()) {
        return childrenIter.next();
    }

    return null;
}
项目:cagrid-core    文件:HBMClassDiscriminatorResolver.java   
public HBMClassDiscriminatorResolver(DomainModel model) {
    this.model = model;
    this.discriminators = new HashMap<String, Object>();
    // filter for discriminator elements
    this.discriminatorFilter = new ElementFilter("discriminator");
    // filter for joined-subclass elements
    this.joinedSubclassFilter = new ElementFilter("joined-subclass");
}
项目:proactive-component-monitoring    文件:Line2dChart.java   
public void generateChart(Element eTimit, BenchmarkStatistics bstats, ConfigChart cChart) {
    Element eTimitClone = (Element) eTimit.clone();

    // Apply filter on elements
    while (true) {
        @SuppressWarnings("unchecked")
        Iterator<Element> it = eTimitClone.getDescendants(new ElementFilter(cChart.get("tag")));
        try {
            while (it.hasNext()) {
                XMLHelper.tagFiltering(it.next(), cChart.get("filter").split(","));
            }
        } catch (java.util.ConcurrentModificationException e) {
            continue;
        }
        break;
    }

    // Get values from XML tree (Element)
    @SuppressWarnings("unchecked")
    List fstats = eTimitClone.getChildren();
    this.series = new Element[fstats.size()];
    this.categories = new Comparable[fstats.size()];

    for (int i = 0; i < fstats.size(); i++) {
        Element fstat = (Element) fstats.get(i);
        fstat.removeContent(new ElementFilter(cChart.get("tag")).negate());
        this.series[i] = fstat.getChild(cChart.get("tag"));
        this.categories[i] = fstat.getAttributeValue("name");
    }
    this.wantedTag = ((Element) this.series[0].getChildren().get(0)).getName();
    this.names = cChart.get("filter").split(",");
    this.selectedAttributeName = cChart.get("attribute");

    this.buildFinalChart(cChart);
}
项目:proactive-component-monitoring    文件:BenchmarkResultWriter.java   
/**
 * This method remove benchmarks that have extrem total time values.
 * (ie. it remove the min and the max)
 */
public void removeExtremums() {
    Document doc = XMLHelper.readFile(this.filename);
    Element root = doc.getRootElement();
    Iterator<Element> it = root.getDescendants(new ElementFilter("timers"));

    // Look for the max and min values...
    double vMax = Double.MIN_VALUE;
    double vMin = Double.MAX_VALUE;
    Element max = null;
    Element min = null;
    int size = 0;

    while (it.hasNext()) {
        size++;
        Element timers = it.next();
        Element eTimer = timers.getChild("timer");
        if (eTimer == null) {
            continue;
        }
        double value = Double.valueOf(eTimer.getAttributeValue("avg"));
        if (value > vMax) {
            vMax = value;
            max = timers;
        }
        if (value < vMin) {
            vMin = value;
            min = timers;
        }
    }

    // ... end remove them if there is more than 3 runs
    if ((size >= 3) && (max != null) && (min != null)) {
        max.getParentElement().detach();
        min.getParentElement().detach();
    }

    // then save the result
    XMLHelper.writeFile(doc, this.filename);
}
项目:edct-formbuilder    文件:XFormsUIBuilder.java   
@SuppressWarnings("unchecked")
public static Element removeChildByName( Element parent, String elementName ) {
    List<Element> children = parent.getContent( new ElementFilter( elementName, XFormsConstants.XFORMS_NAMESPACE ));
    if ( children.isEmpty() ) return null;
    Element child = (Element)children.get( 0 ).clone();
    parent.removeChild( elementName, XFormsConstants.XFORMS_NAMESPACE );
    return child;
}
项目:edct-formbuilder    文件:XFormsUtils.java   
@SuppressWarnings("unchecked")
public static List<Element> findEditableFormControlElements( Element parent ) {
    List<Element> editableElements = new ArrayList<Element>();
    Iterator<Element> iterator = parent.getDescendants( new ElementFilter() );
    while ( iterator.hasNext() ) {
        Element current = iterator.next();
        if ( isEditableFormControlElement( current ) ) {
            editableElements.add( current );
        }
    }

    return editableElements;
}
项目:consulo    文件:JDOMUtil.java   
@SuppressWarnings("unused")
@Nullable
@Deprecated
public static Element cloneElement(@Nonnull Element element, @Nonnull ElementFilter elementFilter) {
  Element result = new Element(element.getName(), element.getNamespace());
  List<Attribute> attributes = element.getAttributes();
  if (!attributes.isEmpty()) {
    ArrayList<Attribute> list = new ArrayList<Attribute>(attributes.size());
    for (Attribute attribute : attributes) {
      list.add(attribute.clone());
    }
    result.setAttributes(list);
  }

  for (Namespace namespace : element.getAdditionalNamespaces()) {
    result.addNamespaceDeclaration(namespace);
  }

  boolean hasContent = false;
  for (Content content : element.getContent()) {
    if (content instanceof Element) {
      if (elementFilter.matches(content)) {
        hasContent = true;
      }
      else {
        continue;
      }
    }
    result.addContent(content.clone());
  }
  return hasContent ? result : null;
}
项目:elexis-3-base    文件:XMLExporterTest.java   
@Test
public void doExportVatTest() throws IOException{
    TestSzenario szenario = TestData.getTestSzenarioInstance();
    assertNotNull(szenario.getRechnungen());
    assertFalse(szenario.getRechnungen().isEmpty());
    XMLExporter exporter = new XMLExporter();
    List<Rechnung> rechnungen = szenario.getRechnungen();
    for (Rechnung rechnung : rechnungen) {
        Document result =
            exporter.doExport(rechnung, getTempDestination(), IRnOutputter.TYPE.ORIG, true);
        assertNotNull(result);
        if (rechnung.getStatus() == RnStatus.FEHLERHAFT) {
            printFaildDocument(result);
            fail();
        }
        // check if the vat is included
        Element root = result.getRootElement();
        Iterator<?> iter = root.getDescendants(new ElementFilter("vat_rate"));
        assertTrue(iter.hasNext());
        while (iter.hasNext()) {
            Element vat_rate = (Element) iter.next();
            Attribute rate = vat_rate.getAttribute("vat_rate");
            Attribute vat = vat_rate.getAttribute("vat");
            if ("0.00".equals(rate.getValue())) {
                assertEquals(0.0, Double.parseDouble(vat.getValue()), 0.01);
            } else {
                Attribute amount = vat_rate.getAttribute("amount");
                Double rateDouble = Double.parseDouble(rate.getValue());
                Double amountDouble = Double.parseDouble(amount.getValue());
                Double expectedVat = (amountDouble / (100.0 + rateDouble)) * rateDouble;
                assertEquals(expectedVat, Double.parseDouble(vat.getValue()), 0.01);
            }
        }
    }
}
项目:elexis-3-base    文件:XMLExporterTest.java   
@Test
public void doExportObligationTest() throws IOException{
    TestSzenario szenario = TestData.getTestSzenarioInstance();
    assertNotNull(szenario.getRechnungen());
    assertFalse(szenario.getRechnungen().isEmpty());
    XMLExporter exporter = new XMLExporter();
    List<Rechnung> rechnungen = szenario.getRechnungen();
    for (Rechnung rechnung : rechnungen) {
        Document result =
            exporter.doExport(rechnung, getTempDestination(), IRnOutputter.TYPE.ORIG, true);
        assertNotNull(result);
        if (rechnung.getStatus() == RnStatus.FEHLERHAFT) {
            printFaildDocument(result);
            fail();
        }
        // check if the amount_obligations amount of the balance element is correct
        Element root = result.getRootElement();
        Iterator<?> iter = root.getDescendants(new ElementFilter("balance"));
        assertTrue(iter.hasNext());
        while (iter.hasNext()) {
            Element balance = (Element) iter.next();
            Attribute amount = balance.getAttribute("amount");
            Attribute obligations = balance.getAttribute("amount_obligations");
            assertNotNull(amount);
            assertNotNull(obligations);
            Double amountDouble = Double.parseDouble(amount.getValue());
            Double obligationsDouble = Double.parseDouble(obligations.getValue());
            assertTrue(amountDouble > 0.0D);
            assertTrue(obligationsDouble > 0.0D);
            assertTrue(amountDouble > obligationsDouble);
        }
    }
}