Example usage for org.w3c.dom Document createComment

List of usage examples for org.w3c.dom Document createComment

Introduction

In this page you can find the example usage for org.w3c.dom Document createComment.

Prototype

public Comment createComment(String data);

Source Link

Document

Creates a Comment node given the specified string.

Usage

From source file:org.gvnix.support.WebProjectUtils.java

/**
 * Append a js definition in loadScript.tagx
 * <p/>//from  w w w .j a va  2 s  . co  m
 * This first append a "spring:url" (if not exists) and then add the "link"
 * tag (if not exists)
 * 
 * @param docTagx {@code .tagx} file document
 * @param root XML root node
 * @param varName name of variable to hold js url
 * @param location js location
 * @return document has changed
 */
public static boolean addJSToTag(Document docTagx, Element root, String varName, String location) {
    boolean modified = false;

    // add url resolution
    modified = addUrlToTag(docTagx, root, varName, location);

    // Add script
    Element scriptElement = XmlUtils.findFirstElement(String.format("script[@src='${%s}']", varName), root);
    if (scriptElement == null) {
        scriptElement = docTagx.createElement("script");
        scriptElement.setAttribute("src", "${".concat(varName).concat("}"));
        scriptElement.setAttribute("type", "text/javascript");
        scriptElement.appendChild(docTagx.createComment("required for FF3 and Opera"));
        root.appendChild(scriptElement);
        modified = true;
    }
    return modified;
}

From source file:org.gvnix.support.WebProjectUtils.java

/**
 * Append a js definition in loadScript.tagx
 * <p/>//w w  w.  j  av a  2  s .c om
 * This first append a "spring:url" (if not exists) and then add the "link"
 * tag (if not exists)
 * 
 * @param docTagx {@code .tagx} file document
 * @param root XML root node
 * @param varName name of variable to hold js url
 * @param location js location
 * @return document has changed
 */
public static boolean updateJSToTag(Document docTagx, Element root, String varName, String location) {
    boolean modified = false;

    // add url resolution
    modified = updateUrlToTag(docTagx, root, varName, location);

    // Add script
    Element scriptElement = XmlUtils.findFirstElement(String.format("script[@src='${%s}']", varName), root);
    if (scriptElement == null) {
        scriptElement = docTagx.createElement("script");
        scriptElement.setAttribute("src", "${".concat(varName).concat("}"));
        scriptElement.setAttribute("type", "text/javascript");
        scriptElement.appendChild(docTagx.createComment("required for FF3 and Opera"));
        root.appendChild(scriptElement);
        modified = true;
    }
    return modified;
}

From source file:org.gvnix.support.WebProjectUtils.java

/**
 * Add variable to contain request Locale in string format.
 * <p/>/* w  w w  . java  2s. c om*/
 * 
 * <pre>
 * {@code
 * <c:set var="VAR_NAME">
 *   <!-- Get the user local from the page context (it was set by
 *        Spring MVC's locale resolver) -->
 *   <c:set var="jqlocale">${pageContext.response.locale}</c:set>
 *   <c:if test="${fn:length(jqlocale) eq 2}">
 *     <c:out value="${jqlocale}" />
 *   </c:if>
 *   <c:if test="${fn:length(jqlocale) gt 2}">
 *     <c:out value="${fn:substringBefore(jqlocale, '_')}" default="en" />
 *   </c:if>
 *   <c:if test="${fn:length(jqlocale) lt 2}">
 *     <c:out value="en" />
 *   </c:if>
 * </c:set>
 * }
 * </pre>
 * 
 * @param docTagx {@code .tagx} file document
 * @param root XML root node
 * @param varName name of variable to create, see {@code VAR_NAME} in
 *        example above
 */
public static boolean addLocaleVarToTag(Document docTagx, Element root, String varName) {

    // Add locale var
    Element varElement = XmlUtils.findFirstElement(String.format("c:set[@var='${%s}']", varName), root);
    if (varElement == null) {
        varElement = docTagx.createElement("c:set");
        varElement.setAttribute("var", varName);
        varElement.appendChild(docTagx.createComment(
                " Get the user local from the page context (it was set by Spring MVC's locale resolver) "));

        Element pElement = docTagx.createElement("c:set");
        pElement.setAttribute("var", "jqlocale");
        pElement.appendChild(docTagx.createTextNode("${pageContext.response.locale}"));
        varElement.appendChild(pElement);

        Element ifElement = docTagx.createElement("c:if");
        ifElement.setAttribute("test", "${fn:length(jqlocale) eq 2}");

        Element outElement = docTagx.createElement("c:out");
        outElement.setAttribute(VALUE, "${jqlocale}");
        ifElement.appendChild(outElement);
        varElement.appendChild(ifElement);

        ifElement = docTagx.createElement("c:if");
        ifElement.setAttribute("test", "${fn:length(jqlocale) gt 2}");

        outElement = docTagx.createElement("c:out");
        outElement.setAttribute(VALUE, "${fn:substringBefore(jqlocale, '_')}");
        outElement.setAttribute("default", "en");
        ifElement.appendChild(outElement);
        varElement.appendChild(ifElement);

        ifElement = docTagx.createElement("c:if");
        ifElement.setAttribute("test", "${fn:length(jqlocale) lt 2}");

        outElement = docTagx.createElement("c:out");
        outElement.setAttribute(VALUE, "en");
        ifElement.appendChild(outElement);
        varElement.appendChild(ifElement);

        root.appendChild(varElement);

        return true;
    }
    return false;
}

From source file:org.gvnix.web.screen.roo.addon.WebScreenOperationsImpl.java

/**
 * Updates load-scripts.tagx adding in the right position some elements:
 * <ul>/*from www.  jav  a 2 s.com*/
 * <li><code>spring:url</code> elements for JS and CSS</li>
 * <li><code>link</code> element for CSS</li>
 * <li><code>script</code> element for JS</li>
 * </ul>
 */
private void modifyLoadScriptsTagx() {
    PathResolver pathResolver = projectOperations.getPathResolver();
    String loadScriptsTagx = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""),
            "WEB-INF/tags/util/load-scripts.tagx");

    if (!fileManager.exists(loadScriptsTagx)) {
        // load-scripts.tagx doesn't exist, so nothing to do
        return;
    }

    InputStream loadScriptsIs = fileManager.getInputStream(loadScriptsTagx);

    Document loadScriptsXml;
    try {
        loadScriptsXml = XmlUtils.getDocumentBuilder().parse(loadScriptsIs);
    } catch (Exception ex) {
        throw new IllegalStateException("Could not open load-scripts.tagx file", ex);
    }

    Element lsRoot = loadScriptsXml.getDocumentElement();

    Node nextSibiling;

    // spring:url elements
    Element testElement = XmlUtils.findFirstElement("/root/url[@var='pattern_css_url']", lsRoot);
    if (testElement == null) {
        Element urlPatternCss = new XmlElementBuilder("spring:url", loadScriptsXml)
                .addAttribute(VALUE, "/resources/styles/pattern.css").addAttribute(VAR, "pattern_css_url")
                .build();
        Element urlQlJs = new XmlElementBuilder("spring:url", loadScriptsXml)
                .addAttribute(VALUE, "/resources/scripts/quicklinks.js").addAttribute(VAR, "qljs_url").build();
        // Add i18n messages for quicklinks.js
        List<Element> qlJsI18n = new ArrayList<Element>();
        qlJsI18n.add(new XmlElementBuilder("spring:message", loadScriptsXml)
                .addAttribute("code", "message_selectrowtodelete_alert")
                .addAttribute(VAR, "msg_selectrowtodelete_alert").addAttribute("htmlEscape", "false").build());
        qlJsI18n.add(new XmlElementBuilder("spring:message", loadScriptsXml)
                .addAttribute("code", "message_selectrowtoupdate_alert")
                .addAttribute(VAR, "msg_selectrowtoupdate_alert").addAttribute("htmlEscape", "false").build());
        qlJsI18n.add(new XmlElementBuilder("spring:message", loadScriptsXml)
                .addAttribute("code", "message_updateonlyonerow_alert")
                .addAttribute(VAR, "msg_updateonlyonerow_alert").addAttribute("htmlEscape", "false").build());
        StringBuilder qlJsI18nScriptText = new StringBuilder("<!--\n");
        qlJsI18nScriptText.append("var GVNIX_MSG_SELECT_ROW_TO_DELETE=\"${msg_selectrowtodelete_alert}\";\n");
        qlJsI18nScriptText.append("var GVNIX_MSG_SELECT_ROW_TO_UPDATE=\"${msg_selectrowtoupdate_alert}\";\n");
        qlJsI18nScriptText.append("var GVNIX_MSG_UPDATE_ONLY_ONE_ROW=\"${msg_updateonlyonerow_alert}\";\n");
        qlJsI18nScriptText.append("-->\n");
        Element qlJsI18nScript = new XmlElementBuilder("script", loadScriptsXml)
                .setText(qlJsI18nScriptText.toString()).build();
        List<Element> springUrlElements = XmlUtils.findElements("/root/url", lsRoot);
        // Element lastSpringUrl = null;
        if (!springUrlElements.isEmpty()) {
            Element lastSpringUrl = springUrlElements.get(springUrlElements.size() - 1);
            if (lastSpringUrl != null) {
                nextSibiling = lastSpringUrl.getNextSibling().getNextSibling();
                lsRoot.insertBefore(urlPatternCss, nextSibiling);
                lsRoot.insertBefore(urlQlJs, nextSibiling);
                lsRoot.insertBefore(qlJsI18nScript, nextSibiling);
                for (Element item : qlJsI18n) {
                    lsRoot.insertBefore(item, qlJsI18nScript);
                }
            }
        } else {
            // Add at the end of the document
            lsRoot.appendChild(urlPatternCss);
            lsRoot.appendChild(urlQlJs);
            for (Element item : qlJsI18n) {
                lsRoot.appendChild(item);
            }
            lsRoot.appendChild(qlJsI18nScript);
        }
    }

    // pattern.css stylesheet element
    testElement = XmlUtils.findFirstElement("/root/link[@href='${pattern_css_url}']", lsRoot);
    if (testElement == null) {
        Element linkPatternCss = new XmlElementBuilder("link", loadScriptsXml).addAttribute("rel", "stylesheet")
                .addAttribute("type", "text/css").addAttribute("media", "screen")
                .addAttribute("href", "${pattern_css_url}").build();
        linkPatternCss.appendChild(loadScriptsXml.createComment(" required for FF3 and Opera "));
        Node linkTrundraCssNode = XmlUtils.findFirstElement("/root/link[@href='${tundra_url}']", lsRoot);
        if (linkTrundraCssNode != null) {
            nextSibiling = linkTrundraCssNode.getNextSibling().getNextSibling();
            lsRoot.insertBefore(linkPatternCss, nextSibiling);
        } else {
            // Add ass last link element
            // Element lastLink = null;
            List<Element> linkElements = XmlUtils.findElements("/root/link", lsRoot);
            if (!linkElements.isEmpty()) {
                Element lastLink = linkElements.get(linkElements.size() - 1);
                if (lastLink != null) {
                    nextSibiling = lastLink.getNextSibling().getNextSibling();
                    lsRoot.insertBefore(linkPatternCss, nextSibiling);
                }
            } else {
                // Add at the end of document
                lsRoot.appendChild(linkPatternCss);
            }
        }
    }

    // quicklinks.js script element
    testElement = XmlUtils.findFirstElement("/root/script[@src='${qljs_url}']", lsRoot);
    if (testElement == null) {
        Element scriptQlJs = new XmlElementBuilder("script", loadScriptsXml).addAttribute("src", "${qljs_url}")
                .addAttribute("type", "text/javascript").build();
        scriptQlJs.appendChild(loadScriptsXml.createComment(" required for FF3 and Opera "));
        List<Element> scrtiptElements = XmlUtils.findElements("/root/script", lsRoot);
        // Element lastScript = null;
        if (!scrtiptElements.isEmpty()) {
            Element lastScript = scrtiptElements.get(scrtiptElements.size() - 1);
            if (lastScript != null) {
                nextSibiling = lastScript.getNextSibling().getNextSibling();
                lsRoot.insertBefore(scriptQlJs, nextSibiling);
            }
        } else {
            // Add at the end of document
            lsRoot.appendChild(scriptQlJs);
        }
    }

    writeToDiskIfNecessary(loadScriptsTagx, loadScriptsXml.getDocumentElement());

}

