Example usage for javax.servlet.http HttpServletResponse encodeUrl

List of usage examples for javax.servlet.http HttpServletResponse encodeUrl

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse encodeUrl.

Prototype

@Deprecated
public String encodeUrl(String url);

Source Link

Usage

From source file:org.apache.struts.taglib.TagUtils.java

/**
 * Compute a hyperlink URL based on the <code>forward</code>,
 * <code>href</code>, <code>action</code> or <code>page</code> parameter
 * that is not null. The returned URL will have already been passed to
 * <code>response.encodeURL()</code> for adding a session identifier.
 *
 * @param pageContext      PageContext for the tag making this call
 * @param forward          Logical forward name for which to look up the
 *                         context-relative URI (if specified)
 * @param href             URL to be utilized unmodified (if specified)
 * @param page             Module-relative page for which a URL should be
 *                         created (if specified)
 * @param action           Logical action name for which to look up the
 *                         context-relative URI (if specified)
 * @param params           Map of parameters to be dynamically included
 *                         (if any)/*www.j a va 2  s  .c o m*/
 * @param anchor           Anchor to be dynamically included (if any)
 * @param redirect         Is this URL for a <code>response.sendRedirect()</code>?
 * @param encodeSeparator  This is only checked if redirect is set to
 *                         false (never encoded for a redirect).  If true,
 *                         query string parameter separators are encoded
 *                         as &gt;amp;, else &amp; is used.
 * @param useLocalEncoding If set to true, urlencoding is done on the
 *                         bytes of character encoding from
 *                         ServletResponse#getCharacterEncoding. Use UTF-8
 *                         otherwise.
 * @return URL with session identifier
 * @throws java.net.MalformedURLException if a URL cannot be created for
 *                                        the specified parameters
 */
public String computeURLWithCharEncoding(PageContext pageContext, String forward, String href, String page,
        String action, String module, Map params, String anchor, boolean redirect, boolean encodeSeparator,
        boolean useLocalEncoding) throws MalformedURLException {
    String charEncoding = "UTF-8";

    if (useLocalEncoding) {
        charEncoding = pageContext.getResponse().getCharacterEncoding();
    }

    // TODO All the computeURL() methods need refactoring!
    // Validate that exactly one specifier was included
    int n = 0;

    if (forward != null) {
        n++;
    }

    if (href != null) {
        n++;
    }

    if (page != null) {
        n++;
    }

    if (action != null) {
        n++;
    }

    if (n != 1) {
        throw new MalformedURLException(messages.getMessage("computeURL.specifier"));
    }

    // Look up the module configuration for this request
    ModuleConfig moduleConfig = getModuleConfig(module, pageContext);

    // Calculate the appropriate URL
    StringBuffer url = new StringBuffer();
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    if (forward != null) {
        ForwardConfig forwardConfig = moduleConfig.findForwardConfig(forward);

        if (forwardConfig == null) {
            throw new MalformedURLException(messages.getMessage("computeURL.forward", forward));
        }

        // **** removed - see bug 37817 ****
        //  if (forwardConfig.getRedirect()) {
        //      redirect = true;
        //  }

        if (forwardConfig.getPath().startsWith("/")) {
            url.append(request.getContextPath());
            url.append(RequestUtils.forwardURL(request, forwardConfig, moduleConfig));
        } else {
            url.append(forwardConfig.getPath());
        }
    } else if (href != null) {
        url.append(href);
    } else if (action != null) {
        ActionServlet servlet = (ActionServlet) pageContext.getServletContext()
                .getAttribute(Globals.ACTION_SERVLET_KEY);
        String actionIdPath = RequestUtils.actionIdURL(action, moduleConfig, servlet);
        if (actionIdPath != null) {
            action = actionIdPath;
            url.append(request.getContextPath());
            url.append(actionIdPath);
        } else {
            url.append(instance.getActionMappingURL(action, module, pageContext, false));
        }
    } else /* if (page != null) */
    {
        url.append(request.getContextPath());
        url.append(this.pageURL(request, page, moduleConfig));
    }

    // Add anchor if requested (replacing any existing anchor)
    if (anchor != null) {
        String temp = url.toString();
        int hash = temp.indexOf('#');

        if (hash >= 0) {
            url.setLength(hash);
        }

        url.append('#');
        url.append(this.encodeURL(anchor, charEncoding));
    }

    // Add dynamic parameters if requested
    if ((params != null) && (params.size() > 0)) {
        // Save any existing anchor
        String temp = url.toString();
        int hash = temp.indexOf('#');

        if (hash >= 0) {
            anchor = temp.substring(hash + 1);
            url.setLength(hash);
            temp = url.toString();
        } else {
            anchor = null;
        }

        // Define the parameter separator
        String separator = null;

        if (redirect) {
            separator = "&";
        } else if (encodeSeparator) {
            separator = "&amp;";
        } else {
            separator = "&";
        }

        // Add the required request parameters
        boolean question = temp.indexOf('?') >= 0;
        Iterator keys = params.keySet().iterator();

        while (keys.hasNext()) {
            String key = (String) keys.next();
            Object value = params.get(key);

            if (value == null) {
                if (!question) {
                    url.append('?');
                    question = true;
                } else {
                    url.append(separator);
                }

                url.append(this.encodeURL(key, charEncoding));
                url.append('='); // Interpret null as "no value"
            } else if (value instanceof String) {
                if (!question) {
                    url.append('?');
                    question = true;
                } else {
                    url.append(separator);
                }

                url.append(this.encodeURL(key, charEncoding));
                url.append('=');
                url.append(this.encodeURL((String) value, charEncoding));
            } else if (value instanceof String[]) {
                String[] values = (String[]) value;

                for (int i = 0; i < values.length; i++) {
                    if (!question) {
                        url.append('?');
                        question = true;
                    } else {
                        url.append(separator);
                    }

                    url.append(this.encodeURL(key, charEncoding));
                    url.append('=');
                    url.append(this.encodeURL(values[i], charEncoding));
                }
            } else /* Convert other objects to a string */
            {
                if (!question) {
                    url.append('?');
                    question = true;
                } else {
                    url.append(separator);
                }

                url.append(this.encodeURL(key, charEncoding));
                url.append('=');
                url.append(this.encodeURL(value.toString(), charEncoding));
            }
        }

        // Re-add the saved anchor (if any)
        if (anchor != null) {
            url.append('#');
            url.append(this.encodeURL(anchor, charEncoding));
        }
    }

    // Perform URL rewriting to include our session ID (if any)
    // but only if url is not an external URL
    if ((href == null) && (pageContext.getSession() != null)) {
        HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

        if (redirect) {
            return (response.encodeRedirectURL(url.toString()));
        }

        return (response.encodeURL(url.toString()));
    }

    return (url.toString());
}

From source file:org.sakaiproject.login.tool.SkinnableLogin.java

public LoginRenderContext startPageContext(String skin, HttpServletRequest request,
        HttpServletResponse response) {
    LoginRenderEngine rengine = loginService.getRenderEngine(loginContext, request);
    LoginRenderContext rcontext = rengine.newRenderContext(request);

    if (StringUtils.isEmpty(skin)) {
        skin = serverConfigurationService.getString("skin.default", "default");
    }/*from  w  w  w .  ja v a2s .  c om*/

    String skinRepo = serverConfigurationService.getString("skin.repo");
    String uiService = serverConfigurationService.getString("ui.service", "Sakai");
    String passwordResetUrl = getPasswordResetUrl();

    String eidWording = rb.getString("userid");
    String pwWording = rb.getString("log.pass");
    String loginRequired = rb.getString("log.logreq");
    String loginWording = rb.getString("log.login");
    String cancelWording = rb.getString("log.cancel");
    String passwordResetWording = rb.getString("log.password.reset");

    rcontext.put("action", response.encodeURL(Web.returnUrl(request, null)));
    rcontext.put("pageSkinRepo", skinRepo);
    rcontext.put("pageSkin", skin);
    rcontext.put("uiService", uiService);
    rcontext.put("pageScriptPath", getScriptPath());
    rcontext.put("loginEidWording", eidWording);
    rcontext.put("loginPwWording", pwWording);
    rcontext.put("loginRequired", loginRequired);
    rcontext.put("loginWording", loginWording);
    rcontext.put("cancelWording", cancelWording);
    rcontext.put("passwordResetUrl", passwordResetUrl);
    rcontext.put("passwordResetWording", passwordResetWording);

    String eid = StringEscapeUtils.escapeHtml(request.getParameter("eid"));
    String pw = StringEscapeUtils.escapeHtml(request.getParameter("pw"));

    if (eid == null)
        eid = "";
    if (pw == null)
        pw = "";

    rcontext.put("eid", eid);
    rcontext.put("password", pw);

    return rcontext;
}

