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

项目:incubator-sdap-mudrod    文件:AggregateTriples.java   
/**
 * Method of going through OWL structure
 */
public void loopxml() {
  Iterator<?> processDescendants = rootNode.getDescendants(new ElementFilter());
  String text = "";

  while (processDescendants.hasNext()) {
    Element e = (Element) processDescendants.next();
    String currentName = e.getName();
    text = e.getTextTrim();
    if ("".equals(text)) {
      LOG.info(currentName);
    } else {
      LOG.info("{} : {}", currentName, text);
    }
  }
}
项目:incubator-sdap-mudrod    文件:AggregateTriples.java   
/**
 * Method of identifying a specific child given a element name
 *
 * @param str element name
 * @param ele parent element
 * @return the element of child
 */
public Element findChild(String str, Element ele) {
  Iterator<?> processDescendants = ele.getDescendants(new ElementFilter());
  String name = "";
  Element result = null;

  while (processDescendants.hasNext()) {
    Element e = (Element) processDescendants.next();
    name = e.getName();
    if (name.equals(str)) {
      result = e;
      return result;
    }
  }
  return result;

}
项目:mudrod    文件:AggregateTriples.java   
/**
 * Method of going through OWL structure
 */
public void loopxml() {
  Iterator<?> processDescendants = rootNode.getDescendants(new ElementFilter());
  String text = "";

  while (processDescendants.hasNext()) {
    Element e = (Element) processDescendants.next();
    String currentName = e.getName();
    text = e.getTextTrim();
    if ("".equals(text)) {
      LOG.info(currentName);
    } else {
      LOG.info("{} : {}", currentName, text);
    }
  }
}
项目:mudrod    文件:AggregateTriples.java   
/**
 * Method of identifying a specific child given a element name
 *
 * @param str element name
 * @param ele parent element
 * @return the element of child
 */