From source file:org.gvnix.web.theme.roo.addon.ThemeOperationsImpl.java

/**
 * Updates load-scripts.tagx adding in the right position some elements:
 * <ul>//from  w  w w.ja v  a2  s.co m
 * <li><code>spring:url</code> elements for JS and CSS</li>
 * <li><code>link</code> element for CSS</li>
 * <li><code>script</code> element for JS</li>
 * </ul>
 */
private void modifyLoadScriptsTagx() {
    PathResolver pathResolver = projectOperations.getPathResolver();
    String loadScriptsTagx = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""),
            "WEB-INF/tags/util/load-scripts.tagx");

    if (!fileManager.exists(loadScriptsTagx)) {
        // load-scripts.tagx doesn't exist, so nothing to do
        return;
    }

    InputStream loadScriptsIs = fileManager.getInputStream(loadScriptsTagx);

    Document loadScriptsXml;
    try {
        loadScriptsXml = org.springframework.roo.support.util.XmlUtils.getDocumentBuilder()
                .parse(loadScriptsIs);
    } catch (Exception ex) {
        throw new IllegalStateException("Could not open load-scripts.tagx file", ex);
    }

    Element lsRoot = loadScriptsXml.getDocumentElement();
    // Add new tag namesapces
    Element jspRoot = org.springframework.roo.support.util.XmlUtils.findFirstElement("/root", lsRoot);
    jspRoot.setAttribute("xmlns:util", "urn:jsptagdir:/WEB-INF/tags/util");

    Node nextSibiling;

    // spring:url elements
    Element testElement = org.springframework.roo.support.util.XmlUtils
            .findFirstElement("/root/url[@var='roo_css-ie_url']", lsRoot);
    if (testElement == null) {
        Element urlCitIECss = new XmlElementBuilder(SPRING_URL, loadScriptsXml)
                .addAttribute(VALUE_ATTRIBUTE, "/resources/styles/cit-IE.css")
                .addAttribute(VAR_ATTRIBUTE, "roo_css-ie_url").build();
        Element urlApplicationCss = new XmlElementBuilder(SPRING_URL, loadScriptsXml)
                .addAttribute(VALUE_ATTRIBUTE, "/resources/styles/application.css")
                .addAttribute(VAR_ATTRIBUTE, "application_css_url").build();
        Element urlYuiEventJs = new XmlElementBuilder(SPRING_URL, loadScriptsXml)
                .addAttribute(VALUE_ATTRIBUTE, "/resources/scripts/yui/yahoo-dom-event.js")
                .addAttribute(VAR_ATTRIBUTE, "yui_event").build();
        Element urlYuiCoreJs = new XmlElementBuilder(SPRING_URL, loadScriptsXml)
                .addAttribute(VALUE_ATTRIBUTE, "/resources/scripts/yui/container_core-min.js")
                .addAttribute(VAR_ATTRIBUTE, "yui_core").build();
        Element urlYoiMenuJs = new XmlElementBuilder(SPRING_URL, loadScriptsXml)
                .addAttribute(VALUE_ATTRIBUTE, "/resources/scripts/yui/menu-min.js")
                .addAttribute(VAR_ATTRIBUTE, "yui_menu").build();
        Element urlCitJs = new XmlElementBuilder(SPRING_URL, loadScriptsXml)
                .addAttribute(VALUE_ATTRIBUTE, "/resources/scripts/utils.js")
                .addAttribute(VAR_ATTRIBUTE, "cit_js_url").build();
        List<Element> springUrlElements = org.springframework.roo.support.util.XmlUtils
                .findElements("/root/url", lsRoot);
        // Element lastSpringUrl = null;
        if (!springUrlElements.isEmpty()) {
            Element lastSpringUrl = springUrlElements.get(springUrlElements.size() - 1);
            if (lastSpringUrl != null) {
                nextSibiling = lastSpringUrl.getNextSibling().getNextSibling();
                lsRoot.insertBefore(urlCitIECss, nextSibiling);
                lsRoot.insertBefore(urlApplicationCss, nextSibiling);
                lsRoot.insertBefore(urlYuiEventJs, nextSibiling);
                lsRoot.insertBefore(urlYuiCoreJs, nextSibiling);
                lsRoot.insertBefore(urlYoiMenuJs, nextSibiling);
                lsRoot.insertBefore(urlCitJs, nextSibiling);
            }
        } else {
            // Add at the end of the document
            lsRoot.appendChild(urlCitIECss);
            lsRoot.appendChild(urlApplicationCss);
            lsRoot.appendChild(urlYuiEventJs);
            lsRoot.appendChild(urlYuiCoreJs);
            lsRoot.appendChild(urlYoiMenuJs);
            lsRoot.appendChild(urlCitJs);
        }
    }

    Element setUserLocale = org.springframework.roo.support.util.XmlUtils.findFirstElement("/root/set/out",
            lsRoot);
    setUserLocale.setAttribute("default", "es");

    // cit-IE.css stylesheet element
    testElement = org.springframework.roo.support.util.XmlUtils
            .findFirstElement("/root/iecondition/link[@href='${roo_css-ie_url}']", lsRoot);
    if (testElement == null) {
        Element ifIE = new XmlElementBuilder("util:iecondition", loadScriptsXml).build();

        Element linkCitIECss = new XmlElementBuilder("link", loadScriptsXml).addAttribute("rel", "stylesheet")
                .addAttribute(TYPE_ATTRIBUTE, "text/css").addAttribute(HREF_ATTRIBUTE, "${roo_css-ie_url}")
                .build();
        ifIE.appendChild(linkCitIECss);
        Node linkFaviconNode = org.springframework.roo.support.util.XmlUtils
                .findFirstElement("/root/link[@href='${favicon}']", lsRoot);
        if (linkFaviconNode != null) {
            nextSibiling = linkFaviconNode.getNextSibling().getNextSibling();
            lsRoot.insertBefore(ifIE, linkFaviconNode);
        } else {
            // Add ass last link element
            // Element lastLink = null;
            List<Element> linkElements = org.springframework.roo.support.util.XmlUtils
                    .findElements("/root/link", lsRoot);
            if (!linkElements.isEmpty()) {
                Element lastLink = linkElements.get(linkElements.size() - 1);
                if (lastLink != null) {
                    nextSibiling = lastLink.getNextSibling().getNextSibling();
                    lsRoot.insertBefore(ifIE, nextSibiling);
                }
            } else {
                // Add at the end of document
                lsRoot.appendChild(ifIE);
            }
        }
    }

    // pattern.css stylesheet element
    testElement = org.springframework.roo.support.util.XmlUtils
            .findFirstElement("/root/link[@href='${application_css_url}']", lsRoot);
    if (testElement == null) {
        Element linkApplicationCss = new XmlElementBuilder("link", loadScriptsXml)
                .addAttribute("rel", "stylesheet").addAttribute(TYPE_ATTRIBUTE, "text/css")
                .addAttribute("media", "screen").addAttribute(HREF_ATTRIBUTE, "${application_css_url}").build();
        linkApplicationCss.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA));
        Node linkFaviconNode = org.springframework.roo.support.util.XmlUtils
                .findFirstElement("/root/link[@href='${favicon}']", lsRoot);
        if (linkFaviconNode != null) {
            nextSibiling = linkFaviconNode.getNextSibling().getNextSibling();
            lsRoot.insertBefore(linkApplicationCss, linkFaviconNode);
        } else {
            // Add ass last link element
            // Element lastLink = null;
            List<Element> linkElements = org.springframework.roo.support.util.XmlUtils
                    .findElements("/root/link", lsRoot);
            if (!linkElements.isEmpty()) {
                Element lastLink = linkElements.get(linkElements.size() - 1);
                if (lastLink != null) {
                    nextSibiling = lastLink.getNextSibling().getNextSibling();
                    lsRoot.insertBefore(linkApplicationCss, nextSibiling);
                }
            } else {
                // Add at the end of document
                lsRoot.appendChild(linkApplicationCss);
            }
        }
    }

    // utils.js script element
    testElement = org.springframework.roo.support.util.XmlUtils
            .findFirstElement("/root/script[@src='${cit_js_url}']", lsRoot);
    if (testElement == null) {
        Element scriptYuiEventJs = new XmlElementBuilder(SCRIPT, loadScriptsXml)
                .addAttribute(SRC, "${yui_event}").addAttribute(TYPE_ATTRIBUTE, TEXT_JSCRPT).build();
        scriptYuiEventJs.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA));
        Element scriptYuiCoreJs = new XmlElementBuilder(SCRIPT, loadScriptsXml).addAttribute(SRC, "${yui_core}")
                .addAttribute(TYPE_ATTRIBUTE, TEXT_JSCRPT).build();
        scriptYuiCoreJs.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA));
        Element scriptYoiMenuJs = new XmlElementBuilder(SCRIPT, loadScriptsXml).addAttribute(SRC, "${yui_menu}")
                .addAttribute(TYPE_ATTRIBUTE, TEXT_JSCRPT).build();
        scriptYoiMenuJs.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA));
        Element scriptCitJs = new XmlElementBuilder(SCRIPT, loadScriptsXml).addAttribute(SRC, "${cit_js_url}")
                .addAttribute(TYPE_ATTRIBUTE, TEXT_JSCRPT).build();
        scriptCitJs.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA));
        List<Element> scrtiptElements = org.springframework.roo.support.util.XmlUtils
                .findElements("/root/script", lsRoot);
        // Element lastScript = null;
        if (!scrtiptElements.isEmpty()) {
            Element lastScript = scrtiptElements.get(scrtiptElements.size() - 1);
            if (lastScript != null) {
                nextSibiling = lastScript.getNextSibling().getNextSibling();
                lsRoot.insertBefore(scriptYuiEventJs, nextSibiling);
                lsRoot.insertBefore(scriptYuiCoreJs, nextSibiling);
                lsRoot.insertBefore(scriptYoiMenuJs, nextSibiling);
                lsRoot.insertBefore(scriptCitJs, nextSibiling);
            }
        } else {
            // Add at the end of document
            lsRoot.appendChild(scriptYuiEventJs);
            lsRoot.appendChild(scriptYuiCoreJs);
            lsRoot.appendChild(scriptYoiMenuJs);
            lsRoot.appendChild(scriptCitJs);
        }
    }

    writeToDiskIfNecessary(loadScriptsTagx, loadScriptsXml.getDocumentElement());

}

