You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2009/05/21 09:26:23 UTC
svn commit: r776988 [2/3] - in /ofbiz/trunk/framework/webtools: config/
servicedef/ src/org/ofbiz/webtools/labelmanager/ webapp/webtools/WEB-INF/
webapp/webtools/WEB-INF/actions/labelmanager/ webapp/webtools/labelmanager/
widget/
Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelReferences.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelReferences.java?rev=776988&r1=776987&r2=776988&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelReferences.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelReferences.java Thu May 21 07:26:22 2009
@@ -20,1135 +20,318 @@
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Collection;
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 javax.xml.parsers.ParserConfigurationException;
import javolution.util.FastList;
-import javolution.util.FastMap;
+import javolution.util.FastSet;
+import org.ofbiz.base.component.ComponentConfig;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.FileUtil;
-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.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.ModelParam;
import org.ofbiz.service.ModelService;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
public class LabelReferences {
public static final String module = LabelReferences.class.getName();
- private static final String uiLabelMap = "${uiLabelMap.";
- private static final String uiLabelMapInLayoutSettings = "uiLabelMap.";
+ private static final String bracketedUiLabelMap = "${uiLabelMap.";
+ private static final String uiLabelMap = "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>>();
+ private static final String getMessage = "UtilProperties.getMessage(";
+ protected Map<String, Map<String, Integer>> references = new TreeMap<String, Map<String, Integer>>();
+ protected GenericDelegator delegator;
+ protected DispatchContext dispatchContext;
+ protected Map<String, LabelInfo> labels;
+ protected Set<String> labelSet = FastSet.newInstance();
+ protected Set<String> rootFolders = FastSet.newInstance();
+
+ public LabelReferences(GenericDelegator delegator, LabelManagerFactory factory) {
+ this.delegator = delegator;
+ this.labels = factory.getLabels();
+ this.dispatchContext = new DispatchContext("LabelManagerDispCtx:" + delegator.getDelegatorName(), null, this.getClass().getClassLoader(), null);
+ Collection<LabelInfo> infoList = this.labels.values();
+ for (LabelInfo labelInfo : infoList) {
+ this.labelSet.add(labelInfo.getLabelKey());
+ }
+ Collection<ComponentConfig> componentConfigs = ComponentConfig.getAllComponents();
+ for (ComponentConfig config : componentConfigs) {
+ String rootFolder = config.getRootLocation();
+ rootFolder = rootFolder.replace('\\', '/');
+ if (!rootFolder.endsWith("/")) {
+ rootFolder = rootFolder + "/";
+ }
+ this.rootFolders.add(rootFolder);
+ }
+ this.rootFolders.add(System.getProperty("ofbiz.home") + "/specialpurpose/shark/");
+ }
+
+ public Map<String, Map<String, Integer>> getLabelReferences() throws IOException, SAXException, ParserConfigurationException, GenericServiceException {
+ if (this.labels.size() == 0) {
+ // Nothing to search for
+ return references;
+ }
// 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 widgets files
+ List<File> fileList = FastList.newInstance();
+ for (String rootFolder : this.rootFolders) {
+ fileList.addAll(FileUtil.findXmlFiles(rootFolder + "webapp", null, null, null));
+ fileList.addAll(FileUtil.findXmlFiles(rootFolder + "widget", null, null, null));
+ }
+ for (File file : fileList) {
+ String inFile = FileUtil.readString("UTF-8", file);
+ if (inFile.contains("</forms>")) {
+ getLabelsFromFormWidgets(inFile, file);
+ continue;
+ }
+ if (inFile.contains("</screens>") || inFile.contains("</menus>") || inFile.contains("</trees>")) {
+ findUiLabelMapInFile(inFile, file.getPath());
+ continue;
+ }
+
+ }
// 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);
- pos = endLabel;
- } else {
- pos = pos + uiLabelMap.length();
- }
- }
- }
- }
- /*
- * 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);
- }
- } catch (IOException ioe) {
- throw new GeneralException(ioe.getMessage());
- }
- }
-
- private static void getJavaLabels(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 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;
- }
- }
- pos += 1;
- }
- }
- } catch (IOException ioe) {
- 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)) {
- checkSimpleMethodTag(elem2, fileNameURI);
- for (Element elem3 : UtilXml.childElementList(elem2)) {
- checkSimpleMethodTag(elem3, fileNameURI);
- for (Element elem4 : UtilXml
- .childElementList(elem3)) {
- checkSimpleMethodTag(elem4, fileNameURI);
- for (Element elem5 : UtilXml
- .childElementList(elem4)) {
- checkSimpleMethodTag(elem5, fileNameURI);
- for (Element elem6 : UtilXml
- .childElementList(elem5)) {
- checkSimpleMethodTag(elem6, fileNameURI);
- }
- }
- }
- }
- }
- }
- }
- } catch (IOException ioe) {
- throw new GeneralException(ioe.getMessage());
- } catch (Exception e) {
- 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);
- }
- }
-
- 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) {
- String fileNameURI = formsFile.toURI().toString();
- Document formDocument = UtilXml.readXmlDocument(formsFile
- .toURI().toURL());
- Element rootElem = formDocument.getDocumentElement();
-
- for (Element elem1 : UtilXml.childElementList(rootElem)) {
- Map<String, String> autoFieldsEntity = FastMap
- .newInstance();
- Map<String, String> autoFieldsService = FastMap
- .newInstance();
- checkFormsTag(elem1, fileNameURI, autoFieldsEntity,
- autoFieldsService);
- for (Element elem2 : UtilXml.childElementList(elem1)) {
- checkFormsTag(elem2, fileNameURI, autoFieldsEntity,
- autoFieldsService);
- for (Element elem3 : UtilXml.childElementList(elem2)) {
- checkFormsTag(elem3, fileNameURI, autoFieldsEntity,
- autoFieldsService);
- for (Element elem4 : UtilXml
- .childElementList(elem3)) {
- checkFormsTag(elem4, fileNameURI,
- autoFieldsEntity, autoFieldsService);
- for (Element elem5 : UtilXml
- .childElementList(elem4)) {
- 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());
- } catch (Exception e) {
- throw new GeneralException(e.getMessage());
- }
- }
-
- 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, autoFieldsEntity);
- // auto fields service labels
- } else if ("auto-fields-service".equals(elem.getTagName())) {
- getAutoFieldsServiceTag(elem, fileNameURI, autoFieldsService);
- // field labels
- } else if ("field".equals(elem.getTagName())) {
- getFieldTag(elem, fileNameURI, autoFieldsEntity, autoFieldsService);
- // option description labels
- } else if ("option".equals(elem.getTagName())) {
- getOptionTag(elem, fileNameURI);
- // hyperlink/sub-hyperlink description labels
- } 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)) {
- checkScreensTag(elem2, fileNameURI);
- for (Element elem3 : UtilXml.childElementList(elem2)) {
- checkScreensTag(elem3, fileNameURI);
- for (Element elem4 : UtilXml
- .childElementList(elem3)) {
- checkScreensTag(elem4, fileNameURI);
- for (Element elem5 : UtilXml
- .childElementList(elem4)) {
- checkScreensTag(elem5, fileNameURI);
- for (Element elem6 : UtilXml
- .childElementList(elem5)) {
- checkScreensTag(elem6, fileNameURI);
- for (Element elem7 : UtilXml
- .childElementList(elem6)) {
- checkScreensTag(elem7, fileNameURI);
- for (Element elem8 : UtilXml
- .childElementList(elem7)) {
- checkScreensTag(elem8,
- fileNameURI);
- for (Element elem9 : UtilXml
- .childElementList(elem8)) {
- checkScreensTag(elem9,
- fileNameURI);
- for (Element elem10 : UtilXml
- .childElementList(elem9)) {
- checkScreensTag(elem10,
- fileNameURI);
- for (Element elem11 : UtilXml
- .childElementList(elem10)) {
- checkScreensTag(
- elem11,
- fileNameURI);
- for (Element elem12 : UtilXml
- .childElementList(elem11)) {
- checkScreensTag(
- elem12,
- fileNameURI);
- for (Element elem13 : UtilXml
- .childElementList(elem12)) {
- checkScreensTag(
- elem13,
- fileNameURI);
- for (Element elem14 : UtilXml
- .childElementList(elem13)) {
- checkScreensTag(
- elem14,
- fileNameURI);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } catch (IOException ioe) {
- throw new GeneralException(ioe.getMessage());
- } catch (Exception e) {
- throw new GeneralException(e.getMessage());
- }
- }
-
- private static void checkScreensTag(Element elem, String fileNameURI) {
- // set labels
- if ("set".equals(elem.getTagName())) {
- getSetTag(elem, fileNameURI);
- // screenlet labels
- } else if ("screenlet".equals(elem.getTagName())) {
- getScreenletTag(elem, fileNameURI);
- // label labels
- } else if ("label".equals(elem.getTagName())) {
- getLabelTag(elem, fileNameURI);
- // link labels
- } else if ("link".equals(elem.getTagName())) {
- 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)) {
- checkMenuTag(elem2, fileNameURI);
- for (Element elem3 : UtilXml.childElementList(elem2)) {
- checkMenuTag(elem3, fileNameURI);
- for (Element elem4 : UtilXml
- .childElementList(elem3)) {
- checkMenuTag(elem4, fileNameURI);
- for (Element elem5 : UtilXml
- .childElementList(elem4)) {
- checkMenuTag(elem5, fileNameURI);
- }
- }
- }
- }
- }
- }
- } catch (IOException ioe) {
- throw new GeneralException(ioe.getMessage());
- } catch (Exception e) {
- 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) {
+ private void setLabelReference(String labelKey, String filePath) {
Map<String, Integer> reference = references.get(labelKey);
if (UtilValidate.isEmpty(reference)) {
reference = new TreeMap<String, Integer>();
- reference.put(fileNameURI, new Integer(1));
+ reference.put(filePath, new Integer(1));
references.put(labelKey, reference);
} else {
- Integer labelsInFile = reference.get(fileNameURI);
+ Integer labelsInFile = reference.get(filePath);
if (UtilValidate.isEmpty(labelsInFile)) {
labelsInFile = new Integer(1);
} else {
labelsInFile = new Integer(labelsInFile.intValue() + 1);
}
- reference.put(fileNameURI, labelsInFile);
+ reference.put(filePath, 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);
- stringFound = true;
- pos = graph;
+ private void getLabelsFromFtlFiles() throws IOException {
+ for (String rootFolder : this.rootFolders) {
+ List<File> ftlFiles = FileUtil.findFiles("ftl", rootFolder, null, null);
+ for (File file : ftlFiles) {
+ String inFile = FileUtil.readString("UTF-8", file);
+ int pos = inFile.indexOf(bracketedUiLabelMap);
+ while (pos >= 0) {
+ int endPos = inFile.indexOf("}", pos);
+ if (endPos >= 0) {
+ String labelKey = inFile.substring(pos + bracketedUiLabelMap.length(), endPos);
+ if (this.labelSet.contains(labelKey)) {
+ setLabelReference(labelKey, file.getPath());
+ }
+ pos = endPos;
+ } else {
+ pos = pos + bracketedUiLabelMap.length();
}
- pos += 1;
+ pos = inFile.indexOf(bracketedUiLabelMap, pos);
}
}
}
- 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)
- || "titleProperty".equals(setField) || "title"
- .equals(setField))) {
- // set field with hardcoded labels
- if (!getLabelFromTag(element, fileNameURI, setValue, uiLabelMap)) {
- setLabelReference(setValue, fileNameURI);
- }
- } else if (UtilValidate.isNotEmpty(fromField)
- && ("layoutSettings.companyName".equals(setField) || "layoutSettings.companySubtitle"
- .equals(setField))) {
- // set field labels
- if (fromField.startsWith(uiLabelMapInLayoutSettings)) {
- setLabelReference(fromField.substring(
- uiLabelMapInLayoutSettings.length(), fromField
- .length()), fileNameURI);
- // set field with hardcoded labels
- } else {
- setLabelReference(fromField, fileNameURI);
+ private void getLabelsFromJavaFiles() throws IOException {
+ for (String rootFolder : this.rootFolders) {
+ List<File> javaFiles = FileUtil.findFiles("java", rootFolder + "src", null, null);
+ for (File javaFile : javaFiles) {
+ String inFile = FileUtil.readString("UTF-8", javaFile);
+ int pos = inFile.indexOf(getMessage);
+ while (pos >= 0) {
+ int endLabel = inFile.indexOf(")", pos);
+ if (endLabel >= 0) {
+ String[] args = inFile.substring(pos + getMessage.length(), endLabel).split(",");
+ for (String labelKey : this.labelSet) {
+ String searchString = "\"" + labelKey + "\"";
+ if (searchString.equals(args[1].trim())) {
+ setLabelReference(labelKey, javaFile.getPath());
+ }
+ }
+ pos = endLabel;
+ } else {
+ pos = pos + getMessage.length();
+ }
+ pos = inFile.indexOf(getMessage, pos);
}
}
}
}
- 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);
+ protected void findUiLabelMapInFile(String inFile, String filePath) {
+ int pos = inFile.indexOf(uiLabelMap);
+ while (pos >= 0) {
+ String endStr = "}";
+ if ("\"".equals(inFile.substring(pos - 1, pos))) {
+ endStr = "\"";
}
- }
- }
-
- 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.getModelReader()
- .getModelEntity(entityName);
-
- for (Iterator<ModelField> f = entity.getFieldsIterator(); f
- .hasNext();) {
- ModelField field = f.next();
- autoFieldsEntity.put(field.getName(), "N");
+ int endPos = inFile.indexOf(endStr, pos);
+ if (endPos >= 0) {
+ String labelKey = inFile.substring(pos + uiLabelMap.length(), endPos);
+ if (this.labelSet.contains(labelKey)) {
+ setLabelReference(labelKey, filePath);
}
+ pos = endPos;
+ } else {
+ pos = pos + uiLabelMap.length();
}
- } catch (Exception e) {
- throw new GeneralException(e.getMessage());
+ pos = inFile.indexOf(uiLabelMap, pos);
}
}
- 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
- .getDispatchContext().getModelService(serviceName);
- List<ModelParam> modelParams = modelService
- .getInModelParamList();
- Iterator<ModelParam> modelParamIter = modelParams.iterator();
-
- while (modelParamIter.hasNext()) {
- 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
- .getModelReader().getModelEntity(
- modelParam.entityName);
-
- if (modelEntity != null) {
- ModelField modelField = modelEntity
- .getField(modelParam.fieldName);
-
- if (modelField != null) {
- autoFieldsService.put(modelField
- .getName(), "N");
- }
- }
- } catch (GenericEntityException e) {
- Debug.logError(e, module);
- }
- }
+ protected void findLabelKeyInElement(String inFile, String filePath, String elementName) {
+ String searchString = "<" + elementName;
+ int pos = inFile.indexOf(searchString);
+ while (pos >= 0) {
+ int endLabel = inFile.indexOf(">", pos);
+ if (endLabel >= 0) {
+ String args = inFile.substring(pos + searchString.length(), endLabel);
+ for (String labelKey : this.labelSet) {
+ String arg = "\"" + labelKey + "\"";
+ if (args.contains(arg)) {
+ setLabelReference(labelKey, filePath);
}
}
+ pos = endLabel;
+ } else {
+ pos = pos + searchString.length();
}
- } catch (Exception e) {
- throw new GeneralException(e.getMessage());
+ pos = inFile.indexOf(searchString, pos);
}
}
- 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);
+ private void getLabelsFromSimpleMethodFiles() throws IOException {
+ for (String rootFolder : this.rootFolders) {
+ List<File> simpleMethodsFiles = FileUtil.findFiles("xml", rootFolder + "script", null, null);
+ for (File file : simpleMethodsFiles) {
+ String inFile = FileUtil.readString("UTF-8", file);
+ findUiLabelMapInFile(inFile, file.getPath());
+ findLabelKeyInElement(inFile, file.getPath(), "fail-property");
}
}
}
- 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;
- } else if ("ignored".equals(fieldTypeElem.getTagName())) {
- escludeField = true;
+ private void getLabelsFromFormWidgets(String inFile, File file) throws MalformedURLException, SAXException, ParserConfigurationException, IOException, GenericServiceException {
+ Set<String> fieldNames = FastSet.newInstance();
+ findUiLabelMapInFile(inFile, file.getPath());
+ Document formDocument = UtilXml.readXmlDocument(file.toURL());
+ Element rootElem = formDocument.getDocumentElement();
+ for (Element formElement : UtilXml.childElementList(rootElem, "form")) {
+ for (Element elem : UtilXml.childElementList(formElement, "auto-fields-service")) {
+ getAutoFieldsServiceTag(elem, fieldNames);
}
- }
-
- if (!escludeField) {
- // field name labels
- if (UtilValidate.isEmpty(fieldTitle)) {
- setLabelReference(labelKey, fileNameURI);
- } else {
- // field title with hardcoded labels
- if (!getLabelFromTag(element, fileNameURI, fieldTitle,
- uiLabelMap)) {
- setLabelReference(fieldTitle, fileNameURI);
- }
+ for (Element elem : UtilXml.childElementList(formElement, "auto-fields-entity")) {
+ getAutoFieldsEntityTag(elem, fieldNames);
}
-
- if (UtilValidate.isNotEmpty(tooltip)) {
- // tooltip with hardcoded labels
- if (!getLabelFromTag(element, fileNameURI, tooltip, uiLabelMap)) {
- setLabelReference(tooltip, fileNameURI);
+ for (String field : fieldNames) {
+ String labelKey = formFieldTitle.concat(field);
+ if (this.labelSet.contains(labelKey)) {
+ setLabelReference(labelKey, file.getPath());
}
}
}
}
- 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);
- }
- // label value labels
- } else if (UtilValidate.isNotEmpty(labelValue)) {
- // label value with hardcoded labels
- if (!getLabelFromTag(element, fileNameURI, labelValue, uiLabelMap)) {
- 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);
+ private void getLabelsFromOfbizComponents() throws IOException, SAXException, ParserConfigurationException {
+ List<File> componentsFiles = FileUtil.findXmlFiles(null, null, "ofbiz-component", "http://ofbiz.apache.org/dtds/ofbiz-component.xsd");
+ for (File componentFile : componentsFiles) {
+ String filePath = componentFile.getPath();
+ Document menuDocument = UtilXml.readXmlDocument(componentFile.toURL());
+ Element rootElem = menuDocument.getDocumentElement();
+ for (Element elem1 : UtilXml.childElementList(rootElem)) {
+ checkOfbizComponentTag(elem1, filePath);
+ for (Element elem2 : UtilXml.childElementList(elem1)) {
+ checkOfbizComponentTag(elem2, filePath);
+ }
}
}
}
- 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);
- }
+ private void checkOfbizComponentTag(Element elem, String filePath) {
+ // webapp labels
+ if ("webapp".equals(elem.getTagName())) {
+ getWebappTag(elem, filePath);
}
}
- 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);
+ private void getAutoFieldsEntityTag(Element element, Set<String> fieldNames) {
+ 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 = delegator.getModelEntity(entityName);
+ for (Iterator<ModelField> f = entity.getFieldsIterator(); f.hasNext();) {
+ ModelField field = f.next();
+ fieldNames.add(field.getName());
}
}
}
- private static void getWebappTag(Element element, String fileNameURI) {
- String title = UtilFormatOut.checkNull(element.getAttribute("title"));
- String appBarDisplay = UtilFormatOut.checkNull(element
- .getAttribute("app-bar-display"));
-
- // 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));
- }
- }
+ private void getAutoFieldsServiceTag(Element element, Set<String> fieldNames) throws GenericServiceException {
+ 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 = dispatchContext.getModelService(serviceName);
+ List<ModelParam> modelParams = modelService.getInModelParamList();
+ Iterator<ModelParam> modelParamIter = modelParams.iterator();
+ while (modelParamIter.hasNext()) {
+ 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;
+ modelEntity = delegator.getModelEntity(modelParam.entityName);
- EntityConditionList<EntityExpr> ecl = null;
- if (exprs.size() > 0) {
- ecl = EntityCondition.makeCondition(exprs,
- EntityOperator.AND);
- }
+ if (modelEntity != null) {
+ ModelField modelField = modelEntity.getField(modelParam.fieldName);
- 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);
+ if (modelField != null) {
+ fieldNames.add(modelField.getName());
}
}
}
}
}
- } 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);
+ private void getWebappTag(Element element, String filePath) {
+ String title = UtilFormatOut.checkNull(element.getAttribute("title"));
+ String appBarDisplay = UtilFormatOut.checkNull(element.getAttribute("app-bar-display"));
+ // title labels
+ if (UtilValidate.isNotEmpty(title) && UtilValidate.isNotEmpty(appBarDisplay) && "true".equalsIgnoreCase(appBarDisplay)) {
+ setLabelReference(title, filePath);
}
}
+
}
Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java?rev=776988&r1=776987&r2=776988&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java Thu May 21 07:26:22 2009
@@ -1,27 +1,26 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* 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
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.ofbiz.webtools.labelmanager;
-import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.net.URI;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -29,6 +28,8 @@
import org.apache.commons.lang.StringEscapeUtils;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.FileUtil;
+import org.ofbiz.base.util.UtilGenerics;
+import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilXml;
@@ -48,25 +49,64 @@
private static final String module = SaveLabelsToXmlFile.class.getName();
public static Map<String, Object> saveLabelsToXmlFile(DispatchContext dctx, Map<String, ? extends Object> context) {
- Locale locale = (Locale)context.get("locale");
- String labelFileName = (String)context.get("labelFileName");
+ Locale locale = (Locale) context.get("locale");
+ String fileName = (String) context.get("fileName");
+ if (UtilValidate.isEmpty(fileName)) {
+ Debug.logError("labelFileName cannot be empty", module);
+ return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "saveLabelsToXmlFile.exceptionDuringSaveLabelsToXmlFile", locale));
+ }
+ String key = (String) context.get("key");
+ String keyComment = (String) context.get("keyComment");
+ String update_label = (String) context.get("update_label");
+ 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"));
String apacheLicenseText = null;
try {
- apacheLicenseText = getApacheLicenseText();
+ apacheLicenseText = FileUtil.readString("UTF-8", FileUtil.getFile("component://webtools/config/APACHE2_HEADER_FOR_XML"));
} catch (IOException e) {
Debug.logWarning(e, "Unable to read Apache License text file", module);
}
try {
- LabelManagerFactory.getLabelManagerFactory(dctx.getDelegator().getDelegatorName());
- Map<String, LabelInfo> labels = LabelManagerFactory.getLabels();
- Map<String, String> fileNamesFound = LabelManagerFactory.getFileNamesFound();
- Set<String> labelsList = LabelManagerFactory.getLabelsList();
- Set<String> localesFound = LabelManagerFactory.getLocalesFound();
- for (String fileName : fileNamesFound.keySet()) {
- if (UtilValidate.isNotEmpty(labelFileName) && !(labelFileName.equalsIgnoreCase(fileName))) {
- continue;
+ LabelManagerFactory factory = LabelManagerFactory.getInstance();
+ LabelFile labelFile = factory.getLabelFile(fileName);
+ if (labelFile == null) {
+ Debug.logError("Invalid file name: " + fileName, module);
+ return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "saveLabelsToXmlFile.exceptionDuringSaveLabelsToXmlFile", locale));
+ }
+ synchronized(SaveLabelsToXmlFile.class) {
+ factory.findMatchingLabels(null, fileName, null, null);
+ Map<String, LabelInfo> labels = factory.getLabels();
+ Set<String> labelsList = factory.getLabelsList();
+ Set<String> localesFound = factory.getLocalesFound();
+ // Remove a Label
+ if (UtilValidate.isNotEmpty(removeLabel)) {
+ labels.remove(key + LabelManagerFactory.keySeparator + fileName);
+ } else if (UtilValidate.isNotEmpty(confirm)) {
+ LabelInfo label = labels.get(key + LabelManagerFactory.keySeparator + fileName);
+ // Update a Label
+ if (update_label.equalsIgnoreCase("Y")) {
+ if (UtilValidate.isNotEmpty(label)) {
+ factory.updateLabelValue(localeNames, localeValues, localeComments, label, key, keyComment, fileName);
+ }
+ // Insert a new Label
+ } else {
+ if (UtilValidate.isNotEmpty(label)) {
+ return ServiceUtil.returnError(UtilProperties.getMessage(resource, "WebtoolsLabelManagerNewLabelExisting", UtilMisc.toMap("key", key, "fileName", fileName), locale));
+ } else {
+ if (UtilValidate.isEmpty(key)) {
+ return ServiceUtil.returnError(UtilProperties.getMessage(resource, "WebtoolsLabelManagerNewLabelEmptyKey", locale));
+ } else {
+ int notEmptyLabels = factory.updateLabelValue(localeNames, localeValues, localeComments, null, key, keyComment, fileName);
+ if (notEmptyLabels == 0) {
+ return ServiceUtil.returnError(UtilProperties.getMessage(resource, "WebtoolsLabelManagerNewLabelEmpty", locale));
+ }
+ }
+ }
+ }
}
- String uri = fileNamesFound.get(fileName);
Document resourceDocument = UtilXml.makeEmptyXmlDocument("resource");
Element resourceElem = resourceDocument.getDocumentElement();
resourceElem.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
@@ -90,7 +130,8 @@
}
if (UtilValidate.isNotEmpty(valueString)) {
valueString = StringEscapeUtils.unescapeHtml(valueString);
- Element valueElem = UtilXml.addChildElementValue(propertyElem, "value", valueString, resourceDocument);;
+ Element valueElem = UtilXml.addChildElementValue(propertyElem, "value", valueString, resourceDocument);
+ ;
valueElem.setAttribute("xml:lang", localeFound);
if (valueString.trim().length() == 0) {
valueElem.setAttribute("xml:space", "preserve");
@@ -102,10 +143,7 @@
}
}
}
- }
- if (UtilValidate.isNotEmpty(uri)) {
- File outFile = new File(new URI(uri));
- FileOutputStream fos = new FileOutputStream(outFile);
+ FileOutputStream fos = new FileOutputStream(labelFile.file);
try {
if (apacheLicenseText != null) {
fos.write(apacheLicenseText.getBytes());
@@ -113,7 +151,8 @@
UtilXml.writeXmlDocument(resourceElem, fos, "UTF-8", !(apacheLicenseText == null), true, 4);
} finally {
fos.close();
- // clear cache to see immediately the new labels and translations in OFBiz
+ // clear cache to see immediately the new labels and
+ // translations in OFBiz
UtilCache.clearCache("properties.UtilPropertiesBundleCache");
}
}
@@ -124,15 +163,4 @@
}
return ServiceUtil.returnSuccess();
}
-
- public static String getApacheLicenseText() throws IOException {
- String apacheLicenseText = null;
- String basePath = System.getProperty("ofbiz.home");
- if (UtilValidate.isNotEmpty(basePath)) {
- String apacheLicenseFileName = basePath + "/framework/webtools/config/APACHE2_HEADER_FOR_XML";
- File apacheLicenseFile = new File(apacheLicenseFileName);
- apacheLicenseText = FileUtil.readString("UTF-8", apacheLicenseFile);
- }
- return apacheLicenseText;
- }
}
Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/LabelManager.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/LabelManager.groovy?rev=776988&r1=776987&r2=776988&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/LabelManager.groovy (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/LabelManager.groovy Thu May 21 07:26:22 2009
@@ -20,14 +20,20 @@
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.webtools.labelmanager.*;
-LabelManagerFactory.getLabelManagerFactory(delegator.getDelegatorName());
-context.labels = LabelManagerFactory.getLabels();
-context.labelsList = LabelManagerFactory.getLabelsList();
-context.localesFound = LabelManagerFactory.getLocalesFound();
-context.fileNamesFound = LabelManagerFactory.getFileNamesFound();
-context.componentNamesFound = LabelManagerFactory.getComponentNamesFound();
-context.references = LabelManagerFactory.getReferences();
-context.referencesList = LabelManagerFactory.getReferencesList();
-context.duplicatedLocalesLabels = LabelManagerFactory.getDuplicatedLocalesLabels();
-context.duplicatedLocalesLabelsList = LabelManagerFactory.getDuplicatedLocalesLabelsList();
-context.keySeparator = LabelManagerFactory.keySeparator;
+LabelManagerFactory factory = LabelManagerFactory.getInstance();
+context.factory = factory;
+factory.findMatchingLabels(parameters.labelComponentName, parameters.labelFileName, parameters.labelKey, parameters.labelLocaleName)
+context.labels = factory.getLabels();
+context.labelsList = factory.getLabelsList();
+context.localesFound = factory.getLocalesFound();
+context.filesFound = factory.getFilesFound();
+context.componentNamesFound = factory.getComponentNamesFound();
+context.duplicatedLocalesLabels = factory.getDuplicatedLocalesLabels();
+context.duplicatedLocalesLabelsList = factory.getDuplicatedLocalesLabelsList();
+context.keySeparator = factory.keySeparator;
+if ("Y".equals(parameters.onlyNotUsedLabels)) {
+ LabelReferences refsObject = new LabelReferences(delegator, factory);
+ Map references = refsObject.getLabelReferences();
+ context.references = references;
+ context.referencesList = references.keySet();
+}
Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/UpdateManager.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/UpdateManager.groovy?rev=776988&r1=776987&r2=776988&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/UpdateManager.groovy (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/UpdateManager.groovy Thu May 21 07:26:22 2009
@@ -20,11 +20,12 @@
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.webtools.labelmanager.*;
-LabelManagerFactory.getLabelManagerFactory(delegator.getDelegatorName());
-context.labels = LabelManagerFactory.getLabels();
-context.localesFound = LabelManagerFactory.getLocalesFound();
-context.fileNamesFound = LabelManagerFactory.getFileNamesFound();
-context.componentNamesFound = LabelManagerFactory.getComponentNamesFound();
+LabelManagerFactory factory = LabelManagerFactory.getInstance();
+factory.findMatchingLabels(null, parameters.sourceFileName, parameters.sourceKey, null)
+context.labels = factory.getLabels();
+context.localesFound = factory.getLocalesFound();
+context.filesFound = factory.getFilesFound();
+context.componentNamesFound = factory.getComponentNamesFound();
if (parameters.sourceKey && parameters.sourceFileName) {
context.label = context.labels.get(parameters.sourceKey + LabelManagerFactory.keySeparator + parameters.sourceFileName);
Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewFile.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewFile.groovy?rev=776988&r1=776987&r2=776988&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewFile.groovy (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewFile.groovy Thu May 21 07:26:22 2009
@@ -17,13 +17,24 @@
* under the License.
*/
import java.net.URI;
-import org.ofbiz.base.util.FileUtil;
-import org.ofbiz.base.util.StringUtil;
+import org.ofbiz.base.util.*;
+import org.w3c.dom.*;
+import java.io.ByteArrayOutputStream;
+import org.apache.commons.lang.StringEscapeUtils;
-fileToString = "";
+fileString = "";
if (parameters.fileName) {
- file = new File(new URI(parameters.fileName));
- fileToString = FileUtil.readString("UTF-8", file);
- rows = StringUtil.split(fileToString, System.getProperty("line.separator"));
+ file = new File(parameters.fileName);
+ if (parameters.fileName.endsWith(".xml")) {
+ Document document = UtilXml.readXmlDocument(file.toURL(), false);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ UtilXml.writeXmlDocument(document, os, "UTF-8", true, true, 4);
+ os.close();
+ fileString = os.toString();
+ } else {
+ fileString = FileUtil.readString("UTF-8", file);
+ }
+ rows = fileString.split(System.getProperty("line.separator"));
+ context.rows = rows.size();
}
-context.rows = rows;
+context.fileString = fileString;
Added: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewReferences.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewReferences.groovy?rev=776988&view=auto
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewReferences.groovy (added)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewReferences.groovy Thu May 21 07:26:22 2009
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.webtools.labelmanager.*;
+
+LabelManagerFactory factory = LabelManagerFactory.getInstance();
+context.factory = factory;
+factory.findMatchingLabels(parameters.labelComponentName, parameters.labelFileName, parameters.sourceKey, parameters.labelLocaleName)
+context.labels = factory.getLabels();
+context.labelsList = factory.getLabelsList();
+context.localesFound = factory.getLocalesFound();
+context.filesFound = factory.getFilesFound();
+context.componentNamesFound = factory.getComponentNamesFound();
+context.duplicatedLocalesLabels = factory.getDuplicatedLocalesLabels();
+context.duplicatedLocalesLabelsList = factory.getDuplicatedLocalesLabelsList();
+context.keySeparator = factory.keySeparator;
+LabelReferences refsObject = new LabelReferences(delegator, factory);
+Map references = refsObject.getLabelReferences();
+context.references = references;
+context.referencesList = references.keySet();
Propchange: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewReferences.groovy
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewReferences.groovy
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/ViewReferences.groovy
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml?rev=776988&r1=776987&r2=776988&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml Thu May 21 07:26:22 2009
@@ -449,20 +449,6 @@
<response name="success" type="view" value="UpdateLabel"/>
</request-map>
- <request-map uri="UpdateLabelKey">
- <security https="true" auth="true"/>
- <event type="service" invoke="updateLabelKey"/>
- <response name="success" type="view" value="SearchLabels"/>
- <response name="error" type="view" value="UpdateLabel"/>
- </request-map>
-
- <request-map uri="UpdateAndSaveLabelKey">
- <security https="true" auth="true"/>
- <event type="service" invoke="updateAndSaveLabelKey"/>
- <response name="success" type="view" value="SearchLabels"/>
- <response name="error" type="view" value="UpdateLabel"/>
- </request-map>
-
<request-map uri="ViewReferences">
<security https="true" auth="true"/>
<response name="success" type="view" value="ViewReferences"/>