Author: timotei
Date: Tue Jul 26 17:34:03 2011
New Revision: 50434

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50434&view=rev
Log:
eclipse plugin: Transform the SchemaParser's
getOutput method to a general utility method

Modified:
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java?rev=50434&r1=50433&r2=50434&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java 
Tue Jul 26 17:34:03 2011
@@ -358,40 +358,6 @@
        }
 
        /**
-        * Returns the 'wmlwise' output of a specified tag using the specified 
indent
-        * @param tag The tag which contents to output
-        * @param indent The indentation space
-        */
-       public String getOutput(Tag tag, int indent)
-       {
-               if (tag == null)
-                       return ""; //$NON-NLS-1$
-               StringBuilder res = new StringBuilder();
-               // tag name
-               res.append(StringUtils.multiples("\t", indent) + "[" + 
tag.getName() + "]\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-               // tag description (if any)
-               res.append(getOutput(tag.getDescription(), indent + 1));
-
-               for (TagKey key : tag.getKeyChildren())
-               {
-                       res.append(StringUtils.multiples("\t", indent) + 
//$NON-NLS-1$
-                                       "\t" + key.getName() + "=" + 
key.getValue() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-               }
-               for (Tag tmpTag : tag.getTagChildren())
-               {
-                       // skip recursive calls
-                       if (tmpTag.getTagChildren().contains(tag))
-                               continue;
-                       res.append(getOutput(tmpTag, indent + 1));
-               }
-
-               // closing tag
-               res.append(StringUtils.multiples("\t", indent) + //$NON-NLS-1$
-                               "[/" + tag.getName() + "]\n"); //$NON-NLS-1$ 
//$NON-NLS-2$
-               return res.toString();
-       }
-
-       /**
         * Returns the cardinality as a character of the specified value
         * required = 1
         * optional = ?

Modified: trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java?rev=50434&r1=50433&r2=50434&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java Tue Jul 
26 17:34:03 2011
@@ -81,6 +81,46 @@
     }
 
     /**
+     * Returns a WML string representation of the specified tag
+     * @param tag The tag to get the WML String representation for
+     * @return The string representation
+     */
+    public static String toWMLString( WMLTag tag )
+    {
+        return toWMLString( tag, "" );
+    }
+
+    private static String toWMLString( WMLTag tag, String indent )
+    {
+        StringBuilder res = new StringBuilder( );
+
+        res.append( indent + "[" + tag.getName( )  );
+        if ( ! tag.get_extendedTagName( ).isEmpty( ) )
+            res.append( ":" + tag.get_extendedTagName( ) );
+        res.append( "]\n"); //$NON-NLS-1$ //$NON-NLS-2$
+
+        for ( WMLExpression expression : tag.getExpressions( ) ) {
+            if ( expression instanceof WMLKey )
+                res.append( indent + "\t" + toWMLString( ( WMLKey ) expression 
) );
+            else if ( expression instanceof WMLTag )
+                res.append( indent + "\t" + toWMLString( ( WMLTag ) expression 
) );
+        }
+
+        res.append( indent + "[/" + tag.getEndName( )  + "]\n" );
+        return res.toString( );
+    }
+
+    /**
+     * Returns a WML string representation of the specified key
+     * @param tag The key to get the WML String representation for
+     * @return The string representation
+     */
+    public static String toWMLString( WMLKey key )
+    {
+        return key.getName( ) + "=" + getKeyValue( key.getValue( ) );
+    }
+
+    /**
      * Returns the string representation of the specified WML object
      * with the preceeding space/new lines cleaned
      * @param object A WML EObject


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to