public Element findChild(String str, Element ele) {
  Iterator<?> processDescendants = ele.getDescendants(new ElementFilter());
  String name = "";
  Element result = null;

  while (processDescendants.hasNext()) {
    Element e = (Element) processDescendants.next();
    name = e.getName();
    if (name.equals(str)) {
      result = e;
      return result;
    }
  }
  return result;

}
项目:marklogic-spring-batch    文件:HttpXmlItemReader.java   
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
    ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class);
    if (!response.getStatusCode().equals(HttpStatus.OK)) {
        throw new ItemStreamException(response.getStatusCode() + " HTTP response is returned");
    }
    ;
    MediaType type = response.getHeaders().getContentType();
    if (MediaType.APPLICATION_XML.equals(type) ||
            MediaType.APPLICATION_ATOM_XML.equals(type) ||
            MediaType.APPLICATION_XHTML_XML.equals(type) ||
            MediaType.APPLICATION_RSS_XML.equals(type) ||
            "text/xml".equals(type.toString())) {
        SAXBuilder jdomBuilder = new SAXBuilder();
        try {
            Document document = jdomBuilder.build(new StringReader(response.getBody()));
            ElementFilter ef = new ElementFilter(aggregateRecordElement);
            aggregateRecordElementItr = document.getRootElement().getDescendants(ef);
        } catch (Exception ex) {
            throw new ItemStreamException(ex);
        }
    }
}
项目:epubfx    文件:CoverpageBookProcessor.java   
private ImageResource getFirstImageSource(Resource CoverPageResource, Resources resources)
{
    try
    {
        Document titlePageDocument = ResourceUtil.getAsDocument(CoverPageResource);
        Filter<Element> imgFilter = new ElementFilter("img");
        List<Element> imageElements = titlePageDocument.getRootElement().getContent(imgFilter);
        for (Element imageElement : imageElements)
        {
            String relativeImageHref = imageElement.getAttributeValue("src");
            String absoluteImageHref = calculateAbsoluteImageHref(relativeImageHref, CoverPageResource.getHref());
            ImageResource imageResource = (ImageResource)resources.getByHref(absoluteImageHref);
            if (imageResource != null)
            {
                return imageResource;
            }
        }
    }
    catch (Exception e)
    {
        log.error(e.getMessage(), e);
    }
    return null;
}
项目:gocd    文件:GoConfigMigrationIntegrationTest.java   
@Test
public void shouldRemoveAllLuauConfigurationFromConfig() throws Exception {
    String configString =
            "<cruise schemaVersion='66'>"
                    + "<server siteUrl='https://hostname'>"
                    + "<security>"
                    + "      <luau url='https://luau.url.com' clientKey='0d010cf97ec505ee3788a9b5b8cf71d482c394ae88d32f0333' authState='authorized' />"
                    + "      <ldap uri='ldap' managerDn='managerDn' encryptedManagerPassword='+XhtUNvVAxJdHGF4qQGnWw==' searchFilter='(sAMAccountName={0})'>"
                    + "        <bases>"
                    + "          <base value='ou=Enterprise,ou=Principal,dc=corporate,dc=thoughtworks,dc=com' />"
                    + "        </bases>"
                    + "      </ldap>"
                    + "      <roles>"
                    + "         <role name='luau-role'><groups><luauGroup>luau-group</luauGroup></groups></role>"
                    + "         <role name='ldap-role'><users><user>some-user</user></users></role>"
                    + "</roles>"
                    + "</security>"
                    + "</server>"
                    + "</cruise>";

    String migratedContent = migrateXmlString(configString, 66);
    Document document = new SAXBuilder().build(new StringReader(migratedContent));

    assertThat(document.getDescendants(new ElementFilter("luau")).hasNext(), is(false));
    assertThat(document.getDescendants(new ElementFilter("groups")).hasNext(), is(false));
}
项目:mycore    文件:MCRWCMSDefaultSectionProvider.java   
public JsonArray toJSON(Element rootElement) {
    JsonArray sectionArray = new JsonArray();
    for (Element section : rootElement.getChildren(MyCoReWebPageProvider.XML_SECTION)) {
        // get infos of element
        String title = section.getAttributeValue(MyCoReWebPageProvider.XML_TITLE);
        String lang = section.getAttributeValue(MyCoReWebPageProvider.XML_LANG, Namespace.XML_NAMESPACE);
        String data = null;
        if (section.getContent(new ElementFilter()).size() > 1) {
            Element div = new Element("div");
            while (section.getChildren().size() > 0) {
                div.addContent(section.getChildren().get(0).detach());
            }
            section.addContent(div);
        }
        try {
            data = getContent(section);
        } catch (IOException ioExc) {
            LOGGER.error("while reading section data.", ioExc);
            continue;
        }

        // create json object
        JsonObject jsonObject = new JsonObject();
        if (title != null && !title.equals("")) {
            jsonObject.addProperty(JSON_TITLE, title);
        }
        if (lang != null && !lang.equals("")) {
            jsonObject.addProperty(JSON_LANG, lang);
        }
        String invalidElementName = validateElement(section);
        if (invalidElementName != null) {
            jsonObject.addProperty("hidden", "true");
            jsonObject.addProperty("invalidElement", invalidElementName);
        }
        jsonObject.addProperty(JSON_DATA, data);
        // add to array
        sectionArray.add(jsonObject);
    }
    return sectionArray;
}
项目:mycore    文件:MCRQLSearchUtils.java   
/**
 * Build MCRQuery from editor XML input
 */
public static MCRQuery buildFormQuery(Element root) {
    Element conditions = root.getChild("conditions");

    if (conditions.getAttributeValue("format", "xml").equals("xml")) {
        Element condition = conditions.getChildren().get(0);
        renameElements(condition);

        // Remove conditions without values
        List<Element> empty = new ArrayList<>();
        for (Iterator<Element> it = conditions.getDescendants(new ElementFilter("condition")); it.hasNext();) {
            Element cond = it.next();
            if (cond.getAttribute("value") == null) {
                empty.add(cond);
            }
        }

        // Remove empty sort conditions
        Element sortBy = root.getChild("sortBy");
        if (sortBy != null) {
            for (Element field : sortBy.getChildren("field")) {
                if (field.getAttributeValue("name", "").length() == 0) {
                    empty.add(field);
                }
            }
        }

        for (int i = empty.size() - 1; i >= 0; i--) {
            empty.get(i).detach();
        }

        if (sortBy != null && sortBy.getChildren().size() == 0) {
            sortBy.detach();
        }
    }

    return MCRQuery.parseXML(root.getDocument());
}
项目:ldapchai    文件:NmasResponseSet.java   
static ChallengeSet parseNmasUserResponseXML( final String str )
        throws IOException, JDOMException, ChaiValidationException
{
    final List<Challenge> returnList = new ArrayList<Challenge>();

    final Reader xmlreader = new StringReader( str );
    final SAXBuilder builder = new SAXBuilder();
    final Document doc = builder.build( xmlreader );

    final Element rootElement = doc.getRootElement();
    final int minRandom = StringHelper.convertStrToInt( rootElement.getAttributeValue( "RandomQuestions" ), 0 );

    final String guidValue;
    {
        final Attribute guidAttribute = rootElement.getAttribute( "GUID" );
        guidValue = guidAttribute == null ? null : guidAttribute.getValue();
    }

    for ( Iterator iter = doc.getDescendants( new ElementFilter( "Challenge" ) ); iter.hasNext(); )
    {
        final Element loopQ = ( Element ) iter.next();
        final int maxLength = StringHelper.convertStrToInt( loopQ.getAttributeValue( "MaxLength" ), 255 );
        final int minLength = StringHelper.convertStrToInt( loopQ.getAttributeValue( "MinLength" ), 2 );
        final String defineStrValue = loopQ.getAttributeValue( "Define" );
        final boolean adminDefined = "Admin".equalsIgnoreCase( defineStrValue );
        final String typeStrValue = loopQ.getAttributeValue( "Type" );
        final boolean required = "Required".equalsIgnoreCase( typeStrValue );
        final String challengeText = loopQ.getText();

        final Challenge challenge = new ChaiChallenge( required, challengeText, minLength, maxLength, adminDefined, 0, false );
        returnList.add( challenge );
    }

    return new ChaiChallengeSet( returnList, minRandom, null, guidValue );
}
项目:RaAuto    文件:UserInputContainer.java   
/**
 * Prepares the user input by replacing the variables in the xml (masked
 * values).
 */
public void prepareUserInputdata() {
    IteratorIterable<Element> cIterator = xmlMetaDataDoc
            .getDescendants(new ElementFilter());
    String lineValue;
    String inputRegEx = INPUT_REG_EX;
    if (cIterator != null) {
        while (cIterator.hasNext()) {
            lineValue = cIterator.next().getValue();
            if (lineValue.matches(inputRegEx)) {
                addKeyValueToHashMap(lineValue);
            }
        }
    }
}
项目:yawl    文件:JDOMUtil.java   
/****************************************************************************/

    public static Element selectElement(Document doc, String path) {
        XPathExpression<Element> expression =
                XPathFactory.instance().compile(path, new ElementFilter());
        return expression.evaluateFirst(doc);
    }
