de.viaboxx.nlstools.tasks
Class MessageBundleTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by de.viaboxx.nlstools.tasks.MessageBundleTask
All Implemented Interfaces:
Cloneable

public class MessageBundleTask
extends org.apache.tools.ant.Task

Description: Generates the interface with message constants and property files (resource bundles) from the descriptions in a xml file.


Values for:

 writeProperties = true (=.properties), false, xml (=.xml)
 writeJson = true (=compressed .js file), false, pretty (formatted .js file)
 writeInterface = true (keys + bundle name), false, small_enum, small (bundle name only), Flex (ActionScript class), smallFlex (bundle name only)
  enum (keys + bundle name + enum of all keys), small_enum (bundle name + enum of all keys)
 

This utility can generate: Properties: .properties, .xml JSON: .js SQL-Script: .sql Interface: .java

overwrite = (default false) deleteOldFiles = (default true)

debugMode = (default false) ignores translations and sets the key as label

Configuration: bundles = the XML (or Excel)-bundles input file(s), separated by ; sourcePath = to write .java interface to propertyPath = to write .properties/.xml to toCharset = (optional, default: null) the charset, e.g. UTF-8, to write properties files jsonPath = to write .js to jsonFile = null or the hard-coded json file name sqlScriptDir = to write .sql to flexLayout=true: output format is "de_DE/path/bundle.properties" (Adobe Flex directory format) flexLayout=false: output format is "path/bundle_de_DE.properties" (default, java style) preserveNewlines=true: newlines will *not* be escaped when writing properties files preserveNewlines=false: (default) newlines will be escaped when writing properties files allowedLocales: ';'-separated list of locales that should be written, all other locales will NOT be written, if empty, all locales are written.

Example:
 <taskdef name="msgbundle" classname="de.viaboxx.nlstools.tasks.MessageBundleTask">
 <classpath refid="maven.test.classpath"/>
 </taskdef>
 

<msgbundle overwrite="true" bundles="src/main/bundles/Customer.xml;../utilities/base/src/main/bundles/Common.xml" writeProperties="true" writeJson="true" jsonPath="src\main\webapp\js" jsonFile="i18n" propertyPath="src\main\webapp\WEB-INF\classes"/>

Author:
Roman Stumm

Field Summary
protected  String bundles
           
protected  String jsonFile
           
protected  String jsonPath
           
protected  String propertyPath
           
protected  String sourcePath
           
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
MessageBundleTask()
           
 
Method Summary
 void execute()
           
 String getBundles()
          the path+name of the xml files (; separated)
 String getJsonFile()
           
 String getJsonPath()
           
 String getPropertyPath()
          the root path to store the property files
 String getSqlScriptDir()
           
 String getToCharset()
           
 String getWriteInterface()
          true, false, small, Flex, smallFlex when the interface file shall be generated
 String getWriteJson()
           
 String getWriteProperties()
           
 boolean isDebugMode()
          true when the label shall be the same as the key
 boolean isFlexLayout()
           
 boolean isOverwrite()
          true when the files shall be generated, even if they are up-to-date
 boolean isPreserveNewlines()
           
protected  MBBundles loadBundles()
          read/parse XML file
 void setAllowedLocales(String allowedLocales)
           
 void setBundles(String aConfigFile)
           
 void setDebugMode(boolean debugMode)
           
 void setDeleteOldFiles(boolean aDeleteOldFiles)
          if true, delete old .properties files before generating new ones.
 void setFlexLayout(boolean flexLayout)
           
 void setJsonFile(String jsonFile)
           
 void setJsonPath(String jsonPath)
           
 void setOverwrite(boolean aOverwrite)
           
 void setPreserveNewlines(boolean preserveNewlines)
           
 void setPropertyPath(String aPropertyPath)
           
 void setSourcePath(String aSourcePath)
           
 void setSqlScriptDir(String aSqlScriptDir)
           
 void setToCharset(String toCharset)
           
 void setWriteInterface(String aWriteInterface)
           
 void setWriteJson(String writeJson)
           
 void setWriteProperties(String aWriteProperties)
           
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bundles

protected String bundles

sourcePath

protected String sourcePath

propertyPath

protected String propertyPath

jsonPath

protected String jsonPath

jsonFile

protected String jsonFile
Constructor Detail

MessageBundleTask

public MessageBundleTask()
Method Detail

getToCharset

public String getToCharset()

setToCharset

public void setToCharset(String toCharset)

getJsonPath

public String getJsonPath()

setJsonPath

public void setJsonPath(String jsonPath)

isFlexLayout

public boolean isFlexLayout()

setFlexLayout

public void setFlexLayout(boolean flexLayout)

setDeleteOldFiles

public void setDeleteOldFiles(boolean aDeleteOldFiles)
if true, delete old .properties files before generating new ones.

Parameters:
aDeleteOldFiles - - (default = true)

getWriteProperties

public String getWriteProperties()

setWriteProperties

public void setWriteProperties(String aWriteProperties)

getWriteJson

public String getWriteJson()

setWriteJson

public void setWriteJson(String writeJson)

getWriteInterface

public String getWriteInterface()
true, false, small, Flex, smallFlex when the interface file shall be generated


setWriteInterface

public void setWriteInterface(String aWriteInterface)

isOverwrite

public boolean isOverwrite()
true when the files shall be generated, even if they are up-to-date


setOverwrite

public void setOverwrite(boolean aOverwrite)

isDebugMode

public boolean isDebugMode()
true when the label shall be the same as the key


setDebugMode

public void setDebugMode(boolean debugMode)

getBundles

public String getBundles()
the path+name of the xml files (; separated)


setBundles

public void setBundles(String aConfigFile)

setSourcePath

public void setSourcePath(String aSourcePath)

getPropertyPath

public String getPropertyPath()
the root path to store the property files


setPropertyPath

public void setPropertyPath(String aPropertyPath)

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException

getJsonFile

public String getJsonFile()

setJsonFile

public void setJsonFile(String jsonFile)

loadBundles

protected MBBundles loadBundles()
                         throws Exception
read/parse XML file

Throws:
Exception

getSqlScriptDir

public String getSqlScriptDir()

setSqlScriptDir

public void setSqlScriptDir(String aSqlScriptDir)

isPreserveNewlines

public boolean isPreserveNewlines()

setPreserveNewlines

public void setPreserveNewlines(boolean preserveNewlines)

setAllowedLocales

public void setAllowedLocales(String allowedLocales)


Copyright © 2012. All Rights Reserved.