Package org.apache.myfaces.renderkit.html.util

Examples of org.apache.myfaces.renderkit.html.util.AddResource


     */
    private void encodeJavascript(FacesContext context, UIComponent component) throws IOException
    {
        // render javascript function for client-side toggle (it won't be used if user has opted for server-side toggle)
        String javascriptLocation = ((HtmlTree)component).getJavascriptLocation();
        AddResource addResource = AddResourceFactory.getInstance(context);
        if (javascriptLocation == null)
        {
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, HtmlTreeRenderer.class, "javascript/tree.js");
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, HtmlTreeRenderer.class, "javascript/cookielib.js");
        }
        else
        {
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, javascriptLocation + "/tree.js");
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, javascriptLocation + "/cookielib.js");
        }
    }
View Full Code Here


     * @return The image src information.
     */
    private String getImageSrc(FacesContext context, UIComponent component, String imageName, boolean withContextPath)
    {
        String imageLocation = ((HtmlTree)component).getImageLocation();
        AddResource addResource = AddResourceFactory.getInstance(context);
        if (imageLocation == null)
        {
            return addResource.getResourceUri(context, HtmlTreeRenderer.class,
                                              "images/" + imageName, withContextPath);
        }
        else
        {
            return addResource.getResourceUri(context, imageLocation + "/" + imageName, withContextPath);
        }
    }
View Full Code Here

        }
    }

    public String getDefaultImagePath(FacesContext context, String relativePathInResourceFolder)
    {
        AddResource instance = AddResourceFactory.getInstance(context);
        return instance.getResourceUri(context, HtmlTree.class, relativePathInResourceFolder, false);
    }
View Full Code Here

        }
    }

    protected String getImageUrl(FacesContext context, String userValue, String resourceValue)
    {
        AddResource addResource = AddResourceFactory.getInstance(context);
        if(userValue != null)
        {
            return addResource.getResourceUri(context, userValue, false);
        }
        return addResource.getResourceUri(context, HtmlTree.class, resourceValue, false);
    }
