From f522a0a7baf7e79ed933ed7714e6c6c15c51ac0a Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Tue, 28 Aug 2001 14:57:20 +0000 Subject: [PATCH] Begin integration of i18n'ed messages. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269632 13f79535-47bb-0310-9956-ffa450edef68 --- .../aspect/DefaultAspectManager.java | 14 ++- .../components/aspect/Resources.properties | 2 + .../components/builder/ATIProjectBuilder.java | 77 ++++++++-------- .../builder/DefaultProjectBuilder.java | 92 +++++++++++++------ .../components/builder/Resources.properties | 25 +++++ 5 files changed, 142 insertions(+), 68 deletions(-) create mode 100644 proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/Resources.properties create mode 100644 proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/DefaultAspectManager.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/DefaultAspectManager.java index de94dc570..d9e76cc94 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/DefaultAspectManager.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/DefaultAspectManager.java @@ -8,6 +8,8 @@ package org.apache.myrmidon.components.aspect; import java.util.HashMap; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.parameters.Parameters; @@ -25,6 +27,9 @@ import org.apache.myrmidon.aspects.NoopAspectHandler; public class DefaultAspectManager implements AspectManager, Initializable { + private static final Resources REZ = + ResourceManager.getPackageResources( DefaultAspectManager.class ); + private HashMap m_aspectMap = new HashMap(); private AspectHandler[] m_aspects = new AspectHandler[ 0 ]; private String[] m_names = new String[ 0 ]; @@ -50,7 +55,8 @@ public class DefaultAspectManager final AspectHandler entry = (AspectHandler)m_aspectMap.remove( name ); if( null == entry ) { - throw new TaskException( "No such aspect with name '" + name + "'" ); + final String message = REZ.getString( "no.aspect", name ); + throw new TaskException( message ); } rebuildArrays(); @@ -75,7 +81,8 @@ public class DefaultAspectManager final AspectHandler handler = (AspectHandler)m_aspectMap.get( name ); if( null == handler ) { - throw new TaskException( "No such aspect with name '" + name + "'" ); + final String message = REZ.getString( "no.aspect", name ); + throw new TaskException( message ); } handler.aspectSettings( parameters, elements ); @@ -98,7 +105,8 @@ public class DefaultAspectManager public void aspectSettings( final Parameters parameters, final Configuration[] elements ) throws TaskException { - throw new UnsupportedOperationException( "Can not provide Settings to AspectManager" ); + final String message = REZ.getString( "no.settings" ); + throw new UnsupportedOperationException( message ); } public void postCreate( final Task task ) diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/Resources.properties new file mode 100644 index 000000000..ebe4ee2f8 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/Resources.properties @@ -0,0 +1,2 @@ +no.aspect=No such aspect with name {0}. +no.settings=Can not provide Settings to AspectManager. \ No newline at end of file diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ATIProjectBuilder.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ATIProjectBuilder.java index 878c7bc40..c1e3b4cb5 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ATIProjectBuilder.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/ATIProjectBuilder.java @@ -7,25 +7,27 @@ */ package org.apache.myrmidon.components.builder; -import java.net.URL; import java.io.InputStream; +import java.net.URL; import java.util.Properties; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; -import org.apache.avalon.framework.configuration.SAXConfigurationHandler; -import org.apache.avalon.framework.parameters.Parameterizable; -import org.apache.avalon.framework.parameters.Parameters; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import javax.xml.transform.TransformerFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; -import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; +import org.apache.avalon.framework.configuration.SAXConfigurationHandler; +import org.apache.avalon.framework.parameters.Parameterizable; +import org.apache.avalon.framework.parameters.Parameters; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; /** * Default implementation to construct project from a build file. @@ -36,14 +38,8 @@ public class ATIProjectBuilder extends DefaultProjectBuilder implements Parameterizable { - private final static String PARAM_EXCEPTION = - "Malformed PI: expected "; - - private final static String PARAMS_EXCEPTION = - "Malformed PI: expected "; - - private final static String STYLE_EXCEPTION = - "Malformed PI: expected "; + private static final Resources REZ = + ResourceManager.getPackageResources( ATIProjectBuilder.class ); private Parameters m_parameters; private URL m_systemID; @@ -82,12 +78,12 @@ public class ATIProjectBuilder if( target.equals( "xsl-param" ) ) handleParameter( data ); else if( target.equals( "xsl-params" ) ) handleParameters( data, sourceID ); - else if( target.equals( "xsl-stylesheet" ) ) + else if( target.equals( "xsl-stylesheet" ) ) { if( null != transformer ) { - throw new SAXException( "Build file can not contain " + - "two xsl-stylesheet PIs" ); + final String message = REZ.getString( "ati.two.stylesheet.pis" ); + throw new SAXException( message ); } final TransformerFactory factory = TransformerFactory.newInstance(); @@ -113,9 +109,9 @@ public class ATIProjectBuilder final SAXResult result = new SAXResult( handler ); transformer.transform( new StreamSource( sourceID.toString() ), result ); - //transformer.transform( new StreamSource( sourceID.toString() ), + //transformer.transform( new StreamSource( sourceID.toString() ), //new StreamResult( System.out ) ); - } + } } private void handleParameter( final String data ) @@ -124,22 +120,25 @@ public class ATIProjectBuilder int index = data.indexOf( '\"' ); if( -1 == index ) { - throw new SAXException( PARAM_EXCEPTION ); + final String message = REZ.getString( "ati.param.error" ); + throw new SAXException( message ); } index = data.indexOf( '\"', index + 1 ); if( -1 == index ) { - throw new SAXException( PARAM_EXCEPTION ); + final String message = REZ.getString( "ati.param.error" ); + throw new SAXException( message ); } //split between two "attributes" occurs on index final String[] name = parseAttribute( data.substring( 0, index + 1 ) ); final String[] value = parseAttribute( data.substring( index + 1 ).trim() ); - + if( !name[ 0 ].equals( "name" ) || !value[ 0 ].equals( "value" ) ) { - throw new SAXException( PARAM_EXCEPTION ); + final String message = REZ.getString( "ati.param.error" ); + throw new SAXException( message ); } m_parameters.setParameter( name[ 1 ], value[ 1 ] ); @@ -151,7 +150,8 @@ public class ATIProjectBuilder final String[] params = parseAttribute( data ); if( !params[ 0 ].equals( "location" ) ) { - throw new SAXException( PARAMS_EXCEPTION ); + final String message = REZ.getString( "ati.params.error" ); + throw new SAXException( message ); } try @@ -165,7 +165,8 @@ public class ATIProjectBuilder } catch( final Exception e ) { - throw new SAXException( "Error loading parameters: " + e ); + final String message = REZ.getString( "ati.loading-params.error", params[ 1 ], e ); + throw new SAXException( message ); } } @@ -175,14 +176,16 @@ public class ATIProjectBuilder final String[] stylesheet = parseAttribute( data ); if( !stylesheet[ 0 ].equals( "href" ) ) { - throw new SAXException( STYLE_EXCEPTION ); + final String message = REZ.getString( "ati.style.error" ); + throw new SAXException( message ); } try { return new URL( baseSource, stylesheet[ 1 ] ).toString(); } catch( final Exception e ) { - throw new SAXException( "Error locating stylesheet '" + stylesheet[ 1 ] + - "' due to " + e ); + final String message = + REZ.getString( "ati.loading-style.error", stylesheet[ 1 ], e ); + throw new SAXException( message ); } } @@ -193,20 +196,20 @@ public class ATIProjectBuilder int index = data.indexOf( '=' ); if( -1 == index ) { - throw new SAXException( "Expecting an attribute but received '" + - data + "'" ); + final String message = REZ.getString( "ati.attribue-expected.error", data ); + throw new SAXException( message ); } final int size = data.length(); - if( '\"' != data.charAt( index + 1 ) || + if( '\"' != data.charAt( index + 1 ) || '\"' != data.charAt( size - 1 ) || size - 1 == index ) { - throw new SAXException( "Expecting the value of attribute " + - data.substring( 0, index ) + - " to be enclosed in quotes" ); + final String message = + REZ.getString( "ati.attribue-unquoted.error", data.substring( 0, index ) ); + throw new SAXException( message ); } - + final String[] result = new String[ 2 ]; result[ 0 ] = data.substring( 0, index ); result[ 1 ] = data.substring( index + 2, size - 1 ); diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java index 2464b106f..9e3055c4c 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/DefaultProjectBuilder.java @@ -29,6 +29,8 @@ import org.apache.myrmidon.components.model.Project; import org.apache.myrmidon.components.model.Target; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; +import org.apache.avalon.excalibur.i18n.ResourceManager; +import org.apache.avalon.excalibur.i18n.Resources; /** * Default implementation to construct project from a build file. @@ -39,6 +41,9 @@ public class DefaultProjectBuilder extends AbstractLoggable implements ProjectBuilder { + private static final Resources REZ = + ResourceManager.getPackageResources( DefaultProjectBuilder.class ); + private final static int PROJECT_REFERENCES = 0; private final static int LIBRARY_IMPORTS = 1; private final static int IMPLICIT_TASKS = 2; @@ -117,7 +122,8 @@ public class DefaultProjectBuilder { if( !configuration.getName().equals( "project" ) ) { - throw new Exception( "Project file must be enclosed in project element" ); + final String message = REZ.getString( "ant.no-project-element.error" ); + throw new Exception( message ); } //get project-level attributes @@ -129,7 +135,11 @@ public class DefaultProjectBuilder final File baseDirectory = (new File( file.getParentFile(), baseDirectoryName )).getAbsoluteFile(); - getLogger().debug( "Project " + file + " base directory: " + baseDirectory ); + if( getLogger().isDebugEnabled() ) + { + final String message = REZ.getString( "ant.project-banner.notice", file, baseDirectory ); + getLogger().debug( message ); + } //create project and ... final DefaultProject project = new DefaultProject(); @@ -205,9 +215,9 @@ public class DefaultProjectBuilder if( name.equals( "target" ) ) buildTarget( project, element ); else { - throw new Exception( "Unknown top-level element " + name + - " at " + element.getLocation() + - ". Expecting target" ); + final String message = + REZ.getString( "ant.unknown-toplevel-element.error", name, element.getLocation() ); + throw new Exception( message ); } } @@ -228,20 +238,23 @@ public class DefaultProjectBuilder if( null == name ) { - throw new Exception( "Malformed projectref without a name attribute at " + - element.getLocation() ); + final String message = + REZ.getString( "ant.projectref-no-name.error", element.getLocation() ); + throw new Exception( message ); } if( !validName( name ) ) { - throw new Exception( "Projectref with an invalid name attribute at " + - element.getLocation() ); + final String message = + REZ.getString( "ant.projectref-bad-name.error", element.getLocation() ); + throw new Exception( message ); } if( null == location ) { - throw new Exception( "Malformed projectref without a location attribute at " + - element.getLocation() ); + final String message = + REZ.getString( "ant.projectref-no-location.error", element.getLocation() ); + throw new Exception( message ); } final File baseDirectory = project.getBaseDirectory(); @@ -270,17 +283,18 @@ public class DefaultProjectBuilder if( null == library ) { - throw new Exception( "Malformed import without a library attribute at " + - element.getLocation() ); + final String message = + REZ.getString( "ant.import-no-library.error", element.getLocation() ); + throw new Exception( message ); } if( null == name || null == type ) { if( null != name || null != type ) { - throw new Exception( "Malformed import at " + element.getLocation() + - ". If name or type attribute is specified, both " + - "attributes must be specified." ); + final String message = + REZ.getString( "ant.import-malformed.error", element.getLocation() ); + throw new Exception( message ); } } @@ -303,34 +317,49 @@ public class DefaultProjectBuilder if( null == name ) { - throw new Exception( "Discovered un-named target at " + - target.getLocation() ); + final String message = + REZ.getString( "ant.target-noname.error", target.getLocation() ); + throw new Exception( message ); } if( !validName( name ) ) { - throw new Exception( "Target with an invalid name at " + - target.getLocation() ); + final String message = + REZ.getString( "ant.target-bad-name.error", target.getLocation() ); + throw new Exception( message ); } - getLogger().debug( "Parsing target: " + name ); + if( getLogger().isDebugEnabled() ) + { + final String message = REZ.getString( "ant.target-parse.notice", name ); + getLogger().debug( message ); + } if( null != ifCondition && null != unlessCondition ) { - throw new Exception( "Discovered invalid target that has both a if and " + - "unless condition at " + target.getLocation() ); + final String message = + REZ.getString( "ant.target-bad-logic.error", target.getLocation() ); + throw new Exception( message ); } Condition condition = null; if( null != ifCondition ) { - getLogger().debug( "Target if condition: " + ifCondition ); + if( getLogger().isDebugEnabled() ) + { + final String message = REZ.getString( "ant.target-if.notice", ifCondition ); + getLogger().debug( message ); + } condition = new Condition( true, ifCondition ); } else if( null != unlessCondition ) { - getLogger().debug( "Target unless condition: " + unlessCondition ); + if( getLogger().isDebugEnabled() ) + { + final String message = REZ.getString( "ant.target-unless.notice", unlessCondition ); + getLogger().debug( message ); + } condition = new Condition( false, unlessCondition ); } @@ -348,11 +377,18 @@ public class DefaultProjectBuilder if( 0 == dependency.length() ) { - throw new Exception( "Discovered empty dependency in target " + - target.getName() + " at " + target.getLocation() ); + final String message = REZ.getString( "ant.target-bad-dependency.error", + target.getName(), + target.getLocation() ); + throw new Exception( message ); } - getLogger().debug( "Target dependency: " + dependency ); + if( getLogger().isDebugEnabled() ) + { + final String message = REZ.getString( "ant.target-dependency.notice", dependency ); + getLogger().debug( message ); + } + dependsList.add( dependency ); } diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties new file mode 100644 index 000000000..70b141a6f --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/builder/Resources.properties @@ -0,0 +1,25 @@ +ati.two.stylesheet.pis=Build file can not contain two xsl-stylesheet PIs. +ati.params.error=Malformed PI: expected +ati.param.error=Malformed PI: expected +ati.style.error=Malformed PI: expected +ati.loading-params.error=Error loading parameters {0}. Reason: {1}. +ati.loading-style.error=Error locating stylesheet {0}. Reason: {1}. +ati.attribue-expected.error=Expecting an attribute but received {0}. +ati.attribue-unquoted.error=Expecting the value of attribute {0} to be enclosed in quotes. + +ant.project-banner.notice=Project {0} base directory: {1}. +ant.target-parse.notice=Parsing target: {0}. +ant.target-if.notice=Target if condition: {0} +ant.target- unless.notice=Target unless condition: {0} +ant.target-dependency.notice=Target dependency: {0} +ant.no-project-element.error=Project file must be enclosed in project element. +ant.unknown-toplevel-element.error=Unknown top-level element {0} at {1}. +ant.projectref-no-name.error=Malformed projectref without a name attribute at {0}. +ant.projectref-bad-name.error=Projectref with an invalid name attribute at {0}. +ant.projectref-no-location.error=Malformed projectref without a location attribute at {0}. +ant.import-no-library.error=Malformed import without a library attribute at {0}. +ant.import-malformed.error=Malformed import at {0}. If name or type attribute is specified, both attributes must be specified. +ant.target-noname.error=Discovered un-named target at {0}. +ant.target-bad-name.error=Target with an invalid name at {0}. +ant.target-bad-logic.error=Discovered invalid target that has both a if and unless condition at {0}. +ant.target-bad-dependency.error=Discovered empty dependency in target {0} at {1}. \ No newline at end of file