You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2006/06/15 09:38:21 UTC

svn commit: r414498 - /myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentClassicTagBase.java

Author: dennisbyrne
Date: Thu Jun 15 00:38:21 2006
New Revision: 414498

URL: http://svn.apache.org/viewvc?rev=414498&view=rev
Log:
implemented 8 methods

Modified:
    myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentClassicTagBase.java

Modified: myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentClassicTagBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentClassicTagBase.java?rev=414498&r1=414497&r2=414498&view=diff
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentClassicTagBase.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java/javax/faces/webapp/UIComponentClassicTagBase.java Thu Jun 15 00:38:21 2006
@@ -1,8 +1,10 @@
 package javax.faces.webapp;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
+import javax.faces.application.Application;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIOutput;
 import javax.faces.component.UIViewRoot;
@@ -41,6 +43,14 @@
     
     private String jspId;
     
+    private List<String> children ;
+    
+    private List<String> facets ;
+    
+    private boolean created ;
+    
+    private static final String VERBATIM_COMP_TYPE = "javax.faces.HtmlOutputText";
+    
     public void doInitBody() throws JspException
     {
         throw new UnsupportedOperationException("1.2");
@@ -56,52 +66,11 @@
         throw new UnsupportedOperationException("1.2");
     }
 
-    private boolean isDuplicateId(String componentId)
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    private String generateIncrementedId(String componentId)
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    protected List<String> getCreatedComponents()
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    private String createId() throws JspException
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
     public void setJspId(String id)
     {
         throw new UnsupportedOperationException("1.2");
     }
 
-    private void updatePreviousJspIdAndIteratorStatus(String id)
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    private boolean isIncludedOrForwarded()
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-    
-    private UIComponent createFacet(FacesContext context, UIComponent parent,
-            String name, String newId) throws JspException
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    private UIComponent getChild(UIComponent component, String componentId)
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
     protected UIComponent findComponent(FacesContext context)
             throws JspException
     {
@@ -114,114 +83,180 @@
         throw new UnsupportedOperationException("1.2");
     }
 
