LabelReferences4.patch from Marco "New tool to get labels information" https://issues.apache.org/jira/browse/OFBIZ-2070 OFBIZ-2070
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@748732 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -38,8 +38,11 @@ import org.ofbiz.base.util.UtilProperties;
|
||||
import org.ofbiz.base.util.UtilValidate;
|
||||
import org.ofbiz.base.util.UtilXml;
|
||||
import org.ofbiz.base.util.cache.UtilCache;
|
||||
import org.ofbiz.entity.GenericDelegator;
|
||||
import org.ofbiz.entity.model.ModelReader;
|
||||
import org.ofbiz.service.DispatchContext;
|
||||
import org.ofbiz.service.GenericServiceException;
|
||||
import org.ofbiz.service.LocalDispatcher;
|
||||
import org.ofbiz.service.ServiceUtil;
|
||||
import org.w3c.dom.Comment;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -63,7 +66,7 @@ public class LabelManagerFactory {
|
||||
protected static Map<String, Map<String, Integer>> references = null;
|
||||
protected static int duplicatedLocalesLabels = 0;
|
||||
|
||||
protected static String delegatorName;
|
||||
protected static GenericDelegator delegator;
|
||||
protected static ModelReader entityModelReader;
|
||||
protected static DispatchContext dispatchContext;
|
||||
|
||||
@@ -73,7 +76,7 @@ public class LabelManagerFactory {
|
||||
}
|
||||
|
||||
LabelManagerFactory lmf = labelManagerFactoryCache.get(delegatorName);
|
||||
|
||||
|
||||
if (lmf == null) {
|
||||
lmf = new LabelManagerFactory(delegatorName);
|
||||
labelManagerFactoryCache.put(delegatorName, lmf);
|
||||
@@ -82,10 +85,9 @@ public class LabelManagerFactory {
|
||||
}
|
||||
|
||||
protected LabelManagerFactory(String delegatorName) throws GeneralException {
|
||||
LabelManagerFactory.delegatorName = delegatorName;
|
||||
LabelManagerFactory.entityModelReader = ModelReader.getModelReader(delegatorName);
|
||||
LabelManagerFactory.dispatchContext = new DispatchContext("LabelManagerDispCtx", null, this.getClass().getClassLoader(), null);
|
||||
|
||||
delegator = GenericDelegator.getGenericDelegator(delegatorName);
|
||||
entityModelReader = ModelReader.getModelReader(delegatorName);
|
||||
dispatchContext = new DispatchContext("LabelManagerFactoryDispCtx", null, this.getClass().getClassLoader(), null);
|
||||
prepareAll();
|
||||
}
|
||||
|
||||
@@ -99,53 +101,63 @@ public class LabelManagerFactory {
|
||||
int duplicatedLocales = 0;
|
||||
|
||||
try {
|
||||
boolean sharkComponent = false;
|
||||
Collection<ComponentConfig> componentConfigs = ComponentConfig.getAllComponents();
|
||||
|
||||
for (ComponentConfig componentConfig: componentConfigs) {
|
||||
String componentName = componentConfig.getComponentName();
|
||||
List<File> resourceFiles = FileUtil.findXmlFiles(componentConfig.getRootLocation(), null, "resource", null);
|
||||
boolean cycle = true;
|
||||
while (cycle) {
|
||||
for (File resourceFile: resourceFiles) {
|
||||
String fileName = resourceFile.getName();
|
||||
Document resourceDocument = UtilXml.readXmlDocument(resourceFile.toURI().toURL());
|
||||
Element resourceElem = resourceDocument.getDocumentElement();
|
||||
String labelKeyComment = "";
|
||||
|
||||
for (File resourceFile: resourceFiles) {
|
||||
String fileName = resourceFile.getName();
|
||||
Document resourceDocument = UtilXml.readXmlDocument(resourceFile.toURI().toURL());
|
||||
Element resourceElem = resourceDocument.getDocumentElement();
|
||||
String labelKeyComment = "";
|
||||
for (Node propertyNode: UtilXml.childNodeList(resourceElem.getFirstChild())) {
|
||||
if (propertyNode instanceof Element) {
|
||||
Element propertyElem = (Element)propertyNode;
|
||||
String labelKey = StringUtil.htmlSpecialChars(propertyElem.getAttribute("key"), true, true, false);
|
||||
String labelComment = "";
|
||||
|
||||
for (Node propertyNode: UtilXml.childNodeList(resourceElem.getFirstChild())) {
|
||||
if (propertyNode instanceof Element) {
|
||||
Element propertyElem = (Element)propertyNode;
|
||||
String labelKey = StringUtil.htmlSpecialChars(propertyElem.getAttribute("key"), true, true, false);
|
||||
String labelComment = "";
|
||||
for (Node valueNode: UtilXml.childNodeList(propertyElem.getFirstChild())) {
|
||||
if (valueNode instanceof Element) {
|
||||
Element valueElem = (Element)valueNode;
|
||||
String localeName = valueElem.getAttribute("xml:lang");
|
||||
String labelValue = StringUtil.htmlSpecialChars(UtilXml.nodeValue(valueElem.getFirstChild()), true, true, false);
|
||||
LabelInfo label = (LabelInfo)labels.get(labelKey + keySeparator + fileName);
|
||||
|
||||
for (Node valueNode: UtilXml.childNodeList(propertyElem.getFirstChild())) {
|
||||
if (valueNode instanceof Element) {
|
||||
Element valueElem = (Element)valueNode;
|
||||
String localeName = valueElem.getAttribute("xml:lang");
|
||||
String labelValue = StringUtil.htmlSpecialChars(UtilXml.nodeValue(valueElem.getFirstChild()), true, true, false);
|
||||
LabelInfo label = (LabelInfo)labels.get(labelKey + keySeparator + fileName);
|
||||
|
||||
if (UtilValidate.isEmpty(label)) {
|
||||
label = new LabelInfo(labelKey, labelKeyComment, fileName, componentName, localeName, labelValue, labelComment);
|
||||
labels.put(labelKey + keySeparator + fileName, label);
|
||||
} else {
|
||||
if (label.setLabelValue(localeName, labelValue, labelComment, false)) {
|
||||
duplicatedLocales++;
|
||||
if (UtilValidate.isEmpty(label)) {
|
||||
label = new LabelInfo(labelKey, labelKeyComment, fileName, componentName, localeName, labelValue, labelComment);
|
||||
labels.put(labelKey + keySeparator + fileName, label);
|
||||
} else {
|
||||
if (label.setLabelValue(localeName, labelValue, labelComment, false)) {
|
||||
duplicatedLocales++;
|
||||
}
|
||||
}
|
||||
localesFound.add(localeName);
|
||||
componentNamesFound.add(componentName);
|
||||
fileNamesFound.put(fileName, resourceFile.toURI().toString());
|
||||
fileComponent.put(fileName, componentName);
|
||||
labelComment = "";
|
||||
} else if (valueNode instanceof Comment) {
|
||||
labelComment = labelComment + StringUtil.htmlSpecialChars(valueNode.getNodeValue(), true, true, false);
|
||||
}
|
||||
localesFound.add(localeName);
|
||||
componentNamesFound.add(componentName);
|
||||
fileNamesFound.put(fileName, resourceFile.toURI().toString());
|
||||
fileComponent.put(fileName, componentName);
|
||||
labelComment = "";
|
||||
} else if (valueNode instanceof Comment) {
|
||||
labelComment = labelComment + StringUtil.htmlSpecialChars(valueNode.getNodeValue(), true, true, false);
|
||||
}
|
||||
labelKeyComment = "";
|
||||
} else if (propertyNode instanceof Comment) {
|
||||
labelKeyComment = labelKeyComment + StringUtil.htmlSpecialChars(propertyNode.getNodeValue(), true, true, false);
|
||||
}
|
||||
labelKeyComment = "";
|
||||
} else if (propertyNode instanceof Comment) {
|
||||
labelKeyComment = labelKeyComment + StringUtil.htmlSpecialChars(propertyNode.getNodeValue(), true, true, false);
|
||||
}
|
||||
}
|
||||
if (!sharkComponent) {
|
||||
componentName = "shark";
|
||||
resourceFiles = FileUtil.findXmlFiles(System.getProperty("ofbiz.home") + "/specialpurpose/shark", null, "resource", null);
|
||||
sharkComponent = true;
|
||||
} else {
|
||||
cycle = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +171,18 @@ public class LabelManagerFactory {
|
||||
duplicatedLocalesLabels = duplicatedLocales;
|
||||
}
|
||||
|
||||
public static GenericDelegator getDelegator() {
|
||||
return delegator;
|
||||
}
|
||||
|
||||
public static ModelReader getModelReader() {
|
||||
return entityModelReader;
|
||||
}
|
||||
|
||||
public static DispatchContext getDispatchContext() {
|
||||
return dispatchContext;
|
||||
}
|
||||
|
||||
public static Map<String, LabelInfo> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
@@ -186,39 +210,43 @@ public class LabelManagerFactory {
|
||||
public static Map<String, Map<String, Integer>> getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
|
||||
public static Set<String> getLabelsList() {
|
||||
return labels.keySet();
|
||||
}
|
||||
|
||||
|
||||
public static Set<String> getReferencesList() {
|
||||
return references.keySet();
|
||||
}
|
||||
|
||||
|
||||
public static int getLabelReferenceFile(String key) {
|
||||
int refFile = 0;
|
||||
boolean keyFound = false;
|
||||
|
||||
|
||||
if (key == null) {
|
||||
key = "";
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> e: fileNamesFound.entrySet()) {
|
||||
String keyToSearch = key + keySeparator + e.getKey();
|
||||
|
||||
|
||||
if (labels.containsKey(keyToSearch)) {
|
||||
keyFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!keyFound) {
|
||||
Map<String, Integer> reference = references.get(key);
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(reference)) {
|
||||
refFile = reference.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return refFile;
|
||||
}
|
||||
|
||||
|
||||
public static int getDuplicatedLocalesLabels() {
|
||||
return duplicatedLocalesLabels;
|
||||
}
|
||||
@@ -266,6 +294,35 @@ public class LabelManagerFactory {
|
||||
return ServiceUtil.returnSuccess();
|
||||
}
|
||||
|
||||
public static Map<String, Object> updateAndSaveLabelKey(DispatchContext dctx, Map<String, ? extends Object> context) {
|
||||
String key = (String)context.get("key");
|
||||
String keyComment = (String)context.get("keyComment");
|
||||
String update_label = (String)context.get("update_label");
|
||||
String fileName = (String)context.get("fileName");
|
||||
String confirm = (String)context.get("confirm");
|
||||
String removeLabel = (String)context.get("removeLabel");
|
||||
List<String> localeNames = UtilGenerics.cast(context.get("localeNames"));
|
||||
List<String> localeValues = UtilGenerics.cast(context.get("localeValues"));
|
||||
List<String> localeComments = UtilGenerics.cast(context.get("localeComments"));
|
||||
Locale locale = (Locale) context.get("locale");
|
||||
LocalDispatcher dispatcher = dctx.getDispatcher();
|
||||
|
||||
Map<String, Object> contextInput = UtilMisc.toMap("key", key, "keyComment", keyComment, "update_label", update_label,
|
||||
"fileName", fileName, "confirm", confirm, "removeLabel", removeLabel,
|
||||
"localeNames", localeNames, "localeValues", localeValues, "localeComments", localeComments);
|
||||
try {
|
||||
Map<String, Object> updatedKey = dispatcher.runSync("updateLabelKey", contextInput);
|
||||
|
||||
if (ServiceUtil.isError(updatedKey)) {
|
||||
return updatedKey;
|
||||
} else {
|
||||
return dispatcher.runSync("saveLabelsToXmlFile", UtilMisc.toMap("fileName", fileName));
|
||||
}
|
||||
} catch (GenericServiceException e) {
|
||||
return ServiceUtil.returnError("error on saving label key :" + key);
|
||||
}
|
||||
}
|
||||
|
||||
private static int updateLabelValue(List<String> localeNames, List<String> localeValues, List<String> localeComments, LabelInfo label, String key, String keyComment, String fileName) {
|
||||
int notEmptyLabels = 0;
|
||||
int i = 0;
|
||||
@@ -295,3 +352,4 @@ public class LabelManagerFactory {
|
||||
return notEmptyLabels;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@@ -23,7 +23,12 @@ import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javolution.util.FastList;
|
||||
import javolution.util.FastMap;
|
||||
|
||||
import org.ofbiz.base.util.Debug;
|
||||
import org.ofbiz.base.util.FileUtil;
|
||||
@@ -31,7 +36,14 @@ import org.ofbiz.base.util.GeneralException;
|
||||
import org.ofbiz.base.util.UtilFormatOut;
|
||||
import org.ofbiz.base.util.UtilValidate;
|
||||
import org.ofbiz.base.util.UtilXml;
|
||||
import org.ofbiz.entity.GenericDelegator;
|
||||
import org.ofbiz.entity.GenericEntityException;
|
||||
import org.ofbiz.entity.GenericValue;
|
||||
import org.ofbiz.entity.condition.EntityComparisonOperator;
|
||||
import org.ofbiz.entity.condition.EntityCondition;
|
||||
import org.ofbiz.entity.condition.EntityConditionList;
|
||||
import org.ofbiz.entity.condition.EntityExpr;
|
||||
import org.ofbiz.entity.condition.EntityOperator;
|
||||
import org.ofbiz.entity.model.ModelEntity;
|
||||
import org.ofbiz.entity.model.ModelField;
|
||||
import org.ofbiz.service.ModelParam;
|
||||
@@ -46,46 +58,55 @@ public class LabelReferences {
|
||||
private static final String uiLabelMapInLayoutSettings = "uiLabelMap.";
|
||||
private static final String formFieldTitle = "FormFieldTitle_";
|
||||
private static final String getMessage = "UtilProperties.getMessage";
|
||||
private static final String getEntityLabel = ".get(\"";
|
||||
private static final String startExpression = "${";
|
||||
private static final String endExpression = "}";
|
||||
private static Map<String, Map<String, Integer>> references = null;
|
||||
|
||||
|
||||
public static Map<String, Map<String, Integer>> getLabelReferences() throws GeneralException {
|
||||
references = new TreeMap<String, Map<String, Integer>>();
|
||||
|
||||
|
||||
// get labels from FTL files
|
||||
getLabelsFromFtlFiles();
|
||||
|
||||
|
||||
// get labels from java files
|
||||
getLabelsFromJavaFiles();
|
||||
|
||||
|
||||
// get labels from simple method files
|
||||
getLabelsFromSimpleMethodFiles();
|
||||
|
||||
|
||||
// get labels from form widgets files
|
||||
getLabelsFromFormWidgets();
|
||||
|
||||
|
||||
// get labels from screen widgets files
|
||||
getLabelsFromScreenWidgets();
|
||||
|
||||
|
||||
// get labels from menu widgets files
|
||||
getLabelsFromMenuWidgets();
|
||||
|
||||
|
||||
// get labels from tree widgets files
|
||||
getLabelsFromTreeWidgets();
|
||||
|
||||
// get labels from Ofbiz components files
|
||||
getLabelsFromOfbizComponents();
|
||||
|
||||
return references;
|
||||
}
|
||||
|
||||
|
||||
private static void getLabelsFromFtlFiles() throws GeneralException {
|
||||
try {
|
||||
List<File> ftlFiles = FileUtil.findFiles("ftl", null, null, uiLabelMap);
|
||||
|
||||
|
||||
for (File ftlFile: ftlFiles) {
|
||||
String fileNameURI = ftlFile.toURI().toString();
|
||||
String inFile = FileUtil.readString("UTF-8", ftlFile);
|
||||
int pos = 0;
|
||||
while (pos >= 0){
|
||||
pos = inFile.indexOf(uiLabelMap, pos);
|
||||
|
||||
|
||||
if (pos >= 0) {
|
||||
int endLabel = inFile.indexOf("}", pos);
|
||||
|
||||
|
||||
if (endLabel >= 0) {
|
||||
String labelKey = inFile.substring(pos + uiLabelMap.length(), endLabel);
|
||||
setLabelReference(labelKey, fileNameURI);
|
||||
@@ -96,15 +117,22 @@ public class LabelReferences {
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
ftlFiles = FileUtil.findFiles("ftl", null, null, getEntityLabel);
|
||||
|
||||
for (File ftlFile: ftlFiles) {
|
||||
getFtlEntityLabels(ftlFile, getEntityLabel);
|
||||
}
|
||||
*/
|
||||
} catch(IOException ioe) {
|
||||
throw new GeneralException(ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getLabelsFromJavaFiles() throws GeneralException {
|
||||
try {
|
||||
List<File> javaFiles = FileUtil.findFiles("java", null, null, getMessage);
|
||||
|
||||
|
||||
for (File javaFile: javaFiles) {
|
||||
getJavaLabels(javaFile, getMessage);
|
||||
}
|
||||
@@ -112,7 +140,7 @@ public class LabelReferences {
|
||||
throw new GeneralException(ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getJavaLabels(File javaFile, String message) throws GeneralException {
|
||||
try {
|
||||
String fileNameURI = javaFile.toURI().toString();
|
||||
@@ -120,32 +148,32 @@ public class LabelReferences {
|
||||
int pos = 0;
|
||||
while (pos >= 0){
|
||||
pos = inFile.indexOf(message, pos);
|
||||
|
||||
|
||||
if (pos >= 0) {
|
||||
int offSet = (pos + 200 > inFile.length()) ? inFile.length() : pos + 200;
|
||||
String searchComma = inFile.substring(pos, offSet);
|
||||
int firstComma = searchComma.indexOf(",\"", 0);
|
||||
|
||||
|
||||
if (firstComma < 0) {
|
||||
firstComma = searchComma.indexOf(", \"", 0);
|
||||
pos = pos + firstComma + 3;
|
||||
} else {
|
||||
pos = pos + firstComma + 2;
|
||||
}
|
||||
|
||||
|
||||
if (firstComma >= 0) {
|
||||
offSet = (pos + 100 > inFile.length()) ? inFile.length() : pos + 100;
|
||||
searchComma = inFile.substring(pos, offSet);
|
||||
int secondComma = searchComma.indexOf("\",", 0);
|
||||
int endString = pos;
|
||||
|
||||
|
||||
if (secondComma < 0) {
|
||||
secondComma = searchComma.indexOf("\" ,", 0);
|
||||
endString = endString + secondComma + 1;
|
||||
} else {
|
||||
endString = endString + secondComma;
|
||||
}
|
||||
|
||||
|
||||
if (secondComma >= 0) {
|
||||
setLabelReference(inFile.substring(pos, endString), fileNameURI);
|
||||
pos = endString;
|
||||
@@ -158,16 +186,50 @@ public class LabelReferences {
|
||||
throw new GeneralException(ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getFtlEntityLabels(File javaFile, String message) throws GeneralException {
|
||||
try {
|
||||
String fileNameURI = javaFile.toURI().toString();
|
||||
String inFile = FileUtil.readString("UTF-8", javaFile);
|
||||
int pos = 0;
|
||||
while (pos >= 0){
|
||||
pos = inFile.indexOf(message, pos);
|
||||
|
||||
if (pos >= 0) {
|
||||
int offSet = (pos + 200 > inFile.length()) ? inFile.length() : pos + 200;
|
||||
String searchDoubleQuote = inFile.substring(pos + 6, offSet);
|
||||
int firstComma = searchDoubleQuote.indexOf("\"", 0);
|
||||
|
||||
if (firstComma >= 0) {
|
||||
offSet = (firstComma + 100 > inFile.length()) ? inFile.length() : firstComma + 100;
|
||||
String searchLocale = searchDoubleQuote.substring(firstComma, offSet);
|
||||
int endMethodName = searchLocale.indexOf(", locale)", 0);
|
||||
|
||||
if (endMethodName < 0) {
|
||||
endMethodName = searchLocale.indexOf(",locale)", 0);
|
||||
}
|
||||
if (endMethodName >= 0) {
|
||||
setLabelReference(inFile.substring(pos + 6, pos + 6 + firstComma), fileNameURI);
|
||||
pos = pos + 6;
|
||||
}
|
||||
}
|
||||
pos += 1;
|
||||
}
|
||||
}
|
||||
} catch(IOException ioe) {
|
||||
throw new GeneralException(ioe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void getLabelsFromSimpleMethodFiles() throws GeneralException {
|
||||
try {
|
||||
List<File> simpleMethodsFiles = FileUtil.findXmlFiles(null, null, "simple-methods", "http://ofbiz.apache.org/dtds/simple-methods.xsd");
|
||||
|
||||
|
||||
for (File simpleMethodFile: simpleMethodsFiles) {
|
||||
String fileNameURI = simpleMethodFile.toURI().toString();
|
||||
Document simpleMethodDocument = UtilXml.readXmlDocument(simpleMethodFile.toURI().toURL());
|
||||
Element rootElem = simpleMethodDocument.getDocumentElement();
|
||||
|
||||
|
||||
for (Element elem1: UtilXml.childElementList(rootElem)) {
|
||||
checkSimpleMethodTag(elem1, fileNameURI);
|
||||
for (Element elem2: UtilXml.childElementList(elem1)) {
|
||||
@@ -193,41 +255,54 @@ public class LabelReferences {
|
||||
throw new GeneralException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void checkSimpleMethodTag(Element elem, String fileNameURI) throws GeneralException {
|
||||
// fail-property labels
|
||||
if ("fail-property".equals(elem.getTagName())) {
|
||||
getFailPropertyTag(elem, fileNameURI);
|
||||
// property-to-field labels
|
||||
} else if ("property-to-field".equals(elem.getTagName())) {
|
||||
getPropertyToFieldTag(elem, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getLabelsFromFormWidgets() throws GeneralException {
|
||||
try {
|
||||
List<File> formsFiles = FileUtil.findXmlFiles(null, null, "forms", "http://ofbiz.apache.org/dtds/widget-form.xsd");
|
||||
|
||||
|
||||
for (File formsFile: formsFiles) {
|
||||
Map<String, String> autoFieldsEntity = FastMap.newInstance();
|
||||
Map<String, String> autoFieldsService = FastMap.newInstance();
|
||||
String fileNameURI = formsFile.toURI().toString();
|
||||
Document formDocument = UtilXml.readXmlDocument(formsFile.toURI().toURL());
|
||||
Element rootElem = formDocument.getDocumentElement();
|
||||
|
||||
|
||||
for (Element elem1: UtilXml.childElementList(rootElem)) {
|
||||
checkFormsTag(elem1, fileNameURI);
|
||||
checkFormsTag(elem1, fileNameURI, autoFieldsEntity, autoFieldsService);
|
||||
for (Element elem2: UtilXml.childElementList(elem1)) {
|
||||
checkFormsTag(elem2, fileNameURI);
|
||||
checkFormsTag(elem2, fileNameURI, autoFieldsEntity, autoFieldsService);
|
||||
for (Element elem3: UtilXml.childElementList(elem2)) {
|
||||
checkFormsTag(elem3, fileNameURI);
|
||||
checkFormsTag(elem3, fileNameURI, autoFieldsEntity, autoFieldsService);
|
||||
for (Element elem4: UtilXml.childElementList(elem3)) {
|
||||
checkFormsTag(elem4, fileNameURI);
|
||||
checkFormsTag(elem4, fileNameURI, autoFieldsEntity, autoFieldsService);
|
||||
for (Element elem5: UtilXml.childElementList(elem4)) {
|
||||
checkFormsTag(elem5, fileNameURI);
|
||||
checkFormsTag(elem5, fileNameURI, autoFieldsEntity, autoFieldsService);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> entry: autoFieldsEntity.entrySet()) {
|
||||
if ("N".equals(entry.getValue())) {
|
||||
String labelKey = formFieldTitle + entry.getKey();
|
||||
setLabelReference(labelKey, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> entry: autoFieldsService.entrySet()) {
|
||||
if ("N".equals(entry.getValue())) {
|
||||
String labelKey = formFieldTitle + entry.getKey();
|
||||
setLabelReference(labelKey, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(IOException ioe) {
|
||||
throw new GeneralException(ioe.getMessage());
|
||||
@@ -235,17 +310,17 @@ public class LabelReferences {
|
||||
throw new GeneralException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkFormsTag(Element elem, String fileNameURI) throws GeneralException {
|
||||
|
||||
private static void checkFormsTag(Element elem, String fileNameURI, Map<String, String> autoFieldsEntity, Map<String, String> autoFieldsService) throws GeneralException {
|
||||
// auto fields entity labels
|
||||
if ("auto-fields-entity".equals(elem.getTagName())) {
|
||||
getAutoFieldsEntityTag(elem, fileNameURI);
|
||||
getAutoFieldsEntityTag(elem, fileNameURI, autoFieldsEntity);
|
||||
// auto fields service labels
|
||||
} else if ("auto-fields-service".equals(elem.getTagName())) {
|
||||
getAutoFieldsServiceTag(elem, fileNameURI);
|
||||
getAutoFieldsServiceTag(elem, fileNameURI, autoFieldsService);
|
||||
// field labels
|
||||
} else if ("field".equals(elem.getTagName())) {
|
||||
getFieldTag(elem, fileNameURI);
|
||||
getFieldTag(elem, fileNameURI, autoFieldsEntity, autoFieldsService);
|
||||
// option description labels
|
||||
} else if ("option".equals(elem.getTagName())) {
|
||||
getOptionTag(elem, fileNameURI);
|
||||
@@ -253,18 +328,24 @@ public class LabelReferences {
|
||||
} else if ("hyperlink".equals(elem.getTagName()) ||
|
||||
"sub-hyperlink".equals(elem.getTagName())) {
|
||||
getHyperlinkTag(elem, fileNameURI);
|
||||
// entity-options labels
|
||||
} else if ("entity-options".equals(elem.getTagName())) {
|
||||
getEntityOptionsTag(elem, fileNameURI);
|
||||
// display-entity labels
|
||||
} else if ("display-entity".equals(elem.getTagName())) {
|
||||
getDisplayEntityTag(elem, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getLabelsFromScreenWidgets() throws GeneralException {
|
||||
try {
|
||||
List<File> screensFiles = FileUtil.findXmlFiles(null, null, "screens", "http://ofbiz.apache.org/dtds/widget-screen.xsd");
|
||||
|
||||
|
||||
for (File screensFile: screensFiles) {
|
||||
String fileNameURI = screensFile.toURI().toString();
|
||||
Document screenDocument = UtilXml.readXmlDocument(screensFile.toURI().toURL());
|
||||
Element rootElem = screenDocument.getDocumentElement();
|
||||
|
||||
|
||||
for (Element elem1: UtilXml.childElementList(rootElem)) {
|
||||
checkScreensTag(elem1, fileNameURI);
|
||||
for (Element elem2: UtilXml.childElementList(elem1)) {
|
||||
@@ -314,7 +395,7 @@ public class LabelReferences {
|
||||
throw new GeneralException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void checkScreensTag(Element elem, String fileNameURI) {
|
||||
// set labels
|
||||
if ("set".equals(elem.getTagName())) {
|
||||
@@ -330,16 +411,16 @@ public class LabelReferences {
|
||||
getLinkTag(elem, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getLabelsFromMenuWidgets() throws GeneralException {
|
||||
try {
|
||||
List<File> menusFiles = FileUtil.findXmlFiles(null, null, "menus", "http://ofbiz.apache.org/dtds/widget-menu.xsd");
|
||||
|
||||
|
||||
for (File menuFiles: menusFiles) {
|
||||
String fileNameURI = menuFiles.toURI().toString();
|
||||
Document menuDocument = UtilXml.readXmlDocument(menuFiles.toURI().toURL());
|
||||
Element rootElem = menuDocument.getDocumentElement();
|
||||
|
||||
|
||||
for (Element elem1: UtilXml.childElementList(rootElem)) {
|
||||
checkMenuTag(elem1, fileNameURI);
|
||||
for (Element elem2: UtilXml.childElementList(elem1)) {
|
||||
@@ -362,23 +443,92 @@ public class LabelReferences {
|
||||
throw new GeneralException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void checkMenuTag(Element elem, String fileNameURI) {
|
||||
// menu-item labels
|
||||
if ("menu-item".equals(elem.getTagName())) {
|
||||
getMenuItemTag(elem, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getLabelsFromTreeWidgets() throws GeneralException {
|
||||
try {
|
||||
List<File> treeFiles = FileUtil.findXmlFiles(null, null, "menus", "http://ofbiz.apache.org/dtds/widget-tree.xsd");
|
||||
|
||||
for (File treeFile: treeFiles) {
|
||||
String fileNameURI = treeFile.toURI().toString();
|
||||
Document menuDocument = UtilXml.readXmlDocument(treeFile.toURI().toURL());
|
||||
Element rootElem = menuDocument.getDocumentElement();
|
||||
|
||||
for (Element elem1: UtilXml.childElementList(rootElem)) {
|
||||
checkTreeTag(elem1, fileNameURI);
|
||||
for (Element elem2: UtilXml.childElementList(elem1)) {
|
||||
checkTreeTag(elem2, fileNameURI);
|
||||
for (Element elem3: UtilXml.childElementList(elem2)) {
|
||||
checkTreeTag(elem3, fileNameURI);
|
||||
for (Element elem4: UtilXml.childElementList(elem3)) {
|
||||
checkTreeTag(elem4, fileNameURI);
|
||||
for (Element elem5: UtilXml.childElementList(elem4)) {
|
||||
checkTreeTag(elem5, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(IOException ioe) {
|
||||
throw new GeneralException(ioe.getMessage());
|
||||
} catch(Exception e) {
|
||||
throw new GeneralException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkTreeTag(Element elem, String fileNameURI) {
|
||||
// link labels
|
||||
if ("link".equals(elem.getTagName())) {
|
||||
getLinkTag(elem, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
private static void getLabelsFromOfbizComponents() throws GeneralException {
|
||||
try {
|
||||
List<File> componentsFiles = FileUtil.findXmlFiles(null, null, "ofbiz-component", "http://ofbiz.apache.org/dtds/ofbiz-component.xsd");
|
||||
|
||||
for (File componentFile: componentsFiles) {
|
||||
String fileNameURI = componentFile.toURI().toString();
|
||||
Document menuDocument = UtilXml.readXmlDocument(componentFile.toURI().toURL());
|
||||
Element rootElem = menuDocument.getDocumentElement();
|
||||
|
||||
for (Element elem1: UtilXml.childElementList(rootElem)) {
|
||||
checkOfbizComponentTag(elem1, fileNameURI);
|
||||
for (Element elem2: UtilXml.childElementList(elem1)) {
|
||||
checkOfbizComponentTag(elem2, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(IOException ioe) {
|
||||
throw new GeneralException(ioe.getMessage());
|
||||
} catch(Exception e) {
|
||||
throw new GeneralException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkOfbizComponentTag(Element elem, String fileNameURI) {
|
||||
// webapp labels
|
||||
if ("webapp".equals(elem.getTagName())) {
|
||||
getWebappTag(elem, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setLabelReference(String labelKey, String fileNameURI) {
|
||||
Map<String, Integer> reference = references.get(labelKey);
|
||||
if (UtilValidate.isEmpty(reference)) {
|
||||
reference = new TreeMap<String, Integer>();
|
||||
reference.put(fileNameURI, new Integer(1));
|
||||
references.put(labelKey, reference);
|
||||
references.put(labelKey, reference);
|
||||
} else {
|
||||
Integer labelsInFile = reference.get(fileNameURI);
|
||||
|
||||
|
||||
if (UtilValidate.isEmpty(labelsInFile)) {
|
||||
labelsInFile = new Integer(1);
|
||||
}
|
||||
@@ -388,19 +538,19 @@ public class LabelReferences {
|
||||
reference.put(fileNameURI, labelsInFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean getLabelFromTag(Element element, String fileNameURI, String attributeValue, String stringToSearch) {
|
||||
boolean stringFound = false;
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(attributeValue)) {
|
||||
int pos = 0;
|
||||
|
||||
|
||||
while (pos >= 0){
|
||||
pos = attributeValue.indexOf(stringToSearch, pos);
|
||||
|
||||
|
||||
if (pos >= 0) {
|
||||
int graph = attributeValue.indexOf("}", pos);
|
||||
|
||||
|
||||
if (graph >= 0) {
|
||||
String labelKey = attributeValue.substring(pos + stringToSearch.length(), graph);
|
||||
setLabelReference(labelKey, fileNameURI);
|
||||
@@ -413,12 +563,12 @@ public class LabelReferences {
|
||||
}
|
||||
return stringFound;
|
||||
}
|
||||
|
||||
|
||||
private static void getSetTag(Element element, String fileNameURI) {
|
||||
String setField = UtilFormatOut.checkNull(element.getAttribute("field"));
|
||||
String setValue = UtilFormatOut.checkNull(element.getAttribute("value"));
|
||||
String fromField = UtilFormatOut.checkNull(element.getAttribute("from-field"));
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(setField)) {
|
||||
if (UtilValidate.isNotEmpty(setValue) &&
|
||||
("applicationTitle".equals(setField) ||
|
||||
@@ -426,7 +576,7 @@ public class LabelReferences {
|
||||
"title".equals(setField))) {
|
||||
// set field with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, setValue, uiLabelMap)) {
|
||||
setLabelReference(setValue, fileNameURI);;
|
||||
setLabelReference(setValue, fileNameURI);
|
||||
}
|
||||
} else if (UtilValidate.isNotEmpty(fromField) &&
|
||||
("layoutSettings.companyName".equals(setField) ||
|
||||
@@ -441,71 +591,71 @@ public class LabelReferences {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getScreenletTag(Element element, String fileNameURI) {
|
||||
String screenTitle = UtilFormatOut.checkNull(element.getAttribute("title"));
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(screenTitle)) {
|
||||
// screenlet title with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, screenTitle, uiLabelMap)) {
|
||||
setLabelReference(screenTitle, fileNameURI);;
|
||||
setLabelReference(screenTitle, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void getAutoFieldsEntityTag(Element element, String fileNameURI) throws GeneralException {
|
||||
|
||||
private static void getAutoFieldsEntityTag(Element element, String fileNameURI, Map<String, String> autoFieldsEntity) throws GeneralException {
|
||||
try {
|
||||
String entityName = UtilFormatOut.checkNull(element.getAttribute("entity-name"));
|
||||
String defaultFieldType = UtilFormatOut.checkNull(element.getAttribute("default-field-type"));
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(entityName) && UtilValidate.isNotEmpty(defaultFieldType) && (!("hidden".equals(defaultFieldType)))) {
|
||||
ModelEntity entity = LabelManagerFactory.entityModelReader.getModelEntity(entityName);
|
||||
|
||||
ModelEntity entity = LabelManagerFactory.getModelReader().getModelEntity(entityName);
|
||||
|
||||
for (Iterator<ModelField> f = entity.getFieldsIterator(); f.hasNext();) {
|
||||
ModelField field = f.next();
|
||||
setLabelReference(formFieldTitle + field.getName(), fileNameURI);
|
||||
autoFieldsEntity.put(field.getName(), "N");
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
throw new GeneralException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void getAutoFieldsServiceTag(Element element, String fileNameURI) throws GeneralException {
|
||||
|
||||
private static void getAutoFieldsServiceTag(Element element, String fileNameURI, Map<String, String> autoFieldsService) throws GeneralException {
|
||||
try {
|
||||
String serviceName = UtilFormatOut.checkNull(element.getAttribute("service-name"));
|
||||
String defaultFieldType = UtilFormatOut.checkNull(element.getAttribute("default-field-type"));
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(serviceName) && (!("hidden".equals(defaultFieldType)))) {
|
||||
ModelService modelService = LabelManagerFactory.dispatchContext.getModelService(serviceName);
|
||||
ModelService modelService = LabelManagerFactory.getDispatchContext().getModelService(serviceName);
|
||||
List<ModelParam> modelParams = modelService.getInModelParamList();
|
||||
Iterator<ModelParam> modelParamIter = modelParams.iterator();
|
||||
|
||||
|
||||
while (modelParamIter.hasNext()) {
|
||||
ModelParam modelParam = (ModelParam) modelParamIter.next();
|
||||
// skip auto params that the service engine populates...
|
||||
if ("userLogin".equals(modelParam.name) || "locale".equals(modelParam.name) || "timeZone".equals(modelParam.name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (modelParam.formDisplay) {
|
||||
if (UtilValidate.isNotEmpty(modelParam.entityName) && UtilValidate.isNotEmpty(modelParam.fieldName)) {
|
||||
ModelEntity modelEntity;
|
||||
try {
|
||||
modelEntity = LabelManagerFactory.entityModelReader.getModelEntity(modelParam.entityName);
|
||||
|
||||
modelEntity = LabelManagerFactory.getModelReader().getModelEntity(modelParam.entityName);
|
||||
|
||||
if (modelEntity != null) {
|
||||
ModelField modelField = modelEntity.getField(modelParam.fieldName);
|
||||
|
||||
|
||||
if (modelField != null) {
|
||||
setLabelReference(formFieldTitle + modelField.getName(), fileNameURI);
|
||||
autoFieldsService.put(modelField.getName(), "N");
|
||||
}
|
||||
}
|
||||
} catch (GenericEntityException e) {
|
||||
Debug.logError(e, module);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setLabelReference(formFieldTitle + modelParam.name, fileNameURI);
|
||||
}
|
||||
}
|
||||
@@ -514,25 +664,34 @@ public class LabelReferences {
|
||||
throw new GeneralException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getHyperlinkTag(Element element, String fileNameURI) {
|
||||
String hyperlinkDescription = UtilFormatOut.checkNull(element.getAttribute("description"));
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(hyperlinkDescription)) {
|
||||
// hyperlink description with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, hyperlinkDescription, uiLabelMap)) {
|
||||
setLabelReference(hyperlinkDescription, fileNameURI);;
|
||||
setLabelReference(hyperlinkDescription, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void getFieldTag(Element element, String fileNameURI) {
|
||||
String labelKey = UtilFormatOut.checkNull(element.getAttribute("name"));
|
||||
labelKey = formFieldTitle + labelKey;
|
||||
String fieldTitle = UtilFormatOut.checkNull(element.getAttribute("title"));
|
||||
String tooltip = UtilFormatOut.checkNull(element.getAttribute("tooltip"));
|
||||
boolean escludeField= false;
|
||||
|
||||
|
||||
private static void getFieldTag(Element element, String fileNameURI, Map<String, String> autoFieldsEntity, Map<String, String> autoFieldsService) {
|
||||
String fieldName = UtilFormatOut.checkNull(element.getAttribute("name"));
|
||||
String labelKey = formFieldTitle + fieldName;
|
||||
String fieldTitle = UtilFormatOut.checkNull(element.getAttribute("title"));
|
||||
String tooltip = UtilFormatOut.checkNull(element.getAttribute("tooltip"));
|
||||
|
||||
if (UtilValidate.isNotEmpty(autoFieldsEntity) && UtilValidate.isNotEmpty(autoFieldsEntity.get(fieldName))) {
|
||||
autoFieldsEntity.put(fieldName, "Y");
|
||||
}
|
||||
|
||||
if (UtilValidate.isNotEmpty(autoFieldsService) && UtilValidate.isNotEmpty(autoFieldsService.get(fieldName))) {
|
||||
autoFieldsService.put(fieldName, "Y");
|
||||
}
|
||||
|
||||
boolean escludeField = false;
|
||||
|
||||
for (Element fieldTypeElem: UtilXml.childElementList(element)) {
|
||||
if ("hidden".equals(fieldTypeElem.getTagName())) {
|
||||
escludeField = true;
|
||||
@@ -540,7 +699,7 @@ public class LabelReferences {
|
||||
escludeField = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!escludeField) {
|
||||
// field name labels
|
||||
if (UtilValidate.isEmpty(fieldTitle)) {
|
||||
@@ -548,88 +707,278 @@ public class LabelReferences {
|
||||
} else {
|
||||
// field title with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, fieldTitle, uiLabelMap)) {
|
||||
setLabelReference(fieldTitle, fileNameURI);;
|
||||
setLabelReference(fieldTitle, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(tooltip)) {
|
||||
// tooltip with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, tooltip, uiLabelMap)) {
|
||||
setLabelReference(tooltip, fileNameURI);;
|
||||
setLabelReference(tooltip, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getLabelTag(Element element, String fileNameURI) {
|
||||
String labelText = UtilFormatOut.checkNull(element.getAttribute("text"));
|
||||
String labelValue = UtilFormatOut.checkNull(UtilXml.elementValue(element));
|
||||
|
||||
|
||||
// label text labels
|
||||
if (UtilValidate.isNotEmpty(labelText)) {
|
||||
// label text with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, labelText, uiLabelMap)) {
|
||||
setLabelReference(labelText, fileNameURI);;
|
||||
setLabelReference(labelText, fileNameURI);
|
||||
}
|
||||
// label value labels
|
||||
} else if (UtilValidate.isNotEmpty(labelValue)) {
|
||||
// label value with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, labelValue, uiLabelMap)) {
|
||||
setLabelReference(labelValue, fileNameURI);;
|
||||
setLabelReference(labelValue, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getMenuItemTag(Element element, String fileNameURI) {
|
||||
String menuItemTitle = UtilFormatOut.checkNull(element.getAttribute("title"));
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(menuItemTitle)) {
|
||||
// menu item title with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, menuItemTitle, uiLabelMap)) {
|
||||
setLabelReference(menuItemTitle, fileNameURI);;
|
||||
setLabelReference(menuItemTitle, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getFailPropertyTag(Element element, String fileNameURI) {
|
||||
String propertyValue = UtilFormatOut.checkNull(element.getAttribute("property"));
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(propertyValue)) {
|
||||
// fail-property labels
|
||||
setLabelReference(propertyValue, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getOptionTag(Element element, String fileNameURI) {
|
||||
String description = UtilFormatOut.checkNull(element.getAttribute("description"));
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(description)) {
|
||||
// option description with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, description, uiLabelMap)) {
|
||||
setLabelReference(description, fileNameURI);;
|
||||
setLabelReference(description, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void getLinkTag(Element element, String fileNameURI) {
|
||||
String linkText = UtilFormatOut.checkNull(element.getAttribute("text"));
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(linkText)) {
|
||||
// link text with hardcoded labels
|
||||
if (!getLabelFromTag(element, fileNameURI, linkText, uiLabelMap)) {
|
||||
setLabelReference(linkText, fileNameURI);;
|
||||
setLabelReference(linkText, fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void getPropertyToFieldTag(Element element, String fileNameURI) {
|
||||
String property = UtilFormatOut.checkNull(element.getAttribute("property"));
|
||||
|
||||
private static void getWebappTag(Element element, String fileNameURI) {
|
||||
String title = UtilFormatOut.checkNull(element.getAttribute("title"));
|
||||
String appBarDisplay = UtilFormatOut.checkNull(element.getAttribute("app-bar-display"));
|
||||
|
||||
// property-to-field labels
|
||||
if (UtilValidate.isNotEmpty(property)) {
|
||||
setLabelReference(property, fileNameURI);
|
||||
// title labels
|
||||
if (UtilValidate.isNotEmpty(title) && UtilValidate.isNotEmpty(appBarDisplay) && "true".equalsIgnoreCase(appBarDisplay)) {
|
||||
setLabelReference(title, fileNameURI);
|
||||
}
|
||||
}
|
||||
|
||||
private static void getEntityOptionsTag(Element element, String fileNameURI) {
|
||||
String entityName = UtilFormatOut.checkNull(element.getAttribute("entity-name"));
|
||||
String description = UtilFormatOut.checkNull(element.getAttribute("description"));
|
||||
Set<String> fields = new TreeSet<String>();
|
||||
Set<String> pkFields = new TreeSet<String>();
|
||||
|
||||
try {
|
||||
|
||||
if (UtilValidate.isNotEmpty(entityName)) {
|
||||
GenericDelegator delegator = LabelManagerFactory.getDelegator();
|
||||
ModelEntity entity = delegator.getModelEntity(entityName);
|
||||
|
||||
if (UtilValidate.isNotEmpty(entity) && UtilValidate.isNotEmpty(entity.getDefaultResourceName())) {
|
||||
int pos = 0;
|
||||
while (pos >= 0){
|
||||
pos = description.indexOf(startExpression, pos);
|
||||
|
||||
if (pos >= 0) {
|
||||
int endLabel = description.indexOf(endExpression, pos);
|
||||
|
||||
if (endLabel >= 0) {
|
||||
String fieldName = description.substring(pos + startExpression.length(), endLabel);
|
||||
if (!fieldName.startsWith(uiLabelMapInLayoutSettings)) {
|
||||
for (Map.Entry<String, LabelInfo> e: LabelManagerFactory.getLabels().entrySet()) {
|
||||
String keyToSearch = entityName + "." + fieldName;
|
||||
if (e.getKey().startsWith(keyToSearch)) {
|
||||
fields.add(fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
pos = endLabel;
|
||||
} else {
|
||||
pos = pos + startExpression.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search primary keys of entity
|
||||
Iterator<ModelField> iter = entity.getPksIterator();
|
||||
while (iter != null && iter.hasNext()) {
|
||||
ModelField curField = iter.next();
|
||||
pkFields.add(curField.getName());
|
||||
}
|
||||
Iterator<String> fieldsIt = fields.iterator();
|
||||
while (fieldsIt != null && fieldsIt.hasNext()) {
|
||||
String fieldName = fieldsIt.next();
|
||||
List<EntityExpr> exprs = FastList.newInstance();
|
||||
for (Element entityConstraintElem: UtilXml.childElementList(element)) {
|
||||
if ("entity-constraint".equals(entityConstraintElem.getTagName())) {
|
||||
String constraintName = UtilFormatOut.checkNull(entityConstraintElem.getAttribute("name"));
|
||||
String constraintOperator = UtilFormatOut.checkNull(entityConstraintElem.getAttribute("operator"));
|
||||
String constraintValue = UtilFormatOut.checkNull(entityConstraintElem.getAttribute("value"));
|
||||
|
||||
EntityComparisonOperator operator = new EntityComparisonOperator(EntityOperator.ID_EQUALS, "=");
|
||||
if ("between".equals(constraintValue)) {
|
||||
operator = new EntityComparisonOperator(EntityOperator.ID_BETWEEN, "BETWEEN");
|
||||
} else if ("greater-equals".equals(constraintValue)) {
|
||||
operator = new EntityComparisonOperator(EntityOperator.ID_GREATER_THAN_EQUAL_TO, ">=");
|
||||
} else if ("greater".equals(constraintValue)) {
|
||||
operator = new EntityComparisonOperator(EntityOperator.ID_GREATER_THAN, ">");
|
||||
} else if ("in".equals(constraintValue)) {
|
||||
operator = new EntityComparisonOperator(EntityOperator.ID_IN, "IN");
|
||||
} else if ("less-equals".equals(constraintValue)) {
|
||||
operator = new EntityComparisonOperator(EntityOperator.ID_LESS_THAN_EQUAL_TO, "<=");
|
||||
} else if ("less".equals(constraintValue)) {
|
||||
operator = new EntityComparisonOperator(EntityOperator.ID_LESS_THAN, "<");
|
||||
} else if ("like".equals(constraintValue)) {
|
||||
operator = new EntityComparisonOperator(EntityOperator.ID_LIKE, "LIKE");
|
||||
} else if ("not-equals".equals(constraintValue)) {
|
||||
operator = new EntityComparisonOperator(EntityOperator.ID_NOT_EQUAL, "<>");
|
||||
}
|
||||
|
||||
exprs.add(EntityCondition.makeCondition(constraintName, operator, constraintValue));
|
||||
}
|
||||
}
|
||||
|
||||
EntityConditionList<EntityExpr> ecl = null;
|
||||
if (exprs.size() > 0) {
|
||||
ecl = EntityCondition.makeCondition(exprs, EntityOperator.AND);
|
||||
}
|
||||
|
||||
StringBuilder keyBuffer = new StringBuilder();
|
||||
keyBuffer.append(entityName);
|
||||
keyBuffer.append('.');
|
||||
keyBuffer.append(fieldName);
|
||||
List<GenericValue> entityRecords = delegator.findList(entityName, ecl, pkFields, null, null, false);
|
||||
|
||||
for (GenericValue entityRecord: entityRecords) {
|
||||
boolean pkFound = false;
|
||||
StringBuilder pkBuffer = new StringBuilder(keyBuffer.toString());
|
||||
Iterator <String> itPkFields = pkFields.iterator();
|
||||
while (itPkFields != null && itPkFields.hasNext()) {
|
||||
String pkField = itPkFields.next();
|
||||
Object pkFieldValue = entityRecord.get(pkField);
|
||||
|
||||
if (UtilValidate.isNotEmpty(pkFieldValue)) {
|
||||
pkBuffer.append('.');
|
||||
pkBuffer.append(pkFieldValue);
|
||||
pkFound = true;
|
||||
}
|
||||
}
|
||||
if (pkFound) {
|
||||
setLabelReference(pkBuffer.toString(), fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (GenericEntityException e) {
|
||||
Debug.logError(e, "Problem getting records from " + entityName, module);
|
||||
}
|
||||
}
|
||||
|
||||
private static void getDisplayEntityTag(Element element, String fileNameURI) {
|
||||
String entityName = UtilFormatOut.checkNull(element.getAttribute("entity-name"));
|
||||
String description = UtilFormatOut.checkNull(element.getAttribute("description"));
|
||||
Set<String> fields = new TreeSet<String>();
|
||||
Set<String> pkFields = new TreeSet<String>();
|
||||
|
||||
try {
|
||||
|
||||
if (UtilValidate.isNotEmpty(entityName)) {
|
||||
GenericDelegator delegator = LabelManagerFactory.getDelegator();
|
||||
ModelEntity entity = delegator.getModelEntity(entityName);
|
||||
|
||||
if (UtilValidate.isNotEmpty(entity) && UtilValidate.isNotEmpty(entity.getDefaultResourceName())) {
|
||||
int pos = 0;
|
||||
while (pos >= 0){
|
||||
pos = description.indexOf(startExpression, pos);
|
||||
|
||||
if (pos >= 0) {
|
||||
int endLabel = description.indexOf(endExpression, pos);
|
||||
|
||||
if (endLabel >= 0) {
|
||||
String fieldName = description.substring(pos + startExpression.length(), endLabel);
|
||||
if (!fieldName.startsWith(uiLabelMapInLayoutSettings)) {
|
||||
for (Map.Entry<String, LabelInfo> e: LabelManagerFactory.getLabels().entrySet()) {
|
||||
String keyToSearch = entityName + "." + fieldName;
|
||||
if (e.getKey().startsWith(keyToSearch)) {
|
||||
fields.add(fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
pos = endLabel;
|
||||
} else {
|
||||
pos = pos + startExpression.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Search primary keys of entity
|
||||
Iterator<ModelField> iter = entity.getPksIterator();
|
||||
while (iter != null && iter.hasNext()) {
|
||||
ModelField curField = iter.next();
|
||||
pkFields.add(curField.getName());
|
||||
}
|
||||
Iterator<String> fieldsIt = fields.iterator();
|
||||
while (fieldsIt != null && fieldsIt.hasNext()) {
|
||||
String fieldName = fieldsIt.next();
|
||||
StringBuilder keyBuffer = new StringBuilder();
|
||||
keyBuffer.append(entityName);
|
||||
keyBuffer.append('.');
|
||||
keyBuffer.append(fieldName);
|
||||
List<GenericValue> entityRecords = delegator.findList(entityName, null, pkFields, null, null, false);
|
||||
|
||||
for (GenericValue entityRecord: entityRecords) {
|
||||
boolean pkFound = false;
|
||||
StringBuilder pkBuffer = new StringBuilder(keyBuffer.toString());
|
||||
Iterator <String> itPkFields = pkFields.iterator();
|
||||
while (itPkFields != null && itPkFields.hasNext()) {
|
||||
String pkField = itPkFields.next();
|
||||
Object pkFieldValue = entityRecord.get(pkField);
|
||||
|
||||
if (UtilValidate.isNotEmpty(pkFieldValue)) {
|
||||
pkBuffer.append('.');
|
||||
pkBuffer.append(pkFieldValue);
|
||||
pkFound = true;
|
||||
}
|
||||
}
|
||||
if (pkFound) {
|
||||
setLabelReference(pkBuffer.toString(), fileNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (GenericEntityException e) {
|
||||
Debug.logError(e, "Problem getting records from " + entityName, module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user