You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by st...@apache.org on 2011/10/20 12:49:36 UTC
svn commit: r1186730 [13/22] - in /myfaces/commons/branches/jsf_20: examples/
examples/myfaces-commons-examples/src/main/java/org/apache/myfaces/commons/examples/
examples/myfaces-commons-examples/src/main/java/org/apache/myfaces/commons/examples/acces...
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceLoaderWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceLoaderWrapper.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceLoaderWrapper.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceLoaderWrapper.java Thu Oct 20 10:49:18 2011
@@ -1,55 +1,55 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler;
-
-import org.apache.myfaces.commons.resourcehandler.resource.ResourceLoader;
-import org.apache.myfaces.commons.resourcehandler.resource.ResourceLoaderWrapper;
-import org.apache.myfaces.commons.resourcehandler.resource.ResourceMeta;
-
-/**
- * Resource Loader that just wraps ResourceMetaImpl into ExtendedResourceMetaImpl,
- * to allow cache request path expressions.
- *
- * @author Leonardo Uribe
- *
- */
-public class ExtendedResourceLoaderWrapper extends ResourceLoaderWrapper
-{
- private ResourceLoader _delegate;
-
- public ExtendedResourceLoaderWrapper(ResourceLoader delegate)
- {
- this._delegate = delegate;
- }
-
- @Override
- public ResourceMeta createResourceMeta(String prefix, String libraryName,
- String libraryVersion, String resourceName, String resourceVersion)
- {
- return new ExtendedResourceMetaImpl(
- super.createResourceMeta(prefix, libraryName, libraryVersion,
- resourceName, resourceVersion));
- }
-
- public ResourceLoader getWrapped()
- {
- return _delegate;
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler;
+
+import org.apache.myfaces.commons.resourcehandler.resource.ResourceLoader;
+import org.apache.myfaces.commons.resourcehandler.resource.ResourceLoaderWrapper;
+import org.apache.myfaces.commons.resourcehandler.resource.ResourceMeta;
+
+/**
+ * Resource Loader that just wraps ResourceMetaImpl into ExtendedResourceMetaImpl,
+ * to allow cache request path expressions.
+ *
+ * @author Leonardo Uribe
+ *
+ */
+public class ExtendedResourceLoaderWrapper extends ResourceLoaderWrapper
+{
+ private ResourceLoader _delegate;
+
+ public ExtendedResourceLoaderWrapper(ResourceLoader delegate)
+ {
+ this._delegate = delegate;
+ }
+
+ @Override
+ public ResourceMeta createResourceMeta(String prefix, String libraryName,
+ String libraryVersion, String resourceName, String resourceVersion)
+ {
+ return new ExtendedResourceMetaImpl(
+ super.createResourceMeta(prefix, libraryName, libraryVersion,
+ resourceName, resourceVersion));
+ }
+
+ public ResourceLoader getWrapped()
+ {
+ return _delegate;
+ }
+
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceLoaderWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMeta.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMeta.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMeta.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMeta.java Thu Oct 20 10:49:18 2011
@@ -1,37 +1,37 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler;
-
-import javax.el.ValueExpression;
-
-import org.apache.myfaces.commons.resourcehandler.resource.ResourceMeta;
-
-/**
- * This abstract class extends from default ResourceMeta to allow cache request path expressions on
- * the resource cache and reuse it across requests.
- *
- * @author Leonardo Uribe
- *
- */
-public abstract class ExtendedResourceMeta extends ResourceMeta
-{
- public abstract ValueExpression getRequestPathExpression();
-
- public abstract void setRequestPathExpression(ValueExpression expression);
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler;
+
+import javax.el.ValueExpression;
+
+import org.apache.myfaces.commons.resourcehandler.resource.ResourceMeta;
+
+/**
+ * This abstract class extends from default ResourceMeta to allow cache request path expressions on
+ * the resource cache and reuse it across requests.
+ *
+ * @author Leonardo Uribe
+ *
+ */
+public abstract class ExtendedResourceMeta extends ResourceMeta
+{
+ public abstract ValueExpression getRequestPathExpression();
+
+ public abstract void setRequestPathExpression(ValueExpression expression);
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMeta.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMetaImpl.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMetaImpl.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMetaImpl.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMetaImpl.java Thu Oct 20 10:49:18 2011
@@ -1,99 +1,99 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler;
-
-import javax.el.ValueExpression;
-import javax.faces.FacesWrapper;
-
-import org.apache.myfaces.commons.resourcehandler.resource.ResourceMeta;
-
-/**
- * This class extends from ExtendedResourceMeta to allow cache request path expressions on
- * the resource cache and reuse it across requests.
- *
- * @author Leonardo Uribe
- *
- */
-public class ExtendedResourceMetaImpl extends ExtendedResourceMeta implements FacesWrapper<ResourceMeta>
-{
- private ResourceMeta _delegate;
- private ValueExpression _requestPath;
-
- public ExtendedResourceMetaImpl(ResourceMeta delegate)
- {
- _delegate = delegate;
- }
-
- public ValueExpression getRequestPathExpression()
- {
- return _requestPath;
- }
-
- public void setRequestPathExpression(ValueExpression expression)
- {
- _requestPath = expression;
- }
-
- @Override
- public String getLibraryName()
- {
- return getWrapped().getLibraryName();
- }
-
- @Override
- public String getResourceName()
- {
- return getWrapped().getResourceName();
- }
-
- @Override
- public String getLocalePrefix()
- {
- return getWrapped().getLocalePrefix();
- }
-
- @Override
- public String getLibraryVersion()
- {
- return getWrapped().getLibraryVersion();
- }
-
- @Override
- public String getResourceVersion()
- {
- return getWrapped().getResourceVersion();
- }
-
- @Override
- public String getResourceIdentifier()
- {
- return getWrapped().getResourceIdentifier();
- }
-
- @Override
- public boolean couldResourceContainValueExpressions()
- {
- return getWrapped().couldResourceContainValueExpressions();
- }
-
- public ResourceMeta getWrapped()
- {
- return _delegate;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler;
+
+import javax.el.ValueExpression;
+import javax.faces.FacesWrapper;
+
+import org.apache.myfaces.commons.resourcehandler.resource.ResourceMeta;
+
+/**
+ * This class extends from ExtendedResourceMeta to allow cache request path expressions on
+ * the resource cache and reuse it across requests.
+ *
+ * @author Leonardo Uribe
+ *
+ */
+public class ExtendedResourceMetaImpl extends ExtendedResourceMeta implements FacesWrapper<ResourceMeta>
+{
+ private ResourceMeta _delegate;
+ private ValueExpression _requestPath;
+
+ public ExtendedResourceMetaImpl(ResourceMeta delegate)
+ {
+ _delegate = delegate;
+ }
+
+ public ValueExpression getRequestPathExpression()
+ {
+ return _requestPath;
+ }
+
+ public void setRequestPathExpression(ValueExpression expression)
+ {
+ _requestPath = expression;
+ }
+
+ @Override
+ public String getLibraryName()
+ {
+ return getWrapped().getLibraryName();
+ }
+
+ @Override
+ public String getResourceName()
+ {
+ return getWrapped().getResourceName();
+ }
+
+ @Override
+ public String getLocalePrefix()
+ {
+ return getWrapped().getLocalePrefix();
+ }
+
+ @Override
+ public String getLibraryVersion()
+ {
+ return getWrapped().getLibraryVersion();
+ }
+
+ @Override
+ public String getResourceVersion()
+ {
+ return getWrapped().getResourceVersion();
+ }
+
+ @Override
+ public String getResourceIdentifier()
+ {
+ return getWrapped().getResourceIdentifier();
+ }
+
+ @Override
+ public boolean couldResourceContainValueExpressions()
+ {
+ return getWrapped().couldResourceContainValueExpressions();
+ }
+
+ public ResourceMeta getWrapped()
+ {
+ return _delegate;
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ExtendedResourceMetaImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/GZIPResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/GZIPResourceLoader.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/GZIPResourceLoader.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/GZIPResourceLoader.java Thu Oct 20 10:49:18 2011
@@ -1,348 +1,348 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.zip.GZIPOutputStream;
-
-import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
-
-import org.apache.myfaces.commons.resourcehandler.resource.ResourceLoader;
-import org.apache.myfaces.commons.resourcehandler.resource.ResourceLoaderWrapper;
-import org.apache.myfaces.commons.resourcehandler.resource.ResourceMeta;
-import org.apache.myfaces.commons.resourcehandler.resource.ValueExpressionFilterInputStream;
-
-/**
- *
- * @author Leonardo Uribe
- * @author Jakob Korherr
- *
- */
-public class GZIPResourceLoader extends ResourceLoaderWrapper
-{
-
- public final static String COMPRESSED_FILES_MAP = "oam.commons.COMPRESSED_FILES_MAP";
-
- /**
- * Subdir of the ServletContext tmp dir to store compressed resources.
- */
- private static final String COMPRESSION_BASE_DIR = "oam-resourcehandler-cache/";
-
- /**
- * Suffix for compressed files.
- */
- private static final String COMPRESSED_FILE_SUFFIX = ".gzip";
-
- /**
- * Size of the byte array buffer.
- */
- private static final int BUFFER_SIZE = 2048;
-
- private ResourceLoader delegate;
-
- private volatile File _tempDir;
-
- private final ExtendedDefaultResourceHandlerSupport _extendedDefaultResourceHandlerSupport;
-
- public GZIPResourceLoader(ResourceLoader delegate, ExtendedDefaultResourceHandlerSupport extendedDefaultResourceHandlerSupport)
- {
- this.delegate = delegate;
- _extendedDefaultResourceHandlerSupport = extendedDefaultResourceHandlerSupport;
- initialize();
- }
-
- protected void initialize()
- {
- //Get startup FacesContext
- FacesContext facesContext = FacesContext.getCurrentInstance();
-
- //1. Create temporal directory for compressed resources
- Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();
- File tempdir = (File) applicationMap.get("javax.servlet.context.tempdir");
- File imagesDir = new File(tempdir, COMPRESSION_BASE_DIR);
- if (!imagesDir.exists())
- {
- imagesDir.mkdirs();
- }
- else
- {
- //Clear the cache
- deleteDir(imagesDir);
- imagesDir.mkdirs();
- }
- _tempDir = imagesDir;
-
- //2. Create map for register compressed resources
- Map<String, FileProducer> compressedFilesMap = new ConcurrentHashMap<String, FileProducer>();
- facesContext.getExternalContext().getApplicationMap().put(COMPRESSED_FILES_MAP, compressedFilesMap);
- }
-
- private static boolean deleteDir(File dir)
- {
- if (dir.isDirectory())
- {
- String[] children = dir.list();
- for (int i = 0; i < children.length; i++)
- {
- boolean success = deleteDir(new File(dir, children[i]));
- if (!success)
- {
- return false;
- }
- }
- }
- return dir.delete();
- }
-
- @Override
- public URL getResourceURL(ResourceMeta resourceMeta)
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
-
- if (!_extendedDefaultResourceHandlerSupport.isCompressable(resourceMeta) || !_extendedDefaultResourceHandlerSupport.userAgentSupportsCompression(facesContext))
- {
- return super.getResourceURL(resourceMeta);
- }
-
- if (resourceExists(resourceMeta))
- {
- File file = createOrGetCompressedFile(facesContext, resourceMeta);
-
- try
- {
- return file.toURL();
- }
- catch (MalformedURLException e)
- {
- throw new FacesException(e);
- }
- }
- else
- {
- return null;
- }
- }
-
- @Override
- public InputStream getResourceInputStream(ResourceMeta resourceMeta)
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
-
- if (!_extendedDefaultResourceHandlerSupport.isCompressable(resourceMeta) || !_extendedDefaultResourceHandlerSupport.userAgentSupportsCompression(facesContext))
- {
- return super.getResourceInputStream(resourceMeta);
- }
-
- if (resourceExists(resourceMeta))
- {
- File file = createOrGetCompressedFile(facesContext, resourceMeta);
-
- try
- {
- return new BufferedInputStream(new FileInputStream(file));
- }
- catch (FileNotFoundException e)
- {
- throw new FacesException(e);
- }
- }
- else
- {
- return null;
- }
- }
-
- @Override
- public boolean resourceExists(ResourceMeta resourceMeta)
- {
- return super.resourceExists(resourceMeta);
- }
-
- @SuppressWarnings("unchecked")
- private File createOrGetCompressedFile(FacesContext facesContext, ResourceMeta resourceMeta)
- {
- String identifier = resourceMeta.getResourceIdentifier();
- File file = getCompressedFile(resourceMeta);
- if (!file.exists())
- {
- Map<String, FileProducer> map = (Map<String, FileProducer>)
- facesContext.getExternalContext().getApplicationMap().get(COMPRESSED_FILES_MAP);
-
- FileProducer creator = map.get(identifier);
-
- if (creator == null)
- {
- synchronized(this)
- {
- creator = map.get(identifier);
-
- if (creator == null)
- {
- creator = new FileProducer();
- map.put(identifier, creator);
- }
- }
- }
-
- if (!creator.isCreated())
- {
- creator.createFile(facesContext, resourceMeta, file, this);
- }
- }
- return file;
- }
-
- private File getCompressedFile(ResourceMeta resourceMeta)
- {
- return new File(_tempDir, resourceMeta.getResourceIdentifier() + COMPRESSED_FILE_SUFFIX);
- }
-
- private boolean couldResourceContainValueExpressions(ResourceMeta resourceMeta)
- {
- return resourceMeta.couldResourceContainValueExpressions() || resourceMeta.getResourceName().endsWith(".css");
- }
-
-
- /**
- * Uses GZIPOutputStream to compress this resource.
- * It will be stored where getCompressedFile() points to.
- *
- * Note that the resource really must be compressable (isCompressable() must return true).
- *
- * @return
- */
- protected void createCompressedFileVersion(FacesContext facesContext, ResourceMeta resourceMeta, File target)
- {
- //File target = getCompressedFile(resourceMeta);
- target.mkdirs(); // ensure necessary directories exist
- target.delete(); // remove any existing file
-
- InputStream inputStream = null;
- FileOutputStream fileOutputStream;
- GZIPOutputStream gzipOutputStream = null;
- try
- {
- if (couldResourceContainValueExpressions(resourceMeta))
- {
- inputStream = new ValueExpressionFilterInputStream(
- getWrapped().getResourceInputStream(resourceMeta),
- resourceMeta.getLibraryName(),
- resourceMeta.getResourceName());
- }
- else
- {
- inputStream = getWrapped().getResourceInputStream(resourceMeta);
- }
- fileOutputStream = new FileOutputStream(target);
- gzipOutputStream = new GZIPOutputStream(fileOutputStream);
- byte[] buffer = new byte[BUFFER_SIZE];
-
- pipeBytes(inputStream, gzipOutputStream, buffer);
- }
- catch (FileNotFoundException e)
- {
- throw new FacesException("Unexpected exception while create file:", e);
- }
- catch (IOException e)
- {
- throw new FacesException("Unexpected exception while create file:", e);
- }
- finally
- {
- if (inputStream != null)
- {
- try
- {
- inputStream.close();
- }
- catch (IOException e)
- {
- // Ignore
- }
- }
- if (gzipOutputStream != null)
- {
- // also closes fileOutputStream
- try
- {
- gzipOutputStream.close();
- }
- catch (IOException e)
- {
- // Ignore
- }
- }
- }
- }
-
- /**
- * Reads the specified input stream into the provided byte array storage and
- * writes it to the output stream.
- */
- private static void pipeBytes(InputStream in, OutputStream out, byte[] buffer) throws IOException
- {
- int length;
-
- while ((length = (in.read(buffer))) >= 0)
- {
- out.write(buffer, 0, length);
- }
- }
-
- public static class FileProducer {
-
- public volatile boolean created = false;
-
- public FileProducer()
- {
- super();
- }
-
- public boolean isCreated()
- {
- return created;
- }
-
- public synchronized void createFile(FacesContext facesContext, ResourceMeta resourceMeta, File file, GZIPResourceLoader loader)
- {
- if (!created)
- {
- loader.createCompressedFileVersion(facesContext, resourceMeta, file);
- created = true;
- }
- }
- }
-
- public ResourceLoader getWrapped()
- {
- return delegate;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.zip.GZIPOutputStream;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.commons.resourcehandler.resource.ResourceLoader;
+import org.apache.myfaces.commons.resourcehandler.resource.ResourceLoaderWrapper;
+import org.apache.myfaces.commons.resourcehandler.resource.ResourceMeta;
+import org.apache.myfaces.commons.resourcehandler.resource.ValueExpressionFilterInputStream;
+
+/**
+ *
+ * @author Leonardo Uribe
+ * @author Jakob Korherr
+ *
+ */
+public class GZIPResourceLoader extends ResourceLoaderWrapper
+{
+
+ public final static String COMPRESSED_FILES_MAP = "oam.commons.COMPRESSED_FILES_MAP";
+
+ /**
+ * Subdir of the ServletContext tmp dir to store compressed resources.
+ */
+ private static final String COMPRESSION_BASE_DIR = "oam-resourcehandler-cache/";
+
+ /**
+ * Suffix for compressed files.
+ */
+ private static final String COMPRESSED_FILE_SUFFIX = ".gzip";
+
+ /**
+ * Size of the byte array buffer.
+ */
+ private static final int BUFFER_SIZE = 2048;
+
+ private ResourceLoader delegate;
+
+ private volatile File _tempDir;
+
+ private final ExtendedDefaultResourceHandlerSupport _extendedDefaultResourceHandlerSupport;
+
+ public GZIPResourceLoader(ResourceLoader delegate, ExtendedDefaultResourceHandlerSupport extendedDefaultResourceHandlerSupport)
+ {
+ this.delegate = delegate;
+ _extendedDefaultResourceHandlerSupport = extendedDefaultResourceHandlerSupport;
+ initialize();
+ }
+
+ protected void initialize()
+ {
+ //Get startup FacesContext
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ //1. Create temporal directory for compressed resources
+ Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();
+ File tempdir = (File) applicationMap.get("javax.servlet.context.tempdir");
+ File imagesDir = new File(tempdir, COMPRESSION_BASE_DIR);
+ if (!imagesDir.exists())
+ {
+ imagesDir.mkdirs();
+ }
+ else
+ {
+ //Clear the cache
+ deleteDir(imagesDir);
+ imagesDir.mkdirs();
+ }
+ _tempDir = imagesDir;
+
+ //2. Create map for register compressed resources
+ Map<String, FileProducer> compressedFilesMap = new ConcurrentHashMap<String, FileProducer>();
+ facesContext.getExternalContext().getApplicationMap().put(COMPRESSED_FILES_MAP, compressedFilesMap);
+ }
+
+ private static boolean deleteDir(File dir)
+ {
+ if (dir.isDirectory())
+ {
+ String[] children = dir.list();
+ for (int i = 0; i < children.length; i++)
+ {
+ boolean success = deleteDir(new File(dir, children[i]));
+ if (!success)
+ {
+ return false;
+ }
+ }
+ }
+ return dir.delete();
+ }
+
+ @Override
+ public URL getResourceURL(ResourceMeta resourceMeta)
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (!_extendedDefaultResourceHandlerSupport.isCompressable(resourceMeta) || !_extendedDefaultResourceHandlerSupport.userAgentSupportsCompression(facesContext))
+ {
+ return super.getResourceURL(resourceMeta);
+ }
+
+ if (resourceExists(resourceMeta))
+ {
+ File file = createOrGetCompressedFile(facesContext, resourceMeta);
+
+ try
+ {
+ return file.toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new FacesException(e);
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public InputStream getResourceInputStream(ResourceMeta resourceMeta)
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (!_extendedDefaultResourceHandlerSupport.isCompressable(resourceMeta) || !_extendedDefaultResourceHandlerSupport.userAgentSupportsCompression(facesContext))
+ {
+ return super.getResourceInputStream(resourceMeta);
+ }
+
+ if (resourceExists(resourceMeta))
+ {
+ File file = createOrGetCompressedFile(facesContext, resourceMeta);
+
+ try
+ {
+ return new BufferedInputStream(new FileInputStream(file));
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new FacesException(e);
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public boolean resourceExists(ResourceMeta resourceMeta)
+ {
+ return super.resourceExists(resourceMeta);
+ }
+
+ @SuppressWarnings("unchecked")
+ private File createOrGetCompressedFile(FacesContext facesContext, ResourceMeta resourceMeta)
+ {
+ String identifier = resourceMeta.getResourceIdentifier();
+ File file = getCompressedFile(resourceMeta);
+ if (!file.exists())
+ {
+ Map<String, FileProducer> map = (Map<String, FileProducer>)
+ facesContext.getExternalContext().getApplicationMap().get(COMPRESSED_FILES_MAP);
+
+ FileProducer creator = map.get(identifier);
+
+ if (creator == null)
+ {
+ synchronized(this)
+ {
+ creator = map.get(identifier);
+
+ if (creator == null)
+ {
+ creator = new FileProducer();
+ map.put(identifier, creator);
+ }
+ }
+ }
+
+ if (!creator.isCreated())
+ {
+ creator.createFile(facesContext, resourceMeta, file, this);
+ }
+ }
+ return file;
+ }
+
+ private File getCompressedFile(ResourceMeta resourceMeta)
+ {
+ return new File(_tempDir, resourceMeta.getResourceIdentifier() + COMPRESSED_FILE_SUFFIX);
+ }
+
+ private boolean couldResourceContainValueExpressions(ResourceMeta resourceMeta)
+ {
+ return resourceMeta.couldResourceContainValueExpressions() || resourceMeta.getResourceName().endsWith(".css");
+ }
+
+
+ /**
+ * Uses GZIPOutputStream to compress this resource.
+ * It will be stored where getCompressedFile() points to.
+ *
+ * Note that the resource really must be compressable (isCompressable() must return true).
+ *
+ * @return
+ */
+ protected void createCompressedFileVersion(FacesContext facesContext, ResourceMeta resourceMeta, File target)
+ {
+ //File target = getCompressedFile(resourceMeta);
+ target.mkdirs(); // ensure necessary directories exist
+ target.delete(); // remove any existing file
+
+ InputStream inputStream = null;
+ FileOutputStream fileOutputStream;
+ GZIPOutputStream gzipOutputStream = null;
+ try
+ {
+ if (couldResourceContainValueExpressions(resourceMeta))
+ {
+ inputStream = new ValueExpressionFilterInputStream(
+ getWrapped().getResourceInputStream(resourceMeta),
+ resourceMeta.getLibraryName(),
+ resourceMeta.getResourceName());
+ }
+ else
+ {
+ inputStream = getWrapped().getResourceInputStream(resourceMeta);
+ }
+ fileOutputStream = new FileOutputStream(target);
+ gzipOutputStream = new GZIPOutputStream(fileOutputStream);
+ byte[] buffer = new byte[BUFFER_SIZE];
+
+ pipeBytes(inputStream, gzipOutputStream, buffer);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new FacesException("Unexpected exception while create file:", e);
+ }
+ catch (IOException e)
+ {
+ throw new FacesException("Unexpected exception while create file:", e);
+ }
+ finally
+ {
+ if (inputStream != null)
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (IOException e)
+ {
+ // Ignore
+ }
+ }
+ if (gzipOutputStream != null)
+ {
+ // also closes fileOutputStream
+ try
+ {
+ gzipOutputStream.close();
+ }
+ catch (IOException e)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Reads the specified input stream into the provided byte array storage and
+ * writes it to the output stream.
+ */
+ private static void pipeBytes(InputStream in, OutputStream out, byte[] buffer) throws IOException
+ {
+ int length;
+
+ while ((length = (in.read(buffer))) >= 0)
+ {
+ out.write(buffer, 0, length);
+ }
+ }
+
+ public static class FileProducer {
+
+ public volatile boolean created = false;
+
+ public FileProducer()
+ {
+ super();
+ }
+
+ public boolean isCreated()
+ {
+ return created;
+ }
+
+ public synchronized void createFile(FacesContext facesContext, ResourceMeta resourceMeta, File file, GZIPResourceLoader loader)
+ {
+ if (!created)
+ {
+ loader.createCompressedFileVersion(facesContext, resourceMeta, file);
+ created = true;
+ }
+ }
+ }
+
+ public ResourceLoader getWrapped()
+ {
+ return delegate;
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/GZIPResourceLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/ResourceUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/application/FacesServletMapping.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/DefaultMyFacesResourceHandlerUrlProvider.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/DefaultMyFacesResourceHandlerUrlProvider.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/DefaultMyFacesResourceHandlerUrlProvider.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/DefaultMyFacesResourceHandlerUrlProvider.java Thu Oct 20 10:49:18 2011
@@ -1,77 +1,77 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler.config;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.List;
-
-import javax.faces.FacesException;
-import javax.faces.context.ExternalContext;
-
-import org.apache.myfaces.commons.util.ClassUtils;
-
-/**
- * Default implementation used to load myfaces-resources-config.xml files
- *
- * @author Leonardo Uribe
- *
- */
-public class DefaultMyFacesResourceHandlerUrlProvider extends MyFacesResourceHandlerUrlProvider
-{
-
- public Collection<URL> getMetaInfConfigurationResources(ExternalContext context) throws IOException
- {
- ClassLoader contextClassLoader = ClassUtils.getContextClassLoader();
- Enumeration<URL> metaInfConfigUrls = null;
- List<URL> configUrls = new ArrayList<URL>();
-
- try
- {
- // NOTE that there could be multiple config files (in different jar files)
- metaInfConfigUrls = contextClassLoader.getResources(META_INF_CONFIG_FILE);
- }
- catch (IOException e)
- {
- throw new FacesException("Could not open " + MyFacesResourceHandlerUrlProvider.META_INF_CONFIG_FILE, e);
- }
-
- if (metaInfConfigUrls != null && metaInfConfigUrls.hasMoreElements())
- {
- while (metaInfConfigUrls.hasMoreElements())
- {
- URL url = metaInfConfigUrls.nextElement();
- if (url != null)
- {
- configUrls.add(url);
- }
- }
- }
-
- return configUrls;
- }
-
- public URL getWebInfConfigurationResource(ExternalContext context) throws IOException
- {
- return context.getResource(WEB_INF_CONFIG_FILE);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler.config;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+
+import org.apache.myfaces.commons.util.ClassUtils;
+
+/**
+ * Default implementation used to load myfaces-resources-config.xml files
+ *
+ * @author Leonardo Uribe
+ *
+ */
+public class DefaultMyFacesResourceHandlerUrlProvider extends MyFacesResourceHandlerUrlProvider
+{
+
+ public Collection<URL> getMetaInfConfigurationResources(ExternalContext context) throws IOException
+ {
+ ClassLoader contextClassLoader = ClassUtils.getContextClassLoader();
+ Enumeration<URL> metaInfConfigUrls = null;
+ List<URL> configUrls = new ArrayList<URL>();
+
+ try
+ {
+ // NOTE that there could be multiple config files (in different jar files)
+ metaInfConfigUrls = contextClassLoader.getResources(META_INF_CONFIG_FILE);
+ }
+ catch (IOException e)
+ {
+ throw new FacesException("Could not open " + MyFacesResourceHandlerUrlProvider.META_INF_CONFIG_FILE, e);
+ }
+
+ if (metaInfConfigUrls != null && metaInfConfigUrls.hasMoreElements())
+ {
+ while (metaInfConfigUrls.hasMoreElements())
+ {
+ URL url = metaInfConfigUrls.nextElement();
+ if (url != null)
+ {
+ configUrls.add(url);
+ }
+ }
+ }
+
+ return configUrls;
+ }
+
+ public URL getWebInfConfigurationResource(ExternalContext context) throws IOException
+ {
+ return context.getResource(WEB_INF_CONFIG_FILE);
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/DefaultMyFacesResourceHandlerUrlProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/MyFacesResourceHandlerConfigParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/MyFacesResourceHandlerUrlProvider.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/MyFacesResourceHandlerUrlProvider.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/MyFacesResourceHandlerUrlProvider.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/MyFacesResourceHandlerUrlProvider.java Thu Oct 20 10:49:18 2011
@@ -1,42 +1,42 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler.config;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Collection;
-
-import javax.faces.context.ExternalContext;
-
-/**
- * Provides a way to lookup for myfaces-resources-config.xml urls
- *
- * @author Leonardo Uribe
- *
- */
-public abstract class MyFacesResourceHandlerUrlProvider
-{
- public static final String META_INF_CONFIG_FILE = "META-INF/myfaces-resources-config.xml";
-
- public static final String WEB_INF_CONFIG_FILE = "/WEB-INF/myfaces-resources-config.xml";
-
- public abstract Collection<URL> getMetaInfConfigurationResources(ExternalContext context) throws IOException;
-
- public abstract URL getWebInfConfigurationResource(ExternalContext context) throws IOException;
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler.config;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+
+import javax.faces.context.ExternalContext;
+
+/**
+ * Provides a way to lookup for myfaces-resources-config.xml urls
+ *
+ * @author Leonardo Uribe
+ *
+ */
+public abstract class MyFacesResourceHandlerUrlProvider
+{
+ public static final String META_INF_CONFIG_FILE = "META-INF/myfaces-resources-config.xml";
+
+ public static final String WEB_INF_CONFIG_FILE = "/WEB-INF/myfaces-resources-config.xml";
+
+ public abstract Collection<URL> getMetaInfConfigurationResources(ExternalContext context) throws IOException;
+
+ public abstract URL getWebInfConfigurationResource(ExternalContext context) throws IOException;
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/MyFacesResourceHandlerUrlProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/Library.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/Library.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/Library.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/Library.java Thu Oct 20 10:49:18 2011
@@ -1,56 +1,56 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler.config.element;
-
-/**
- *
- * @author Leonardo Uribe
- *
- */
-public class Library
-{
- private String _name;
- private String _requestPath;
- private String _redirectName;
-
- public String getName()
- {
- return _name;
- }
- public void setName(String name)
- {
- this._name = name;
- }
- public String getRequestPath()
- {
- return _requestPath;
- }
- public void setRequestPath(String requestPath)
- {
- this._requestPath = requestPath;
- }
- public String getRedirectName()
- {
- return _redirectName;
- }
- public void setRedirectName(String redirectName)
- {
- this._redirectName = redirectName;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler.config.element;
+
+/**
+ *
+ * @author Leonardo Uribe
+ *
+ */
+public class Library
+{
+ private String _name;
+ private String _requestPath;
+ private String _redirectName;
+
+ public String getName()
+ {
+ return _name;
+ }
+ public void setName(String name)
+ {
+ this._name = name;
+ }
+ public String getRequestPath()
+ {
+ return _requestPath;
+ }
+ public void setRequestPath(String requestPath)
+ {
+ this._requestPath = requestPath;
+ }
+ public String getRedirectName()
+ {
+ return _redirectName;
+ }
+ public void setRedirectName(String redirectName)
+ {
+ this._redirectName = redirectName;
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/Library.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/MyFacesResourcesConfig.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/MyFacesResourcesConfig.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/MyFacesResourcesConfig.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/MyFacesResourcesConfig.java Thu Oct 20 10:49:18 2011
@@ -1,63 +1,63 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler.config.element;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- *
- * @author Leonardo Uribe
- *
- */
-public class MyFacesResourcesConfig
-{
- private Map<String, Library> libraries = new HashMap<String, Library>();
-
- private Map<String, Library> unmodifiableMap;
-
- public void addLibrary(Library library)
- {
- libraries.put(library.getName(), library);
- unmodifiableMap = null;
- }
-
- public Library getLibrary(String name)
- {
- return libraries.get(name);
- }
-
- public Map<String, Library> getLibraries()
- {
- if (unmodifiableMap == null)
- {
- unmodifiableMap = Collections.unmodifiableMap(libraries);
- }
- return unmodifiableMap;
- }
-
- public void merge(MyFacesResourcesConfig config)
- {
- for (Map.Entry<String, Library> entry : config.getLibraries().entrySet())
- {
- this.addLibrary(entry.getValue());
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler.config.element;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author Leonardo Uribe
+ *
+ */
+public class MyFacesResourcesConfig
+{
+ private Map<String, Library> libraries = new HashMap<String, Library>();
+
+ private Map<String, Library> unmodifiableMap;
+
+ public void addLibrary(Library library)
+ {
+ libraries.put(library.getName(), library);
+ unmodifiableMap = null;
+ }
+
+ public Library getLibrary(String name)
+ {
+ return libraries.get(name);
+ }
+
+ public Map<String, Library> getLibraries()
+ {
+ if (unmodifiableMap == null)
+ {
+ unmodifiableMap = Collections.unmodifiableMap(libraries);
+ }
+ return unmodifiableMap;
+ }
+
+ public void merge(MyFacesResourcesConfig config)
+ {
+ for (Map.Entry<String, Library> entry : config.getLibraries().entrySet())
+ {
+ this.addLibrary(entry.getValue());
+ }
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/config/element/MyFacesResourcesConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/AliasResourceMetaImpl.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/AliasResourceMetaImpl.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/AliasResourceMetaImpl.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/AliasResourceMetaImpl.java Thu Oct 20 10:49:18 2011
@@ -1,96 +1,96 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler.resource;
-
-/**
- * Contains the metadata information to reference a resource
- *
- * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
- * @version $Revision: 700544 $ $Date: 2008-09-30 13:44:02 -0500 (Mar, 30 Sep 2008) $
- */
-public class AliasResourceMetaImpl extends ResourceMetaImpl
-{
- private String _realResourceName;
-
- private boolean _couldContainValueExpressions;
-
- public AliasResourceMetaImpl(String prefix, String libraryName, String libraryVersion,
- String resourceName, String resourceVersion, String realResourceName, boolean couldContainValueExpressions)
- {
- super(prefix, libraryName, libraryVersion,
- resourceName, resourceVersion);
- _realResourceName = realResourceName;
- _couldContainValueExpressions = couldContainValueExpressions;
- }
-
- public String getRealResourceName()
- {
- return _realResourceName;
- }
-
- public void setRealResourceName(String realResourceName)
- {
- _realResourceName = realResourceName;
- }
-
- @Override
- public String getResourceIdentifier()
- {
- StringBuilder builder = new StringBuilder();
- boolean firstSlashAdded = false;
- if (getLocalePrefix() != null && getLocalePrefix().length() > 0)
- {
- builder.append(getLocalePrefix());
- firstSlashAdded = true;
- }
- if (getLibraryName() != null)
- {
- if (firstSlashAdded) builder.append('/');
- builder.append(getLibraryName());
- firstSlashAdded = true;
- }
- if (getLibraryVersion() != null)
- {
- if (firstSlashAdded) builder.append('/');
- builder.append(getLibraryVersion());
- firstSlashAdded = true;
- }
- if (getRealResourceName() != null)
- {
- if (firstSlashAdded) builder.append('/');
- builder.append(getRealResourceName());
- firstSlashAdded = true;
- }
- if (getResourceVersion() != null)
- {
- if (firstSlashAdded) builder.append('/');
- builder.append(getResourceVersion());
- builder.append(
- getRealResourceName().substring(getRealResourceName().lastIndexOf('.')));
- firstSlashAdded = true;
- }
- return builder.toString();
- }
-
- @Override
- public boolean couldResourceContainValueExpressions()
- {
- return _couldContainValueExpressions;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler.resource;
+
+/**
+ * Contains the metadata information to reference a resource
+ *
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 700544 $ $Date: 2008-09-30 13:44:02 -0500 (Mar, 30 Sep 2008) $
+ */
+public class AliasResourceMetaImpl extends ResourceMetaImpl
+{
+ private String _realResourceName;
+
+ private boolean _couldContainValueExpressions;
+
+ public AliasResourceMetaImpl(String prefix, String libraryName, String libraryVersion,
+ String resourceName, String resourceVersion, String realResourceName, boolean couldContainValueExpressions)
+ {
+ super(prefix, libraryName, libraryVersion,
+ resourceName, resourceVersion);
+ _realResourceName = realResourceName;
+ _couldContainValueExpressions = couldContainValueExpressions;
+ }
+
+ public String getRealResourceName()
+ {
+ return _realResourceName;
+ }
+
+ public void setRealResourceName(String realResourceName)
+ {
+ _realResourceName = realResourceName;
+ }
+
+ @Override
+ public String getResourceIdentifier()
+ {
+ StringBuilder builder = new StringBuilder();
+ boolean firstSlashAdded = false;
+ if (getLocalePrefix() != null && getLocalePrefix().length() > 0)
+ {
+ builder.append(getLocalePrefix());
+ firstSlashAdded = true;
+ }
+ if (getLibraryName() != null)
+ {
+ if (firstSlashAdded) builder.append('/');
+ builder.append(getLibraryName());
+ firstSlashAdded = true;
+ }
+ if (getLibraryVersion() != null)
+ {
+ if (firstSlashAdded) builder.append('/');
+ builder.append(getLibraryVersion());
+ firstSlashAdded = true;
+ }
+ if (getRealResourceName() != null)
+ {
+ if (firstSlashAdded) builder.append('/');
+ builder.append(getRealResourceName());
+ firstSlashAdded = true;
+ }
+ if (getResourceVersion() != null)
+ {
+ if (firstSlashAdded) builder.append('/');
+ builder.append(getResourceVersion());
+ builder.append(
+ getRealResourceName().substring(getRealResourceName().lastIndexOf('.')));
+ firstSlashAdded = true;
+ }
+ return builder.toString();
+ }
+
+ @Override
+ public boolean couldResourceContainValueExpressions()
+ {
+ return _couldContainValueExpressions;
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/AliasResourceMetaImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/BaseResourceHandlerSupport.java
URL: http://svn.apache.org/viewvc/myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/BaseResourceHandlerSupport.java?rev=1186730&r1=1186729&r2=1186730&view=diff
==============================================================================
--- myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/BaseResourceHandlerSupport.java (original)
+++ myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/BaseResourceHandlerSupport.java Thu Oct 20 10:49:18 2011
@@ -1,229 +1,229 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.myfaces.commons.resourcehandler.resource;
-
-import java.util.Map;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-
-import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
-import org.apache.myfaces.commons.resourcehandler.application.FacesServletMapping;
-import org.apache.myfaces.commons.util.WebConfigParamUtils;
-
-/**
- * A ResourceHandlerSupport implementation for use with standard Java Servlet engines,
- * ie an engine that supports javax.servlet, and uses a standard web.xml file.
- *
- * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
- * @version $Revision: 946779 $ $Date: 2010-05-20 15:31:42 -0500 (Jue, 20 May 2010) $
- */
-public class BaseResourceHandlerSupport extends ResourceHandlerSupport
-{
-
- /**
- * Set the max time in miliseconds set on the "Expires" header for a resource.
- * (default to one week in miliseconds or 604800000)
- */
- @JSFWebConfigParam(since="2.0", defaultValue="604800000")
- public static final String RESOURCE_MAX_TIME_EXPIRES = "org.apache.myfaces.RESOURCE_MAX_TIME_EXPIRES";
-
- /**
- * Identifies the FacesServlet mapping in the current request map.
- */
- private static final String CACHED_SERVLET_MAPPING =
- BaseResourceHandlerSupport.class.getName() + ".CACHED_SERVLET_MAPPING";
-
- private Long _startupTime;
-
- private Long _maxTimeExpires;
-
- public BaseResourceHandlerSupport()
- {
- _startupTime = System.currentTimeMillis();
- }
-
- public ResourceLoader[] getResourceLoaders()
- {
- return null;
- }
-
- public String calculateResourceBasePath(FacesContext facesContext)
- {
- FacesServletMapping mapping = getFacesServletMapping(facesContext);
- ExternalContext externalContext = facesContext.getExternalContext();
-
- if (mapping != null)
- {
- String resourceBasePath = null;
- if (mapping.isExtensionMapping())
- {
- // Mapping using a suffix. In this case we have to strip
- // the suffix. If we have a url like:
- // http://localhost:8080/testjsf20/javax.faces.resource/imagen.jpg.jsf?ln=dojo
- //
- // The servlet path is /javax.faces.resource/imagen.jpg.jsf
- //
- // For obtain the resource name we have to remove the .jsf suffix and
- // the prefix ResourceHandler.RESOURCE_IDENTIFIER
- resourceBasePath = externalContext.getRequestServletPath();
- int stripPoint = resourceBasePath.lastIndexOf('.');
- if (stripPoint > 0)
- {
- resourceBasePath = resourceBasePath.substring(0, stripPoint);
- }
- }
- else
- {
- // Mapping using prefix. In this case we have to strip
- // the prefix used for mapping. If we have a url like:
- // http://localhost:8080/testjsf20/faces/javax.faces.resource/imagen.jpg?ln=dojo
- //
- // The servlet path is /faces
- // and the path info is /javax.faces.resource/imagen.jpg
- //
- // For obtain the resource name we have to remove the /faces prefix and
- // then the prefix ResourceHandler.RESOURCE_IDENTIFIER
- resourceBasePath = externalContext.getRequestPathInfo();
- }
- return resourceBasePath;
- }
- else
- {
- //If no mapping is detected, just return the
- //information follows the servlet path but before
- //the query string
- return externalContext.getRequestPathInfo();
- }
- }
-
- public boolean isExtensionMapping()
- {
- FacesServletMapping mapping = getFacesServletMapping(
- FacesContext.getCurrentInstance());
- if (mapping != null)
- {
- if (mapping.isExtensionMapping())
- {
- return true;
- }
- }
- return false;
- }
-
- public String getMapping()
- {
- FacesServletMapping mapping = getFacesServletMapping(
- FacesContext.getCurrentInstance());
- if (mapping != null)
- {
- if (mapping.isExtensionMapping())
- {
- return mapping.getExtension();
- }
- else
- {
- return mapping.getPrefix();
- }
- }
- return "";
- }
-
- /**
- * Read the web.xml file that is in the classpath and parse its internals to
- * figure out how the FacesServlet is mapped for the current webapp.
- */
- protected FacesServletMapping getFacesServletMapping(FacesContext context)
- {
- Map<Object, Object> attributes = context.getAttributes();
-
- // Has the mapping already been determined during this request?
- FacesServletMapping mapping = (FacesServletMapping) attributes.get(CACHED_SERVLET_MAPPING);
- if (mapping == null)
- {
- ExternalContext externalContext = context.getExternalContext();
- mapping = calculateFacesServletMapping(externalContext.getRequestServletPath(),
- externalContext.getRequestPathInfo());
-
- attributes.put(CACHED_SERVLET_MAPPING, mapping);
- }
- return mapping;
- }
-
- /**
- * Determines the mapping of the FacesServlet in the web.xml configuration
- * file. However, there is no need to actually parse this configuration file
- * as runtime information is sufficient.
- *
- * @param servletPath The servletPath of the current request
- * @param pathInfo The pathInfo of the current request
- * @return the mapping of the FacesServlet in the web.xml configuration file
- */
- protected static FacesServletMapping calculateFacesServletMapping(
- String servletPath, String pathInfo)
- {
- if (pathInfo != null)
- {
- // If there is a "extra path", it's definitely no extension mapping.
- // Now we just have to determine the path which has been specified
- // in the url-pattern, but that's easy as it's the same as the
- // current servletPath. It doesn't even matter if "/*" has been used
- // as in this case the servletPath is just an empty string according
- // to the Servlet Specification (SRV 4.4).
- return FacesServletMapping.createPrefixMapping(servletPath);
- }
- else
- {
- // In the case of extension mapping, no "extra path" is available.
- // Still it's possible that prefix-based mapping has been used.
- // Actually, if there was an exact match no "extra path"
- // is available (e.g. if the url-pattern is "/faces/*"
- // and the request-uri is "/context/faces").
- int slashPos = servletPath.lastIndexOf('/');
- int extensionPos = servletPath.lastIndexOf('.');
- if (extensionPos > -1 && extensionPos > slashPos)
- {
- String extension = servletPath.substring(extensionPos);
- return FacesServletMapping.createExtensionMapping(extension);
- }
- else
- {
- // There is no extension in the given servletPath and therefore
- // we assume that it's an exact match using prefix-based mapping.
- return FacesServletMapping.createPrefixMapping(servletPath);
- }
- }
- }
-
- public long getStartupTime()
- {
- return _startupTime;
- }
-
- public long getMaxTimeExpires()
- {
- if (_maxTimeExpires == null)
- {
- _maxTimeExpires = WebConfigParamUtils.getLongInitParameter(
- FacesContext.getCurrentInstance().getExternalContext(),
- RESOURCE_MAX_TIME_EXPIRES, 604800000L);
- }
- return _maxTimeExpires;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.resourcehandler.resource;
+
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
+import org.apache.myfaces.commons.resourcehandler.application.FacesServletMapping;
+import org.apache.myfaces.commons.util.WebConfigParamUtils;
+
+/**
+ * A ResourceHandlerSupport implementation for use with standard Java Servlet engines,
+ * ie an engine that supports javax.servlet, and uses a standard web.xml file.
+ *
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 946779 $ $Date: 2010-05-20 15:31:42 -0500 (Jue, 20 May 2010) $
+ */
+public class BaseResourceHandlerSupport extends ResourceHandlerSupport
+{
+
+ /**
+ * Set the max time in miliseconds set on the "Expires" header for a resource.
+ * (default to one week in miliseconds or 604800000)
+ */
+ @JSFWebConfigParam(since="2.0", defaultValue="604800000")
+ public static final String RESOURCE_MAX_TIME_EXPIRES = "org.apache.myfaces.RESOURCE_MAX_TIME_EXPIRES";
+
+ /**
+ * Identifies the FacesServlet mapping in the current request map.
+ */
+ private static final String CACHED_SERVLET_MAPPING =
+ BaseResourceHandlerSupport.class.getName() + ".CACHED_SERVLET_MAPPING";
+
+ private Long _startupTime;
+
+ private Long _maxTimeExpires;
+
+ public BaseResourceHandlerSupport()
+ {
+ _startupTime = System.currentTimeMillis();
+ }
+
+ public ResourceLoader[] getResourceLoaders()
+ {
+ return null;
+ }
+
+ public String calculateResourceBasePath(FacesContext facesContext)
+ {
+ FacesServletMapping mapping = getFacesServletMapping(facesContext);
+ ExternalContext externalContext = facesContext.getExternalContext();
+
+ if (mapping != null)
+ {
+ String resourceBasePath = null;
+ if (mapping.isExtensionMapping())
+ {
+ // Mapping using a suffix. In this case we have to strip
+ // the suffix. If we have a url like:
+ // http://localhost:8080/testjsf20/javax.faces.resource/imagen.jpg.jsf?ln=dojo
+ //
+ // The servlet path is /javax.faces.resource/imagen.jpg.jsf
+ //
+ // For obtain the resource name we have to remove the .jsf suffix and
+ // the prefix ResourceHandler.RESOURCE_IDENTIFIER
+ resourceBasePath = externalContext.getRequestServletPath();
+ int stripPoint = resourceBasePath.lastIndexOf('.');
+ if (stripPoint > 0)
+ {
+ resourceBasePath = resourceBasePath.substring(0, stripPoint);
+ }
+ }
+ else
+ {
+ // Mapping using prefix. In this case we have to strip
+ // the prefix used for mapping. If we have a url like:
+ // http://localhost:8080/testjsf20/faces/javax.faces.resource/imagen.jpg?ln=dojo
+ //
+ // The servlet path is /faces
+ // and the path info is /javax.faces.resource/imagen.jpg
+ //
+ // For obtain the resource name we have to remove the /faces prefix and
+ // then the prefix ResourceHandler.RESOURCE_IDENTIFIER
+ resourceBasePath = externalContext.getRequestPathInfo();
+ }
+ return resourceBasePath;
+ }
+ else
+ {
+ //If no mapping is detected, just return the
+ //information follows the servlet path but before
+ //the query string
+ return externalContext.getRequestPathInfo();
+ }
+ }
+
+ public boolean isExtensionMapping()
+ {
+ FacesServletMapping mapping = getFacesServletMapping(
+ FacesContext.getCurrentInstance());
+ if (mapping != null)
+ {
+ if (mapping.isExtensionMapping())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public String getMapping()
+ {
+ FacesServletMapping mapping = getFacesServletMapping(
+ FacesContext.getCurrentInstance());
+ if (mapping != null)
+ {
+ if (mapping.isExtensionMapping())
+ {
+ return mapping.getExtension();
+ }
+ else
+ {
+ return mapping.getPrefix();
+ }
+ }
+ return "";
+ }
+
+ /**
+ * Read the web.xml file that is in the classpath and parse its internals to
+ * figure out how the FacesServlet is mapped for the current webapp.
+ */
+ protected FacesServletMapping getFacesServletMapping(FacesContext context)
+ {
+ Map<Object, Object> attributes = context.getAttributes();
+
+ // Has the mapping already been determined during this request?
+ FacesServletMapping mapping = (FacesServletMapping) attributes.get(CACHED_SERVLET_MAPPING);
+ if (mapping == null)
+ {
+ ExternalContext externalContext = context.getExternalContext();
+ mapping = calculateFacesServletMapping(externalContext.getRequestServletPath(),
+ externalContext.getRequestPathInfo());
+
+ attributes.put(CACHED_SERVLET_MAPPING, mapping);
+ }
+ return mapping;
+ }
+
+ /**
+ * Determines the mapping of the FacesServlet in the web.xml configuration
+ * file. However, there is no need to actually parse this configuration file
+ * as runtime information is sufficient.
+ *
+ * @param servletPath The servletPath of the current request
+ * @param pathInfo The pathInfo of the current request
+ * @return the mapping of the FacesServlet in the web.xml configuration file
+ */
+ protected static FacesServletMapping calculateFacesServletMapping(
+ String servletPath, String pathInfo)
+ {
+ if (pathInfo != null)
+ {
+ // If there is a "extra path", it's definitely no extension mapping.
+ // Now we just have to determine the path which has been specified
+ // in the url-pattern, but that's easy as it's the same as the
+ // current servletPath. It doesn't even matter if "/*" has been used
+ // as in this case the servletPath is just an empty string according
+ // to the Servlet Specification (SRV 4.4).
+ return FacesServletMapping.createPrefixMapping(servletPath);
+ }
+ else
+ {
+ // In the case of extension mapping, no "extra path" is available.
+ // Still it's possible that prefix-based mapping has been used.
+ // Actually, if there was an exact match no "extra path"
+ // is available (e.g. if the url-pattern is "/faces/*"
+ // and the request-uri is "/context/faces").
+ int slashPos = servletPath.lastIndexOf('/');
+ int extensionPos = servletPath.lastIndexOf('.');
+ if (extensionPos > -1 && extensionPos > slashPos)
+ {
+ String extension = servletPath.substring(extensionPos);
+ return FacesServletMapping.createExtensionMapping(extension);
+ }
+ else
+ {
+ // There is no extension in the given servletPath and therefore
+ // we assume that it's an exact match using prefix-based mapping.
+ return FacesServletMapping.createPrefixMapping(servletPath);
+ }
+ }
+ }
+
+ public long getStartupTime()
+ {
+ return _startupTime;
+ }
+
+ public long getMaxTimeExpires()
+ {
+ if (_maxTimeExpires == null)
+ {
+ _maxTimeExpires = WebConfigParamUtils.getLongInitParameter(
+ FacesContext.getCurrentInstance().getExternalContext(),
+ RESOURCE_MAX_TIME_EXPIRES, 604800000L);
+ }
+ return _maxTimeExpires;
+ }
+}
Propchange: myfaces/commons/branches/jsf_20/myfaces-commons-resourcehandler/src/main/java/org/apache/myfaces/commons/resourcehandler/resource/BaseResourceHandlerSupport.java
------------------------------------------------------------------------------
svn:eol-style = native