From source file:org.eclipse.vtp.framework.engine.http.HttpConnector.java

/**
 * Writes an index page for the current deployments.
 * //from w w w.java2  s . co  m
 * @param res The HTTP response.
 * @param deployment The current deployment.
 * @throws IOException If the connection fails.
 */
private void writeIndex(HttpServletResponse res, Deployment deployment) throws IOException {
    String deploymentID = deployment.getID();
    res.setStatus(HttpServletResponse.SC_OK);
    res.setContentType("text/html");
    PrintWriter writer = res.getWriter();
    writer.println("<html>");
    writer.println("<head><title>Deployments</title></head>");
    writer.println("<body>");
    if (deploymentID != null) {
        writer.print("<p>CURRENT: ");
        writer.print(deploymentID);
        writer.println("</p>");
    }
    synchronized (this) {
        for (Map.Entry<String, Deployment> entry : deploymentsByPath.entrySet()) {
            writer.print("<p><a href=\"");
            writer.print(res.encodeURL(entry.getKey()));
            writer.print("\">");
            writer.print(entry.getValue().getProcessID());
            writer.println("</a></p>");
        }
    }
    writer.println("</body>");
    writer.println("</html>");
    writer.flush();
    writer.close();
}

From source file:org.apache.catalina.manager.HTMLManagerServlet.java

/**
 * Render a HTML list of the currently active Contexts in our virtual host,
 * and memory and server status information.
 *
 * @param writer Writer to render to/*from ww w  .j  a va 2s . co  m*/
 * @param message a message to display
 */
