Example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml4

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml4.

Prototype

public static final String escapeHtml4(final String input) 

Source Link

Document

Escapes the characters in a String using HTML entities.

For example:

"bread" & "butter"

becomes:

"bread" & "butter".

Usage

From source file:org.miloss.fgsms.presentation.UddiInquiry.java

private String nameListToString(List<Name> name) {
    StringBuilder ret = new StringBuilder();
    if (name == null || name.isEmpty()) {
        return "";
    }/*from w  w w .  j  av  a2  s  .co m*/
    for (int i = 0; i < name.size(); i++) {
        ret.append(StringEscapeUtils.escapeHtml4(name.get(i).getValue())).append(" ");
    }
    return ret.toString().trim();
}

From source file:org.miloss.fgsms.presentation.UddiInquiry.java

private String descirptionToString(List<Description> name) {
    StringBuilder ret = new StringBuilder();
    if (name == null || name.isEmpty()) {
        return "";
    }/*from   w w w. ja  v  a  2 s . com*/
    for (int i = 0; i < name.size(); i++) {
        ret.append(StringEscapeUtils.escapeHtml4(name.get(i).getValue())).append(" ");
    }
    return ret.toString().trim();
}

From source file:org.miloss.fgsms.presentation.UddiInquiry.java

public String PublishEndpoints(String[] urls, PCS pcs, SecurityWrapper c, String bizkey, boolean updateFederationPolicy) {
    String ret = "";
    for (int i = 0; i < urls.length; i++) {
        String bindingkey = "";
        boolean worked = false;
        ServicePolicyResponseMsg servicePolicy = null;
        try {//from  ww w  . ja va 2s.c  o m
            ServicePolicyRequestMsg res = new ServicePolicyRequestMsg();
            res.setClassification(c);
            res.setURI(urls[i]);
            servicePolicy = pcs.getServicePolicy(res);

            SaveService add = new SaveService();

            add.setAuthInfo(LoginWrapper());
            BusinessService svc = new BusinessService();
            svc.setBusinessKey(bizkey);
            Name n = new Name();
            n.setLang(PublicationConstants.lang);
            if (!Utility.stringIsNullOrEmpty(servicePolicy.getPolicy().getDisplayName())) {
                n.setValue(servicePolicy.getPolicy().getDisplayName());
            } else {
                n.setValue(servicePolicy.getPolicy().getURL());
            }
            svc.getName().add(n);
            Description d = new Description();
            d.setLang(PublicationConstants.lang);
            d.setValue(servicePolicy.getPolicy().getDescription());
            svc.getDescription().add(d);
            if (!Utility.stringIsNullOrEmpty(servicePolicy.getPolicy().getPOC())) {
                d = new Description();
                d.setLang(PublicationConstants.lang);
                d.setValue("POC: " + servicePolicy.getPolicy().getPOC());
                svc.getDescription().add(d);
            }

            BindingTemplates bts = new BindingTemplates();
            BindingTemplate bt = new BindingTemplate();

            AccessPoint ap = new AccessPoint();
            ap.setUseType(PublicationConstants.UDDI_USE_TYPE_ENDPOINT);
            ap.setValue(servicePolicy.getPolicy().getURL());

            /*
             * CategoryBag cb = new CategoryBag(); KeyedReference kr = new
             * KeyedReference();
             * kr.setKeyName("uddi:uddi.org:categorization:types");
             * kr.setKeyValue()
             */
            bt.setAccessPoint(ap);
            bts.getBindingTemplate().add(bt);
            svc.setBindingTemplates(bts);
            add.getBusinessService().add(svc);
            ServiceDetail saveService = config.publish.saveService(add);
            bindingkey = saveService.getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0).getBindingKey();
            worked = true;
            ret += "Successfully Registered " + StringEscapeUtils.escapeHtml4(urls[i]) + "<br>";
        } catch (Exception ex) {
            ret += "Could not register the service at " + StringEscapeUtils.escapeHtml4(urls[i]) + " reason: " + StringEscapeUtils.escapeHtml4(ex.getMessage()) + "<br>";
        }
        if (worked && updateFederationPolicy && servicePolicy != null && !Utility.stringIsNullOrEmpty(bindingkey)) {
            SetServicePolicyRequestMsg req = new SetServicePolicyRequestMsg();
            req.setClassification(servicePolicy.getClassification());
            req.setPolicy(servicePolicy.getPolicy());
            req.setURL(servicePolicy.getPolicy().getURL());
            //check if federation target exist, if it does update it
            FederationPolicy fp = getOrCreateFedPol(servicePolicy.getPolicy());
            fp.setImplementingClassName("org.miloss.fgsms.uddipub.UddiPublisher");
            fp.getParameterNameValue().add(Utility.newNameValuePair("Binding", bindingkey, false, false));
            // fp.setBindingKey(bindingkey);
            try {
                pcs.setServicePolicy(req);
                ret += "Service Policy Updated for <a href=\"manage.jsp?url=" + URLEncoder.encode(urls[i]) + "\">" + StringEscapeUtils.escapeHtml4(urls[i]) + "</a>. Don't forget to select what kind of data you want to be published!<br>";
            } catch (AccessDeniedException ex) {
                ret += "Could not update the service policy, access was denied.<br>";
            } catch (ServiceUnavailableException ex) {
                ret += "Could not update the service policy, error message: " + Utility.encodeHTML(ex.getMessage()) + "<br>";
            }
        }
        ret += "<br><hr><br>";
    }
    return ret;
}