From source file:org.hammurapi.TaskBase.java

/**
 * @param collection/*  w w  w  .j a v a2 s . c  om*/
 * @throws FileNotFoundException
 * @throws RenderingException
 */
protected void writeWaiverStubs(final Collection rejectedViolations)
        throws RenderingException, FileNotFoundException {
    if (waiverStubs != null) {
        class WaiverStubsRenderer extends AbstractRenderer {
            WaiverStubsRenderer() {
                super(new RenderRequest(rejectedViolations));
            }

            public Element render(Document document) {
                Element ret = document.createElement("waivers");
                Iterator it = rejectedViolations.iterator();
                final Date now = new Date();
                while (it.hasNext()) {
                    final Violation violation = (Violation) it.next();

                    StringBuffer comment = new StringBuffer();
                    comment.append("Source: ");
                    comment.append(violation.getSource().getSourceURL());

                    comment.append("\nLine: ");
                    comment.append(violation.getSource().getLine());

                    comment.append("\nCol: ");
                    comment.append(violation.getSource().getColumn());

                    comment.append("\nDescription: ");
                    comment.append(violation.getDescriptor().getDescription());

                    comment.append("\nMesssage: ");
                    comment.append(violation.getMessage());

                    ret.appendChild(document.createComment(comment.toString()));

                    Waiver waiver = new Waiver() {

                        public String getInspectorName() {
                            return violation.getDescriptor().getName();
                        }

                        public Date getExpirationDate() {
                            return now;
                        }

                        public String getReason() {
                            return "*** Put reason here ***";
                        }

                        public boolean waive(Violation violation, boolean peek) {
                            // This 'waiver' will never waive anything, it is used only for rendering
                            return false;
                        }

                        public boolean isActive() {
                            // This 'waiver' will never waive anything, it is used only for rendering
                            return false;
                        }

                        Collection signatures = new HashSet();

                        {
                            if (violation.getSource() instanceof Signed) {
                                signatures.add(((Signed) violation.getSource()).getSignature());
                            }
                        }

                        public Collection getSignatures() {
                            return signatures;
                        }
                    };
                    ret.appendChild(DetailedResultsRenderer.renderWaiver(waiver, document));
                }
                return ret;
            }
        }
        WaiverStubsRenderer renderer = new WaiverStubsRenderer();
        renderer.setEmbeddedStyle(false);
        renderer.render(new FileOutputStream(waiverStubs));
    }
}

