Author: ltheussl
Date: Mon May 19 05:11:53 2008
New Revision: 657808

URL: http://svn.apache.org/viewvc?rev=657808&view=rev
Log:
Write value of style AttributeSet as a css string

Modified:
    
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java
    
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/SinkUtils.java
    
maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptMarkup.java

Modified: 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java?rev=657808&r1=657807&r2=657808&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/markup/Markup.java
 Mon May 19 05:11:53 2008
@@ -73,4 +73,10 @@
 
     /** star character: '*' */
     char STAR = '*';
+
+    /** colon character: ':' */
+    char COLON = ':';
+
+    /** semicolon character: ';' */
+    char SEMICOLON = ';';
 }

Modified: 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/SinkUtils.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/SinkUtils.java?rev=657808&r1=657807&r2=657808&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/SinkUtils.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/SinkUtils.java
 Mon May 19 05:11:53 2008
@@ -27,6 +27,7 @@
 import javax.swing.text.MutableAttributeSet;
 
 import org.apache.maven.doxia.markup.Markup;
+import org.apache.maven.doxia.sink.SinkEventAttributeSet;
 
 /**
  * Collection of common utility methods for sinks.
@@ -41,6 +42,7 @@
     /** Do not instantiate. */
     private SinkUtils()
     {
+        // Utility class
     }
 
     /**
@@ -139,19 +141,19 @@
 
     static
     {
-        SINK_IMG_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, IMG_ATTRIBUTES  );
+        SINK_IMG_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, IMG_ATTRIBUTES );
         SINK_SECTION_ATTRIBUTES =
-                join( SINK_BASE_ATTRIBUTES, new String[] 
{SinkEventAttributes.ALIGN}  );
+                join( SINK_BASE_ATTRIBUTES, new String[] 
{SinkEventAttributes.ALIGN} );
         SINK_VERBATIM_ATTRIBUTES =
                 join( SINK_BASE_ATTRIBUTES,
-                new String[] {SinkEventAttributes.ALIGN, 
SinkEventAttributes.DECORATION, SinkEventAttributes.WIDTH}  );
-        SINK_HR_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, HR_ATTRIBUTES  );
-        SINK_LINK_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, LINK_ATTRIBUTES  );
-        SINK_TABLE_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, TABLE_ATTRIBUTES  
);
+                new String[] {SinkEventAttributes.ALIGN, 
SinkEventAttributes.DECORATION, SinkEventAttributes.WIDTH} );
+        SINK_HR_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, HR_ATTRIBUTES );
+        SINK_LINK_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, LINK_ATTRIBUTES );
+        SINK_TABLE_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, TABLE_ATTRIBUTES );
         SINK_TR_ATTRIBUTES =
                 join( SINK_BASE_ATTRIBUTES,
-                new String[] {SinkEventAttributes.ALIGN, 
SinkEventAttributes.BGCOLOR, SinkEventAttributes.VALIGN}  );
-        SINK_TD_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, TABLE_CELL_ATTRIBUTES 
 );
+                new String[] {SinkEventAttributes.ALIGN, 
SinkEventAttributes.BGCOLOR, SinkEventAttributes.VALIGN} );
+        SINK_TD_ATTRIBUTES = join( SINK_BASE_ATTRIBUTES, TABLE_CELL_ATTRIBUTES 
);
     }
 
     private static String[] join( String[] a, String[] b )
@@ -169,7 +171,10 @@
      * Utility method to get an AttributeSet as a String.
      * The resulting String is in the form ' name1="value1" name2="value2" 
...',
      * ie it can be appended directly to an xml start tag. Attribute values 
that are itself
-     * AttributeSets are ignored, all other keys and values are written as 
Strings.
+     * AttributeSets are ignored unless the Attribute name is 
SinkEventAttributeSet.STYLE,
+     * in which case they are written as outlined at
+     * [EMAIL PROTECTED] org.apache.maven.doxia.sink.SinkEventAttributes#STYLE 
SinkEventAttributes.STYLE}.
+     * All other keys and values are written as Strings.
      *
      * @param att The AttributeSet. May be null, in which case an empty String 
is returned.
      * @return the AttributeSet as a String in a form that can be appended to 
an xml start tag.
@@ -190,8 +195,17 @@
             Object key = names.nextElement();
             Object value = att.getAttribute( key );
 
-            // AttributeSets are ignored
-            if ( !(value instanceof AttributeSet) )
+            if ( value instanceof AttributeSet )
+            {
+                // Other AttributeSets are ignored
+                if ( SinkEventAttributeSet.STYLE.equals( key.toString() ) )
+                {
+                    sb.append( Markup.SPACE ).append( key.toString() ).append( 
Markup.EQUAL )
+                        .append( Markup.QUOTE ).append( asCssString( 
(AttributeSet) value ) )
+                        .append( Markup.QUOTE );
+                }
+            }
+            else
             {
                 sb.append( Markup.SPACE ).append( key.toString() ).append( 
Markup.EQUAL )
                     .append( Markup.QUOTE ).append( value.toString() ).append( 
Markup.QUOTE );
@@ -201,6 +215,33 @@
         return sb.toString();
     }
 
+    private static String asCssString( AttributeSet att )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        Enumeration names = att.getAttributeNames();
+
+        while ( names.hasMoreElements() )
+        {
+            Object key = names.nextElement();
+            Object value = att.getAttribute( key );
+
+            // don't go recursive
+            if ( !( value instanceof AttributeSet ) )
+            {
+                sb.append( key.toString() ).append( Markup.COLON )
+                    .append( Markup.SPACE ).append( value.toString() );
+
+                if ( names.hasMoreElements() )
+                {
+                    sb.append( Markup.SEMICOLON ).append( Markup.SPACE );
+                }
+            }
+        }
+
+        return sb.toString();
+    }
+
     /**
      * Filters the given AttributeSet.
      * Removes all attributes whose name (key) is not contained in the sorted 
array valids.

Modified: 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptMarkup.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptMarkup.java?rev=657808&r1=657807&r2=657808&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptMarkup.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptMarkup.java
 Mon May 19 05:11:53 2008
@@ -41,9 +41,6 @@
     /** APT backslash markup char: '\\' */
     char BACKSLASH = '\\';
 
-    /** colon character: ':' */
-    char COLON = ':';
-
     /** APT comment markup char: '~' */
     char COMMENT = '~';
 


Reply via email to