From source file:org.moe.gradle.utils.JUnitTestCollector.java

private static String getHTMLString(String str) {
    return StringEscapeUtils.escapeHtml4(str);
}

From source file:org.moe.natjgen.Statistics.java

private static String escHTML(String v) {
    if (v == null) {
        return null;
    }//from   w  ww. j  a va 2 s . co m
    return StringEscapeUtils.escapeHtml4(v);
}

From source file:org.moe.natjgen.XcodeFullDocumentation.java

private String prettyString(StringBuilder capture) {
    if (capture.length() == 0)
        return null;

    // Remove heading new-lines
    while (capture.length() == 0 && (capture.charAt(0) == '\n' || capture.charAt(0) == '\r')) {
        capture.deleteCharAt(0);//from  w w w.  j  av  a  2  s. c o  m
    }

    // Remove trailing new-lines
    while (capture.length() == 0
            && (capture.charAt(capture.length() - 1) == '\n' || capture.charAt(capture.length() - 1) == '\r')) {
        capture.deleteCharAt(capture.length() - 1);
    }

    String htmlencoded = StringEscapeUtils.escapeHtml4(capture.toString());
    String[] words = htmlencoded.split("\\s+");

    // Try to create lines with the maximum length of MAX_LINE_WIDTH
    capture.setLength(0);
    int lineLength = 0;
    for (String word : words) {
        if (lineLength > 0) {
            if (lineLength + word.length() > MAX_LINE_WIDTH) {
                capture.append("\n");
                lineLength = 0;
            } else {
                capture.append(" ");
            }
        }
        capture.append(word);
        lineLength += word.length();
    }

    for (HTMLTagReplacement replacement : replacements) {
        replaceAll(capture, replacement.openPlaceholder, replacement.openHtml);
        replaceAll(capture, replacement.closePlaceholder, replacement.closeHtml);
    }
    replaceAll(capture, "/*", "&#47;*");
    replaceAll(capture, "*/", "*&#47;");

    for (int i = 0; i < capture.length(); ++i) {
        char c = capture.charAt(i);
        if (!CharUtils.isAscii(c)) {
            capture.replace(i, i + 1, "&#x;");
            capture.insert(i + 3, String.format("%04X", new Integer(c)));
            i += 7;
        }
    }

    return capture.toString();
}

From source file:org.mule.devkit.doclet.ClassInfo.java

/**
 * Turns into the main class page// w  w  w  .  j a v  a2  s.c om
 */
