You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/06/23 12:56:44 UTC
svn commit: r670515 - in
/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet:
AbstractStylesheet.java StylesheetRenderer.java TextResourceFilter.java
TextResourceFilterProvider.java
Author: skitching
Date: Mon Jun 23 03:56:44 2008
New Revision: 670515
URL: http://svn.apache.org/viewvc?rev=670515&view=rev
Log:
Tabs to spaces only
Modified:
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/AbstractStylesheet.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilter.java
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilterProvider.java
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/AbstractStylesheet.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/AbstractStylesheet.java?rev=670515&r1=670514&r2=670515&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/AbstractStylesheet.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/AbstractStylesheet.java Mon Jun 23 03:56:44 2008
@@ -38,38 +38,38 @@
public abstract class AbstractStylesheet extends UIComponentBase
implements UserRoleAware
{
- public static final String COMPONENT_TYPE = "org.apache.myfaces.Stylesheet";
- public static final String COMPONENT_FAMILY = "javax.faces.Output";
- private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Stylesheet";
-
- /**
- * URL for CSS-file.
- *
- * @JSFProperty
- * required="true"
- */
- public abstract String getPath();
-
- /**
- * Inline the stylesheet file content as in contrast to referencing it as .
- *
- * @JSFProperty
- * defaultValue = "false"
- * @return true if the styles are inlined to the jsp file
- */
- public abstract boolean isInline();
-
- /**
- * true|false. When true, any EL expression in the stylesheet will
- * be evaluated and replaced by its string representation on the
- * first access. The stylesheet will be processed only once.
- * Every subsequent request will get a cached view.
- *
- * @JSFProperty
- * defaultValue = "false"
- * @return true if the stylesheet should be filtered before sending to the browser
- */
- public abstract boolean isFiltered();
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.Stylesheet";
+ public static final String COMPONENT_FAMILY = "javax.faces.Output";
+ private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Stylesheet";
+
+ /**
+ * URL for CSS-file.
+ *
+ * @JSFProperty
+ * required="true"
+ */
+ public abstract String getPath();
+
+ /**
+ * Inline the stylesheet file content as in contrast to referencing it as .
+ *
+ * @JSFProperty
+ * defaultValue = "false"
+ * @return true if the styles are inlined to the jsp file
+ */
+ public abstract boolean isInline();
+
+ /**
+ * true|false. When true, any EL expression in the stylesheet will
+ * be evaluated and replaced by its string representation on the
+ * first access. The stylesheet will be processed only once.
+ * Every subsequent request will get a cached view.
+ *
+ * @JSFProperty
+ * defaultValue = "false"
+ * @return true if the stylesheet should be filtered before sending to the browser
+ */
+ public abstract boolean isFiltered();
/**
* Define the target media of the styles:
@@ -103,15 +103,15 @@
*
* @JSFProperty
*/
- public abstract String getMedia();
+ public abstract String getMedia();
- public boolean isRendered()
- {
- if (!UserRoleUtils.isVisibleOnUserRole(this))
- {
- return false;
- }
- return super.isRendered();
- }
+ public boolean isRendered()
+ {
+ if (!UserRoleUtils.isVisibleOnUserRole(this))
+ {
+ return false;
+ }
+ return super.isRendered();
+ }
}
\ No newline at end of file
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java?rev=670515&r1=670514&r2=670515&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java Mon Jun 23 03:56:44 2008
@@ -40,79 +40,79 @@
*/
public class StylesheetRenderer extends HtmlRenderer
{
- public void encodeEnd(FacesContext context, UIComponent component)
- throws IOException
- {
+ public void encodeEnd(FacesContext context, UIComponent component)
+ throws IOException
+ {
- if ((context == null) || (component == null))
- {
- throw new NullPointerException();
- }
- Stylesheet stylesheet = (Stylesheet) component;
- ResponseWriter writer = context.getResponseWriter();
-
- //A path starting with / or not is the same for this component,
- //because ctx.getExternalContext().getResourceAsStream(file);
- //or ServletContext.getResourceAsStream() specifies that
- //ALL resources must start with '/'
- String path = stylesheet.getPath();
+ if ((context == null) || (component == null))
+ {
+ throw new NullPointerException();
+ }
+ Stylesheet stylesheet = (Stylesheet) component;
+ ResponseWriter writer = context.getResponseWriter();
+
+ //A path starting with / or not is the same for this component,
+ //because ctx.getExternalContext().getResourceAsStream(file);
+ //or ServletContext.getResourceAsStream() specifies that
+ //ALL resources must start with '/'
+ String path = stylesheet.getPath();
if (path.startsWith("/"))
{
path = path.substring(1);
- }
+ }
- if (stylesheet.isInline())
- {
- //include as inline css
- writer.startElement("style", component);
- writer.writeAttribute("type", "text/css", null);
- if (stylesheet.getMedia() != null)
- {
- writer.writeAttribute("media", stylesheet.getMedia(), null);
- }
- //writer.writeText("<!--\n", null);
+ if (stylesheet.isInline())
+ {
+ //include as inline css
+ writer.startElement("style", component);
+ writer.writeAttribute("type", "text/css", null);
+ if (stylesheet.getMedia() != null)
+ {
+ writer.writeAttribute("media", stylesheet.getMedia(), null);
+ }
+ //writer.writeText("<!--\n", null);
- Object text;
- if (stylesheet.isFiltered())
- {
- ResourceInfo info = TextResourceFilter.getInstance(context).getOrCreateFilteredResource(context, path);
- text = info.getText();
- }
- else
- {
- text = RendererUtils.loadResourceFile(context,'/'+ path);
- }
- if (text != null)
- {
- writer.writeText(text, null);
- }
- //writer.writeText("\n-->", null);
- writer.endElement("style");
- }
- else
- {
- //refere as link-element
- writer.startElement("link", component);
- writer.writeAttribute("rel", "stylesheet", null);
- writer.writeAttribute("type", "text/css", null);
- if (stylesheet.getMedia() != null)
- {
- writer.writeAttribute("media", stylesheet.getMedia(), null);
- }
+ Object text;
+ if (stylesheet.isFiltered())
+ {
+ ResourceInfo info = TextResourceFilter.getInstance(context).getOrCreateFilteredResource(context, path);
+ text = info.getText();
+ }
+ else
+ {
+ text = RendererUtils.loadResourceFile(context,'/'+ path);
+ }
+ if (text != null)
+ {
+ writer.writeText(text, null);
+ }
+ //writer.writeText("\n-->", null);
+ writer.endElement("style");
+ }
+ else
+ {
+ //refere as link-element
+ writer.startElement("link", component);
+ writer.writeAttribute("rel", "stylesheet", null);
+ writer.writeAttribute("type", "text/css", null);
+ if (stylesheet.getMedia() != null)
+ {
+ writer.writeAttribute("media", stylesheet.getMedia(), null);
+ }
- String stylesheetPath;
- if (stylesheet.isFiltered())
- {
- TextResourceFilter.getInstance(context).getOrCreateFilteredResource(context, path);
- stylesheetPath = AddResourceFactory.getInstance(context).getResourceUri(context, TextResourceFilterProvider.class, path, true);
- }
- else
- {
- stylesheetPath = context.getApplication().getViewHandler().getResourceURL(context, path);
- }
+ String stylesheetPath;
+ if (stylesheet.isFiltered())
+ {
+ TextResourceFilter.getInstance(context).getOrCreateFilteredResource(context, path);
+ stylesheetPath = AddResourceFactory.getInstance(context).getResourceUri(context, TextResourceFilterProvider.class, path, true);
+ }
+ else
+ {
+ stylesheetPath = context.getApplication().getViewHandler().getResourceURL(context, path);
+ }
- writer.writeURIAttribute("href", stylesheetPath, "path");
- writer.endElement("link");
- }
- }
+ writer.writeURIAttribute("href", stylesheetPath, "path");
+ writer.endElement("link");
+ }
+ }
}
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilter.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilter.java?rev=670515&r1=670514&r2=670515&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilter.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilter.java Mon Jun 23 03:56:44 2008
@@ -43,169 +43,169 @@
*/
public class TextResourceFilter implements Serializable
{
- private static final Log log = LogFactory.getLog(TextResourceFilter.class);
+ private static final Log log = LogFactory.getLog(TextResourceFilter.class);
- private final static String CONTEXT_KEY = TextResourceFilter.class.getName() + ".INSTANCE";
+ private final static String CONTEXT_KEY = TextResourceFilter.class.getName() + ".INSTANCE";
- private final Map filteredResources = Collections.synchronizedMap(new TreeMap());
+ private final Map filteredResources = Collections.synchronizedMap(new TreeMap());
- public static class ResourceInfo
- {
- private final long lastModified;
- private final String text;
-
- protected ResourceInfo(long lastModified, String text)
- {
- this.lastModified = lastModified;
- this.text = text;
- }
-
- public long getLastModified()
- {
- return lastModified;
- }
-
- public String getText()
- {
- return text;
- }
-
- public int getSize()
- {
- return text.length();
- }
- }
-
- protected TextResourceFilter()
- {
- }
-
- protected static TextResourceFilter create()
- {
- return new TextResourceFilter();
- }
-
- /**
- * get the application stylesheet filter
- */
- public static TextResourceFilter getInstance(ServletContext context)
- {
- TextResourceFilter filterText = (TextResourceFilter) context.getAttribute(CONTEXT_KEY);
- if (filterText == null)
- {
- filterText = create();
- context.setAttribute(CONTEXT_KEY, filterText);
- }
-
- return filterText;
- }
-
- /**
- * get the application stylesheet filter
- */
- public static TextResourceFilter getInstance(FacesContext context)
- {
- TextResourceFilter filterText = (TextResourceFilter) context.getExternalContext().getApplicationMap().get(CONTEXT_KEY);
- if (filterText == null)
- {
- filterText = create();
- context.getExternalContext().getApplicationMap().put(CONTEXT_KEY, filterText);
- }
-
- return filterText;
- }
-
- /**
- * gets the filtered content of the resource pointing to with <code>path</code>
- *
- * This will <b>not</b> filter the resource if its not already done before.
- */
- public ResourceInfo getFilteredResource(String path)
- {
- ResourceInfo filteredResource = (ResourceInfo) filteredResources.get(path);
- if (filteredResource == null)
- {
- return null;
- }
-
- return filteredResource;
- }
-
- /**
- * <p>
- * filteres the resource
- * </p>
- *
- * Notice: This method is not synchronized for performance reasons (the map is)
- * the worst case is that we filter a resource twice the first time wich is not
- * a problem
- */
- public ResourceInfo getOrCreateFilteredResource(FacesContext context, String path) throws IOException
- {
- if (path.startsWith("/"))
- {
- // the resource loader do not use the leading "/", so strip it here
- path = path.substring(1);
- }
-
- ResourceInfo filteredResource = getFilteredResource(path);
- if (filteredResource != null)
- {
- return filteredResource;
- }
-
- //Tomcat ASF Bugzilla Bug 43241
- //ServletContext.getResourceAsStream() does not follow API spec
- //ALL resources must start with '/'
- String text = RendererUtils.loadResourceFile(context,'/' + path);
- if (text == null)
- {
- // avoid loading the errorneous resource over and over again
- text = "";
- }
-
- StringWriter stringWriter = new StringWriter();
- PrintWriter writer = new PrintWriter(stringWriter);
- BufferedReader reader = null;
- try
- {
- reader = new BufferedReader(new StringReader(text.toString()));
-
- String line;
- while ((line = reader.readLine()) != null)
- {
- int pos = line.indexOf("#{");
- if (pos > -1 && line.indexOf("}", pos) > -1)
- {
- line = RendererUtils.getStringValue(context, context.getApplication().createValueBinding(line));
- }
-
- if (line != null)
- {
- writer.println(line);
- }
- }
- }
- finally
- {
- if (reader != null)
- {
- try
- {
- reader.close();
- }
- catch (IOException e)
- {
- log.warn(e.getLocalizedMessage(), e);
- }
- }
+ public static class ResourceInfo
+ {
+ private final long lastModified;
+ private final String text;
+
+ protected ResourceInfo(long lastModified, String text)
+ {
+ this.lastModified = lastModified;
+ this.text = text;
+ }
+
+ public long getLastModified()
+ {
+ return lastModified;
+ }
+
+ public String getText()
+ {
+ return text;
+ }
+
+ public int getSize()
+ {
+ return text.length();
+ }
+ }
+
+ protected TextResourceFilter()
+ {
+ }
+
+ protected static TextResourceFilter create()
+ {
+ return new TextResourceFilter();
+ }
+
+ /**
+ * get the application stylesheet filter
+ */
+ public static TextResourceFilter getInstance(ServletContext context)
+ {
+ TextResourceFilter filterText = (TextResourceFilter) context.getAttribute(CONTEXT_KEY);
+ if (filterText == null)
+ {
+ filterText = create();
+ context.setAttribute(CONTEXT_KEY, filterText);
+ }
+
+ return filterText;
+ }
+
+ /**
+ * get the application stylesheet filter
+ */
+ public static TextResourceFilter getInstance(FacesContext context)
+ {
+ TextResourceFilter filterText = (TextResourceFilter) context.getExternalContext().getApplicationMap().get(CONTEXT_KEY);
+ if (filterText == null)
+ {
+ filterText = create();
+ context.getExternalContext().getApplicationMap().put(CONTEXT_KEY, filterText);
+ }
+
+ return filterText;
+ }
+
+ /**
+ * gets the filtered content of the resource pointing to with <code>path</code>
+ *
+ * This will <b>not</b> filter the resource if its not already done before.
+ */
+ public ResourceInfo getFilteredResource(String path)
+ {
+ ResourceInfo filteredResource = (ResourceInfo) filteredResources.get(path);
+ if (filteredResource == null)
+ {
+ return null;
+ }
+
+ return filteredResource;
+ }
+
+ /**
+ * <p>
+ * filteres the resource
+ * </p>
+ *
+ * Notice: This method is not synchronized for performance reasons (the map is)
+ * the worst case is that we filter a resource twice the first time wich is not
+ * a problem
+ */
+ public ResourceInfo getOrCreateFilteredResource(FacesContext context, String path) throws IOException
+ {
+ if (path.startsWith("/"))
+ {
+ // the resource loader do not use the leading "/", so strip it here
+ path = path.substring(1);
+ }
+
+ ResourceInfo filteredResource = getFilteredResource(path);
+ if (filteredResource != null)
+ {
+ return filteredResource;
+ }
+
+ //Tomcat ASF Bugzilla � Bug 43241
+ //ServletContext.getResourceAsStream() does not follow API spec
+ //ALL resources must start with '/'
+ String text = RendererUtils.loadResourceFile(context,'/' + path);
+ if (text == null)
+ {
+ // avoid loading the errorneous resource over and over again
+ text = "";
+ }
+
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter writer = new PrintWriter(stringWriter);
+ BufferedReader reader = null;
+ try
+ {
+ reader = new BufferedReader(new StringReader(text.toString()));
+
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ int pos = line.indexOf("#{");
+ if (pos > -1 && line.indexOf("}", pos) > -1)
+ {
+ line = RendererUtils.getStringValue(context, context.getApplication().createValueBinding(line));
+ }
+
+ if (line != null)
+ {
+ writer.println(line);
+ }
+ }
+ }
+ finally
+ {
+ if (reader != null)
+ {
+ try
+ {
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ log.warn(e.getLocalizedMessage(), e);
+ }
+ }
- writer.close();
- }
+ writer.close();
+ }
- filteredResource = new ResourceInfo(System.currentTimeMillis(), stringWriter.toString());
- filteredResources.put(path, filteredResource);
+ filteredResource = new ResourceInfo(System.currentTimeMillis(), stringWriter.toString());
+ filteredResources.put(path, filteredResource);
- return filteredResource;
- }
+ return filteredResource;
+ }
}
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilterProvider.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilterProvider.java?rev=670515&r1=670514&r2=670515&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilterProvider.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/TextResourceFilterProvider.java Mon Jun 23 03:56:44 2008
@@ -30,31 +30,31 @@
*/
public class TextResourceFilterProvider implements ResourceProvider
{
- public boolean exists(ServletContext context, String resource)
- {
- return TextResourceFilter.getInstance(context).getFilteredResource(resource) != null;
- }
+ public boolean exists(ServletContext context, String resource)
+ {
+ return TextResourceFilter.getInstance(context).getFilteredResource(resource) != null;
+ }
- public int getContentLength(ServletContext context, String resource) throws IOException
- {
- return TextResourceFilter.getInstance(context).getFilteredResource(resource).getSize();
- }
+ public int getContentLength(ServletContext context, String resource) throws IOException
+ {
+ return TextResourceFilter.getInstance(context).getFilteredResource(resource).getSize();
+ }
- public long getLastModified(ServletContext context, String resource) throws IOException
- {
- return TextResourceFilter.getInstance(context).getFilteredResource(resource).getLastModified();
- }
+ public long getLastModified(ServletContext context, String resource) throws IOException
+ {
+ return TextResourceFilter.getInstance(context).getFilteredResource(resource).getLastModified();
+ }
- public InputStream getInputStream(ServletContext context, String resource) throws IOException
- {
- return new ByteArrayInputStream(
- TextResourceFilter.getInstance(context).getFilteredResource(resource).getText().getBytes(
- getEncoding(context, resource)
- ));
- }
+ public InputStream getInputStream(ServletContext context, String resource) throws IOException
+ {
+ return new ByteArrayInputStream(
+ TextResourceFilter.getInstance(context).getFilteredResource(resource).getText().getBytes(
+ getEncoding(context, resource)
+ ));
+ }
- public String getEncoding(ServletContext context, String resource) throws IOException
- {
- return "UTF-8";
- }
+ public String getEncoding(ServletContext context, String resource) throws IOException
+ {
+ return "UTF-8";
+ }
}