2
0
Fork 0

Added i18n lib and added paging on mongo and meta backends.

This commit is contained in:
Willem Cazander 2012-05-08 04:38:07 +02:00
parent fe5842768f
commit efcbdbd519
45 changed files with 1767 additions and 28 deletions

View file

@ -7,6 +7,7 @@
<relativePath>..</relativePath>
</parent>
<artifactId>vasc-lib</artifactId>
<groupId>net.forwardfire.vasc.lib</groupId>
<packaging>pom</packaging>
<name>vasc-lib</name>
<description>vasc-lib</description>

View file

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc-lib</artifactId>
<groupId>net.forwardfire.vasc</groupId>
<groupId>net.forwardfire.vasc.lib</groupId>
<version>0.3.5-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

View file

@ -0,0 +1,92 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n;
import java.util.List;
import java.util.Locale;
import net.forwardfire.vasc.lib.i18n.config.BundleConfig;
import net.forwardfire.vasc.lib.i18n.config.BundleConfigParser;
/**
* AbstractRootApplicationBundle adds the logic to auto init the MergeableResourceBundle.
*
* @author Willem Cazander
* @version 1.0 May 8, 2012
*/
abstract public class AbstractRootApplicationBundle extends MergeableResourceBundle {
private List<Locale> applicationSupportedLocales = null;
private List<BundleConfig> bundleConfigs = null;
/**
* The method needs to be implemented by the language class bundle of this.
* @return
*/
abstract public SupportedBundleLocale getSupportedBundleLocale();
/**
* @see java.util.ResourceBundle#getLocale()
*/
@Override
public Locale getLocale() {
return getSupportedBundleLocale().toLocale();
}
/**
* @see com.mbuyu.m4n.i18n.MergeableResourceBundle#init()
*/
@Override
protected void init() {
clear();
BundleConfigParser config = new BundleConfigParser();
config.parseConfig();
applicationSupportedLocales = config.getApplicationSupportedLocales();
bundleConfigs = config.getBundleConfigs();
for (BundleConfig bc:bundleConfigs) {
addBundleData(config.loadBundleConfig(bc,getLocale()));
}
}
/**
* Reloads the config and the bundles.
*/
public void reload() {
init();
}
/**
* Returns an collection of BundleConfig objects which are loaded.
* @return
*/
public List<BundleConfig> getBundleConfigs() {
return bundleConfigs;
}
/**
* @return the applicationSupportedLocales
*/
public List<Locale> getApplicationSupportedLocales() {
return applicationSupportedLocales;
}
}

View file

@ -0,0 +1,104 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Logger;
/**
* MergeableResourceBundle is an ResourceBundle which can merge different bundles into one.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class MergeableResourceBundle extends ResourceBundle {
private Logger logger = null;
private Map<String,String> bundleData = null;
/**
* Creates an new MergeableResourceBundle instance.
*/
public MergeableResourceBundle() {
logger = Logger.getLogger(MergeableResourceBundle.class.getName());
bundleData = new HashMap<String,String>(500);
init();
}
/**
* Protected init method to hook on the lazy init loading of bundles.
*/
protected void init() {
}
/**
* Protected method to clear the bundle data.
*/
protected void clear() {
logger.fine("Clearing bundle data current size: "+bundleData.size());
bundleData.clear();
}
/**
* @see java.util.ResourceBundle#handleGetObject(java.lang.String)
*/
@Override
protected Object handleGetObject(String key) {
return bundleData.get(key);
}
/**
* @see java.util.ResourceBundle#getKeys()
*/
@Override
public Enumeration<String> getKeys() {
return Collections.enumeration(bundleData.keySet());
}
/**
* Add all data from map to bundleData.
* @param dataMap
*/
public void addBundleData(Map<String,String> dataMap) {
int startSize = bundleData.size();
bundleData.putAll(dataMap);
logger.fine("Adding bundle data: "+dataMap.size()+" orgSize: "+startSize+" newSize: "+bundleData.size());
}
/**
* Add all data from ResourceBundle to bundleData.
* @param bundle
*/
public void addBundleData(ResourceBundle bundle) {
int startSize = bundleData.size();
for (String key:bundle.keySet()) {
String value = bundle.getString(key);
bundleData.put(key, value);
}
logger.fine("Adding bundle data: "+bundle.keySet().size()+" orgSize: "+startSize+" newSize: "+bundleData.size());
}
}