public void list(HttpServletRequest request, HttpServletResponse response, String message) throws IOException {

    if (debug >= 1)
        log("list: Listing contexts for virtual host '" + deployer.getName() + "'");

    PrintWriter writer = response.getWriter();

    // HTML Header Section
    writer.print(Constants.HTML_HEADER_SECTION);

    // Body Header Section
    Object[] args = new Object[2];
    args[0] = request.getContextPath();
    args[1] = sm.getString("htmlManagerServlet.title");
    writer.print(MessageFormat.format(Constants.BODY_HEADER_SECTION, args));

    // Message Section
    args = new Object[3];
    args[0] = sm.getString("htmlManagerServlet.messageLabel");
    args[1] = (message == null || message.length() == 0) ? "OK" : message;
    writer.print(MessageFormat.format(Constants.MESSAGE_SECTION, args));

    // Manager Section
    args = new Object[9];
    args[0] = sm.getString("htmlManagerServlet.manager");
    args[1] = response.encodeURL(request.getContextPath() + "/html/list");
    args[2] = sm.getString("htmlManagerServlet.list");
    args[3] = response
            .encodeURL(request.getContextPath() + "/" + sm.getString("htmlManagerServlet.helpHtmlManagerFile"));
    args[4] = sm.getString("htmlManagerServlet.helpHtmlManager");
    args[5] = response
            .encodeURL(request.getContextPath() + "/" + sm.getString("htmlManagerServlet.helpManagerFile"));
    args[6] = sm.getString("htmlManagerServlet.helpManager");
    args[7] = response.encodeURL(request.getContextPath() + "/status");
    args[8] = sm.getString("statusServlet.title");
    writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args));

    // Apps Header Section
    args = new Object[6];
    args[0] = sm.getString("htmlManagerServlet.appsTitle");
    args[1] = sm.getString("htmlManagerServlet.appsPath");
    args[2] = sm.getString("htmlManagerServlet.appsName");
    args[3] = sm.getString("htmlManagerServlet.appsAvailable");
    args[4] = sm.getString("htmlManagerServlet.appsSessions");
    args[5] = sm.getString("htmlManagerServlet.appsTasks");
    writer.print(MessageFormat.format(APPS_HEADER_SECTION, args));

    // Apps Row Section
    // Create sorted map of deployed applications context paths.
    String contextPaths[] = deployer.findDeployedApps();

    TreeMap sortedContextPathsMap = new TreeMap();

    for (int i = 0; i < contextPaths.length; i++) {
        String displayPath = contextPaths[i];
        sortedContextPathsMap.put(displayPath, contextPaths[i]);
    }

    String appsStart = sm.getString("htmlManagerServlet.appsStart");
    String appsStop = sm.getString("htmlManagerServlet.appsStop");
    String appsReload = sm.getString("htmlManagerServlet.appsReload");
    String appsUndeploy = sm.getString("htmlManagerServlet.appsUndeploy");

    Iterator iterator = sortedContextPathsMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry entry = (Map.Entry) iterator.next();
        String displayPath = (String) entry.getKey();
        String contextPath = (String) entry.getKey();
        Context context = deployer.findDeployedApp(contextPath);
        if (displayPath.equals("")) {
            displayPath = "/";
        }

        if (context != null) {
            args = new Object[5];
            args[0] = displayPath;
            args[1] = context.getDisplayName();
            if (args[1] == null) {
                args[1] = "&nbsp;";
            }
            args[2] = new Boolean(context.getAvailable());
            args[3] = response.encodeURL(request.getContextPath() + "/html/sessions?path=" + displayPath);
            if (context.getManager() != null) {
                args[4] = new Integer(context.getManager().findSessions().length);
            } else {
                args[4] = new Integer(0);
            }
            writer.print(MessageFormat.format(APPS_ROW_DETAILS_SECTION, args));

            args = new Object[8];
            args[0] = response.encodeURL(request.getContextPath() + "/html/start?path=" + displayPath);
            args[1] = appsStart;
            args[2] = response.encodeURL(request.getContextPath() + "/html/stop?path=" + displayPath);
            args[3] = appsStop;
            args[4] = response.encodeURL(request.getContextPath() + "/html/reload?path=" + displayPath);
            args[5] = appsReload;
            args[6] = response.encodeURL(request.getContextPath() + "/html/undeploy?path=" + displayPath);
            args[7] = appsUndeploy;
            if (context.getPath().equals(this.context.getPath())) {
                writer.print(MessageFormat.format(MANAGER_APP_ROW_BUTTON_SECTION, args));
            } else if (context.getAvailable()) {
                writer.print(MessageFormat.format(STARTED_APPS_ROW_BUTTON_SECTION, args));
            } else {
                writer.print(MessageFormat.format(STOPPED_APPS_ROW_BUTTON_SECTION, args));
            }

        }
    }

    // Deploy Section
    args = new Object[7];
    args[0] = sm.getString("htmlManagerServlet.deployTitle");
    args[1] = sm.getString("htmlManagerServlet.deployServer");
    args[2] = response.encodeURL(request.getContextPath() + "/html/deploy");
    args[3] = sm.getString("htmlManagerServlet.deployPath");
    args[4] = sm.getString("htmlManagerServlet.deployConfig");
    args[5] = sm.getString("htmlManagerServlet.deployWar");
    args[6] = sm.getString("htmlManagerServlet.deployButton");
    writer.print(MessageFormat.format(DEPLOY_SECTION, args));

    args = new Object[4];
    args[0] = sm.getString("htmlManagerServlet.deployUpload");
    args[1] = response.encodeURL(request.getContextPath() + "/html/upload");
    args[2] = sm.getString("htmlManagerServlet.deployUploadFile");
    args[3] = sm.getString("htmlManagerServlet.deployButton");
    writer.print(MessageFormat.format(UPLOAD_SECTION, args));

    // Server Header Section
    args = new Object[7];
    args[0] = sm.getString("htmlManagerServlet.serverTitle");
    args[1] = sm.getString("htmlManagerServlet.serverVersion");
    args[2] = sm.getString("htmlManagerServlet.serverJVMVersion");
    args[3] = sm.getString("htmlManagerServlet.serverJVMVendor");
    args[4] = sm.getString("htmlManagerServlet.serverOSName");
    args[5] = sm.getString("htmlManagerServlet.serverOSVersion");
    args[6] = sm.getString("htmlManagerServlet.serverOSArch");
    writer.print(MessageFormat.format(Constants.SERVER_HEADER_SECTION, args));

    // Server Row Section
    args = new Object[6];
    args[0] = ServerInfo.getServerInfo();
    args[1] = System.getProperty("java.runtime.version");
    args[2] = System.getProperty("java.vm.vendor");
    args[3] = System.getProperty("os.name");
    args[4] = System.getProperty("os.version");
    args[5] = System.getProperty("os.arch");
    writer.print(MessageFormat.format(Constants.SERVER_ROW_SECTION, args));

    // HTML Tail Section
    writer.print(Constants.HTML_TAIL_SECTION);

    // Finish up the response
    writer.flush();
    writer.close();
}

From source file:org.apache.catalina.servlets.HTMLManagerServlet.java

/**
 * Render a HTML list of the currently active Contexts in our virtual host,
 * and memory and server status information.
 *
 * @param writer Writer to render to/* w w  w .j  av  a2s .  com*/
 * @param message a message to display
 */
public void list(HttpServletRequest request, HttpServletResponse response, String message) throws IOException {

    if (debug >= 1)
        log("list: Listing contexts for virtual host '" + deployer.getName() + "'");

    PrintWriter writer = response.getWriter();

    // HTML Header Section
    writer.print(HTML_HEADER_SECTION);

    // Body Header Section
    Object[] args = new Object[2];
    args[0] = request.getContextPath();
    args[1] = sm.getString("htmlManagerServlet.title");
    writer.print(MessageFormat.format(BODY_HEADER_SECTION, args));

    // Message Section
    args = new Object[3];
    args[0] = sm.getString("htmlManagerServlet.messageLabel");
    args[1] = (message == null || message.length() == 0) ? "OK" : message;
    writer.print(MessageFormat.format(MESSAGE_SECTION, args));

    // Manager Section
    args = new Object[7];
    args[0] = sm.getString("htmlManagerServlet.manager");
    args[1] = response.encodeURL(request.getContextPath() + "/html/list");
    args[2] = sm.getString("htmlManagerServlet.list");
    args[3] = response
            .encodeURL(request.getContextPath() + "/" + sm.getString("htmlManagerServlet.helpHtmlManagerFile"));
    args[4] = sm.getString("htmlManagerServlet.helpHtmlManager");
    args[5] = response
            .encodeURL(request.getContextPath() + "/" + sm.getString("htmlManagerServlet.helpManagerFile"));
    args[6] = sm.getString("htmlManagerServlet.helpManager");
    writer.print(MessageFormat.format(MANAGER_SECTION, args));

    // Apps Header Section
    args = new Object[6];
    args[0] = sm.getString("htmlManagerServlet.appsTitle");
    args[1] = sm.getString("htmlManagerServlet.appsPath");
    args[2] = sm.getString("htmlManagerServlet.appsName");
    args[3] = sm.getString("htmlManagerServlet.appsAvailable");
    args[4] = sm.getString("htmlManagerServlet.appsSessions");
    args[5] = sm.getString("htmlManagerServlet.appsTasks");
    writer.print(MessageFormat.format(APPS_HEADER_SECTION, args));

    // Apps Row Section
    // Create sorted map of deployed applications context paths.
    String contextPaths[] = deployer.findDeployedApps();

    TreeMap sortedContextPathsMap = new TreeMap();

    for (int i = 0; i < contextPaths.length; i++) {
        String displayPath = contextPaths[i];
        sortedContextPathsMap.put(displayPath, contextPaths[i]);
    }

    String appsStart = sm.getString("htmlManagerServlet.appsStart");
    String appsStop = sm.getString("htmlManagerServlet.appsStop");
    String appsReload = sm.getString("htmlManagerServlet.appsReload");
    String appsRemove = sm.getString("htmlManagerServlet.appsRemove");

    Iterator iterator = sortedContextPathsMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry entry = (Map.Entry) iterator.next();
        String displayPath = (String) entry.getKey();
        String contextPath = (String) entry.getKey();
        Context context = deployer.findDeployedApp(contextPath);
        if (displayPath.equals("")) {
            displayPath = "/";
        }

        if (context != null) {
            args = new Object[5];
            args[0] = displayPath;
            args[1] = context.getDisplayName();
            if (args[1] == null) {
                args[1] = "&nbsp;";
            }
            args[2] = new Boolean(context.getAvailable());
            args[3] = response.encodeURL(request.getContextPath() + "/html/sessions?path=" + displayPath);
            args[4] = new Integer(context.getManager().findSessions().length);
            writer.print(MessageFormat.format(APPS_ROW_DETAILS_SECTION, args));

            args = new Object[8];
            args[0] = response.encodeURL(request.getContextPath() + "/html/start?path=" + displayPath);
            args[1] = appsStart;
            args[2] = response.encodeURL(request.getContextPath() + "/html/stop?path=" + displayPath);
            args[3] = appsStop;
            args[4] = response.encodeURL(request.getContextPath() + "/html/reload?path=" + displayPath);
            args[5] = appsReload;
            args[6] = response.encodeURL(request.getContextPath() + "/html/remove?path=" + displayPath);
            args[7] = appsRemove;
            if (context.getPath().equals(this.context.getPath())) {
                writer.print(MessageFormat.format(MANAGER_APP_ROW_BUTTON_SECTION, args));
            } else if (context.getAvailable()) {
                writer.print(MessageFormat.format(STARTED_APPS_ROW_BUTTON_SECTION, args));
            } else {
                writer.print(MessageFormat.format(STOPPED_APPS_ROW_BUTTON_SECTION, args));
            }

        }
    }

    // Install Section
    args = new Object[7];
    args[0] = sm.getString("htmlManagerServlet.installTitle");
    args[1] = sm.getString("htmlManagerServlet.installServer");
    args[2] = response.encodeURL(request.getContextPath() + "/html/install");
    args[3] = sm.getString("htmlManagerServlet.installPath");
    args[4] = sm.getString("htmlManagerServlet.installConfig");
    args[5] = sm.getString("htmlManagerServlet.installWar");
    args[6] = sm.getString("htmlManagerServlet.installButton");
    writer.print(MessageFormat.format(INSTALL_SECTION, args));

    args = new Object[4];
    args[0] = sm.getString("htmlManagerServlet.installUpload");
    args[1] = response.encodeURL(request.getContextPath() + "/html/upload");
    args[2] = sm.getString("htmlManagerServlet.installUploadFile");
    args[3] = sm.getString("htmlManagerServlet.installButton");
    writer.print(MessageFormat.format(UPLOAD_SECTION, args));

    // Server Header Section
    args = new Object[7];
    args[0] = sm.getString("htmlManagerServlet.serverTitle");
    args[1] = sm.getString("htmlManagerServlet.serverVersion");
    args[2] = sm.getString("htmlManagerServlet.serverJVMVersion");
    args[3] = sm.getString("htmlManagerServlet.serverJVMVendor");
    args[4] = sm.getString("htmlManagerServlet.serverOSName");
    args[5] = sm.getString("htmlManagerServlet.serverOSVersion");
    args[6] = sm.getString("htmlManagerServlet.serverOSArch");
    writer.print(MessageFormat.format(SERVER_HEADER_SECTION, args));

    // Server Row Section
    args = new Object[6];
    args[0] = ServerInfo.getServerInfo();
    args[1] = System.getProperty("java.runtime.version");
    args[2] = System.getProperty("java.vm.vendor");
    args[3] = System.getProperty("os.name");
    args[4] = System.getProperty("os.version");
    args[5] = System.getProperty("os.arch");
    writer.print(MessageFormat.format(SERVER_ROW_SECTION, args));

    // HTML Tail Section
    writer.print(HTML_TAIL_SECTION);

    // Finish up the response
    writer.flush();
    writer.close();
}

From source file:org.wings.session.PortletSessionServlet.java

/**
 * init/*from www .  j  a va 2 s .c  o m*/
 */
public final void init(ServletConfig config, HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    try {
        // wingS-Portlet-Bridge: changed form Session to PortletSession
        session = new ExtendedSession();
        SessionManager.setSession(session);

        // set request.url in session, if used in constructor of wings main classs
        //if (request.isRequestedSessionIdValid()) {               
        // get the RenderResponse out of the request
        RenderResponse renderResponse = (RenderResponse) request
                .getAttribute(Const.REQUEST_ATTR_RENDER_RESPONSE);
        if (renderResponse == null) {
            log.error("WingS-Portlet-Bridge: cant get the request attribute "
                    + Const.REQUEST_ATTR_RENDER_RESPONSE);
        }
        PortletURL actionURL = renderResponse.createActionURL();
        // this will fire an event, if the encoding has changed ..
        session.setProperty("request.url",
                new PortletRequestURL(actionURL.toString(), response.encodeURL(actionURL.toString())));
        log.debug("WingS-Portlet-Bridge: created while init PortletRequestURL " + actionURL.toString());
        session.setProperty(Const.WINGS_SESSION_PROPERTY_RENDER_RESPONSE, renderResponse);

        // get the RenderRequest
        RenderRequest renderRequest = (RenderRequest) request.getAttribute(Const.REQUEST_ATTR_RENDER_REQUEST);
        if (renderRequest == null) {
            log.error("WingS-Portlet-Bridge: cant get the request attribute "
                    + Const.REQUEST_ATTR_RENDER_REQUEST);
        }
        session.setProperty(Const.WINGS_SESSION_PROPERTY_RENDER_REQUEST, renderRequest);

        //}

        session.init(config, request, response);

        try {
            // WingS-Portlet-Bridge: load of class for current mode
            String mainClassName = (String) request.getAttribute(Const.REQUEST_ATTR_WINGS_CLASS);
            //               String mainClassName = config.getInitParameter("wings.mainclass");
            log.info("WingS-Portlet-Bridge: loaded mainclass " + mainClassName + " for PortletSessionServlet");
            Class mainClass = null;
            try {
                mainClass = Class.forName(mainClassName, true, Thread.currentThread().getContextClassLoader());
            } catch (ClassNotFoundException e) {
                // fallback, in case the servlet container fails to set the
                // context class loader.
                mainClass = Class.forName(mainClassName);
            }
            mainClass.newInstance();
        } catch (Exception ex) {
            log.fatal("could not load wings.mainclass: " + request.getAttribute(Const.REQUEST_ATTR_WINGS_CLASS),
                    ex);
            throw new ServletException(ex);
        }
    } finally {
        // The session was set by the constructor. After init we
        // expect that only doPost/doGet is called, which set the
        // session also. So remove it here.
        SessionManager.removeSession();
    }
}

