All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.icefaces.impl.context.ICEfacesContext Maven / Gradle / Ivy

There is a newer version: 4.3.0
Show newest version
package org.icefaces.impl.context;

import org.icefaces.util.EnvUtils;

import javax.faces.application.ResourceHandler;
import javax.faces.context.ExternalContext;
import javax.faces.context.ExternalContextWrapper;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextWrapper;
import java.net.URI;

public class ICEfacesContext extends FacesContextWrapper {
    private FacesContext wrapped;

    public ICEfacesContext(FacesContext wrapped) {
        this.wrapped = wrapped;
    }

    public FacesContext getWrapped() {
        return wrapped;
    }

    public ExternalContext getExternalContext() {
        return new ICEfacesExternalContext(wrapped.getExternalContext());
    }

    public static class ICEfacesExternalContext extends ExternalContextWrapper {
        private ExternalContext wrapped;

        public ICEfacesExternalContext(ExternalContext wrapped) {
            this.wrapped = wrapped;
        }

        public ExternalContext getWrapped() {
            return wrapped;
        }

        public String encodeResourceURL(String url) {
            if (EnvUtils.instanceofPortletRequest(wrapped.getRequest())) {
                return wrapped.encodeResourceURL(url);
            }
            //the following tests should not be necessary since the encodeResourceURL should be used only to encode
            //resource URLs, unfortunately Mojarra's OutputLinkRenderer uses this method for encoding the hyperlink URLs
            if (url.contains(ResourceHandler.RESOURCE_IDENTIFIER)) {
                return url;
            }
            String mimeType = wrapped.getMimeType(url);
            if (mimeType != null && (
                    mimeType.startsWith("image/") ||
                            mimeType.startsWith("video/") ||
                            mimeType.startsWith("audio/") ||
                            mimeType.equals("text/css") ||
                            mimeType.equals("text/javascript"))) {
                return url;
            }

            return wrapped.encodeResourceURL(url);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy