[seam-commits] Seam SVN: r8316 - in trunk/ui/src/main/java/org/jboss/seam/ui: component/html and 1 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Jun 2 06:50:09 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-06-02 06:50:09 -0400 (Mon, 02 Jun 2008)
New Revision: 8316

Removed:
   trunk/ui/src/main/java/org/jboss/seam/ui/component/UILoadStyle.java
   trunk/ui/src/main/java/org/jboss/seam/ui/component/html/HtmlLoadStyle.java
   trunk/ui/src/main/java/org/jboss/seam/ui/resource/SafeStyleResources.java
   trunk/ui/src/main/java/org/jboss/seam/ui/resource/StyleResource.java
Log:
JBSEAM-2496

Deleted: trunk/ui/src/main/java/org/jboss/seam/ui/component/UILoadStyle.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/component/UILoadStyle.java	2008-06-02 10:47:51 UTC (rev 8315)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/component/UILoadStyle.java	2008-06-02 10:50:09 UTC (rev 8316)
@@ -1,84 +0,0 @@
-package org.jboss.seam.ui.component;
-
-import java.io.UnsupportedEncodingException;
-
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIParameter;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.component.html.HtmlLoadStyle;
-import org.jboss.seam.navigation.Pages;
-import org.jboss.seam.ui.resource.SafeStyleResources;
-import org.jboss.seam.ui.resource.StyleResource;
-import org.jboss.seam.ui.util.UrlBuilder;
-import org.jboss.seam.util.Reflections;
-
-public abstract class UILoadStyle extends HtmlLoadStyle
-{
-
-   @Override
-   public Object getSrc()
-   {
-
-      UIConversationId uiConversationId = UIConversationId.newInstance();
-      uiConversationId.setViewId(Pages.getViewId(getFacesContext()));
-      String src = super.getSrc() != null ? super.getSrc().toString() : null;
-      SafeStyleResources.instance().addSafeStyleResource(src);
-      try
-      {
-         UrlBuilder urlBuilder = new UrlBuilder(StyleResource.WEB_RESOURCE_PATH + src, null, FacesContext.getCurrentInstance().getResponseWriter().getCharacterEncoding());
-         urlBuilder.addParameter(uiConversationId);
-         if (isIsolated())
-         {
-            UIComponent namingContainer = getParentNamingContainer(this);
-            if (namingContainer != null)
-            {
-               UIParameter idPrefix = new UIParameter();
-               idPrefix.setName("idPrefix");
-               urlBuilder.addParameter("idPrefix", namingContainer.getClientId(getFacesContext()));
-            }
-         }
-         return urlBuilder.getEncodedUrl(); 
-      }
-      catch (UnsupportedEncodingException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-   
-   public abstract boolean isIsolated();
-   
-   
-   public abstract void setIsolated(boolean isolated);
-   
-   
-   private UIComponent getParentNamingContainer(UIComponent cmp)
-   {
-      if (cmp == null)
-      {
-         return null;
-      }
-      else if (cmp instanceof NamingContainer)
-      {
-         return cmp;
-      }
-      else
-      {
-         return getParentNamingContainer(cmp.getParent());
-      }
-   }
-   
-   public static UILoadStyle newInstance() {
-      // Avoid runtime dep on a4j
-      try
-      {
-         return (UILoadStyle) Reflections.classForName("org.jboss.seam.ui.component.html.HtmlLoadStyle").newInstance();
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException("Error loading UILoadStyle");
-      }
-   }
-
-}
\ No newline at end of file

Deleted: trunk/ui/src/main/java/org/jboss/seam/ui/component/html/HtmlLoadStyle.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/component/html/HtmlLoadStyle.java	2008-06-02 10:47:51 UTC (rev 8315)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/component/html/HtmlLoadStyle.java	2008-06-02 10:50:09 UTC (rev 8316)
@@ -1,108 +0,0 @@
-/**
- * GENERATED FILE - DO NOT EDIT
- *
- */
-
-package org.jboss.seam.ui.component.html;
-
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
-
-/**
- * Component-Type org.jboss.seam.ui.LoadStyle
- * Component-Family org.ajax4jsf.LoadStyle
-  	 * Add a stylesheet to the <head> of the page.  Any EL in the CSS will be resolved.
- */
- public class HtmlLoadStyle extends org.jboss.seam.ui.component.UILoadStyle {
-
-  public static final String COMPONENT_TYPE = "org.jboss.seam.ui.LoadStyle";
-
-  /**
-   *  Constructor to init default renderers 
-   */ 
-  public HtmlLoadStyle (){
-  	  }
-
-// Component properties fields
- 	/**
-	 * isolated
-	 * If isolated, any references to html ids will be resolved only within
-			this naming container
-	 */
-	 	 private boolean  _isolated = false;		
-	/**
-	 * Flag indicated what isolated is set.
-	 */
-	 private boolean _isolatedSet = false;	
-	 	     
-// Getters-setters
-    /**
-	 * If isolated, any references to html ids will be resolved only within
-			this naming container
-	 * Setter for isolated
-	 * @param __isolated - new value
-	 */
-	 @Override
-	 public void setIsolated( boolean  __isolated ){
-		this._isolated = __isolated;
-	 		this._isolatedSet = true;
-	 	 }
-
-
-   /**
-	 * If isolated, any references to html ids will be resolved only within
-			this naming container
-	 * Getter for isolated
-	 * @return isolated value from local variable or value bindings
-	 */
-	 @Override
-	 public boolean isIsolated(  ){
-	 		 if(this._isolatedSet){
-			return this._isolated;
-		 }
-    	ValueBinding vb = getValueBinding("isolated");
-    	if (vb != null) {
-    	    Boolean value = (Boolean) vb.getValue(getFacesContext());
-    	    if (null == value) {
-    			return this._isolated;
-    	    }
-    	    return (value.booleanValue());
-    	} else {
-    	    return (this._isolated);
-    	}
-	 	 }
-	      
-// Component family.
-	public static final String COMPONENT_FAMILY = "org.ajax4jsf.LoadStyle";
-
-	@Override
-	public String getFamily() {
-		return COMPONENT_FAMILY;
-	}
-
-// Save state
-// ----------------------------------------------------- StateHolder Methods
-
-	@Override
-   public Object saveState(FacesContext context) {
-        Object values[] = new Object[3];
-        values[0] = super.saveState(context);
- 	        values[1] = new Boolean(_isolated);
-	   	   values[2] = Boolean.valueOf(_isolatedSet);	
-	   	 	
-     	  return values;
-   }
-   
-   @Override
-   public void restoreState(FacesContext context, Object state) {
-        Object values[] = (Object[]) state;
-        super.restoreState(context, values[0]);
- 	        _isolated = ((Boolean)values[1]).booleanValue();
-	   	   _isolatedSet = ((Boolean)values[2]).booleanValue();	
-	   	 	
-     	
-		
-	}	
-// Utilites
-
-}
\ No newline at end of file

Deleted: trunk/ui/src/main/java/org/jboss/seam/ui/resource/SafeStyleResources.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/resource/SafeStyleResources.java	2008-06-02 10:47:51 UTC (rev 8315)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/resource/SafeStyleResources.java	2008-06-02 10:50:09 UTC (rev 8316)
@@ -1,51 +0,0 @@
-package org.jboss.seam.ui.resource;
-
-import static org.jboss.seam.ScopeType.APPLICATION;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.seam.Component;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-
- at Scope(APPLICATION)
- at Name("org.jboss.seam.ui.resource.safeStyleResources")
- at BypassInterceptors
- at Install(precedence = BUILT_IN)
-public class SafeStyleResources
-{
-
-   private Set<String> safeStyleResources = new HashSet<String>();
-   
-   public void addSafeStyleResource(String path)
-   {
-      this.safeStyleResources.add(path);
-   }
-   
-   public boolean isStyleResourceSafe(String path)
-   {
-      if (safeStyleResources.contains(path))
-      {
-         return true;
-      }
-      else
-      {
-         return false;
-      }
-   }
-   
-   public static SafeStyleResources instance()
-   {
-      if ( !Contexts.isApplicationContextActive() )
-      {
-         throw new IllegalStateException("No active application context");
-      }
-      return (SafeStyleResources) (Component.getInstance(SafeStyleResources.class));
-   }
-   
-}

Deleted: trunk/ui/src/main/java/org/jboss/seam/ui/resource/StyleResource.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/resource/StyleResource.java	2008-06-02 10:47:51 UTC (rev 8315)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/resource/StyleResource.java	2008-06-02 10:50:09 UTC (rev 8316)
@@ -1,160 +0,0 @@
-package org.jboss.seam.ui.resource;
-
-import static org.jboss.seam.ScopeType.APPLICATION;
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.core.Expressions;
-import org.jboss.seam.log.Log;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-import org.jboss.seam.servlet.ContextualHttpServletRequest;
-import org.jboss.seam.util.Resources;
-import org.jboss.seam.web.AbstractResource;
-
-/**
- * Serve up stylesheets which are have been run through the EL Interpolator.
- * 
- * @author pmuir
- * 
- */
- at Scope(APPLICATION)
- at Name("org.jboss.seam.ui.resource.styleResource")
- at Install(precedence = BUILT_IN)
- at BypassInterceptors
-public class StyleResource extends AbstractResource
-{
-   
-   private LogProvider log = Logging.getLogProvider(StyleResource.class);
-
-   private static final Pattern EL_PATTERN = Pattern.compile("#" + Pattern.quote("{") + "(.*)"
-            + Pattern.quote("}"));
-   
-   private static final Pattern ID_PATTERN = Pattern.compile("#([A-Za-z][A-Za-z0-9\\-\\_\\:\\.]*)");
-
-   public static final String WEB_RESOURCE_PATH = "/seam/resource/style";
-
-   private static final String RESOURCE_PATH = "/style";
-
-   @Override
-   public void getResource(final HttpServletRequest request, final HttpServletResponse response)
-      throws ServletException, IOException
-   {
-
-      new ContextualHttpServletRequest(request)
-      {
-         @Override
-         public void process() throws IOException 
-         {
-            doWork(request, response);
-         }
-      }.run();
-      
-   }  
-   
-   public void doWork(HttpServletRequest request, HttpServletResponse response)
-            throws IOException
-   {
-      String pathInfo = request.getPathInfo().substring(getResourcePath().length());
-      if (!SafeStyleResources.instance().isStyleResourceSafe(pathInfo))
-      {
-         log.warn(pathInfo + " isn't recognized as a valid stylesheet");
-         response.sendError(HttpServletResponse.SC_NOT_FOUND);
-         return;
-      }
-      InputStream in = Resources.getResourceAsStream( pathInfo, getServletContext() );
-
-      if (in != null)
-      {           
-         CharSequence css = readFile(in);
-         css = parseEL(css);
-         String idPrefix = request.getParameter("idPrefix");
-         css = addIdPrefix(idPrefix, css);
-         response.getWriter().write(css.toString());
-         response.getWriter().flush();
-      }
-      else
-      {
-         response.sendError(HttpServletResponse.SC_NOT_FOUND);
-      }
-
-   }
-
-   // Resolve any EL value binding expression present in CSS
-   // This should be Interpolator.interpolate, but it seems to break on CSS
-   private CharSequence parseEL(CharSequence string)
-   {
-      StringBuffer parsed = new StringBuffer(string.length());
-      Matcher matcher =
-          EL_PATTERN.matcher(string);
-
-      while (matcher.find()) 
-      {
-          String result = Expressions.instance().createValueExpression("#{"+matcher.group(1)+"}", String.class).getValue();
-          if (result != null) 
-          {
-              matcher.appendReplacement(parsed, result);
-          } 
-          else 
-          {
-              matcher.appendReplacement(parsed, "");
-          }
-      }
-      matcher.appendTail(parsed);
-      return parsed;
-   }
-   
-   private CharSequence readFile(InputStream inputStream) throws IOException
-   {
-      BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-      StringBuilder css = new StringBuilder();
-      String line;
-      while ((line = reader.readLine()) != null)
-      {
-         css.append(line);
-         css.append("\n");
-      }
-      inputStream.close();
-      return css;
-   }
-   
-   private CharSequence addIdPrefix(String idPrefix, CharSequence string)
-   {
-      StringBuffer parsed = new StringBuffer(string.length());
-      if (idPrefix != null)
-      {
-         Matcher matcher = ID_PATTERN.matcher(string);
-         while (matcher.find()) {
-            String result = "#" + idPrefix + ":" + matcher.group(1);
-            matcher.appendReplacement(parsed, result);
-        }
-        matcher.appendTail(parsed);
-        return parsed;
-      }
-      else
-      {
-         return string;
-      }
-   }
-
-   @Override
-   public String getResourcePath()
-   {
-      return RESOURCE_PATH;
-   }
-
-}




More information about the seam-commits mailing list