Java 类org.jdom2.util.IteratorIterable 实例源码

项目:mycore    文件:MCRXSLInfoServlet.java   
private void listTemplates() {
    List<Element> list = xsl.getChildren("template", MCRConstants.XSL_NAMESPACE);
    IteratorIterable<Element> callTemplateElements = xsl
        .getDescendants(Filters.element("call-template", MCRConstants.XSL_NAMESPACE));
    LinkedList<Element> templates = new LinkedList<>(list);
    HashSet<String> callNames = new HashSet<>();
    for (Element callTemplate : callTemplateElements) {
        String name = callTemplate.getAttributeValue("name");
        if (callNames.add(name)) {
            templates.add(callTemplate);
        }
    }
    for (Element template : templates) {
        Element copy = template.clone();
        copy.removeContent();
        this.templates.add(copy);
    }
}
项目:jodtemplate    文件:FormatTagsPreprocessor.java   
@Override
public Document process(final Map<String, Object> context, final Document document, final Slide slide,
        final Resources resources, final Configuration configuration) {
    final IteratorIterable<Element> apElements = document.getDescendants(Filters.element(PPTXDocument.P_ELEMENT,
            getNamespace()));
    final List<Element> apElementsList = new ArrayList<>();
    while (apElements.hasNext()) {
        apElementsList.add(apElements.next());
    }
    for (Element ap : apElementsList) {
        final List<Element> apChildrenList = ap.getChildren();
        if (apChildrenList.size() != 0) {
            final List<Element> arabrElementsListResult = processArAndABrElements(apChildrenList, configuration
                    .getParserFactory().createParser());
            int firstArElementIndex = ap.indexOf(ap.getChild(PPTXDocument.R_ELEMENT, getNamespace()));
            if (firstArElementIndex < 0) {
                firstArElementIndex = 0;
            }
            ap.removeChildren(PPTXDocument.R_ELEMENT, getNamespace());
            ap.removeChildren(PPTXDocument.BR_ELEMENT, getNamespace());
            ap.addContent(firstArElementIndex, arabrElementsListResult);
        }
    }
    return document;
}
项目:jodtemplate    文件:StylePostprocessor.java   
@Override
public Document process(final Map<String, Object> context, final Document document, final Slide slide,
        final Resources resources, final Configuration configuration) throws JODTemplateException {
    final IteratorIterable<Element> atElements = document.getDescendants(Filters.element(PPTXDocument.T_ELEMENT,
            getNamespace()));
    final List<Element> atElementsList = new ArrayList<>();
    while (atElements.hasNext()) {
        atElementsList.add(atElements.next());
    }
    for (Element at : atElementsList) {
        if (at.getContentSize() != 0) {
            final Content content = at.getContent(0);
            if (content instanceof Comment) {
                final Comment comment = (Comment) content;
                processComment(comment, at, slide, configuration);
            }
        }
    }
    return document;
}
项目:msf-spaces-sdk-android    文件:SpaceHandler.java   
private List<Element> getChildren(Element parentElement, String tagName) {
    IteratorIterable<Content> iter = parentElement.getDescendants();
    List<Element> children = new ArrayList<Element>();
    while (iter.hasNext()) {
        Element elem;
        try {
            elem = (Element) iter.next();
        } catch (ClassCastException e) {
            continue;
        }
        if (tagName.equalsIgnoreCase(elem.getName())) {
            children.add(elem);
        }
    }
    return children;
}
项目:secure-data-service    文件:XsdTypeProvider.java   
@Override
public RecordMeta getTypeFromParentType(String type, String eventName) {
    Element parentElement = getComplexElement(type);

    while (parentElement != null && eventName != null) {
        for (Element e : parentElement.getDescendants(Filters.element(ELEMENT, XS_NAMESPACE))) {
            if (e.getAttributeValue(NAME).equals(eventName)) {
                return new RecordMetaImpl(eventName, e.getAttributeValue(TYPE), shouldBeList(e, parentElement));
            }
        }

        IteratorIterable<Element> extensions = parentElement.getDescendants(Filters.element(EXTENSION, XS_NAMESPACE));

        if (extensions.hasNext()) {
            parentElement = extensions.next();
        } else {
            parentElement = null;
        }
    }

    return null;
}
项目:jodtemplate    文件:ShortListPreprocessor.java   
@Override
public Document process(final Map<String, Object> context, final Document document, final Slide slide,
        final Resources resources, final Configuration configuration) throws JODTemplateException {
    final IteratorIterable<Element> parentElements = document.getDescendants(
            Filters.element(parentElement, getNamespace()));
    final List<Element> parentElementsList = new ArrayList<>();
    while (parentElements.hasNext()) {
        parentElementsList.add(parentElements.next());
    }

    for (final Element parent : parentElementsList) {
        final IteratorIterable<Element> atElements = parent.getDescendants(
                Filters.element(PPTXDocument.T_ELEMENT, getNamespace()));
        final List<Element> atElementsList = new ArrayList<>();
        while (atElements.hasNext()) {
            atElementsList.add(atElements.next());
        }

        final ExpressionHandler expressionHandler = configuration.getExpressionHandler();
        boolean isLoop = false;
        InlineListExpression expression = null;
        for (final Element at : atElementsList) {
            final String text = at.getText();
            if (configuration.getExpressionHandler().isInlineList(text)) {
                expression = expressionHandler.createInlineListExpression(text);
                at.setText(expressionHandler.createVariable(expression.getVariable()));
                isLoop = true;
            }
        }
        if (isLoop) {
            int apIndex = parent.getParent().indexOf(parent);
            final String beginList = expressionHandler.createBeginList(expression.getWhat(), expression.getAs());
            final String endList = expressionHandler.createEndList();
            parent.getParent().addContent(apIndex, new Comment(beginList));
            apIndex++;
            parent.getParent().addContent(apIndex + 1, new Comment(endList));
        }
    }
    return document;
}
项目:jodtemplate    文件:PicPreprocessor.java   
public Document process(final Map<String, Object> context, final Document document, final Slide slide,
        final Resources resources, final Configuration configuration) throws JODTemplateException {
    final ExpressionHandler expressionHandler = configuration.getExpressionHandler();

    final IteratorIterable<Element> picElements = document.getDescendants(Filters.element(PPTXDocument.PIC_ELEMENT,
            getPresentationmlNamespace()));
    final List<Element> picElementsList = new ArrayList<>();
    while (picElements.hasNext()) {
        picElementsList.add(picElements.next());
    }

    for (Element pic : picElementsList) {
        final Attribute descr = pic.getChild(PPTXDocument.NVPICPR_ELEMENT, getPresentationmlNamespace())
                .getChild(PPTXDocument.CNVPR_ELEMENT, getPresentationmlNamespace())
                .getAttribute(PPTXDocument.DESCR_ATTR);
        if (descr != null && expressionHandler.isExpression(descr.getValue())) {
            final VariableExpression expression = expressionHandler.createVariableExpression(descr.getValue());
            Object value;
            try {
                value = PropertyUtils.getNestedProperty(context, expression.getVariable());
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                throw new JODTemplateException("Unable to get value: " + expression.getVariable());
            }
            if (value instanceof ImageField) {
                final ImageField imageField = (ImageField) value;
                imageService.insertImage(imageField, slide, resources, pic);
            } else {
                throw new JODTemplateException("Field " + expression.getVariable() + " should contain image.");
            }
        }

    }

    return document;
}
项目: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);
            }
        }
    }
}
项目:secure-data-service    文件:XsdTypeProvider.java   
@Override
public RecordMeta getTypeFromParentType(RecordMeta parentMeta, String eventName) {
    Element parentElement = getComplexElement( parentMeta.getType());

    while (parentElement != null && eventName != null) {
        IteratorIterable<Element> res = parentElement.getDescendants(Filters.element(ELEMENT, XS_NAMESPACE));
        for (Element e : res) {
            if (e.getAttributeValue(NAME).equals(eventName)) {
                String elementType = e.getAttributeValue(TYPE);
                if (elementType == null) {
                    Element simple = e.getChild(SIMPLETYPE, XS_NAMESPACE);
                    elementType = getSimpleTypeRestrictionBase(simple);
                }

                return new RecordMetaImpl(eventName, elementType, shouldBeList(e, parentElement), parentMeta.getAction());
            }
        }

        IteratorIterable<Element> extensions = parentElement.getDescendants(Filters
                .element(EXTENSION, XS_NAMESPACE));

        if (extensions.hasNext()) {
            parentElement = getComplexElement(extensions.next().getAttributeValue(BASE));
        } else {
            parentElement = null;
        }
    }

    return null;
}
项目:epubfx    文件:Book.java   
public void renameResource(Resource resource, String oldValue, String newValue)
{
    resources.remove(oldValue); //unter altem namen löschen
    resources.add(resource); //unter neuem wieder hinzufügen

    if (MediaType.CSS.equals(resource.getMediaType()))
    {
        //css umbenannt, erstmal alle XHTMLs durchsuchen
        List<Resource> xhtmlResources = resources.getResourcesByMediaType(MediaType.XHTML);
        Path resourcePath = resource.getHrefAsPath();
        int index = StringUtils.lastIndexOf(oldValue, "/");
        String oldFileName = oldValue;
        if (index > -1)
        {
            oldFileName = oldValue.substring(index + 1);
        }

        index = StringUtils.lastIndexOf(newValue, "/");
        String newFileName = newValue;
        if (index > -1)
        {
            newFileName = newValue.substring(index + 1);
        }

        for (Resource xhtmlResource : xhtmlResources)
        {
            Document document = ((XHTMLResource)xhtmlResource).asNativeFormat();
            Path relativePath = xhtmlResource.getHrefAsPath().relativize(resourcePath);
            AtrributeElementFilter hrefFilter = new AtrributeElementFilter("href", relativePath + "/" + oldFileName);
            IteratorIterable<Element> descendants = document.getDescendants(hrefFilter);
            for (Element descendant : descendants)
            {
                logger.info("found element with attribut href in resource " + xhtmlResource);
                descendant.setAttribute("href", relativePath + "/" + newFileName);
            }
            //nach noch mehr Elementen suchen
            //zB src-Attribut
            xhtmlResource.setData(XHTMLUtils.outputXHTMLDocument(document));
        }

        //weiter nach import etc. in anderen css dateien suchen
    }
    else if(MediaType.XHTML.equals(resource.getMediaType()))
    {
        //nach href
    }
    else if(resource.getMediaType().isBitmapImage())
    {
        //nach href und src
    }
    refreshOpfResource();
}