View Full Code Here

                extendedRequest = new PortletMultipartRequestWrapper( portletRequest, config.getUploadMaxFileSize(),
                        config.getUploadThresholdSize(), config.getUploadRepositoryPath(),
                        config.getUploadMaxSize(), config.isCacheFileSizeErrors());
            }
           
            AddResource addResource= AddResourceFactory.getInstance(this);
           
            if (addResource instanceof AddResource2)
            {
                ((AddResource2)addResource).responseStarted(delegate.getExternalContext().getContext(), extendedRequest);
            }
            else
            {
                addResource.responseStarted();
            }

            if (addResource.requiresBuffer())
            {
                throw new IllegalStateException("buffering not supported in the portal environment. "+
                        " Use for org.apache.myfaces.ADD_RESOURCE_CLASS the value"+
                        " org.apache.myfaces.renderkit.html.util.NonBufferingAddResource.");
            }
           
            externalContextDelegate = new PortletExternalContextWrapper(
                    delegate.getExternalContext(), extendedRequest, extendedResponse, multipartContent);
        }
        else {
            HttpServletResponse httpResponse = (HttpServletResponse) delegate.getExternalContext().getResponse();
            HttpServletRequest httpRequest = (HttpServletRequest) delegate.getExternalContext().getRequest();

            HttpServletRequest extendedRequest = httpRequest;

            // For multipart/form-data requests we need to encapsulate
            // the request using MultipartRequestWrapper. This could not be
            // done on TomahawkFacesContextFactory.getFacesContext(...)
            // because we need an ExternalContext instance to get
            // the init params for the ExtensionsFilter and initialize
            // MultipartRequestWrapper with the correct values.
           
            boolean multipartContent = false;
          
            if (ServletFileUpload.isMultipartContent(httpRequest)) {
                multipartContent = true;
               
                MultipartRequestWrapperConfig config = MultipartRequestWrapperConfig
                        .getMultipartRequestWrapperConfig(delegate
                                .getExternalContext());               
               
                extendedRequest = new MultipartRequestWrapper(httpRequest, config.getUploadMaxFileSize(),
                        config.getUploadThresholdSize(), config.getUploadRepositoryPath(),
                        config.getUploadMaxSize(), config.isCacheFileSizeErrors());
               
            }

            AddResource addResource= AddResourceFactory.getInstance(this);
           
            if (addResource instanceof AddResource2)
            {
                ((AddResource2)addResource).responseStarted(delegate.getExternalContext().getContext(), extendedRequest);
            }
            else
            {
                addResource.responseStarted();
            }

            if (addResource.requiresBuffer() && extensionsResponseWrapper != null)
            {
                //If the request requires buffer, this was already
                //wrapped (on TomahawkFacesContextFactory.getFacesContext(...) ),
                //but we need to save the wrapped response value
                //on a local variable to then reference it on release()
View Full Code Here

        delegate.addMessage(clientId, message);
    }

    public void release() {

        AddResource addResource=null;

        try
        {
            addResource= AddResourceFactory.getInstance(this);
            if (addResource.requiresBuffer())
            {
                if(extensionsResponseWrapper == null) {
                    throw new NullPointerException("When wrapping the faces-context, add-resource told us that no buffer is required, " +
                            "now it is required, and we have a null-extensionsResponseWrapper. Please fix add-resource to be consistent over a single request.");
                }
                extensionsResponseWrapper.finishResponse();

                // write the javascript stuff for myfaces and headerInfo, if needed
                HttpServletResponse servletResponse = extensionsResponseWrapper.getDelegate();
                HttpServletRequest servletRequest = (HttpServletRequest) getExternalContext().getRequest();

                String contentType = extensionsResponseWrapper.getContentType();
               
                // only parse HTML responses
                if (contentType != null && isValidContentType(contentType))
                {
                    String oldResponse = extensionsResponseWrapper.toString();
                    addResource.parseResponse(servletRequest, extensionsResponseWrapper.toString(),
                            servletResponse);

                    addResource.writeMyFacesJavascriptBeforeBodyEnd(servletRequest,
                            servletResponse);

                    if( ! addResource.hasHeaderBeginInfos() ){
                        // writes the response if no header info is needed
                        addResource.writeResponse(servletRequest, servletResponse);
                        return;
                    }

                    // Some headerInfo has to be added
                    addResource.writeWithFullHeader(servletRequest, servletResponse);

                    // writes the response
                    addResource.writeResponse(servletRequest, servletResponse);
                }
                else
                {

                    byte[] responseArray = extensionsResponseWrapper.getBytes();

                    if(responseArray.length > 0)
                    {
                         // When not filtering due to not valid content-type, deliver the byte-array instead of a charset-converted string.
                         // Otherwise a binary stream gets corrupted.
                         servletResponse.getOutputStream().write(responseArray);
                     }
                }
            }
        }
        catch(Throwable th) {
            throw new FacesException(th);
        }
        finally
        {
            try
            {
                if(addResource!=null)
                {
                    addResource.responseFinished();
                }
            }
            finally
            {
                delegate.release();
View Full Code Here

    private void addResourcesToHeader(String themeName, HtmlCommandJSCookMenu menu, FacesContext context) {
        String javascriptLocation = (String) menu.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
        String imageLocation = (String) menu.getAttributes().get(JSFAttr.IMAGE_LOCATION);
        String styleLocation = (String) menu.getAttributes().get(JSFAttr.STYLE_LOCATION);

        AddResource addResource = AddResourceFactory.getInstance(context);

        if (javascriptLocation != null) {
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, javascriptLocation + "/" + JSCOOK_MENU_SCRIPT);
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, javascriptLocation + "/" + JSCOOK_EFFECT_SCRIPT);           
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, javascriptLocation + "/" + MYFACES_HACK_SCRIPT);
        }
        else {
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, HtmlJSCookMenuRenderer.class, JSCOOK_MENU_SCRIPT);
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, HtmlJSCookMenuRenderer.class, JSCOOK_EFFECT_SCRIPT);           
            addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, HtmlJSCookMenuRenderer.class, MYFACES_HACK_SCRIPT);
        }

        addThemeSpecificResources(themeName, styleLocation, javascriptLocation, imageLocation, context);
    }
View Full Code Here

        String themeLocation = (String) builtInThemes.get(themeName);
        if (themeLocation == null) {
            log.debug("Unknown theme name '" + themeName + "' specified.");
        }

        AddResource addResource = AddResourceFactory.getInstance(context);

        if ((imageLocation != null) || (themeLocation != null)) {
            // Generate a javascript variable containing a reference to the
            // directory containing theme image files, for use by the theme
            // javascript file. If neither of these is defined (ie a custom
            // theme was specified but no imageLocation) then presumably the
            // theme.js file uses some other mechanism to determine where
            // its image files are.
            StringBuffer buf = new StringBuffer();
            buf.append("var my");
            buf.append(themeName);
            buf.append("Base='");
            ExternalContext externalContext = context.getExternalContext();
            if (imageLocation != null) {
                buf.append(externalContext.encodeResourceURL(addResource.getResourceUri(context,
                                                                                        imageLocation + "/" + themeName)));
            }
            else {
                buf.append(externalContext.encodeResourceURL(addResource.getResourceUri(context,
                                                                                        HtmlJSCookMenuRenderer.class, themeLocation)));
            }
            buf.append("';");
            addResource.addInlineScriptAtPosition(context, AddResource.HEADER_BEGIN, buf.toString());
        }


        if ((javascriptLocation != null) || (themeLocation != null)) {
            // Generate a <script> tag in the page header pointing to the
            // theme.js file for this theme. If neither of these is defined
            // then presumably the theme.js file is referenced by a <script>
            // tag hard-wired into the page or inserted via some other means.
            if (javascriptLocation != null) {
                // For now, assume that if the user specified a location for a custom
                // version of the jscookMenu.js file then the theme.js file can be found
                // in the same location.
                addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, javascriptLocation + "/" + themeName
                    + "/theme.js");
            }
            else {
                // Using a built-in theme, so we know where the theme.js file is.
                addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, HtmlJSCookMenuRenderer.class, themeName
                    + "/theme.js");
            }
        }

        if ((styleLocation != null) || (themeLocation != null)) {
            // Generate a <link type="text/css"> tag in the page header pointing to
            // the theme stylesheet. If neither of these is defined then presumably
            // the stylesheet is referenced by a <link> tag hard-wired into the page
            // or inserted via some other means.
            if (styleLocation != null) {
                addResource.addStyleSheet(context, AddResource.HEADER_BEGIN, styleLocation + "/" + themeName + "/theme.css");
            }
            else {
                addResource.addStyleSheet(context, AddResource.HEADER_BEGIN, HtmlJSCookMenuRenderer.class, themeName
                    + "/theme.css");
            }
        }
    }
