Added i18n lib and added paging on mongo and meta backends.
This commit is contained in:
parent
fe5842768f
commit
efcbdbd519
45 changed files with 1767 additions and 28 deletions
|
|
@ -7,10 +7,12 @@
|
|||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>vasc-test</artifactId>
|
||||
<groupId>net.forwardfire.vasc.test</groupId>
|
||||
<packaging>pom</packaging>
|
||||
<name>vasc-test</name>
|
||||
<description>vasc-test</description>
|
||||
<modules>
|
||||
<module>vasc-test-frontend-data</module>
|
||||
<module>vasc-test-i18n</module>
|
||||
</modules>
|
||||
</project>
|
||||
23
vasc-test/vasc-test-i18n/.project
Normal file
23
vasc-test/vasc-test-i18n/.project
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-test-i18n</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
19
vasc-test/vasc-test-i18n/pom.xml
Normal file
19
vasc-test/vasc-test-i18n/pom.xml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>vasc-test</artifactId>
|
||||
<groupId>net.forwardfire.vasc.test</groupId>
|
||||
<version>0.3.5-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>vasc-test-i18n</artifactId>
|
||||
<name>vasc-test-i18n</name>
|
||||
<description>vasc-test-i18n</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* 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.test.i18n;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascEntryFieldSet;
|
||||
import net.forwardfire.vasc.core.VascLinkEntry;
|
||||
import net.forwardfire.vasc.core.actions.VascAction;
|
||||
|
||||
|
||||
/**
|
||||
* Parses the Vasc annotations and generates all i18n keys for you.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 23, 2009
|
||||
*/
|
||||
public class VascBundleCheckEntryKeys {
|
||||
|
||||
private ResourceBundle resourceBundle = null;
|
||||
private String imagePrefix = null;
|
||||
private String imagePostfix = null;
|
||||
|
||||
public VascBundleCheckEntryKeys(ResourceBundle resourceBundle) {
|
||||
imagePrefix = "resources/images/models/";
|
||||
imagePostfix = ".png";
|
||||
this.resourceBundle=resourceBundle;
|
||||
}
|
||||
|
||||
public Map<String,String> collectVascKeys(VascEntry ve) {
|
||||
Map<String,String> keys = new HashMap<String,String>(300);
|
||||
keys.put(ve.getName(), ve.getId());
|
||||
keys.put(ve.getImage(), ve.getId());
|
||||
keys.put(ve.getListDescription(), ve.getId());
|
||||
keys.put(ve.getListImage(), imagePrefix+ve.getId()+imagePostfix);
|
||||
keys.put(ve.getEditDescription(), ve.getId());
|
||||
keys.put(ve.getEditImage(), imagePrefix+ve.getId()+imagePostfix);
|
||||
keys.put(ve.getDeleteDescription(), ve.getId());
|
||||
keys.put(ve.getDeleteImage(), imagePrefix+ve.getId()+imagePostfix);
|
||||
keys.put(ve.getCreateDescription(), ve.getId());
|
||||
keys.put(ve.getCreateImage(), imagePrefix+ve.getId()+imagePostfix);
|
||||
for (VascEntryField vef:ve.getVascEntryFields()) {
|
||||
keys.put(vef.getName(), vef.getId());
|
||||
keys.put(vef.getImage(), vef.getId());
|
||||
keys.put(vef.getDescription(), vef.getId());
|
||||
}
|
||||
for (VascEntryFieldSet s:ve.getVascEntryFieldSets()) {
|
||||
keys.put(s.getName(), s.getId());
|
||||
keys.put(s.getDescription(), s.getId());
|
||||
keys.put(s.getImage(), s.getId());
|
||||
}
|
||||
for (VascEntryField vef:ve.getListOptions()) {
|
||||
keys.put(vef.getName(), vef.getId());
|
||||
keys.put(vef.getImage(), vef.getId());
|
||||
keys.put(vef.getDescription(), vef.getId());
|
||||
}
|
||||
for (VascLinkEntry vef:ve.getVascLinkEntries()) {
|
||||
keys.put(vef.getName(), vef.getId());
|
||||
}
|
||||
for (VascAction a:ve.getGlobalActions()) {
|
||||
keys.put(a.getName(), a.getId());
|
||||
keys.put(a.getDescription(), a.getId());
|
||||
keys.put(a.getImage(), a.getId());
|
||||
}
|
||||
for (VascAction a:ve.getRowActions()) {
|
||||
keys.put(a.getName(), a.getId());
|
||||
keys.put(a.getDescription(), a.getId());
|
||||
keys.put(a.getImage(), a.getId());
|
||||
}
|
||||
for (VascAction a:ve.getColumnActions()) {
|
||||
keys.put(a.getName(), a.getId());
|
||||
keys.put(a.getDescription(), a.getId());
|
||||
keys.put(a.getImage(), a.getId());
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
public Map<String,String> generateMissingKeys(VascEntry ve) {
|
||||
Map<String,String> keys = collectVascKeys(ve);
|
||||
List<String> keysResult = new ArrayList<String>(keys.keySet());
|
||||
keysResult.removeAll(resourceBundle.keySet());
|
||||
Collections.sort(keysResult);
|
||||
Map<String,String> data = new HashMap<String,String>(300);
|
||||
for (String key:keysResult) {
|
||||
data.put(key, keys.get(key));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public Map<String,String> generateRemovedKeys(VascEntry ve) {
|
||||
Map<String,String> keys = collectVascKeys(ve);
|
||||
List<String> keysResult = new ArrayList<String>(resourceBundle.keySet());
|
||||
keysResult.removeAll(keys.keySet());
|
||||
Collections.sort(keysResult);
|
||||
Map<String,String> data = new HashMap<String,String>(300);
|
||||
for (String key:keysResult) {
|
||||
data.put(key, keys.get(key));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resourceBundle
|
||||
*/
|
||||
public ResourceBundle getResourceBundle() {
|
||||
return resourceBundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resourceBundle the resourceBundle to set
|
||||
*/
|
||||
public void setResourceBundle(ResourceBundle resourceBundle) {
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the imagePrefix
|
||||
*/
|
||||
public String getImagePrefix() {
|
||||
return imagePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param imagePrefix the imagePrefix to set
|
||||
*/
|
||||
public void setImagePrefix(String imagePrefix) {
|
||||
this.imagePrefix = imagePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the imagePostfix
|
||||
*/
|
||||
public String getImagePostfix() {
|
||||
return imagePostfix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param imagePostfix the imagePostfix to set
|
||||
*/
|
||||
public void setImagePostfix(String imagePostfix) {
|
||||
this.imagePostfix = imagePostfix;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,243 @@
|
|||
/*
|
||||
* 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.test.i18n;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import net.forwardfire.vasc.annotations.VascAnnotationParser;
|
||||
|
||||
/**
|
||||
* Parses the Vasc annotations and generates all i18n keys for you.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 23, 2009
|
||||
*/
|
||||
public class VascBundleKeyGenerator {
|
||||
|
||||
private List<Class<?>> models = null;
|
||||
private Map<String,String> keys = null;
|
||||
private boolean generateName = true;
|
||||
private boolean generateDescription = true;
|
||||
private boolean generateImage = true;
|
||||
private boolean generateHelpId = true;
|
||||
private List<String> dubId = null;
|
||||
|
||||
public VascBundleKeyGenerator() {
|
||||
models = new ArrayList<Class<?>>(30);
|
||||
keys = new HashMap<String,String>(300);
|
||||
dubId = new ArrayList<String>(30);
|
||||
}
|
||||
|
||||
public void addModelClass(Class<?> model) {
|
||||
models.add(model);
|
||||
}
|
||||
|
||||
public List<Class<?>> getModelClasses() {
|
||||
return models;
|
||||
}
|
||||
|
||||
|
||||
public void generateMissingKeys(StringBuffer buffer,ResourceBundle bundle) {
|
||||
if (keys.isEmpty()==false) {
|
||||
keys.clear();
|
||||
dubId.clear();
|
||||
}
|
||||
for (Class<?> modelClass:models) {
|
||||
generatorI18nKeys(modelClass);
|
||||
}
|
||||
|
||||
List<String> keys2 = new ArrayList<String>(keys.keySet());
|
||||
keys2.removeAll(bundle.keySet());
|
||||
Collections.sort(keys2);
|
||||
for (String key:keys2) {
|
||||
String value = keys.get(key);
|
||||
buffer.append(key);
|
||||
buffer.append(" = ");
|
||||
buffer.append(value);
|
||||
buffer.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
public void generateRemoveKeys(StringBuffer buffer,ResourceBundle bundle,String excludeRegex) {
|
||||
if (keys.isEmpty()==false) {
|
||||
keys.clear();
|
||||
dubId.clear();
|
||||
}
|
||||
for (Class<?> modelClass:models) {
|
||||
generatorI18nKeys(modelClass);
|
||||
}
|
||||
|
||||
List<String> keys2 = new ArrayList<String>(bundle.keySet());
|
||||
keys2.removeAll(keys.keySet());
|
||||
Collections.sort(keys2);
|
||||
for (String key:keys2) {
|
||||
// exlude code and user keys
|
||||
if (excludeRegex!=null && key.matches(excludeRegex)) {
|
||||
continue;
|
||||
}
|
||||
buffer.append(key);
|
||||
buffer.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
public void generateKeys(StringBuffer buffer) {
|
||||
if (keys.isEmpty()==false) {
|
||||
keys.clear();
|
||||
dubId.clear();
|
||||
}
|
||||
for (Class<?> modelClass:models) {
|
||||
generatorI18nKeys(modelClass);
|
||||
}
|
||||
List<String> keys2 = new ArrayList<String>(keys.keySet());
|
||||
Collections.sort(keys2);
|
||||
for (String key:keys2) {
|
||||
String value = keys.get(key);
|
||||
buffer.append(key);
|
||||
buffer.append(" = ");
|
||||
buffer.append(value);
|
||||
buffer.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
private void generatorI18nKeys(Class<?> bean) {
|
||||
VascAnnotationParser vap = new VascAnnotationParser();
|
||||
|
||||
String prop1 = bean.getName().substring(bean.getName().lastIndexOf('.')+1);
|
||||
if (isGenerateName()) {
|
||||
appendKey(vap.getVascI18nName(bean),prop1);
|
||||
}
|
||||
if (isGenerateDescription()) {
|
||||
appendKey(vap.getVascI18nDescription(bean),prop1);
|
||||
}
|
||||
if (isGenerateImage()) {
|
||||
appendKey(vap.getVascI18nImage(bean),"resources/images/models/"+prop1+".png");
|
||||
}
|
||||
if (isGenerateHelpId()) {
|
||||
appendKey(vap.getVascI18nHelpId(bean),prop1);
|
||||
}
|
||||
|
||||
String idKey = vap.getVascPrimaryKey(bean);
|
||||
String nameKey = vap.getVascDisplayName(bean);
|
||||
if (idKey!=null && idKey.equals(nameKey)) {
|
||||
dubId.add("idKey and nameKey is the same: "+bean.getName());
|
||||
}
|
||||
|
||||
for (Method method:bean.getMethods()) {
|
||||
if (method.getName().startsWith("get")==false) { //a bit durty
|
||||
continue;
|
||||
}
|
||||
if (method.getName().equals("getClass")==true) {
|
||||
continue;
|
||||
}
|
||||
String prop = method.getName().substring(3);
|
||||
prop = prop.substring(0,1).toLowerCase()+prop.substring(1);
|
||||
|
||||
|
||||
if (isGenerateName()) {
|
||||
appendKey(vap.getVascI18nName(bean, prop),prop);
|
||||
}
|
||||
if (isGenerateDescription()) {
|
||||
appendKey(vap.getVascI18nDescription(bean, prop),prop);
|
||||
}
|
||||
if (isGenerateImage()) {
|
||||
appendKey(vap.getVascI18nImage(bean, prop),"resources/images/models/"+prop1+"-"+prop+".png");
|
||||
}
|
||||
if (isGenerateHelpId()) {
|
||||
appendKey(vap.getVascI18nHelpId(bean),prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void appendKey(String key,String value) {
|
||||
if (keys.containsKey(key)) {
|
||||
return;
|
||||
}
|
||||
keys.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateName
|
||||
*/
|
||||
public boolean isGenerateName() {
|
||||
return generateName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateName the generateName to set
|
||||
*/
|
||||
public void setGenerateName(boolean generateName) {
|
||||
this.generateName = generateName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateDescription
|
||||
*/
|
||||
public boolean isGenerateDescription() {
|
||||
return generateDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateDescription the generateDescription to set
|
||||
*/
|
||||
public void setGenerateDescription(boolean generateDescription) {
|
||||
this.generateDescription = generateDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateImage
|
||||
*/
|
||||
public boolean isGenerateImage() {
|
||||
return generateImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateImage the generateImage to set
|
||||
*/
|
||||
public void setGenerateImage(boolean generateImage) {
|
||||
this.generateImage = generateImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generateHelpId
|
||||
*/
|
||||
public boolean isGenerateHelpId() {
|
||||
return generateHelpId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param generateHelpId the generateHelpId to set
|
||||
*/
|
||||
public void setGenerateHelpId(boolean generateHelpId) {
|
||||
this.generateHelpId = generateHelpId;
|
||||
}
|
||||
|
||||
public List<String> getDubIdNameKeys() {
|
||||
return dubId;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue