當前位置: 首頁>>代碼示例>>Java>>正文


Java HtmlUtil類代碼示例

本文整理匯總了Java中net.sourceforge.stripes.util.HtmlUtil的典型用法代碼示例。如果您正苦於以下問題:Java HtmlUtil類的具體用法?Java HtmlUtil怎麽用?Java HtmlUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HtmlUtil類屬於net.sourceforge.stripes.util包,在下文中一共展示了HtmlUtil類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFieldsPresentValue

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
/** Get the encrypted value of the __fp hidden field. */
protected String getFieldsPresentValue() {
    // Figure out what set of names to include
    Set<String> namesToInclude = new HashSet<String>();

    if (isWizard()) {
        namesToInclude.addAll(this.fieldsPresent.keySet());
    }
    else {
        for (Map.Entry<String,Class<?>> entry : this.fieldsPresent.entrySet()) {
            Class<?> fieldClass = entry.getValue();
            if (InputSelectTag.class.isAssignableFrom(fieldClass)
                    || InputCheckBoxTag.class.isAssignableFrom(fieldClass)) {
                namesToInclude.add(entry.getKey());
            }
        }
    }

    // Combine the names into a delimited String and encrypt it
    String hiddenFieldValue = HtmlUtil.combineValues(namesToInclude);
    return CryptoUtil.encrypt(hiddenFieldValue);
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:23,代碼來源:FormTag.java

示例2: view

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
/**
 * Handler method which will handle a request for a resource in the web application
 * and stream it back to the client inside of an HTML preformatted section.
 */
public Resolution view() {
    final InputStream stream = getContext().getRequest().getSession()
                              .getServletContext().getResourceAsStream(this.resource);
    final BufferedReader reader = new BufferedReader( new InputStreamReader(stream) );

    return new Resolution() {
        public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
            PrintWriter writer = response.getWriter();
            writer.write("<html><head><title>");
            writer.write(resource);
            writer.write("</title></head><body><pre>");

            String line;
            while ( (line = reader.readLine()) != null ) {
                writer.write(HtmlUtil.encode(line));
                writer.write("\n");
            }

            writer.write("</pre></body></html>");
        }
    };
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:27,代碼來源:ViewResourceActionBean.java

示例3: getFieldsPresentInfo

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
/**
 * In a lot of cases (and specifically during wizards) the Stripes form field writes out a
 * hidden field containing a set of field names. This is encrypted to stop the user from
 * monkeying with it. This method retrieves the list of field names, decrypts it and splits it
 * out into a Collection of field names.
 * 
 * @param bean the current ActionBean
 * @return a non-null (though possibly empty) list of field names
 */
protected Collection<String> getFieldsPresentInfo(ActionBean bean) {
    ActionBeanContext ctx = bean.getContext();
    String fieldsPresent = ctx.getRequest().getParameter(StripesConstants.URL_KEY_FIELDS_PRESENT);
    Wizard wizard = bean.getClass().getAnnotation(Wizard.class);
    boolean isWizard = wizard != null;

    if (fieldsPresent == null || "".equals(fieldsPresent)) {
        if (isWizard && !CollectionUtil.contains(wizard.startEvents(), ctx.getEventName())) {
            throw new StripesRuntimeException(
                    "Submission of a wizard form in Stripes absolutely requires that "
                            + "the hidden field Stripes writes containing the names of the fields "
                            + "present on the form is present and encrypted (as Stripes write it). "
                            + "This is necessary to prevent a user from spoofing the system and "
                            + "getting around any security/data checks.");
        }
        else {
            return Collections.emptySet();
        }
    }
    else {
        fieldsPresent = CryptoUtil.decrypt(fieldsPresent);
        return HtmlUtil.splitValues(fieldsPresent);
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:34,代碼來源:DefaultActionBeanPropertyBinder.java

示例4: doEndInputTag

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
/**
 * Determines which source is applicable for the contents of the textarea and then writes
 * out the textarea tag including the body.
 *
 * @return EVAL_PAGE in all cases.
 * @throws JspException if the enclosing form tag cannot be found, or output cannot be written.
 */
@Override
public int doEndInputTag() throws JspException {
    try {
        // Find out if we have a value from the PopulationStrategy
        Object value = getSingleOverrideValue();

        writeOpenTag(getPageContext().getOut(), "textarea");

        // Write out the contents of the text area
        if (value != null) {
            // Most browsers have this annoying habit of eating the first newline
            // in a textarea tag. Since this is probably not desired, sometimes
            // we need to add an extra newline into the output before the value
            String body = getBodyContentAsString();
            if (body == null || !body.equals(value)) {
                getPageContext().getOut().write('\n');
            }

            getPageContext().getOut().write( HtmlUtil.encode(format(value)) );
        }

        writeCloseTag(getPageContext().getOut(), "textarea");

        return EVAL_PAGE;
    }
    catch (IOException ioe) {
        throw new StripesJspException("Could not write out textarea tag.", ioe);
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:37,代碼來源:InputTextAreaTag.java

示例5: writeAttributes

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
/**
 * For every attribute stored in the attributes map for this tag, writes out the tag
 * attributes in the form x="y".  All attributes are HTML encoded before being written
 * to the page to ensure that HTML special characters are rendered properly.
 *
 * @param writer the JspWriter to write the open tag to
 * @throws IOException if the JspWriter causes an exception
 */
protected void writeAttributes(JspWriter writer) throws IOException {
    for (Map.Entry<String,String> attr: getAttributes().entrySet() ) {
        // Skip the output of blank attributes!
        String value = attr.getValue();
        if (value == null) continue;

        writer.print(" ");
        writer.print(attr.getKey());
        writer.print("=\"");
        writer.print( HtmlUtil.encode(value) );
        writer.print("\"");
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:22,代碼來源:HtmlTagSupport.java

示例6: getParamNames

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
/** Returns all the submitted parameters in the current or the former requests. */
@SuppressWarnings("unchecked")
protected Set<String> getParamNames() {
    // Combine actual parameter names with input names from the form, which might not be
    // represented by a real request parameter
    Set<String> paramNames = new HashSet<String>();
    ServletRequest request = getPageContext().getRequest();
    paramNames.addAll(request.getParameterMap().keySet());
    String fieldsPresent = request.getParameter(URL_KEY_FIELDS_PRESENT);
    if (fieldsPresent != null) {
        paramNames.addAll(HtmlUtil.splitValues(CryptoUtil.decrypt(fieldsPresent)));
    }
    return paramNames;
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:15,代碼來源:WizardFieldsTag.java

示例7: fillInValidationErrors

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
/**
 * Makes sure that validation errors have all the necessary information to render
 * themselves properly, including the UrlBinding of the action bean and the field
 * value if it hasn't already been set.
 *
 * @param ctx the ExecutionContext being used to process the current request
 */
public static void fillInValidationErrors(ExecutionContext ctx) {
    ActionBeanContext context = ctx.getActionBeanContext();
    ValidationErrors errors = context.getValidationErrors();

    if (errors.size() > 0) {
        String formAction = StripesFilter.getConfiguration().getActionResolver()
                .getUrlBinding(ctx.getActionBean().getClass());
        HttpServletRequest request = ctx.getActionBeanContext().getRequest();

        /** Since we don't pass form action down the stack, we add it to the errors here. */
        for (Map.Entry<String, List<ValidationError>> entry : errors.entrySet()) {
            String parameterName = entry.getKey();
            List<ValidationError> listOfErrors = entry.getValue();

            for (ValidationError error : listOfErrors) {
                // Make sure we process each error only once, no matter how often we're called
                if (error.getActionPath() == null) {
                    error.setActionPath(formAction);
                    error.setBeanclass(ctx.getActionBean().getClass());

                    // If the value isn't set, set it, otherwise encode the one that's there
                    if (error.getFieldValue() == null) {
                        error.setFieldValue(HtmlUtil.encode(request.getParameter(parameterName)));
                    }
                    else {
                        error.setFieldValue(HtmlUtil.encode(error.getFieldValue()));
                    }
                }
            }
        }
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:40,代碼來源:DispatcherHelper.java

示例8: execute

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // log an exception for the stack trace
    SourcePageNotFoundException exception = new SourcePageNotFoundException(getContext());
    log.error(exception);

    // start the HTML error report
    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.println("<div style=\"font-family: Arial, sans-serif; font-size: 10pt;\">");
    writer.println("<h1>Stripes validation error report</h1><p>");
    writer.println(HtmlUtil.encode(exception.getMessage()));
    writer.println("</p><h2>Validation errors</h2><p>");
    sendErrors(request, response);
    writer.println("</p></div>");
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:16,代碼來源:ValidationErrorReportResolution.java

示例9: sendErrors

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
/**
 * Called by {@link #execute(HttpServletRequest, HttpServletResponse)} to write the actual
 * validation errors to the client. The {@code header}, {@code footer}, {@code beforeError} and
 * {@code afterError} resources are used by this method.
 * 
 * @param request The servlet request.
 * @param response The servlet response.
 */
protected void sendErrors(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // Output all errors in a standard format
    Locale locale = request.getLocale();
    ResourceBundle bundle = null;

    try {
        bundle = StripesFilter.getConfiguration().getLocalizationBundleFactory()
                .getErrorMessageBundle(locale);
    }
    catch (MissingResourceException mre) {
        log.warn(getClass().getName(), " could not find the error messages resource bundle. ",
                "As a result default headers/footers etc. will be used. Check that ",
                "you have a StripesResources.properties in your classpath (unless ",
                "of course you have configured a different bundle).");
    }

    // Fetch the header and footer
    String header = getResource(bundle, "header", ErrorsTag.DEFAULT_HEADER);
    String footer = getResource(bundle, "footer", ErrorsTag.DEFAULT_FOOTER);
    String openElement = getResource(bundle, "beforeError", "<li>");
    String closeElement = getResource(bundle, "afterError", "</li>");

    // Write out the error messages
    PrintWriter writer = response.getWriter();
    writer.write(header);

    for (List<ValidationError> list : getContext().getValidationErrors().values()) {
        for (ValidationError fieldError : list) {
            writer.write(openElement);
            writer.write(HtmlUtil.encode(fieldError.getMessage(locale)));
            writer.write(closeElement);
        }
    }

    writer.write(footer);
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:46,代碼來源:ValidationErrorReportResolution.java

示例10: doEndInputTag

import net.sourceforge.stripes.util.HtmlUtil; //導入依賴的package包/類
/**
 * Locates the option's parent select tag, determines selection state and then writes out
 * an option tag with an appropriate body.
 *
 * @return EVAL_PAGE in all cases.
 * @throws JspException if the option is not contained inside an InputSelectTag or output
 *         cannot be written.
 */
@Override
public int doEndInputTag() throws JspException {
    // Find our mandatory enclosing select tag
    InputSelectTag selectTag = getParentTag(InputSelectTag.class);
    if (selectTag == null) {
        throw new StripesJspException
                ("Option tags must always be contained inside a select tag.");
    }

    // Decide if the label will come from the body of the option, of the label attr
    String actualLabel = getBodyContentAsString();
    if (actualLabel == null) {
        actualLabel = HtmlUtil.encode(this.label);
    }

    // If no explicit value attribute set, use the tag label as the value
    Object actualValue;
    if (this.value == null) {
        actualValue = actualLabel;
    }
    else {
        actualValue = this.value;
    }
    getAttributes().put("value", format(actualValue));

   // Determine if the option should be selected
    if (selectTag.isOptionSelected(actualValue, (this.selected != null))) {
        getAttributes().put("selected", "selected");
    }

    // And finally write the tag out to the page
    try {
        writeOpenTag(getPageContext().getOut(), "option");
        if (actualLabel != null) {
            getPageContext().getOut().write(actualLabel);
        }
        writeCloseTag(getPageContext().getOut(), "option");

        // Clean out the attributes we modified
        getAttributes().remove("selected");
        getAttributes().remove("value");
    }
    catch (IOException ioe) {
        throw new JspException("IOException in InputOptionTag.doEndTag().", ioe);
    }

    return EVAL_PAGE;
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:57,代碼來源:InputOptionTag.java


注:本文中的net.sourceforge.stripes.util.HtmlUtil類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。