From source file:org.htmlcleaner.XWikiDOMSerializer.java

/**
 * Serialize a given SF HTML Cleaner node.
 *
 * @param document the W3C Document to use for creating new DOM elements
 * @param element the W3C element to which we'll add the subnodes to
 * @param tagChildren the SF HTML Cleaner nodes to serialize for that node
 *//*from   w w w  . j a v a2s.c o m*/
private void createSubnodes(Document document, Element element, List<? extends BaseToken> tagChildren) {
    // We've modified the original implementation based in SF's HTML Cleaner to better handle CDATA.
    // More specifically we want to handle the following 3 use cases:
    //
    // Use case 1: useCdata = true && input is:
    // <script>...<![CDATA[...]]>...</script>
    // In this case we must make sure to have only one CDATA block.
    //
    // Use case 2: useCdata = true && input is:
    // <script>...entities not encoded (e.g. "<")...</script>
    // We must generate a CDATA block around the whole content (the HTML Tokenizer split
    // ContentToken on "<" character so we need to join them before creating the CDATA block.
    // We must also unencode any entities (i.e. transform "&lt;" into "<") since we'll be
    // wrapping them in a CDATA section.
    //
    // Use case 3: useCData = false
    // Simply group all ContentToken together.

    StringBuffer bufferedContent = new StringBuffer();

    if (tagChildren != null) {
        for (Object item : tagChildren) {
            // Flush content tokens
            flushContent(document, element, bufferedContent, item);

            if (item instanceof CommentNode) {
                CommentNode commentToken = (CommentNode) item;
                Comment comment = document.createComment(commentToken.getContent());
                element.appendChild(comment);
            } else if (item instanceof ContentNode) {
                ContentNode contentToken = (ContentNode) item;
                bufferedContent.append(contentToken.getContent());
            } else if (item instanceof TagNode) {
                TagNode subTagNode = (TagNode) item;
                Element subelement = document.createElement(subTagNode.getName());
                Map<String, String> attributes = subTagNode.getAttributes();
                for (Map.Entry<String, String> entry : attributes.entrySet()) {
                    String attrName = entry.getKey();
                    String attrValue = entry.getValue();
                    if (this.escapeXml) {
                        attrValue = Utils.escapeXml(attrValue, this.props, true);
                    }
                    subelement.setAttribute(attrName, attrValue);
                }

                // recursively create subnodes
                createSubnodes(document, subelement, subTagNode.getAllChildren());

                element.appendChild(subelement);
            } else if (item instanceof List<?>) {
                @SuppressWarnings("unchecked")
                List<BaseToken> sublist = (List<BaseToken>) item;
                createSubnodes(document, element, sublist);
            }
        }
        flushContent(document, element, bufferedContent, null);
    }
}

