git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270685 13f79535-47bb-0310-9956-ffa450edef68master
@@ -9,6 +9,7 @@ loadprop.file.notice=Loading proeprties from {0}. | |||||
loadprop.missing-file.notice=Unable to find property file: {0}. | loadprop.missing-file.notice=Unable to find property file: {0}. | ||||
loadprop.bad-resolve.error=Unable to resolve and set property named "{0}" to value "{1}". | loadprop.bad-resolve.error=Unable to resolve and set property named "{0}" to value "{1}". | ||||
convert.bad-boolean.error=Error converting object ({0}) to Boolean. | |||||
convert.bad-byte.error=Error converting object ({0}) to Byte. | convert.bad-byte.error=Error converting object ({0}) to Byte. | ||||
convert.bad-class.error=Error converting object ({0}) to Class. | convert.bad-class.error=Error converting object ({0}) to Class. | ||||
convert.bad-double.error=Error converting object ({0}) to Double. | convert.bad-double.error=Error converting object ({0}) to Double. | ||||
@@ -0,0 +1,51 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE.txt file. | |||||
*/ | |||||
package org.apache.antlib.core; | |||||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||||
import org.apache.avalon.excalibur.i18n.Resources; | |||||
import org.apache.avalon.framework.context.Context; | |||||
import org.apache.myrmidon.converter.AbstractConverter; | |||||
import org.apache.myrmidon.converter.ConverterException; | |||||
/** | |||||
* String to boolean converter | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
*/ | |||||
public class StringToBooleanConverter | |||||
extends AbstractConverter | |||||
{ | |||||
private static final Resources REZ = | |||||
ResourceManager.getPackageResources( StringToBooleanConverter.class ); | |||||
public StringToBooleanConverter() | |||||
{ | |||||
super( String.class, Boolean.class ); | |||||
} | |||||
public Object convert( final Object object, final Context context ) | |||||
throws ConverterException | |||||
{ | |||||
final String string = (String)object; | |||||
if( string.equals( "true" ) ) | |||||
{ | |||||
return Boolean.TRUE; | |||||
} | |||||
else if( string.equals( "false" ) ) | |||||
{ | |||||
return Boolean.FALSE; | |||||
} | |||||
else | |||||
{ | |||||
final String message = REZ.getString( "convert.bad-boolean.error", object ); | |||||
throw new ConverterException( message ); | |||||
} | |||||
} | |||||
} | |||||
@@ -18,6 +18,9 @@ | |||||
<converter classname="org.apache.antlib.core.StringToFileConverter" | <converter classname="org.apache.antlib.core.StringToFileConverter" | ||||
source="java.lang.String" | source="java.lang.String" | ||||
destination="java.io.File" /> | destination="java.io.File" /> | ||||
<converter classname="org.apache.antlib.core.StringToBooleanConverter" | |||||
source="java.lang.String" | |||||
destination="java.lang.Boolean" /> | |||||
<converter classname="org.apache.antlib.core.StringToLongConverter" | <converter classname="org.apache.antlib.core.StringToLongConverter" | ||||
source="java.lang.String" | source="java.lang.String" | ||||
destination="java.lang.Long" /> | destination="java.lang.Long" /> | ||||