View file

@ -0,0 +1,73 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n;
import java.util.Locale;
/**
* SupportedBundleLocale defines all the supported locale's of the RootApplicationBundle.
*
* @author Willem Cazander
* @version 1.0 May 8, 2012
*/
public enum SupportedBundleLocale {
en,
de,
fr,
pt,
it,
ru,
nl,
es,
pl,
by,
da,
ro,
sv;
/**
* The default locale if an unsupported locale is requested.
*/
public static final SupportedBundleLocale DEFAULT_LOCALE = en;
/**
* The locale object of this language.
*/
private Locale locale = null;
/**
* Private constructor for enum.
*/
private SupportedBundleLocale() {
locale = new Locale(name());
}
/**
* The locale object of this enum language.
* @return
*/
public Locale toLocale() {
return locale;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle is the fallback if not supported locale bundle is found.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.DEFAULT_LOCALE;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_by extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.by;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_da extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.da;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_de extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.de;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_en extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.en;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_es extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.es;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_fr extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.fr;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_it extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.it;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_nl extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.nl;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_pl extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.pl;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_pt extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.pt;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_ro extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.ro;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_ru extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.ru;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.bundle;
import net.forwardfire.vasc.lib.i18n.AbstractRootApplicationBundle;
import net.forwardfire.vasc.lib.i18n.SupportedBundleLocale;
/**
* RootApplicationBundle_XX loads this language bundle.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class RootApplicationBundle_sv extends AbstractRootApplicationBundle {
@Override
public SupportedBundleLocale getSupportedBundleLocale() {
return SupportedBundleLocale.sv;
}
}

View file

@ -0,0 +1,138 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.config;
/**
* BundleConfig holds the config to load one bundle.
*
* @author Willem Cazander
* @version 1.0 May 8, 2012
*/
public class BundleConfig {
private String name = null;
private String uri = null;
private String exclude = null;
private BundleURIType uriType = BundleURIType.RESOURCE;
private BundleFormat format = BundleFormat.BUNDLE;
private boolean utf8 = true;
private boolean optional = false;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the uri
*/
public String getUri() {
return uri;
}
/**
* @param uri the uri to set
*/
public void setUri(String uri) {
this.uri = uri;
}
/**
* @return the exclude
*/
public String getExclude() {
return exclude;
}
/**
* @param exclude the exclude to set
*/
public void setExclude(String exclude) {
this.exclude = exclude;
}
/**
* @return the uriType
*/
public BundleURIType getUriType() {
return uriType;
}
/**
* @param uriType the uriType to set
*/
public void setUriType(BundleURIType uriType) {
this.uriType = uriType;
}
/**
* @return the format
*/
public BundleFormat getFormat() {
return format;
}
/**
* @param format the format to set
*/
public void setFormat(BundleFormat format) {
this.format = format;
}
/**
* @return the utf8
*/
public boolean isUtf8() {
return utf8;
}
/**
* @param utf8 the utf8 to set
*/
public void setUtf8(boolean utf8) {
this.utf8 = utf8;
}
/**
* @return the optional
*/
public boolean isOptional() {
return optional;
}
/**
* @param optional the optional to set
*/
public void setOptional(boolean optional) {
this.optional = optional;
}
}

View file

@ -0,0 +1,237 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.config;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.ResourceBundle.Control;
import java.util.logging.Logger;
/**
* Loads and reads the configuration to load all resources.
*
* @author Willem Cazander
* @version 1.0 Mar 8, 2012
*/
public class BundleConfigParser {
private Logger logger = null;
public static final String CONFIG_RESOURCE_DEFAULT = "META-INF/root-bundle.properties";
protected static final String BUNDLE_EXTENSION = "properties";
protected static final Control UTF8_CONTROL = new UTF8Control();
protected List<Locale> applicationSupportedLocales = null;
protected List<BundleConfig> bundlesConfigs = null;
public BundleConfigParser() {
logger = Logger.getLogger(BundleConfigParser.class.getName());
applicationSupportedLocales = new ArrayList<Locale>(10);
bundlesConfigs = new ArrayList<BundleConfig>(10);
}
public void parseConfig() {
bundlesConfigs.clear();
applicationSupportedLocales.clear();
Properties properties = new Properties();
readPropertiesResource(properties,CONFIG_RESOURCE_DEFAULT);
parseProperties(properties);
}
public List<Locale> getApplicationSupportedLocales() {
return applicationSupportedLocales;
}
public List<BundleConfig> getBundleConfigs() {
return bundlesConfigs;
}
public Map<String,String> loadBundleConfig(BundleConfig bundle,Locale locale) {
Properties properties = new Properties();
try {
switch (bundle.getUriType()) {
default:
case RESOURCE:
readPropertiesBundle(properties,bundle,locale);
break;
case URL:
readPropertiesStream(properties,new URL(bundle.getUri()).openStream());
break;
case FILE:
readPropertiesFile(properties,new File(bundle.getUri()));
break;
}
} catch (Exception e) {
if (bundle.isOptional()) {
logger.info("Could not load optional bundle with uri: "+bundle.getUri()+" message: "+e.getMessage());
} else {
throw new RuntimeException(e);
}
}
Map<String,String> result = new HashMap<String,String>(100);
for (Object keyObject:properties.keySet()) {
String key = (String)keyObject;
if (bundle.getExclude()!=null && key.matches(bundle.getExclude())) {
logger.finest("Excluding key: "+key+" from bundle: "+bundle.getName());
continue;
}
String value = properties.getProperty(key);
result.put(key,value);
}
logger.info("Loaded "+bundle.getName()+" with total keys: "+result.size());
return result;
}
protected void readPropertiesFile(Properties p,File file) {
logger.info("Reading bundle file: "+file.getAbsoluteFile());
try {
readPropertiesStream(p,new FileInputStream(file));
} catch (Exception e) {
throw new RuntimeException("Could not load resource file error: "+e.getMessage(),e);
}
}
protected void readPropertiesBundle(Properties p,BundleConfig bundle,Locale locale) {
ResourceBundle bundleReal = null;
if (bundle.isUtf8()) {
bundleReal = ResourceBundle.getBundle(bundle.getUri(),locale,UTF8_CONTROL);
} else {
bundleReal = ResourceBundle.getBundle(bundle.getUri(),locale);
}
for (String key:bundleReal.keySet()) {
String value = bundleReal.getString(key);
p.put(key, value);
}
}
protected void readPropertiesResource(Properties p,String resource) {
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = p.getClass().getClassLoader(); // fallback
}
readPropertiesStream(p,cl.getResourceAsStream(resource));
} catch (Exception e) {
throw new RuntimeException("Could not load resource: "+resource+" error: "+e.getMessage(),e);
}
}
protected void readPropertiesStream(Properties p,InputStream in) {
try {
p.load(in);
} catch (Exception e) {
throw new RuntimeException("Could not load properties error: "+e.getMessage(),e);
} finally {
if (in!=null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
protected void parseProperties(Properties p) {
Map<String,BundleConfig> bundles = new HashMap<String,BundleConfig>(10);
for (Object keyO:p.keySet()) {
String keyFull = (String)keyO;
String value = p.getProperty(keyFull);
if (keyFull.contains(".")==false) {
continue;
}
String keyConfig = keyFull.substring(0,keyFull.indexOf('.'));
String keyField = keyFull.substring(keyFull.indexOf('.')+1,keyFull.length());
if ("locale".equals(keyConfig) && "true".equalsIgnoreCase(value)) {
applicationSupportedLocales.add(new Locale(keyField));
continue;
}
BundleConfig c = bundles.get(keyConfig);
if (c==null) {
c = new BundleConfig();
c.setName(keyConfig);
bundles.put(keyConfig,c);
}
if ("uri".equals(keyField)) {
c.setUri(value);
} else if ("type".equals(keyField)) {
c.setUriType(BundleURIType.valueOf(value));
} else if ("exclude".equals(keyField)) {
c.setExclude(value);
} else if ("format".equals(keyField)) {
c.setFormat(BundleFormat.valueOf(value));
} else if ("optional".equals(keyField)) {
c.setOptional(new Boolean(value));
} else if ("utf8".equals(keyField)) {
c.setUtf8(new Boolean(value));
}
}
bundlesConfigs.addAll(bundles.values());
}
protected static class UTF8Control extends Control {
public ResourceBundle newBundle
(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
throws IllegalAccessException, InstantiationException, IOException
{
// The below code is copied from default Control#newBundle() implementation.
// Only the PropertyResourceBundle line is changed to read the file as UTF-8.
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, BUNDLE_EXTENSION);
ResourceBundle bundle = null;
InputStream stream = null;
if (reload) {
URL url = loader.getResource(resourceName);
if (url != null) {
URLConnection connection = url.openConnection();
if (connection != null) {
connection.setUseCaches(false);
stream = connection.getInputStream();
}
}
} else {
stream = loader.getResourceAsStream(resourceName);
}
if (stream != null) {
try {
bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
} finally {
stream.close();
}
}
return bundle;
}
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.config;
/**
* BundleFormat lists the supported bundle format types.
*
* @author Willem Cazander
* @version 1.0 May 8, 2012
*/
public enum BundleFormat {
BUNDLE,
BUNDLE_ONE_FILE,
X18N;
}

View file

@ -0,0 +1,36 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.lib.i18n.config;
/**
* BundleURIType lists the supported uri types to fetch the bundle.
*
* @author Willem Cazander
* @version 1.0 May 8, 2012
*/
public enum BundleURIType {
RESOURCE,
URL,
FILE;
}

View file

@ -0,0 +1,46 @@
package net.forwardfire.vasc.lib.i18n;
import java.util.Locale;
import java.util.ResourceBundle;
import net.forwardfire.vasc.lib.i18n.config.BundleConfigParser;
import junit.framework.TestCase;
/**
* Test some keys and loading options.
*
* @author Willem Cazander
* @version 1.0 May 8, 2012
*/
public class RootBundleTest extends TestCase {
public void testParser() {
BundleConfigParser p = new BundleConfigParser();
p.parseConfig();
assertEquals(2,p.getBundleConfigs().size());
assertEquals(2,p.getApplicationSupportedLocales().size());
}
public void testValues_en() {
ResourceBundle bundle = ResourceBundle.getBundle("net.forwardfire.vasc.lib.i18n.bundle.RootApplicationBundle",new Locale("en"));
assertEquals(6,bundle.keySet().size());
assertEquals("key1_en",bundle.getString("bundle1.key1"));
assertEquals("key2_en",bundle.getString("bundle1.key2"));
assertEquals("key3_en",bundle.getString("bundle1.key3"));
assertEquals("key1_en",bundle.getString("bundle2.key1"));
assertEquals("key2_en",bundle.getString("bundle2.key2"));
assertEquals("key3_en",bundle.getString("bundle2.key3"));
}
public void testValues_nl() {
ResourceBundle bundle = ResourceBundle.getBundle("net.forwardfire.vasc.lib.i18n.bundle.RootApplicationBundle",new Locale("nl"));
assertEquals(6,bundle.keySet().size());
assertEquals("key1_nl",bundle.getString("bundle1.key1"));
assertEquals("key2_nl",bundle.getString("bundle1.key2"));
assertEquals("key3_nl",bundle.getString("bundle1.key3"));
assertEquals("key1_nl",bundle.getString("bundle2.key1"));
assertEquals("key2_nl",bundle.getString("bundle2.key2"));
assertEquals("key3_nl",bundle.getString("bundle2.key3"));
}
}

View file

@ -0,0 +1,22 @@
# We only suport 2 languages.
locale.nl=true
locale.en=true
# bundle list to merge and load
bundle1.uri=net.forwardfire.vasc.lib.i18n.resources.TestBundle1
bundle2.uri=net.forwardfire.vasc.lib.i18n.resources.TestBundle2
# TODO:
#
# bundle2.type=RESOURCE
# bundle2.exclude=yoyo.*
# bundle2.format=PROPERTIES
# bundle2.utf8=true
# bundle2.optional=false
#
# bundle3.uri=http://foo.bar/some/path/bundle.properties
# bundle3.type=URL
#
# bundle4=/tmp/bundle.properties
# bundle4.type=FILE

View file

@ -0,0 +1,4 @@
# Test bundle
bundle1.key1 = key1_en
bundle1.key2 = key2_en
bundle1.key3 = key3_en

View file

@ -0,0 +1,4 @@
# Test bundle
bundle1.key1 = key1_nl
bundle1.key2 = key2_nl
bundle1.key3 = key3_nl

View file

@ -0,0 +1,4 @@
# Test bundle
bundle2.key1 = key1_en
bundle2.key2 = key2_en
bundle2.key3 = key3_en

View file

@ -0,0 +1,4 @@
# Test bundle
bundle2.key1 = key1_nl
bundle2.key2 = key2_nl
bundle2.key3 = key3_nl