From source file:org.jasig.resourceserver.utils.aggr.ResourcesElementsProviderImpl.java

/**
 * Convert the {@link Js} argument to an HTML script tag and append it
 * to the {@link DocumentFragment}.// ww w  .java  2  s .  co m
 */
protected void appendJsNode(HttpServletRequest request, Document document, DocumentFragment head, Js js,
        String relativeRoot) {
    final String scriptPath = getElementPath(request, js, relativeRoot);

    if (resourcesDao.isConditional(js)) {
        Comment c = document.createComment("");
        c.appendData(OPEN_COND_COMMENT_PRE);
        c.appendData(js.getConditional());
        c.appendData(OPEN_COND_COMMENT_POST);
        c.appendData(OPEN_SCRIPT);
        c.appendData(scriptPath);
        c.appendData(CLOSE_SCRIPT);
        c.appendData(CLOSE_COND_COMMENT);
        head.appendChild(c);
    } else {
        Element element = document.createElement(SCRIPT);
        element.setAttribute(TYPE, "text/javascript");
        element.setAttribute(SRC, scriptPath);
        element.appendChild(document.createTextNode(" "));

        head.appendChild(element);
    }
}

From source file:org.jasig.resourceserver.utils.aggr.ResourcesElementsProviderImpl.java

/**
 * Convert the {@link Css} argument to an HTML link tag and append it
 * to the {@link DocumentFragment}.//from  w  ww  .j av  a  2 s  .c  om
 */
