pax_global_header00006660000000000000000000000064115745113700014516gustar00rootroot0000000000000052 comment=59ef44d2c18f04c6c5f35a4d61cfde73e9f74d6b localizer-1.13/000077500000000000000000000000001157451137000134265ustar00rootroot00000000000000localizer-1.13/lib/000077500000000000000000000000001157451137000141745ustar00rootroot00000000000000localizer-1.13/lib/pom.xml000066400000000000000000000012621157451137000155120ustar00rootroot00000000000000 4.0.0 org.jvnet.localizer localizer-parent 1.13 ../pom.xml localizer Localizer junit junit 4.0 test localizer-1.13/lib/src/000077500000000000000000000000001157451137000147635ustar00rootroot00000000000000localizer-1.13/lib/src/main/000077500000000000000000000000001157451137000157075ustar00rootroot00000000000000localizer-1.13/lib/src/main/java/000077500000000000000000000000001157451137000166305ustar00rootroot00000000000000localizer-1.13/lib/src/main/java/org/000077500000000000000000000000001157451137000174175ustar00rootroot00000000000000localizer-1.13/lib/src/main/java/org/jvnet/000077500000000000000000000000001157451137000205455ustar00rootroot00000000000000localizer-1.13/lib/src/main/java/org/jvnet/localizer/000077500000000000000000000000001157451137000225315ustar00rootroot00000000000000localizer-1.13/lib/src/main/java/org/jvnet/localizer/LocaleProvider.java000066400000000000000000000050731157451137000263130ustar00rootroot00000000000000/* * The MIT License * * Copyright (c) 2007-, the localizer project contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.jvnet.localizer; import java.util.Locale; /** * Determines the locale, normally from the context. * *

* For example, in webapps, you might use the current request's Accept-Language * header, or maybe it's just an invocation to {@link Locale#getDefault()}. * *

* A single instance of {@link LocaleProvider} is maintained in this class * for the use by {@link ResourceBundleHolder}. * * @author Kohsuke Kawaguchi */ public abstract class LocaleProvider { /** * Determines the locale to be used. * * @return * must not be null. */ public abstract Locale get(); public static void setProvider(LocaleProvider p) { if(p==null) throw new IllegalArgumentException(); theInstance = p; } /** * Gets the currently installed system-wide {@link LocaleProvider}. * @return * always non-null. */ public static LocaleProvider getProvider() { return theInstance; } /** * Short for {@code getProvider().get()} */ public static Locale getLocale() { return theInstance.get(); } /** * {@link LocaleProvider} that uses {@link Locale#getDefault()}. */ public static final LocaleProvider DEFAULT = new LocaleProvider() { public Locale get() { return Locale.getDefault(); } }; private static volatile LocaleProvider theInstance = DEFAULT; } localizer-1.13/lib/src/main/java/org/jvnet/localizer/Localizable.java000066400000000000000000000054341157451137000256230ustar00rootroot00000000000000/* * The MIT License * * Copyright (c) 2007-, the localizer project contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.jvnet.localizer; import java.util.Locale; import java.text.MessageFormat; import java.io.Serializable; import java.util.MissingResourceException; import static java.util.Arrays.asList; /** * Captures the localizable string. Can be converted to a string just by * supplying a {@link Locale}. * * @author Kohsuke Kawaguchi */ public class Localizable implements Serializable { private final ResourceBundleHolder holder; private final String key; private final Serializable[] args; public Localizable(ResourceBundleHolder holder, String key, Object... args) { this.holder = holder; this.key = key; this.args = new Serializable[args.length]; for (int i = 0; i < args.length; i++) { if (args[i] instanceof Serializable) { this.args[i] = (Serializable)args[i]; } else { // MessageFormat only supports formats of "number", "date", "time" and "choice" // All of which will be formatting objects that must be Serializable // Anything else will just have it's toString() method invoked // by MessageFormat, so we'll just call toString up front. this.args[i] = args[i].toString(); } } } public String toString(Locale locale) { try { return MessageFormat.format(holder.get(locale).getString(key),args); } catch (MissingResourceException e) { throw new RuntimeException("Failed to localize key="+key+",args="+ asList(args),e); } } public String toString() { return toString(LocaleProvider.getLocale()); } } localizer-1.13/lib/src/main/java/org/jvnet/localizer/ResourceBundleHolder.java000066400000000000000000000137131157451137000274600ustar00rootroot00000000000000/* * The MIT License * * Copyright (c) 2007-, the localizer project contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.jvnet.localizer; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; import java.io.ObjectStreamException; import java.net.URL; import java.text.MessageFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.lang.ref.WeakReference; /** * Maintains {@link ResourceBundle}s per locale. * * @author Kohsuke Kawaguchi */ public final class ResourceBundleHolder implements Serializable { /** Need to cache, but not tie up a classloader refernce in cases of unloading */ private static final Map> cache = new WeakHashMap> (); /** * Gets a {@link ResourceBundleHolder} for the given class, * by utilizing a cache if possible. */ public synchronized static ResourceBundleHolder get(Class clazz) { WeakReference entry = cache.get(clazz); if (entry != null) { ResourceBundleHolder rbh = entry.get(); if (rbh != null) return rbh; } ResourceBundleHolder rbh = new ResourceBundleHolder(clazz); cache.put(clazz, new WeakReference(rbh)); return rbh; } private transient final Map bundles = new ConcurrentHashMap(); public final Class owner; /** * {@link Locale} object that corresponds to the base bundle. */ private static final Locale ROOT = new Locale(""); /** * @param owner * The name of the generated resource bundle class. * @deprecated * Use {@link #get(Class)} */ public ResourceBundleHolder(Class owner) { this.owner = owner; } /** * Work around deserialization issues. */ private Object readResolve() throws ObjectStreamException { return get(owner); } /** * Loads {@link ResourceBundle} for the locale. */ public ResourceBundle get(Locale locale) { ResourceBundle rb = bundles.get(locale); if(rb!=null) return rb; // try to update the map synchronized(this) { rb = bundles.get(locale); if(rb!=null) return rb; // turns out this is totally unsable because the getBundle method // always checks Locale.getDefault() and that wins over the bundle for the root locale. // bundles.put(locale, rb=ResourceBundle.getBundle(owner.getName(),locale,owner.getClassLoader())); Locale next = getBaseLocale(locale); String s = locale.toString(); URL res = owner.getResource(owner.getSimpleName()+(s.length()>0?'_'+s:"")+".properties"); if(res!=null) { // found property file for this locale. try { InputStream is = res.openStream(); ResourceBundleImpl bundle = new ResourceBundleImpl(is); is.close(); rb = bundle; if(next!=null) bundle.setParent(get(next)); bundles.put(locale,bundle); } catch (IOException e) { MissingResourceException x = new MissingResourceException("Unable to load resource " + res, owner.getName(), null); x.initCause(e); throw x; } } else { if(next!=null) // no matching resource, so just use the locale for the base bundles.put(locale,rb=get(next)); else throw new MissingResourceException( "No resource was found for "+owner.getName(),owner.getName(),null); } } return rb; } @Override public String toString() { return getClass().getName()+"["+owner.getName()+"]"; } static class ResourceBundleImpl extends PropertyResourceBundle { ResourceBundleImpl(InputStream stream) throws IOException { super(stream); } protected void setParent(ResourceBundle parent) { super.setParent(parent); } } /** * Returns the locale to fall back to. */ private Locale getBaseLocale(Locale l) { if (l.getVariant().length() > 0) return new Locale(l.getLanguage(), l.getCountry()); if (l.getCountry().length() > 0) return new Locale(l.getLanguage()); if (l.getLanguage().length()>0) return ROOT; return null; } /** * Formats a resource specified by the given key by using the default locale */ public String format(String key, Object... args) { return MessageFormat.format(get(LocaleProvider.getLocale()).getString(key),args); } } localizer-1.13/lib/src/test/000077500000000000000000000000001157451137000157425ustar00rootroot00000000000000localizer-1.13/lib/src/test/java/000077500000000000000000000000001157451137000166635ustar00rootroot00000000000000localizer-1.13/lib/src/test/java/foo/000077500000000000000000000000001157451137000174465ustar00rootroot00000000000000localizer-1.13/lib/src/test/java/foo/LocaleTest.java000066400000000000000000000013351157451137000223520ustar00rootroot00000000000000package foo; import junit.framework.TestCase; import java.util.Locale; import org.jvnet.localizer.ResourceBundleHolder; /** * @author Kohsuke Kawaguchi */ public class LocaleTest extends TestCase { public void test1() { Locale.setDefault(Locale.GERMANY); routineCheck(); } public void test2() { Locale.setDefault(Locale.ENGLISH); routineCheck(); } private void routineCheck() { ResourceBundleHolder h = new ResourceBundleHolder(LocaleTest.class); assertEquals("base",h.get(Locale.ENGLISH).getString("abc")); assertEquals("german",h.get(Locale.GERMANY).getString("abc")); assertEquals("german",h.get(Locale.GERMAN).getString("abc")); } } localizer-1.13/lib/src/test/resources/000077500000000000000000000000001157451137000177545ustar00rootroot00000000000000localizer-1.13/lib/src/test/resources/foo/000077500000000000000000000000001157451137000205375ustar00rootroot00000000000000localizer-1.13/lib/src/test/resources/foo/LocaleTest.properties000066400000000000000000000000101157451137000247030ustar00rootroot00000000000000abc=baselocalizer-1.13/lib/src/test/resources/foo/LocaleTest_de.properties000066400000000000000000000000121157451137000253550ustar00rootroot00000000000000abc=germanlocalizer-1.13/maven-plugin/000077500000000000000000000000001157451137000160305ustar00rootroot00000000000000localizer-1.13/maven-plugin/pom.xml000066400000000000000000000032011157451137000173410ustar00rootroot00000000000000 4.0.0 org.jvnet.localizer localizer-parent 1.13 ../pom.xml maven-localizer-plugin maven-plugin Localizer generator org.apache.maven maven-plugin-api 2.0.1 org.apache.maven maven-archiver 2.0.1 org.codehaus.plexus plexus-utils 1.0.4 org.apache.maven maven-artifact 2.0.1 org.apache.ant ant 1.7.0 com.sun.codemodel codemodel 2.1 ${project.groupId} localizer ${project.version} localizer-1.13/maven-plugin/src/000077500000000000000000000000001157451137000166175ustar00rootroot00000000000000localizer-1.13/maven-plugin/src/main/000077500000000000000000000000001157451137000175435ustar00rootroot00000000000000localizer-1.13/maven-plugin/src/main/java/000077500000000000000000000000001157451137000204645ustar00rootroot00000000000000localizer-1.13/maven-plugin/src/main/java/org/000077500000000000000000000000001157451137000212535ustar00rootroot00000000000000localizer-1.13/maven-plugin/src/main/java/org/jvnet/000077500000000000000000000000001157451137000224015ustar00rootroot00000000000000localizer-1.13/maven-plugin/src/main/java/org/jvnet/localizer/000077500000000000000000000000001157451137000243655ustar00rootroot00000000000000localizer-1.13/maven-plugin/src/main/java/org/jvnet/localizer/Generator.java000066400000000000000000000154601157451137000271640ustar00rootroot00000000000000/* * The MIT License * * Copyright (c) 2007-, the localizer project contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.jvnet.localizer; import com.sun.codemodel.JClassAlreadyExistsException; import com.sun.codemodel.JCodeModel; import com.sun.codemodel.JDefinedClass; import com.sun.codemodel.JExpr; import com.sun.codemodel.JInvocation; import com.sun.codemodel.JMethod; import com.sun.codemodel.JMod; import com.sun.codemodel.JVar; import com.sun.codemodel.CodeWriter; import com.sun.codemodel.JPackage; import com.sun.codemodel.writer.FileCodeWriter; import org.apache.tools.ant.DirectoryScanner; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.io.Writer; import java.io.PrintWriter; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; import java.util.Properties; /** * @author Kohsuke Kawaguchi */ public class Generator { private final JCodeModel cm = new JCodeModel(); private final File outputDirectory; private final Reporter reporter; public Generator(File outputDirectory, Reporter reporter) { this.outputDirectory = outputDirectory; this.reporter = reporter; } public void generate(File baseDir, DirectoryScanner ds) throws IOException { for( String relPath : ds.getIncludedFiles() ) { File f = new File(baseDir,relPath); if(!f.getName().endsWith(".properties") || f.getName().contains("_")) continue; try { generate(f,relPath); } catch (IOException e) { IOException x = new IOException("Failed to generate a class from " + f); x.initCause(e); throw x; } } } public void generate(File propertyFile, String relPath) throws IOException { String className = toClassName(relPath); // up to date check File sourceFile = new File(outputDirectory,className.replace('.','/')+".java"); if(sourceFile.exists() && sourceFile.lastModified()>propertyFile.lastModified()) { reporter.debug(sourceFile+" is up to date"); return; } // go generate one Properties props = new Properties(); FileInputStream in = new FileInputStream(propertyFile); try { props.load(in); } catch (IOException e) { in.close(); } try { JDefinedClass c = cm._class(className); c.annotate(SuppressWarnings.class).paramArray("value").param("").param("PMD"); // [RESULT] // private static final ResourceBundleHolder holder = BundleHolder.get(Messages.class); JVar holder = c.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, ResourceBundleHolder.class, "holder", cm.ref(ResourceBundleHolder.class).staticInvoke("get").arg(c.dotclass()) ); for (Entry e : props.entrySet()) { String key = e.getKey().toString(); String value = e.getValue().toString(); int n = countArgs(value); // generate the default format method List args = new ArrayList(); JMethod m = c.method(JMod.PUBLIC | JMod.STATIC, cm.ref(String.class), toJavaIdentifier(key)); for( int i=1; i<=n; i++ ) args.add(m.param(Object.class,"arg"+i)); JInvocation inv = holder.invoke("format").arg(key); for (JVar arg : args) inv.arg(arg); m.body()._return(inv); m.javadoc().add(escape(value)); // generate localizable factory args.clear(); m = c.method(JMod.PUBLIC | JMod.STATIC, cm.ref(Localizable.class), '_'+toJavaIdentifier(key)); for( int i=1; i<=n; i++ ) args.add(m.param(Object.class,"arg"+i)); inv = JExpr._new(cm.ref(Localizable.class)).arg(holder).arg(key); for (JVar arg : args) inv.arg(arg); m.body()._return(inv); m.javadoc().add(escape(value)); } } catch (JClassAlreadyExistsException e) { throw new AssertionError(e); } } private String escape(String value) { return value.replace("&","&").replace("<","<"); } /** * Counts the number of arguments. */ protected int countArgs(String formatString) { return new MessageFormat(formatString).getFormatsByArgumentIndex().length; } protected String toJavaIdentifier(String key) { // TODO: this is fairly dumb implementation return key.replace('.','_').replace('-','_').replace('/','_'); } protected String toClassName(String relPath) { relPath = relPath.substring(0,relPath.length()-".properties".length()); return relPath.replace(File.separatorChar,'.'); } public JCodeModel getCodeModel() { return cm; } public void build() throws IOException { outputDirectory.mkdirs(); cm.build(new CodeWriter() { private final CodeWriter delegate = new FileCodeWriter(outputDirectory); public Writer openSource(JPackage pkg, String fileName) throws IOException { Writer w = super.openSource(pkg, fileName); new PrintWriter(w).println("// CHECKSTYLE:OFF"); return w; } public void close() throws IOException { delegate.close(); } public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { return delegate.openBinary(pkg, fileName); } }); } } localizer-1.13/maven-plugin/src/main/java/org/jvnet/localizer/GeneratorMojo.java000066400000000000000000000100161157451137000300010ustar00rootroot00000000000000/* * The MIT License * * Copyright (c) 2007-, the localizer project contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.jvnet.localizer; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.FileSet; import java.io.File; import java.io.IOException; import java.util.List; /** * @author Kohsuke Kawaguchi * @goal generate * @phase generate-sources */ public class GeneratorMojo extends AbstractMojo { /** * The maven project. * * @parameter expression="${project}" * @required * @readonly */ protected MavenProject project; /** * The directory to place generated property files. * * @parameter default-value="${project.build.directory}/generated-sources" * @required */ protected File outputDirectory; /** * Additional file name mask like "Messages.properties" to further * restrict the resource processing. * * @parameter */ protected String fileMask; public void execute() throws MojoExecutionException, MojoFailureException { String pkg = project.getPackaging(); if(pkg!=null && pkg.equals("pom")) return; // skip POM modules Generator g = new Generator(outputDirectory, new Reporter() { public void debug(String msg) { getLog().debug(msg); } }); for(Resource res : (List)project.getResources()) { File baseDir = new File(res.getDirectory()); if(!baseDir.exists()) continue; // this happens for example when POM inherits the default resource folder but no such folder exists. FileSet fs = new FileSet(); fs.setDir(baseDir); for( String name : (List)res.getIncludes() ) fs.createInclude().setName(name); for( String name : (List)res.getExcludes() ) fs.createExclude().setName(name); for( String relPath : fs.getDirectoryScanner(new Project()).getIncludedFiles() ) { File f = new File(baseDir,relPath); if(!f.getName().endsWith(".properties") || f.getName().contains("_")) continue; if(fileMask!=null && !f.getName().equals(fileMask)) continue; try { g.generate(f,relPath); } catch (IOException e) { throw new MojoExecutionException("Failed to generate a class from "+f,e); } } } try { g.build(); } catch (IOException e) { throw new MojoExecutionException("Failed to generate source files",e); } project.addCompileSourceRoot(outputDirectory.getAbsolutePath()); } } localizer-1.13/maven-plugin/src/main/java/org/jvnet/localizer/GeneratorTask.java000066400000000000000000000041211157451137000277770ustar00rootroot00000000000000/* * The MIT License * * Copyright (c) 2007-, the localizer project contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.jvnet.localizer; import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import java.io.File; import java.io.IOException; /** * Ant task for resource generation. * * @author Kohsuke Kawaguchi */ public class GeneratorTask extends MatchingTask { /** * Source and destination. */ private File dir,todir; public void setDir(File dir) { this.dir = dir; } public void setTodir(File todir) { this.todir = todir; } public void execute() throws BuildException { Generator g = new Generator(todir,new Reporter() { public void debug(String msg) { log(msg, Project.MSG_DEBUG); } }); try { g.generate(dir,getDirectoryScanner(dir)); g.build(); } catch (IOException e) { throw new BuildException(e); } } } localizer-1.13/maven-plugin/src/main/java/org/jvnet/localizer/Reporter.java000066400000000000000000000024101157451137000270270ustar00rootroot00000000000000/* * The MIT License * * Copyright (c) 2007-, the localizer project contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.jvnet.localizer; /** * @author Kohsuke Kawaguchi */ public interface Reporter { void debug(String msg); } localizer-1.13/pom.xml000066400000000000000000000033311157451137000147430ustar00rootroot00000000000000 4.0.0 org.jvnet.localizer localizer-parent pom 1.13 Localizer parent POM lib maven-plugin scm:svn:https://svn.java.net/svn/localizer~svn/tags/localizer-parent-1.13 scm:svn:https://svn.java.net/svn/localizer~svn/tags/localizer-parent-1.13 The MIT license http://www.opensource.org/licenses/mit-license.php repo maven-compiler-plugin 1.5 1.5 maven.jenkins-ci.org http://maven.jenkins-ci.org:8081/content/repositories/releases maven.jenkins-ci.org http://maven.jenkins-ci.org:8081/content/repositories/snapshots java.net2 http://download.java.net/maven/2/ localizer-1.13/src/000077500000000000000000000000001157451137000142155ustar00rootroot00000000000000localizer-1.13/src/site/000077500000000000000000000000001157451137000151615ustar00rootroot00000000000000localizer-1.13/src/site/apt/000077500000000000000000000000001157451137000157455ustar00rootroot00000000000000localizer-1.13/src/site/apt/index.apt000066400000000000000000000066051157451137000175710ustar00rootroot00000000000000What is this? This small tool reads your property files and generate Java classes that enables type-safe access to message resources. For example, when you have a property file called <<>> that looks like this: ----------------------------------------- foo=error at {0} with {1} ----------------------------------------- this tool generates the following <<>>: ----------------------------------------- public class Messages { private final static ResourceBundleHolder holder = new ResourceBundleHolder(Messages.class); /** * error at {0} with {1} */ public static String foo(Object arg1, Object arg2) { return holder.format("foo",arg1,arg2); } /** * error at {0} with {1} */ public static Localizable _foo(Object arg1, Object arg2) { return new Localizable(holder, "foo", arg1, arg2); } } ----------------------------------------- The first method formats the message by using the default locale, and the second method returns an object that can be later formatted into <<>> by specifying Locale. In this way, you can get auto-completion on choosing the right message, you'll never refer to a non-existent message, and you'll always use the right number of arguments. How to use this? For projects built with Maven, add the following entries to your POM. For the list of configurations to the <<>>, refer to {{{#}this document}}: ----------------------------------------- ... ... org.jvnet.localizer maven-localizer-plugin generate org.jvnet.localizer localizer 1.0 ... java.net2 http://download.java.net/maven/2/ ... ----------------------------------------- For projects built with Ant, use the following task to generate source files: ----------------------------------------- ----------------------------------------- The <<>> task is a {{{http://ant.apache.org/manual/dirtasks.html}matching task}}, so you can use the usual FileSet-based filtering technique to specify the property files to be processed. Using LocaleProvider When you use methods that return <<>>, the implementation consults a singleton <<>> for determining the locale to be used. The default implementation simply returns <<>>, but in other situations (for example in web apps), you can have this method return different locales (for example by using <<>>.)localizer-1.13/src/site/site.xml000066400000000000000000000012171157451137000166500ustar00rootroot00000000000000 org.jvnet.maven-javanet-skin maven-javanet-skin 1.0

${reports} localizer-1.13/test/000077500000000000000000000000001157451137000144055ustar00rootroot00000000000000localizer-1.13/test/pom.xml000066400000000000000000000015571157451137000157320ustar00rootroot00000000000000 4.0.0 org.jvnet.localizer localizer-parent 1.4-SNAPSHOT ../pom.xml localizer-test Localizer test module org.jvnet.localizer maven-localizer-plugin generate ${project.groupId} localizer ${project.version} localizer-1.13/test/src/000077500000000000000000000000001157451137000151745ustar00rootroot00000000000000localizer-1.13/test/src/main/000077500000000000000000000000001157451137000161205ustar00rootroot00000000000000localizer-1.13/test/src/main/resources/000077500000000000000000000000001157451137000201325ustar00rootroot00000000000000localizer-1.13/test/src/main/resources/org/000077500000000000000000000000001157451137000207215ustar00rootroot00000000000000localizer-1.13/test/src/main/resources/org/jvnet/000077500000000000000000000000001157451137000220475ustar00rootroot00000000000000localizer-1.13/test/src/main/resources/org/jvnet/localizer/000077500000000000000000000000001157451137000240335ustar00rootroot00000000000000localizer-1.13/test/src/main/resources/org/jvnet/localizer/test/000077500000000000000000000000001157451137000250125ustar00rootroot00000000000000localizer-1.13/test/src/main/resources/org/jvnet/localizer/test/Messages.properties000066400000000000000000000000761157451137000307020ustar00rootroot00000000000000abc=Test message {0} and {1} def=Another message {0} ghi=*/* localizer-1.13/test/src/main/resources/org/jvnet/localizer/test/test.jpeg000066400000000000000000000000001157451137000266260ustar00rootroot00000000000000