项目:ModelDebugging    文件:PluginXMLHelper.java   
public Element updateXDSMLDefinitionInExtensionPoint(Element extensionPoint, String xDSMLName){
    Element result;
    List<Element> elements = extensionPoint.getContent(new ElementFilter(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF));
    if(elements.size() == 0){
        // create extension point
        result = new Element(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF);
        extensionPoint.addContent(result);
    }
    else{
        result = elements.get(0);
    }
    result.setAttribute("name", xDSMLName);
    return result;
}
项目:ModelDebugging    文件:PluginXMLHelper.java   
public Element updateXDSMLDefinitionAttributeInExtensionPoint(Element extensionPoint, String atributeName, String value){
    Element result;
    List<Element> elements = extensionPoint.getContent(new ElementFilter(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF));
    if(elements.size() == 0){
        // create extension point
        result = new Element(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF);
        extensionPoint.addContent(result);
    }
    else{
        result = elements.get(0);
    }
    result.setAttribute(atributeName, value);
    return result;
}
项目:ModelDebugging    文件:PluginXMLHelper.java   
public String getXDSMLDefinitionAttributeInExtensionPointValue(Element extensionPoint, String atributeName){
    Element result;
    List<Element> elements = extensionPoint.getContent(new ElementFilter(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF));
    if(elements.size() == 0){
        // create extension point
        result = new Element(LanguageDefinitionExtensionPoint.GEMOC_LANGUAGE_EXTENSION_POINT_XDSML_DEF);
        extensionPoint.addContent(result);
    }
    else{
        result = elements.get(0);
    }
    return result.getAttributeValue(atributeName);
}
项目:metl    文件:AbstractXMLComponentRuntime.java   
protected Map<Element, Namespace> removeNamespaces(Document document) {
    Map<Element, Namespace> namespaces = new HashMap<Element, Namespace>();
    if (ignoreNamespace && document.hasRootElement()) {
        namespaces.put(document.getRootElement(), document.getRootElement().getNamespace());
        document.getRootElement().setNamespace(null);
        for (Element el : document.getRootElement().getDescendants(new ElementFilter())) {
            Namespace nsp = el.getNamespace();
            if (nsp != null) {
                el.setNamespace(null);
                namespaces.put(el, nsp);
            }
        }
    }
    return namespaces;
}
项目:jgoose    文件:IEC61850_GOOSE_ICD_file.java   
void decodeGSEControlBlock(String appID_name) throws IEC61850_GOOSE_Exception
{   
    boolean found_GSEControlBlock = false;

    // Retrieves all elements named "GSEControl" within IED node
    Filter<Element> elementFilter = new ElementFilter("GSEControl");

    // Search for a GSEControl block with a matching appID
    for (Iterator<Element> GSEControl_IT = IED_section.getDescendants(elementFilter);
            GSEControl_IT.hasNext();)
    {
        Element current_element = GSEControl_IT.next();

        if(current_element.getAttributeValue("type").equals("GOOSE") && 
                current_element.getAttributeValue("appID").equals(appID_name))
        {
            // We found the right control block
            GSEControl_node =  current_element;
            found_GSEControlBlock = true;
        }
    }

    if (found_GSEControlBlock == false)
        throw new IEC61850_GOOSE_Exception("<GSEControl> Block with corresponding appID_name: " + appID_name + " name not found in <IED>");

    gseControlBlockAppIDName = GSEControl_node.getAttributeValue("appID");
    gseControlBlockName = GSEControl_node.getAttributeValue("name");
    gseControlBlockConfRev = GSEControl_node.getAttributeValue("confRev");
    gseControlBlockDatSet = GSEControl_node.getAttributeValue("datSet");

    ln0ClassName = GSEControl_node.getParentElement().getAttributeValue("lnClass");

    return;
}
项目:Slipstream-Mod-Manager    文件:XMLPatcher.java   
public Document patch( Document mainDoc, Document appendDoc ) {
    Document resultDoc = mainDoc.clone();
    Element resultRoot = resultDoc.getRootElement();
    Element appendRoot = appendDoc.getRootElement();

    ElementFilter modFilter = new ElementFilter( modNS );
    for ( Content content : appendRoot.getContent() ) {
        if ( modFilter.matches( content ) ) {
            Element node = (Element)content;

            boolean handled = false;
            List<Element> matchedNodes = handleModFind( resultRoot, node );
            if ( matchedNodes != null ) {
                handled = true;
                for ( Element matchedNode : matchedNodes ) {
                    handleModCommands( matchedNode, node );
                }
            }

            if ( !handled ) {
                throw new IllegalArgumentException( String.format( "Unrecognized mod tag <%s> (%s).", node.getName(), getPathToRoot(node) ) );
            }
        }
        else {
            resultRoot.addContent( content.clone() );
        }
    }

    return resultDoc;
}
项目:bio4j-neo4j    文件:XMLElement.java   
@Override
public List<XMLElement> getChildrenWith(String name) {
    List<XMLElement> list = new ArrayList<XMLElement>();

    ElementFilter filter = new ElementFilter(name);

    for (Object elem : this.root.getContent(filter)) {
        XMLElement temp = new XMLElement((org.jdom2.Element) (elem));
        list.add(temp);

    }
    return list;
}
项目:mycore    文件:MCRRSSFeedImporter.java   
/** If mods:genre was not mapped by conversion/import function, ignore this publication and do not import */
private static boolean shouldIgnore(Element publication) {
    return !publication.getDescendants(new ElementFilter("genre", MCRConstants.MODS_NAMESPACE)).hasNext();
}
项目:jgoose    文件:IEC61850_GOOSE_ICD_file.java   
void decodeGSEBlock(String GSEControlBlock_name) throws IEC61850_GOOSE_Exception
{
    boolean found_GSEBlock = false;
    boolean found_APPID = false;
    boolean found_MACAddress = false;

    // Retrieves all elements named "GSE" within ConnectedAP in Communication section
    Filter<Element> elementFilter = new ElementFilter("GSE");

    // Search for a GSE with a matching cbName
    for (Iterator<Element> GSE_IT = ConnectedAP_in_Comm_section.getDescendants(elementFilter);
        GSE_IT.hasNext();)
    {
        Element current_element = GSE_IT.next();

        if(current_element.getAttributeValue("cbName").equals(GSEControlBlock_name))
        {
            GSE_node = current_element;
            found_GSEBlock = true;
        }
    }

    if (found_GSEBlock == false)
        throw new IEC61850_GOOSE_Exception("<GSE> Block with cbName: " + GSEControlBlock_name + " not found in <ConnectedAP> block");

    gseldInst = GSE_node.getAttributeValue("ldInst");

    // walks to the "Address" children 
    Element GSE_Address = GSE_node.getChild("Address", root_namespace);
    List<Element> p_nodes_LIST = GSE_Address.getChildren("P", root_namespace);

    // Walks all P nodes to retrieve addressing data
    for ( int position = 0; position < p_nodes_LIST.size(); position++)
    {
        if(p_nodes_LIST.get(position).getAttributeValue("type").contentEquals("APPID"))
        {
            gseAPPID = Integer.parseInt(p_nodes_LIST.get(position).getValue());
            found_APPID = true;
        }

        if (p_nodes_LIST.get(position).getAttributeValue("type").contentEquals("MAC-Address"))
        {
            gseMACAddress = p_nodes_LIST.get(position).getValue();
            found_MACAddress = true;
        }
    }

    if (found_APPID == false)
        throw new IEC61850_GOOSE_Exception("<APPID> type not found in <GSE> Block with cbName:" + GSEControlBlock_name);

    if(found_MACAddress == false)
        throw new IEC61850_GOOSE_Exception("<MAC-Address> type not found in <GSE> Block with cbName:" + GSEControlBlock_name);

    // Retrieves the maxtime
    Element GSE_Maxtime = GSE_node.getChild("MaxTime", root_namespace);

    if (GSE_Maxtime == null)
        //throw new IEC61850_GOOSE_Exception("<MaxTime> not found in <GSE> Block with cbName:" + GSEControlBlock_name);
        // If the value is not set in the ICD file, we set it to 0.
        gseMaxTime = 0;

    else
        gseMaxTime =  Integer.parseInt(GSE_Maxtime.getValue());

    // Retrieves the mintime
    Element GSE_Mintime = GSE_node.getChild("MinTime", root_namespace);

    if (GSE_Mintime == null)
        //throw new IEC61850_GOOSE_Exception("<MinTime> not found in <GSE> Block with cbName:" + GSEControlBlock_name);
        // If the value is not set in the ICD file, we set it to 0.
        gseMinTime = 0;

    else
        gseMinTime = Integer.parseInt(GSE_Mintime.getValue());

    return;
}
项目:marmotta    文件:MediawikiProvider.java   
protected static Element queryElement(Document n, String query) {
    return XPathFactory.instance().compile(query, new ElementFilter()).evaluateFirst(n);
}
项目:marmotta    文件:MediawikiProvider.java   
protected static List<Element> queryElements(Document n, String query) {
    return XPathFactory.instance().compile(query, new ElementFilter()).evaluate(n);
}