Example usage for org.apache.commons.collections.functors NOPTransformer INSTANCE

List of usage examples for org.apache.commons.collections.functors NOPTransformer INSTANCE

Introduction

In this page you can find the example usage for org.apache.commons.collections.functors NOPTransformer INSTANCE.

Prototype

Transformer INSTANCE

To view the source code for org.apache.commons.collections.functors NOPTransformer INSTANCE.

Click Source Link

Document

Singleton predicate instance

Usage

From source file:com.gargoylesoftware.htmlunit.html.XPathDomNodeList.java

/**
 * Creates a new node list. The elements will be "calculated" using the specified XPath
 * expression applied on the specified node.
 * @param node the node to serve as root for the XPath expression
 * @param xpath the XPath expression which determines the elements of the node list
 *//*from   ww w  .j  av a  2s  .c  o  m*/
public XPathDomNodeList(final DomNode node, final String xpath) {
    this(node, xpath, NOPTransformer.INSTANCE);
}

From source file:com.sworddance.util.PredicatedTransformingIterator.java

private void initIfNeeded() {
    if (baseIterator == null) {
        FilterIterator filtering = new FilterIterator(iterator);
        filtering.setPredicate(predicate == null ? TruePredicate.INSTANCE : predicate);
        baseIterator = new TransformIterator(filtering);
        baseIterator.setTransformer(transformer == null ? NOPTransformer.INSTANCE : transformer);
    }// w  w  w.  j a  v a 2s.  com
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection.java

/**
 * Initializes the content of this collection. The elements will be "calculated" at each
 * access using the specified XPath expression, applied to the specified node.
 * @param node the node to serve as root for the XPath expression
 * @param xpath the XPath expression which determines the elements of the collection
 */// w ww . j  av a2  s .c o m
public void init(final DomNode node, final String xpath) {
    init(node, xpath, NOPTransformer.INSTANCE);
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection.java

/**
 * Initializes the collection. The elements will be "calculated" as the children of the node.
 * @param node the node to grab children from
 *///  w  ww .ja  v  a 2s  . com
public void initFromChildren(final DomNode node) {
    if (node != null) {
        node_ = node;
        final DomHtmlAttributeChangeListenerImpl listener = new DomHtmlAttributeChangeListenerImpl();
        node_.addDomChangeListener(listener);
        if (node_ instanceof HtmlElement) {
            ((HtmlElement) node_).addHtmlAttributeChangeListener(listener);
            cachedElements_ = null;
        }
    }
    transformer_ = NOPTransformer.INSTANCE;
}

From source file:org.jahia.services.render.filter.StaticAssetsFilter.java

@Override
public String execute(String previousOut, RenderContext renderContext,
        org.jahia.services.render.Resource resource, RenderChain chain) throws Exception {

    String out = previousOut;//from  ww w.ja v  a2 s  . com
    Source source = new Source(previousOut);
    Map<String, Map<String, Map<String, Map<String, String>>>> assetsByTarget = new LinkedHashMap<>();

    List<Element> esiResourceElements = source.getAllElements("jahia:resource");
    Set<String> keys = new HashSet<>();
    for (Element esiResourceElement : esiResourceElements) {
        StartTag esiResourceStartTag = esiResourceElement.getStartTag();
        Map<String, Map<String, Map<String, String>>> assets;
        String targetTag = esiResourceStartTag.getAttributeValue(TARGET_TAG);
        if (targetTag == null) {
            targetTag = "HEAD";
        } else {
            targetTag = targetTag.toUpperCase();
        }
        if (!assetsByTarget.containsKey(targetTag)) {
            assets = LazySortedMap.decorate(TransformedSortedMap.decorate(
                    new TreeMap<String, Map<String, Map<String, String>>>(ASSET_COMPARATOR),
                    LOW_CASE_TRANSFORMER, NOPTransformer.INSTANCE), new AssetsMapFactory());
            assetsByTarget.put(targetTag, assets);
        } else {
            assets = assetsByTarget.get(targetTag);
        }

        String type = esiResourceStartTag.getAttributeValue("type");
        String path = StringUtils.equals(type, "inline")
                ? StringUtils.substring(out, esiResourceStartTag.getEnd(),
                        esiResourceElement.getEndTag().getBegin())
                : URLDecoder.decode(esiResourceStartTag.getAttributeValue("path"), "UTF-8");
        Boolean insert = Boolean.parseBoolean(esiResourceStartTag.getAttributeValue("insert"));
        String key = esiResourceStartTag.getAttributeValue("key");

        // get options
        Map<String, String> optionsMap = getOptionMaps(esiResourceStartTag);

        Map<String, Map<String, String>> stringMap = assets.get(type);
        if (stringMap == null) {
            Map<String, Map<String, String>> assetMap = new LinkedHashMap<>();
            stringMap = assets.put(type, assetMap);
        }

        if (insert) {
            Map<String, Map<String, String>> my = new LinkedHashMap<>();
            my.put(path, optionsMap);
            my.putAll(stringMap);
            stringMap = my;
        } else {
            if ("".equals(key) || !keys.contains(key)) {
                Map<String, Map<String, String>> my = new LinkedHashMap<>();
                my.put(path, optionsMap);
                stringMap.putAll(my);
                keys.add(key);
            }
        }
        assets.put(type, stringMap);
    }

    OutputDocument outputDocument = new OutputDocument(source);

    if (renderContext.isAjaxRequest()) {
        String templateContent = getAjaxResolvedTemplate();
        if (templateContent != null) {
            for (Map.Entry<String, Map<String, Map<String, Map<String, String>>>> entry : assetsByTarget
                    .entrySet()) {
                renderContext.getRequest().setAttribute(STATIC_ASSETS, entry.getValue());
                Element element = source.getFirstElement(TARGET_TAG);
                final EndTag tag = element != null ? element.getEndTag() : null;
                ScriptEngine scriptEngine = scriptEngineUtils.scriptEngine(ajaxTemplateExtension);
                ScriptContext scriptContext = new AssetsScriptContext();
                final Bindings bindings = scriptEngine.createBindings();
                bindings.put(TARGET_TAG, entry.getKey());
                bindings.put("renderContext", renderContext);
                bindings.put("resource", resource);
                scriptContext.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
                // The following binding is necessary for Javascript, which doesn't offer a console by default.
                bindings.put("out", new PrintWriter(scriptContext.getWriter()));
                scriptEngine.eval(templateContent, scriptContext);
                StringWriter writer = (StringWriter) scriptContext.getWriter();
                final String staticsAsset = writer.toString();

                if (StringUtils.isNotBlank(staticsAsset)) {
                    if (tag != null) {
                        outputDocument.replace(tag.getBegin(), tag.getBegin() + 1, "\n" + staticsAsset + "\n<");
                        out = outputDocument.toString();
                    } else {
                        out = staticsAsset + "\n" + previousOut;
                    }
                }
            }
        }
    } else if (resource.getContextConfiguration().equals("page")) {
        if (renderContext.isEditMode()) {
            if (renderContext.getServletPath().endsWith("frame")) {
                boolean doParse = true;
                if (renderContext.getEditModeConfig().getSkipMainModuleTypesDomParsing() != null) {
                    for (String nt : renderContext.getEditModeConfig().getSkipMainModuleTypesDomParsing()) {
                        doParse = !resource.getNode().isNodeType(nt);
                        if (!doParse) {
                            break;
                        }
                    }
                }
                List<Element> bodyElementList = source.getAllElements(HTMLElementName.BODY);
                if (bodyElementList.size() > 0) {
                    Element bodyElement = bodyElementList.get(bodyElementList.size() - 1);
                    EndTag bodyEndTag = bodyElement.getEndTag();
                    outputDocument.replace(bodyEndTag.getBegin(), bodyEndTag.getBegin() + 1, "</div><");

                    bodyElement = bodyElementList.get(0);

                    StartTag bodyStartTag = bodyElement.getStartTag();
                    outputDocument.replace(bodyStartTag.getEnd(), bodyStartTag.getEnd(), "\n"
                            + "<div jahiatype=\"mainmodule\"" + " path=\"" + resource.getNode().getPath()
                            + "\" locale=\"" + resource.getLocale() + "\"" + " template=\""
                            + (resource.getTemplate() != null && !resource.getTemplate().equals("default")
                                    ? resource.getTemplate()
                                    : "")
                            + "\"" + " nodetypes=\""
                            + ConstraintsHelper.getConstraints(renderContext.getMainResource().getNode()) + "\""
                            + ">");
                    if (doParse) {
                        outputDocument.replace(bodyStartTag.getEnd() - 1, bodyStartTag.getEnd(),
                                " jahia-parse-html=\"true\">");
                    }
                }
            }
        }
        if (!assetsByTarget.containsKey("HEAD")) {
            addResources(renderContext, resource, source, outputDocument, "HEAD",
                    new HashMap<String, Map<String, Map<String, String>>>());
        }
        for (Map.Entry<String, Map<String, Map<String, Map<String, String>>>> entry : assetsByTarget
                .entrySet()) {
            String targetTag = entry.getKey();
            Map<String, Map<String, Map<String, String>>> assets = entry.getValue();
            addResources(renderContext, resource, source, outputDocument, targetTag, assets);
        }
        out = outputDocument.toString();
    }

    // Clean all jahia:resource tags
    source = new Source(out);
    outputDocument = new OutputDocument(source);
    for (Element el : source.getAllElements("jahia:resource")) {
        outputDocument.replace(el, "");
    }
    String s = outputDocument.toString();
    s = removeTempTags(s);
    return s.trim();
}