eclipse plugin: Transform the SchemaParser's getOutput method...
...to a general utility method
This commit is contained in:
parent
a6132677d1
commit
06ae888c4f
2 changed files with 40 additions and 34 deletions
|
@ -357,40 +357,6 @@ public class SchemaParser
|
|||
return primitives_;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -80,6 +80,46 @@ public class WMLUtils
|
|||
return result.toString( );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
Loading…
Add table
Reference in a new issue