View Full Code Here

        HttpServletResponse httpResponse = (HttpServletResponse) response;
        HttpServletRequest httpRequest = (HttpServletRequest) request;

        // Serve resources
        AddResource addResource;

        try
        {
            addResource = AddResourceFactory.getInstance(httpRequest,_servletContext);
            if( addResource.isResourceUri(_servletContext, httpRequest ) ){
                addResource.serveResource(_servletContext, httpRequest, httpResponse);
                return;
            }
        }
        catch(Throwable th)
        {
            log.error("Exception wile retrieving addResource",th);
            throw new ServletException(th);
        }

        HttpServletRequest extendedRequest = httpRequest;

        // For multipart/form-data requests
        // This is done by TomahawkFacesContextWrapper
        if (ServletFileUpload.isMultipartContent(httpRequest)) {
            extendedRequest = new MultipartRequestWrapper(httpRequest, _uploadMaxFileSize,
                    _uploadThresholdSize, _uploadRepositoryPath, _uploadMaxSize, _cacheFileSizeErrors);
        }
       
        try
        {
            if (addResource instanceof AddResource2)
            {
                ((AddResource2)addResource).responseStarted(_servletContext, extendedRequest);
            }
            else
            {
                addResource.responseStarted();
            }
           
            //This case is necessary when is used           
            //org.apache.myfaces.renderkit.html.util.DefaultAddResource
            //Buffers the output and add to the header the necessary stuff
            //In other case this is simply ignored (NonBufferingAddResource and
            //StreamingAddResource), because this not require buffering
            //and the chaining continues.
            if (addResource.requiresBuffer())
            {
                ExtensionsResponseWrapper extendedResponse = new ExtensionsResponseWrapper((HttpServletResponse) response);
       
                // Standard request
                chain.doFilter(extendedRequest, extendedResponse);
       
                extendedResponse.finishResponse();
       
                // write the javascript stuff for myfaces and headerInfo, if needed
                HttpServletResponse servletResponse = (HttpServletResponse)response;
       
                // only parse HTML responses
                if (extendedResponse.getContentType() != null && isValidContentType(extendedResponse.getContentType()))
                {
                    addResource.parseResponse(extendedRequest, extendedResponse.toString(),
                            servletResponse);
       
                    addResource.writeMyFacesJavascriptBeforeBodyEnd(extendedRequest,
                            servletResponse);
       
                    if( ! addResource.hasHeaderBeginInfos() ){
                        // writes the response if no header info is needed
                        addResource.writeResponse(extendedRequest, servletResponse);
                        return;
                    }
       
                    // Some headerInfo has to be added
                    addResource.writeWithFullHeader(extendedRequest, servletResponse);
       
                    // writes the response
                    addResource.writeResponse(extendedRequest, servletResponse);
                }
                else
                {

                    byte[] responseArray = extendedResponse.getBytes();

                    if(responseArray.length > 0)
                    {
                        // When not filtering due to not valid content-type, deliver the byte-array instead of a charset-converted string.
                        // Otherwise a binary stream gets corrupted.
                        servletResponse.getOutputStream().write(responseArray);
                    }
                }
            }
            else
            {
                chain.doFilter(extendedRequest, response);
            }
        }
        finally
        {
            addResource.responseFinished();        
        }
       
        //chain.doFilter(extendedRequest, response);
    }
View Full Code Here

            if (log.isWarnEnabled()) log.warn("PanelNavaigationMenu without children.");
        }
    }

    private void addResourcesToHeader(FacesContext context) {
        AddResource addResource = AddResourceFactory.getInstance(context);
        addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN, HtmlPanelNavigationMenu.class, HORIZ_MENU_SCRIPT);
    }
View Full Code Here

TOP

Related Classes of org.apache.myfaces.renderkit.html.util.AddResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.