-    protected int getIndexOfNextChildTag()
-    {
-
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    protected void addChild(UIComponent child)
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    protected void addFacet(String name)
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    private void popUIComponentClassicTagBase()
+    public int doStartTag() throws JspException
     {
         throw new UnsupportedOperationException("1.2");
     }
 
-    private void pushUIComponentClassicTagBase()
+    public int doEndTag() throws JspException
     {
         throw new UnsupportedOperationException("1.2");
-
     }
 
-    private void removeOldChildren()
+    public void release()
     {
         throw new UnsupportedOperationException("1.2");
     }
 
-    private void removeOldFacets()
+    protected int getDoAfterBodyValue() throws JspException
     {
         throw new UnsupportedOperationException("1.2");
     }
 
     protected UIComponent createVerbatimComponentFromBodyContent()
     {
-        throw new UnsupportedOperationException("1.2");
+        
+        // the 'single exit point' rule made this look like perl
+        
+        if( bodyContent == null)
+            return null;
+        
+        String bodyString = bodyContent.getString();
+        
+        if( bodyString == null) // nothing
+            return null;
+        
+        bodyContent.clearBody();
+        
+        String trimmedBody = bodyString.trim();
+        
+        if( "".equals(trimmedBody) ) // whitespace
+            return null;
+        
+        if( trimmedBody.startsWith("<!--") 
+                && trimmedBody.endsWith("-->") ) // comments
+            return null;
+        
+        UIOutput output = createVerbatimComponent();
+        output.setValue(bodyString);
+        
+        return output;
+    }
+    
+    /**
+     * Helper method for addVerbatimBeforeComponent and addVerbatimAfterComponent.
+     */
+    
+    private void addVerbatimComponent(
+            UIComponentClassicTagBase parentTag, 
+            UIComponent verbatim,
+            UIComponent component, int shift){
+        
+        if( component == null )
+            throw new NullPointerException("UIComponent");
+        
+        UIComponent parent = component.getParent();
+        
+        if( parent != null ){
+            
+            List<UIComponent> brood = parent.getChildren();
+            
+            if( ! brood.contains(component) )
+                throw new IllegalStateException("Child component can find parent, but parent does not claim child ");
+            
+            brood.add(brood.indexOf(component) + shift, verbatim);
+            
+        }else if( parent == null && ! ( component instanceof UIViewRoot ) )
+            throw new NullPointerException("Could not find parent ");
+        
     }
-
-    protected UIOutput createVerbatimComponent()
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    protected void addVerbatimBeforeComponent(
+    
+    protected void addVerbatimAfterComponent(
             UIComponentClassicTagBase parentTag, UIComponent verbatim,
             UIComponent component)
     {
-        throw new UnsupportedOperationException("1.2");
+        addVerbatimComponent(parentTag, verbatim, component, 1);
     }
-
-    protected void addVerbatimAfterComponent(
+    
+    protected void addVerbatimBeforeComponent(
             UIComponentClassicTagBase parentTag, UIComponent verbatim,
             UIComponent component)
     {
-        throw new UnsupportedOperationException("1.2");
+        addVerbatimComponent(parentTag, verbatim, component, 0);
     }
-
-    public int doStartTag() throws JspException
-    {
-        throw new UnsupportedOperationException("1.2");
-    }
-
-    public int doEndTag() throws JspException
+    
+    protected UIOutput createVerbatimComponent()
     {
-        throw new UnsupportedOperationException("1.2");
+        FacesContext _ctx = getFacesContext();
+        
+        if( _ctx == null )
+            throw new NullPointerException("FacesContext");
+        
+        Application app = _ctx.getApplication();
+        
+        if( app == null )
+            throw new NullPointerException("Application");
+        
+        UIViewRoot root = _ctx.getViewRoot();
+        
+        if( root == null )
+            throw new NullPointerException("UIViewRoot");    
+        
+        UIComponent component = app.createComponent(VERBATIM_COMP_TYPE);
+        component.setTransient(false);
+        component.getAttributes().put("escape", Boolean.FALSE);
+        component.setId(root.createUniqueId());
+        
+        return (UIOutput)component;
     }
-
-    public void release()
+    
+    protected FacesContext getFacesContext()
     {
-        throw new UnsupportedOperationException("1.2");
+        return ctx != null ? ctx : FacesContext.getCurrentInstance();
     }
 
-    protected int getDoAfterBodyValue() throws JspException
+    protected String getFacetName()
     {
-        throw new UnsupportedOperationException("1.2");
+        if( parent == null || ! ( parent instanceof FacetTag ) )
+            return null;
+        else
+            return ((FacetTag)parent).getName();
     }
-
+    
     public boolean getCreated()
     {
-        throw new UnsupportedOperationException("1.2");
+        return created;
     }
-
-    protected FacesContext getFacesContext()
+    
+    protected int getIndexOfNextChildTag()
     {
-        throw new UnsupportedOperationException("1.2");
+        return getChildren().size();
     }
-
-    protected String getFacetName()
+    
+    protected List<String> getCreatedComponents()
     {
-        throw new UnsupportedOperationException("1.2");
+        return children;
     }
     
     public JspWriter getPreviousOut()
     {
-        throw new UnsupportedOperationException("1.2");
+        if( bodyContent == null)
+            throw new NullPointerException("BodyContent");
+        
+        return bodyContent.getEnclosingWriter();
+    }
+    
+    private List<String> getChildren(){
+        if( children == null)
+            children = new ArrayList<String>();
+        return children;
+    }
+    
+    protected void addChild(UIComponent child)
+    {
+        getChildren().add(child.getId());
+    }
+
+    private List<String> getFacets(){
+        if( facets == null)
+            facets = new ArrayList<String>();
+        return facets;
     }
     
-    //private UIComponent createChild(FacesContext context, UIComponent parent,
-    //        String componentId) throws JspException
-    //{
-    //    
-    //    throw new UnsupportedOperationException("1.2");
-    //
-    //}
+    protected void addFacet(String name)
+    {
+        getFacets().add(name);
+    }
     
     public void setBodyContent(BodyContent bodyContent)
     {