public void makeHDF(Data data) {
    int i, j, n;
    String name = name();
    String qualified = qualifiedName();
    AttributeInfo[] selfAttributes = selfAttributes();
    MethodInfo[] methods = selfMethods();
    FieldInfo[] fields = selfFields();
    FieldInfo[] enumConstants = enumConstants();
    MethodInfo[] ctors = constructors();
    ClassInfo[] inners = innerClasses();

    // class name
    mTypeInfo.makeHDF(data, "class.type");
    mTypeInfo.makeQualifiedHDF(data, "class.qualifiedType");
    data.setValue("class.name", name);
    data.setValue("class.qualified", qualified);
    if (isProtected()) {
        data.setValue("class.scope", "protected");
    } else if (isPublic()) {
        data.setValue("class.scope", "public");
    }
    if (isStatic()) {
        data.setValue("class.static", "static");
    }
    if (isFinal()) {
        data.setValue("class.final", "final");
    }
    if (isAbstract() && !isInterface()) {
        data.setValue("class.abstract", "abstract");
    }

    // module info
    data.setValue("class.moduleName", this.moduleName());
    data.setValue("class.moduleNamespace", this.moduleNamespace());
    data.setValue("class.moduleSchemaLocation", this.moduleSchemaLocation());
    data.setValue("class.moduleSchemaPath", this.moduleSchemaPath());
    try {
        data.setValue("class.moduleSchema", StringEscapeUtils.escapeHtml4(FileUtils.readFileToString(new File(
                "../../../target/generated-sources/mule/META-INF/mule-" + this.moduleName() + ".xsd"))));
    } catch (IOException ioe) {
        Errors.error(Errors.IO_ERROR, position(), "Error reading schema for module " + this.moduleName());
    }
    data.setValue("class.moduleVersion", this.moduleVersion());
    data.setValue("class.moduleMinMuleVersion", this.moduleMinMuleVersion());
    data.setValue("class.moduleSessionAware", Boolean.toString(this.moduleSessionAware()));
    data.setValue("class.moduleOAuthAware", Boolean.toString(this.oauthAware()));

    if (moduleSessionAware()) {
        //ParameterInfo.makeHDF(data, "class.moduleSessionVariables", mModuleConnectVariables, false, mModuleConnectVariablesTypes);
        ParamTagInfo.makeHDF(data, "class.moduleConnectVariables", mModuleConnectVariables);
    }

    // class info
    String kind = kind();
    if (kind != null) {
        data.setValue("class.kind", kind);
    }
    data.setValue("class.since.key", SinceTagger.keyForName(getSince()));
    data.setValue("class.since.name", getSince());
    setFederatedReferences(data, "class");

    // the containing package -- note that this can be passed to type_link,
    // but it also contains the list of all of the packages
    containingPackage().makeClassLinkListHDF(data, "class.package");

    // inheritance hierarchy
    Vector<ClassInfo> superClasses = new Vector<ClassInfo>();
    superClasses.add(this);
    ClassInfo supr = superclass();
    while (supr != null) {
        superClasses.add(supr);
        supr = supr.superclass();
    }
    n = superClasses.size();
    for (i = 0; i < n; i++) {
        supr = superClasses.elementAt(n - i - 1);

        supr.asTypeInfo().makeQualifiedHDF(data, "class.inheritance." + i + ".class");
        supr.asTypeInfo().makeHDF(data, "class.inheritance." + i + ".short_class");
        j = 0;
        for (TypeInfo t : supr.interfaceTypes()) {
            t.makeHDF(data, "class.inheritance." + i + ".interfaces." + j);
            j++;
        }
    }

    // class description
    TagInfo.makeHDF(data, "class.descr", inlineTags());
    TagInfo.makeHDF(data, "class.seeAlso", comment().seeTags());
    TagInfo.makeHDF(data, "class.deprecated", deprecatedTags());

    // known subclasses
    TreeMap<String, ClassInfo> direct = new TreeMap<String, ClassInfo>();
    TreeMap<String, ClassInfo> indirect = new TreeMap<String, ClassInfo>();
    ClassInfo[] all = Converter.rootClasses();
    for (ClassInfo cl : all) {
        if (cl.superclass() != null && cl.superclass().equals(this)) {
            direct.put(cl.name(), cl);
        } else if (cl.isDerivedFrom(this)) {
            indirect.put(cl.name(), cl);
        }
    }
    // direct
    i = 0;
    for (ClassInfo cl : direct.values()) {
        if (cl.checkLevel()) {
            cl.makeShortDescrHDF(data, "class.subclasses.direct." + i);
        }
        i++;
    }
    // indirect
    i = 0;
    for (ClassInfo cl : indirect.values()) {
        if (cl.checkLevel()) {
            cl.makeShortDescrHDF(data, "class.subclasses.indirect." + i);
        }
        i++;
    }

    // hide special cases
    if ("java.lang.Object".equals(qualified) || "java.io.Serializable".equals(qualified)) {
        data.setValue("class.subclasses.hidden", "1");
    } else {
        data.setValue("class.subclasses.hidden", "0");
    }

    // nested classes
    i = 0;
    for (ClassInfo inner : inners) {
        if (inner.checkLevel()) {
            inner.makeShortDescrHDF(data, "class.inners." + i);
        }
        i++;
    }

    // enum constants
    i = 0;
    for (FieldInfo field : enumConstants) {
        field.makeHDF(data, "class.enumConstants." + i);
        i++;
    }

    // constants
    i = 0;
    for (FieldInfo field : fields) {
        if (field.isConstant()) {
            field.makeHDF(data, "class.constants." + i);
            i++;
        }
    }

    // fields
    i = 0;
    for (FieldInfo field : fields) {
        if (!field.isConstant()) {
            field.makeHDF(data, "class.fields." + i);
            i++;
        }
    }

    // constants
    i = 0;
    for (FieldInfo field : mAllSelfFields) {
        if (field.isConfigurable()) {
            field.makeHDF(data, "class.config." + i);
            i++;
        }
    }

    // public constructors
    i = 0;
    for (MethodInfo ctor : ctors) {
        if (ctor.isPublic()) {
            ctor.makeHDF(data, "class.ctors.public." + i);
            i++;
        }
    }

    // protected constructors
    if (Doclava.checkLevel(Doclava.SHOW_PROTECTED)) {
        i = 0;
        for (MethodInfo ctor : ctors) {
            if (ctor.isProtected()) {
                ctor.makeHDF(data, "class.ctors.protected." + i);
                i++;
            }
        }
    }

    // package private constructors
    if (Doclava.checkLevel(Doclava.SHOW_PACKAGE)) {
        i = 0;
        for (MethodInfo ctor : ctors) {
            if (ctor.isPackagePrivate()) {
                ctor.makeHDF(data, "class.ctors.package." + i);
                i++;
            }
        }
    }

    // private constructors
    if (Doclava.checkLevel(Doclava.SHOW_PRIVATE)) {
        i = 0;
        for (MethodInfo ctor : ctors) {
            if (ctor.isPrivate()) {
                ctor.makeHDF(data, "class.ctors.private." + i);
                i++;
            }
        }
    }

    // public methods
    i = 0;
    for (MethodInfo method : methods) {
        if (method.isPublic()) {
            method.makeHDF(data, "class.methods.public." + i);
            i++;
        }
    }

    // protected methods
    if (Doclava.checkLevel(Doclava.SHOW_PROTECTED)) {
        i = 0;
        for (MethodInfo method : methods) {
            if (method.isProtected()) {
                method.makeHDF(data, "class.methods.protected." + i);
                i++;
            }
        }
    }

    // package private methods
    if (Doclava.checkLevel(Doclava.SHOW_PACKAGE)) {
        i = 0;
        for (MethodInfo method : methods) {
            if (method.isPackagePrivate()) {
                method.makeHDF(data, "class.methods.package." + i);
                i++;
            }
        }
    }

    // private methods
    if (Doclava.checkLevel(Doclava.SHOW_PRIVATE)) {
        i = 0;
        for (MethodInfo method : methods) {
            if (method.isPrivate()) {
                method.makeHDF(data, "class.methods.private." + i);
                i++;
            }
        }
    }

    // processors
    i = 0;
    for (MethodInfo method : methods) {
        if (method.isProcessor()) {
            method.makeHDF(data, "class.methods.processor." + i);
            i++;

        }
    }

    // source
    i = 0;
    for (MethodInfo method : methods) {
        if (method.isSource()) {
            method.makeHDF(data, "class.methods.source." + i);
            i++;
        }
    }

    // transformer
    i = 0;
    for (MethodInfo method : methods) {
        if (method.isTransformer()) {
            method.makeHDF(data, "class.methods.transformer." + i);
            i++;
        }
    }

    // xml attributes
    i = 0;
    for (AttributeInfo attr : selfAttributes) {
        if (attr.checkLevel()) {
            attr.makeHDF(data, "class.attrs." + i);
            i++;
        }
    }

    // inherited methods
    Set<ClassInfo> interfaces = new TreeSet<ClassInfo>();
    addInterfaces(getInterfaces(), interfaces);
    ClassInfo cl = superclass();
    i = 0;
    while (cl != null) {
        addInterfaces(cl.getInterfaces(), interfaces);
        makeInheritedHDF(data, i, cl);
        cl = cl.superclass();
        i++;
    }
    for (ClassInfo iface : interfaces) {
        makeInheritedHDF(data, i, iface);
        i++;
    }
}