From source file:org.hdiv.web.servlet.tags.UrlTagHDIV.java

/**
 * Build the URL for the tag from the tag attributes and parameters.
 * @return the URL value as a String//  w  w  w  .j  a  v a  2 s  . c o m
 * @throws JspException
 */
private String createUrl() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
    StringBuilder url = new StringBuilder();
    if (this.type == UrlType.CONTEXT_RELATIVE) {
        // add application context to url
        if (this.context == null) {
            url.append(request.getContextPath());
        } else {
            url.append(this.context);
        }
    }
    if (this.type != UrlType.RELATIVE && this.type != UrlType.ABSOLUTE && !this.value.startsWith("/")) {
        url.append("/");
    }
    url.append(replaceUriTemplateParams(this.value, this.params, this.templateParams));
    url.append(createQueryString(this.params, this.templateParams, (url.indexOf("?") == -1)));

    String urlStr = url.toString();

    urlStr = HDIVRequestUtils.composeLinkUrl(urlStr, request);

    //      HDIVConfig hdivConfig = (HDIVConfig) HDIVUtil.getHDIVConfig(pageContext.getServletContext());
    //      
    //      if (!HDIVRequestUtils.hasExtensionToExclude(urlStr, hdivConfig.getExcludedURLExtensions()))
    //      {
    //         if (HDIVRequestUtils.hasActionOrServletExtension(urlStr, hdivConfig.getProtectedURLPatterns())) {
    //            urlStr = HDIVRequestUtils.addHDIVParameterIfNecessary((HttpServletRequest) pageContext.getRequest(), 
    //                  urlStr, hdivConfig.isValidationInUrlsWithoutParamsActivated());
    //         }
    //      }

    if (this.type != UrlType.ABSOLUTE) {
        // Add the session identifier if needed
        // (Do not embed the session identifier in a remote link!)
        urlStr = response.encodeURL(urlStr);
    }

    // HTML and/or JavaScript escape, if demanded.
    urlStr = isHtmlEscape() ? HtmlUtils.htmlEscape(urlStr) : urlStr;
    urlStr = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(urlStr) : urlStr;

    return urlStr;
}

From source file:jp.terasoluna.fw.web.struts.taglib.PageLinksTag.java

/**
 * Oy?[WJN?StringBuilder?B/*from  ww w  .  ja v a 2 s  .  com*/
 * 
 * @param sb ?StringBuilder
 * @param row \?s?
 * @param startIndex \JnCfbNX
 * @param totalCount ?S??
 */
