jakarta-ecs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject cvs commit: jakarta-ecs/src/java/org/apache/ecs ConcreteElement.java
Date Mon, 30 Jul 2001 14:55:24 GMT
snagy       01/07/30 07:55:24

  Modified:    src/java/org/apache/ecs ConcreteElement.java
  Log:
  Add overloaded method to ConcreteElement.output.
  Submitted by: Tony Barrile
  Reviewed by: Stephan Nagy
  
  Revision  Changes    Path
  1.26      +62 -43    jakarta-ecs/src/java/org/apache/ecs/ConcreteElement.java
  
  Index: ConcreteElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ecs/src/java/org/apache/ecs/ConcreteElement.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ConcreteElement.java	2001/04/04 20:41:02	1.25
  +++ ConcreteElement.java	2001/07/30 14:55:24	1.26
  @@ -69,15 +69,12 @@
       This class is to be subclassed by those elements that are made up of
       other elements. i.e. BODY,HEAD,etc.
   
  -    @version $Id: ConcreteElement.java,v 1.25 2001/04/04 20:41:02 rdonkin Exp $
  +    @version $Id: ConcreteElement.java,v 1.26 2001/07/30 14:55:24 snagy Exp $
       @author <a href="mailto:snagy@servletapi.com">Stephan Nagy</a>
       @author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
   */
   public class ConcreteElement extends ElementAttributes implements Cloneable
   {
  -	/** The line separator to use for pretty printing */
  -	private static String lineSeparator = System.getProperty("line.separator");
  -
       /** @serial registry registry */
       private Hashtable registry = new Hashtable(4); // keep a list of elements that need
to be added to the element
       /** Maintain an ordered list of elements */
  @@ -280,45 +277,44 @@
       }
   
       /**
  -        Override output(OutputStream) incase any elements are in the registry.
  +        Overload output(OutputStream).
           @param output OutputStream to write to.
  +		@param ConcreteElement	Instance of ConcreteElement
       */
  -    public void output(OutputStream out)
  +    public static void output(OutputStream out, ConcreteElement ce) 
   	{
  -		boolean prettyPrint = getPrettyPrint();
  -		int tabLevel = getTabLevel();
  +		boolean prettyPrint = ce.getPrettyPrint();
  +		int tabLevel = ce.getTabLevel();
   		try
   		{
  -			if (registry.size() == 0)
  -			{
  -				if ((prettyPrint && this instanceof Printable) && (tabLevel > 0))
  -					putTabs(tabLevel, out);
  -                super.output(out);
  +			if (ce.registry.size() == 0)
  +			{	
  +				ce.output(out);
   			}
   			else
   			{
  -                if ((prettyPrint && this instanceof Printable) && (tabLevel
> 0))
  -					putTabs(tabLevel, out);
  +                if ((prettyPrint && ce instanceof Printable) && (tabLevel
> 0))
  +					ce.putTabs(tabLevel, out);
   
  -				out.write(createStartTag().getBytes());
  +				out.write(ce.createStartTag().getBytes());
   
                   // If this is a StringElement that has ChildElements still print the TagText
  -                if(getTagText() != null)
  -                    out.write(getTagText().getBytes());
  +                if(ce.getTagText() != null)
  +                    out.write(ce.getTagText().getBytes());
   
  -				Enumeration enum = registryList.elements();
  +				Enumeration enum = ce.registryList.elements();
   
   				while(enum.hasMoreElements())
   				{
  -					Object obj = registry.get((String)enum.nextElement());
  +					Object obj = ce.registry.get((String)enum.nextElement());
   					if(obj instanceof GenericElement)
   					{
   						Element e = (Element)obj;
  -						if (prettyPrint && this instanceof Printable)
  +						if (prettyPrint && ce instanceof Printable)
   						{
  -                            if ( getNeedLineBreak() )
  +                            if ( ce.getNeedLineBreak() )
                               {
  -						    	out.write(lineSeparator.getBytes());
  +						    	out.write('\n');
   							    e.setTabLevel(tabLevel + 1);
                               }
   						}
  @@ -326,30 +322,30 @@
   					}
   					else
   					{
  -						if (prettyPrint && this instanceof Printable)
  +						if (prettyPrint && ce instanceof Printable)
   						{
  -                            if ( getNeedLineBreak() )
  +                            if ( ce.getNeedLineBreak() )
                               {
  -                                out.write(lineSeparator.getBytes());
  -							    putTabs(tabLevel + 1, out);
  +                                out.write('\n');
  +							    ce.putTabs(tabLevel + 1, out);
                               }
   						}
   						String string = obj.toString();
   						out.write(string.getBytes());
   					}
   				}
  -				if (getNeedClosingTag())
  +				if (ce.getNeedClosingTag())
   				{
  - 					if (prettyPrint && this instanceof Printable)
  + 					if (prettyPrint && ce instanceof Printable)
   					{
  -                        if ( getNeedLineBreak() )
  +                        if ( ce.getNeedLineBreak() )
                           {
  -                            out.write(lineSeparator.getBytes());
  +                            out.write('\n');
                               if (tabLevel > 0)
  -                                putTabs(tabLevel, out);
  +                                ce.putTabs(tabLevel, out);
                           }
   					}
  -				   out.write(createEndTag().getBytes());
  +				   out.write(ce.createEndTag().getBytes());
   				}
   			}
   		}
  @@ -358,6 +354,34 @@
   			ioe.printStackTrace(new PrintWriter(out));
   		}
   	}
  +	
  +    /**
  +        Override output(OutputStream) incase any elements are in the registry.
  +        @param output OutputStream to write to.
  +    */
  +    public void output(OutputStream out)
  +	{
  +		if (this.registry.size() == 0)
  +		{
  +				int tabLevel = getTabLevel();
  +				if ((getPrettyPrint() && this instanceof Printable) && (tabLevel >
0))  
  +				{
  +					try 
  +					{
  +						this.putTabs(tabLevel, out);
  +					}
  +					catch(IOException ioe) 
  +					{
  +						ioe.printStackTrace(new PrintWriter(out));					
  +					}
  +				}
  +                super.output(out);
  +		} 
  +		else  
  +		{
  +			output(out,this);
  +		}
  +	}
   
       /**
           Writer version of this method.
  @@ -366,7 +390,7 @@
       {
           output ( new PrintWriter(out) );
       }
  -
  +    
       /**
           Override output(BufferedWriter) incase any elements are in the registry.
           @param output OutputStream to write to.
  @@ -402,7 +426,7 @@
   					if (prettyPrint && this instanceof Printable)
   					{
                           if (getNeedLineBreak()) {
  -							out.write(lineSeparator);
  +							out.write('\n');
   							e.setTabLevel(tabLevel + 1);
   						}
   					}
  @@ -413,7 +437,7 @@
   					if (prettyPrint && this instanceof Printable)
   					{
                           if (getNeedLineBreak()) {
  -							out.write(lineSeparator);
  +							out.write('\n');
   							putTabs(tabLevel + 1, out);
   						}
   					}
  @@ -429,7 +453,7 @@
   				if (prettyPrint && this instanceof Printable)
   				{
                       if (getNeedLineBreak()) {
  -						out.write(lineSeparator);
  +						out.write('\n');
   						if (tabLevel > 0)
   							putTabs(tabLevel, out);
   					}
  @@ -468,10 +492,5 @@
           {
               throw new InternalError(ioe.toString());
           }
  -    }
  -    
  -    public boolean isEmpty()
  -    {
  -        return registryList.isEmpty();
       }
  -}
  \ No newline at end of file
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org


Mime
View raw message