From source file:org.n52.ses.common.environment.SESMiniServlet.java

private void provideLandingPage(HttpServletRequest req, HttpServletResponse resp, ConfigurationRegistry conf)
        throws IOException, UnsupportedEncodingException {
    /*/*  w ww . ja va 2  s  .  co  m*/
     * return landing page
     */
    if (this.landingPage != null) {
        resp.setContentType("text/html");
        synchronized (this) {
            printResponse(req, resp, this.landingPage);
        }

        return;
    }

    InputStreamReader isr = new InputStreamReader(getClass().getResourceAsStream("/landing_page.html"));
    BufferedReader br = new BufferedReader(isr);
    StringBuilder sb = new StringBuilder();

    while (br.ready()) {
        sb.append(br.readLine());
    }
    String html = sb.toString();

    String reqUrl = URLDecoder.decode(req.getRequestURL().toString(),
            (req.getCharacterEncoding() == null ? Charset.defaultCharset().name()
                    : req.getCharacterEncoding()));
    html = html.replace("[SES_URL]",
            reqUrl.substring(0, reqUrl.indexOf(req.getContextPath())) + req.getContextPath());

    /*
     * check if we are init yet
     */
    String sesPortTypeUrl, subMgrUrl, prmUrl = "";
    if (conf != null) {
        String defaulturi = conf.getEnvironment().getDefaultURI().substring(0,
                conf.getEnvironment().getDefaultURI().lastIndexOf("/services"));
        sesPortTypeUrl = defaulturi + "/services/" + SESNotificationProducer.CONTEXT_PATH;
        subMgrUrl = defaulturi + "/services/" + SESSubscriptionManager.CONTEXT_PATH;
        prmUrl = defaulturi + "/services/" + RegisterPublisher.RESOURCE_TYPE;

        conf.setSubscriptionManagerWsdl(subMgrUrl + "?wsdl");

        html = html.replace("<p id=\"ses-status\"><p>",
                "<p style=\"color:#0f0\">The service is active and available.</p>");

        html = html.replace("[GET_CAPS]",
                StringEscapeUtils.escapeHtml4(StartupInitServlet.getGetCapabilitiesRequest(sesPortTypeUrl)));
        /*
         * replace the url
         */
        synchronized (this) {
            if (this.landingPage == null) {
                this.landingPage = html.replace("[SES_PORT_TYPE_URL]", sesPortTypeUrl);
                this.landingPage = this.landingPage.replace("[SUB_MGR_URL]", subMgrUrl);
                this.landingPage = this.landingPage.replace("[PRM_URL]", prmUrl);

                resp.setContentType("text/html");
                printResponse(req, resp, this.landingPage);
            }

        }

    } else {
        /*
         * we do not have the config, warn the user
         */
        html = html.replace("<p id=\"ses-status\"><p>",
                "<p style=\"color:#f00\">The service is currently not available due to unfinished or failed initialization.</p>");

        resp.setContentType("text/html");
        printResponse(req, resp, html);
    }
}

From source file:org.nerve.utils.encode.EncodeUtils.java

public static String htmlEscape(String html) {
    return StringEscapeUtils.escapeHtml4(html);
}

From source file:org.ng200.openolympus.HtmlUtils.java

public static String stringToHtml(final String str) {
    return StringEscapeUtils.escapeHtml4(str).replaceAll("\n", "<br/>").replaceAll(" ", "&nbsp;")
            .replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
}