protected void appendCssNode(HttpServletRequest request, Document document, DocumentFragment head, Css css,
        String relativeRoot) {
    final String stylePath = getElementPath(request, css, relativeRoot);

    if (resourcesDao.isConditional(css)) {
        Comment c = document.createComment("");
        c.appendData(OPEN_COND_COMMENT_PRE);
        c.appendData(css.getConditional());
        c.appendData(OPEN_COND_COMMENT_POST);
        c.appendData(OPEN_STYLE);
        c.appendData(stylePath);
        if (StringUtils.isNotBlank(css.getMedia())) {
            c.appendData("\" media=\"");
            c.appendData(css.getMedia());
        }
        c.appendData(CLOSE_STYLE);
        c.appendData(CLOSE_COND_COMMENT);
        head.appendChild(c);
    } else {
        Element element = document.createElement(LINK);
        element.setAttribute(REL, "stylesheet");
        element.setAttribute(TYPE, "text/css");
        element.setAttribute(HREF, stylePath);
        if (StringUtils.isNotBlank(css.getMedia())) {
            element.setAttribute(MEDIA, css.getMedia());
        }
        head.appendChild(element);
    }
}

From source file:org.jbpm.bpel.sublang.xpath.XPathEvaluator.java

private static Node createNonElementChild(Step step, Element contextElem) {
    if (!step.getPredicates().isEmpty()) {
        log.error("cannot create node for step with predicates: " + step);
        throw new BpelFaultException(BpelConstants.FAULT_SELECTION_FAILURE);
    }// w  ww  .  j  ava 2 s  . c om

    Document contextDoc = contextElem.getOwnerDocument();

    if (step instanceof TextNodeStep)
        return contextDoc.createTextNode("");

    if (step instanceof ProcessingInstructionNodeStep) {
        ProcessingInstructionNodeStep processingStep = (ProcessingInstructionNodeStep) step;
        return contextDoc.createProcessingInstruction(processingStep.getName(), "");
    }

    if (step instanceof CommentNodeStep)
        return contextDoc.createComment("");

    log.error("cannot create node for any-node tests on the child axis: " + step);
    throw new BpelFaultException(BpelConstants.FAULT_SELECTION_FAILURE);
}