protected void addPrevLink(StringBuilder sb, int row, int startIndex, int totalCount) {

    //TagUtilsCX^X??
    TagUtils tagUtils = TagUtils.getInstance();

    // X|Xp??[^
    HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

    //ANVURL
    String url = null;
    url = response.encodeURL(tagUtils.getActionMappingURL(action, pageContext));

    //Oy?[WN??
    for (int i = maxLinkNo; i > 0; i--) {
        String linkKey = PREV_LINKS + i + CHAR_LINKS;
        String linkValue = links.get(linkKey);

        if (linkValue == null || "".equals(linkValue)) {
            continue;
        }

        int index = startIndex - (i * row);
        if (index < 0) {
            sb.append(linkValue + "&nbsp;");
        } else {
            sb.append("<a href=\"" + url);
            if (url.indexOf("?") < 0) {
                sb.append("?");
            } else {
                sb.append("&");
            }
            sb.append(rowProperty);
            sb.append("=");
            sb.append(row);
            sb.append("&");
            sb.append(indexProperty);
            sb.append("=");
            sb.append(index);
            sb.append("\">");
            sb.append(linkValue);
            sb.append("</a>&nbsp;");
        }
    }
}

From source file:jp.terasoluna.fw.web.struts.taglib.PageLinksTag.java

/**
 * y?[WJN?StringBuilder?B//from   w ww. ja va  2  s  .c om
 * 
 * @param sb ?StringBuilder
 * @param row \?s?
 * @param startIndex \JnCfbNX
 * @param totalCount ?S??
 */
protected void addNextLink(StringBuilder sb, int row, int startIndex, int totalCount) {

    //TagUtilsCX^X??
    TagUtils tagUtils = TagUtils.getInstance();

    // X|Xp??[^
    HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

    //ANVURL
    String url = null;
    url = response.encodeURL(tagUtils.getActionMappingURL(action, pageContext));

    //y?[WN??
    for (int i = 1; i <= maxLinkNo; i++) {
        String linkKey = NEXT_LINKS + i + CHAR_LINKS;
        String linkValue = links.get(linkKey);

        if (linkValue == null || "".equals(linkValue)) {
            continue;
        }

        int index = startIndex + (i * row);
        if (index > (totalCount - 1)) {
            sb.append(linkValue + "&nbsp;");
        } else {

            sb.append("<a href=\"" + url);
            if (url.indexOf("?") < 0) {
                sb.append("?");
            } else {
                sb.append("&");
            }
            sb.append(rowProperty);
            sb.append("=");
            sb.append(row);
            sb.append("&");
            sb.append(indexProperty);
            sb.append("=");
            sb.append(index);
            sb.append("\">");
            sb.append(linkValue);
            sb.append("</a>&nbsp;");
        }
    }
}

From source file:org.wings.session.PortletWingServlet.java

private final PortletSessionServlet newSession(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    long timestamp = System.currentTimeMillis();
    try {/* w  ww.  j ava2  s .  c  o m*/
        log.debug("--- new SessionServlet()");

        PortletSessionServlet sessionServlet = new PortletSessionServlet();
        sessionServlet.init(servletConfig, request, response);

        Session session = sessionServlet.getSession();
        /* the request URL is needed already in the setup-phase. Note,
         * that at this point, the URL will always be encoded, since
         * we (or better: the servlet engine) does not know yet, if setting
         * a cookie will be successful (it has to await the response).
         * Subsequent requests might decide, _not_ to encode the sessionid
         * in the URL (see SessionServlet::doGet())                   -hen
         */

        // change for WingS-Portlet-Bridge: get the PortletURL out of the request
        RenderResponse renderResponse = (RenderResponse) request
                .getAttribute(Const.REQUEST_ATTR_RENDER_RESPONSE);

        if (renderResponse == null) {
            log.error("WingS-Portlet-Bridge: cant get actionURL because " + "the request attribute "
                    + Const.REQUEST_ATTR_RENDER_RESPONSE + " is null!");
        }

        PortletURL actionURL = renderResponse.createActionURL();
        PortletRequestURL portletRequestURL = new PortletRequestURL(actionURL.toString(),
                response.encodeURL(actionURL.toString()));
        log.debug("WingS-Portlet-Bridge: created PortletRequestURL " + actionURL.toString());

        session.setProperty("request.url", portletRequestURL);

        sessionServlet.setParent(this);

        log.debug("--- Time needed to create new session " + (System.currentTimeMillis() - timestamp) + "ms");

        return sessionServlet;
    } catch (Exception e) {
        log.fatal("Error on creating new wingS session", e);
        throw new ServletException(e);
    }
}