From d5dc2d53ab09d324755d344ed6d5270ba92d0ee5 Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Sun, 15 Feb 2009 08:42:06 +0000 Subject: [PATCH] Marco's LabelReferences2.patch from "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@744635 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/ofbiz/base/util/FileUtil.java | 26 +- .../webtools/config/WebtoolsUiLabels.xml | 93 +-- framework/webtools/servicedef/services.xml | 4 +- .../labelmanager/LabelManagerFactory.java | 116 ++-- .../labelmanager/LabelReferences.java | 635 ++++++++++++++++++ .../actions/labelmanager/LabelManager.groovy | 3 + .../labelmanager/ViewHardcodedLabels.ftl | 24 + .../webtools/labelmanager/ViewLabels.ftl | 12 +- .../webtools/widget/LabelManagerScreens.xml | 5 +- 9 files changed, 831 insertions(+), 87 deletions(-) create mode 100644 framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelReferences.java create mode 100644 framework/webtools/webapp/webtools/labelmanager/ViewHardcodedLabels.ftl diff --git a/framework/base/src/org/ofbiz/base/util/FileUtil.java b/framework/base/src/org/ofbiz/base/util/FileUtil.java index c5a45bbef8..26a467e916 100644 --- a/framework/base/src/org/ofbiz/base/util/FileUtil.java +++ b/framework/base/src/org/ofbiz/base/util/FileUtil.java @@ -33,11 +33,11 @@ import java.io.Writer; import java.util.List; import java.util.Set; -import org.apache.commons.io.FileUtils; - import javolution.util.FastList; import javolution.util.FastSet; +import org.apache.commons.io.FileUtils; + /** * File Utilities * @@ -215,6 +215,28 @@ public class FileUtil { } } } + + public static List findFiles(String fileExt, String basePath, String partialPath, String stringToFind) throws IOException { + if (basePath == null) { + basePath = System.getProperty("ofbiz.home"); + } + + Set stringsToFindInPath = FastSet.newInstance(); + Set stringsToFindInFile = FastSet.newInstance(); + + if (partialPath != null) { + stringsToFindInPath.add(partialPath); + } + if (stringToFind != null) { + stringsToFindInFile.add(stringToFind); + } + + List fileList = FastList.newInstance(); + FileUtil.searchFiles(fileList, new File(basePath), new SearchTextFilesFilter(fileExt, stringsToFindInPath, stringsToFindInFile), true); + + return fileList; + } + public static List findXmlFiles(String basePath, String partialPath, String rootElementName, String xsdOrDtdName) throws IOException { if (basePath == null) { basePath = System.getProperty("ofbiz.home"); diff --git a/framework/webtools/config/WebtoolsUiLabels.xml b/framework/webtools/config/WebtoolsUiLabels.xml index 59cde845bd..4b03487cba 100644 --- a/framework/webtools/config/WebtoolsUiLabels.xml +++ b/framework/webtools/config/WebtoolsUiLabels.xml @@ -564,16 +564,13 @@ Parte da família OfBiz de software de fonte aberta Parte da família OfBiz de software de fonte aberta - - + Partea de Deschidere Pentru Afaceri Familiale din Open Source Software - - + Входит в состав семейства Open For Business ส่วนหนึ่งของธุรกิจแบบครอบครัวที่เป็นซอฟต์แวร์โอเพนซอส - - + 开源软件OFBiz家族的一部分 OFBiz的一部分 @@ -1471,6 +1468,10 @@ Nom de fichier Nome File + + Hardcoded labels + Label non traducibili + Key Clef @@ -1501,11 +1502,19 @@ La traduction ${key} existe déjà dans le fichier ${fileName} La label ${key} esiste gi‚àö‚Ć nel file ${fileName} + + References + Referenze + Remove Label Supprimer la traduction Rimuovi label + + Row n. + N.riga + Filter Labels Info By Filtrer les traductions @@ -1672,6 +1681,14 @@ หน่วยความจำ 内存 + + This page can be used to export data from the database + Cette page peut être utilisée pour exporter des données depuis la base + Questa pagine può essere usata per esportare i dati dal database + Aceasta pagina poate fi folosita pentru exportarea datelor din database + หน้านี้ใช้การส่งออกข้อมูลจากฐานข้อมูล + 本页面用于从数据库导出数据 + number of time the job will retry on error; use -1 for no limit or leave empty for service default Nombre de fois où le job sera relancé en cas d'erreur; utilisez -1 pour ne définir aucune limite ou laissez vide pour utilisez la valeur par défaut du service @@ -1750,13 +1767,13 @@ Scritti XML per tutti i dati in เขียน XML สำหรับข้อมูลทั้งหมดใน - - This page can be used to export data from the database - Cette page peut être utilisée pour exporter des données depuis la base - Questa pagine può essere usata per esportare i dati dal database - Aceasta pagina poate fi folosita pentru exportarea datelor din database - หน้านี้ใช้การส่งออกข้อมูลจากฐานข้อมูล - 本页面用于从数据库导出数据 + + The exported documents will have a root tag of "<entity-engine-xml>" + Les documents exportés auront une balise de racine de "<entity-engine-xml>" + I documenti esportati avranno un root tag "<entity-engine-xml>" + Documentele exportate vor avea un root tag "<entity-engine-xml>" + การส่งเอกสารจะต้องใช้รูทแท็กของ "<entity-engine-xml>" + 导出的文档会有一个"<entity-engine-xml>"的根标签 Wrote @@ -1819,13 +1836,13 @@ NOTA: Questi risultati delle prestazioni potrebbero variare in base ai differenti database, หมายเหตุ:การกระทำเหล่านี้อาจจะเป็นผลให้เกิดการซื้อขายที่ดีสำหรับความแตกต่าง - - The exported documents will have a root tag of "<entity-engine-xml>" - Les documents exportés auront une balise de racine de "<entity-engine-xml>" - I documenti esportati avranno un root tag "<entity-engine-xml>" - Documentele exportate vor avea un root tag "<entity-engine-xml>" - การส่งเอกสารจะต้องใช้รูทแท็กของ "<entity-engine-xml>" - 导出的文档会有一个"<entity-engine-xml>"的根标签 + + There will be one file for each Entity in the configured delegator for this webapp + Il y aura un dossier pour chaque entité dans le delegator configuré pour cette webapp + C'è un file per ogni Entità nel delegator configurato per questa applicazione web + Exista un file pentru orice Entitate din delegatorul configurat pentru aceasta aplicatie web. + มี 1 ไฟล์สำหรับตัวอย่าง Entity ในการสร้างตัวแทนสำหรับโปรแกรมประยุกต์นี้ + 在为这个应用配置的代表中,会对每个实体有一个文件。 databases, JDBC drivers, JTA implementations (transaction managers), connection pools, @@ -1847,14 +1864,6 @@ server hardware, connessioni di rete). server ฮาร์ดแวร์,เชื่อมโยงเครือข่าย). - - There will be one file for each Entity in the configured delegator for this webapp - Il y aura un dossier pour chaque entité dans le delegator configuré pour cette webapp - C'è un file per ogni Entità nel delegator configurato per questa applicazione web - Exista un file pentru orice Entitate din delegatorul configurat pentru aceasta aplicatie web. - มี 1 ไฟล์สำหรับตัวอย่าง Entity ในการสร้างตัวแทนสำหรับโปรแกรมประยุกต์นี้ - 在为这个应用配置的代表中,会对每个实体有一个文件。 - Complete XML document (root tag: entity-engine-xml) Compléter le document XML (balise racine : entity-engine-xml)( @@ -2299,6 +2308,12 @@ Pop up หน้าหลักเครื่องมือพัฒนาเว็บ 弹出Web工具首页 + + Pre-configured set + Ensemble pré-configuré + Impostazioni Pre-configurate + ตั้งค่าก่อนการสร้าง + Catalog Export Exporter le catalogue @@ -2329,12 +2344,6 @@ Prodotti Parte 4 สินค้าส่วนที่ 4 - - Pre-configured set - Ensemble pré-configuré - Impostazioni Pre-configurate - ตั้งค่าก่อนการสร้าง - Dringlichkeit Priority @@ -3069,6 +3078,14 @@ การเลือกระดับในการกำหนดเวลาที่เหมาะสมที่สุดโดยข้อมูลจำนวนมากผลลัพธ์ที่ได้จะใช้แก้ไขข้อผิดพลาดของแอพพลิเคชั่น Timing(定时)级别会细颗粒地指出应用程序进行情况的信息,适于调试程序。 + + Title + Titre + Titolo + Titlu + หัวเรื่อง + 标题 + The purpose of this Web Tools administration package is to contain all of the Le but de cet d'ensemble d'outils Web d'administration est de contenir tout les outils @@ -3117,14 +3134,6 @@ ความพึงพอใจและความรู้ความสามารถในการจัดการ วิเคราะห์ข้อมูล พัฒนาไปข้างหน้าอย่างเต็มที่ 内容和知识管理、数据分析等。 - - Title - Titre - Titolo - Titlu - หัวเรื่อง - 标题 - To find ALL of Entity Pour trouver TOUT sur l'entité diff --git a/framework/webtools/servicedef/services.xml b/framework/webtools/servicedef/services.xml index 915833a52c..6311b0beca 100644 --- a/framework/webtools/servicedef/services.xml +++ b/framework/webtools/servicedef/services.xml @@ -43,8 +43,8 @@ under the License. location="org.ofbiz.webtools.WebToolsServices" invoke="entityImport" auth="true" use-transaction="false"> Imports an entity xml file or text string - - + + diff --git a/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java b/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java index 4c080864a4..de9fe1ff18 100644 --- a/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java +++ b/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java @@ -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 @@ -35,13 +35,12 @@ import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilXml; - import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.cache.UtilCache; +import org.ofbiz.entity.model.ModelReader; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.ServiceUtil; - import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -51,25 +50,28 @@ public class LabelManagerFactory { public static final String module = LabelManagerFactory.class.getName(); public static final String resource = "WebtoolsUiLabels"; - - public static final String keySeparator = ";"; - + + public static final String keySeparator = "#"; + protected static UtilCache labelManagerFactoryCache = new UtilCache("LabelManagerFactory"); - + protected static Map labels = null; protected static Map fileNamesFound = null; protected static Map fileComponent = null; protected static Set localesFound = null; protected static Set componentNamesFound = null; + protected static Map> references = null; protected static int duplicatedLocalesLabels = 0; - + protected static String delegatorName; - + protected static ModelReader entityModelReader; + protected static DispatchContext dispatchContext; + public static LabelManagerFactory getLabelManagerFactory(String delegatorName) throws GeneralException { if (UtilValidate.isEmpty(delegatorName)) { delegatorName = "default"; } - + LabelManagerFactory lmf = labelManagerFactoryCache.get(delegatorName); if (lmf == null) { @@ -78,47 +80,50 @@ public class LabelManagerFactory { } return lmf; } - + protected LabelManagerFactory(String delegatorName) throws GeneralException { LabelManagerFactory.delegatorName = delegatorName; - + LabelManagerFactory.entityModelReader = ModelReader.getModelReader(delegatorName); + LabelManagerFactory.dispatchContext = new DispatchContext("LabelManagerDispCtx", null, this.getClass().getClassLoader(), null); + prepareAll(); } - + private static void prepareAll() throws GeneralException { labels = new TreeMap(); fileNamesFound = new TreeMap(); fileComponent = new TreeMap(); localesFound = new TreeSet(); componentNamesFound = new TreeSet(); + references = null; int duplicatedLocales = 0; - + try { Collection componentConfigs = ComponentConfig.getAllComponents(); - + for (ComponentConfig componentConfig: componentConfigs) { String componentName = componentConfig.getComponentName(); List resourceFiles = FileUtil.findXmlFiles(componentConfig.getRootLocation(), null, "resource", null); - + 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())) { + + 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); - + if (UtilValidate.isEmpty(label)) { label = new LabelInfo(labelKey, labelKeyComment, fileName, componentName, localeName, labelValue, labelComment); labels.put(labelKey + keySeparator + fileName, label); @@ -130,12 +135,12 @@ public class LabelManagerFactory { localesFound.add(localeName); componentNamesFound.add(componentName); fileNamesFound.put(fileName, resourceFile.toURI().toString()); - fileComponent.put(fileName, componentName); - labelComment = ""; + 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); @@ -143,6 +148,9 @@ public class LabelManagerFactory { } } } + + // get labels references from sources + references = LabelReferences.getLabelReferences(); } catch(IOException ioe) { throw new GeneralException(ioe.getMessage()); } catch(Exception e) { @@ -150,19 +158,19 @@ public class LabelManagerFactory { } duplicatedLocalesLabels = duplicatedLocales; } - + public static Map getLabels() { return labels; } - + public static Set getLocalesFound() { return localesFound; } - + public static Map getFileNamesFound() { return fileNamesFound; } - + public static String getFileComponent(String fileName) { String componentName = null; if (UtilValidate.isNotEmpty(fileName)) { @@ -170,19 +178,51 @@ public class LabelManagerFactory { } return componentName; } - + public static Set getComponentNamesFound() { return componentNamesFound; } + + public static Map> getReferences() { + return references; + } public static Set getLabelsList() { return labels.keySet(); } + public static Set getReferencesList() { + return references.keySet(); + } + + public static int getLabelReferenceFile(String key) { + int refFile = 0; + boolean keyFound = false; + + for (Map.Entry e: fileNamesFound.entrySet()) { + String keyToSearch = key + keySeparator + e.getKey(); + + if (labels.containsKey(keyToSearch)) { + keyFound = true; + break; + } + } + + if (!keyFound) { + Map reference = references.get(key); + + if (UtilValidate.isNotEmpty(reference)) { + refFile = reference.size(); + } + } + + return refFile; + } + public static int getDuplicatedLocalesLabels() { return duplicatedLocalesLabels; } - + public static Map updateLabelKey(DispatchContext dctx, Map context) { String key = (String)context.get("key"); String keyComment = (String)context.get("keyComment"); @@ -194,13 +234,13 @@ public class LabelManagerFactory { List localeValues = UtilGenerics.cast(context.get("localeValues")); List localeComments = UtilGenerics.cast(context.get("localeComments")); Locale locale = (Locale) context.get("locale"); - + // Remove a Label if (UtilValidate.isNotEmpty(removeLabel)) { labels.remove(key + keySeparator + fileName); } else if (UtilValidate.isNotEmpty(confirm)) { LabelInfo label = labels.get(key + keySeparator + fileName); - + // Update a Label if (update_label.equalsIgnoreCase("Y")) { if (UtilValidate.isNotEmpty(label)) { @@ -220,12 +260,12 @@ public class LabelManagerFactory { } } } - } + } } - + return ServiceUtil.returnSuccess(); } - + private static int updateLabelValue(List localeNames, List localeValues, List localeComments, LabelInfo label, String key, String keyComment, String fileName) { int notEmptyLabels = 0; int i = 0; @@ -233,7 +273,7 @@ public class LabelManagerFactory { String localeName = (String)localeNames.get(i); String localeValue = (String)localeValues.get(i); String localeComment = (String)localeComments.get(i); - + if (UtilValidate.isNotEmpty(localeValue) || UtilValidate.isNotEmpty(localeComment)) { if (label == null) { try { @@ -251,7 +291,7 @@ public class LabelManagerFactory { } i++; } - + return notEmptyLabels; } } diff --git a/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelReferences.java b/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelReferences.java new file mode 100644 index 0000000000..8b0ea09e68 --- /dev/null +++ b/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelReferences.java @@ -0,0 +1,635 @@ +/* + * 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.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +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.GenericEntityException; +import org.ofbiz.entity.model.ModelEntity; +import org.ofbiz.entity.model.ModelField; +import org.ofbiz.service.ModelParam; +import org.ofbiz.service.ModelService; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +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 formFieldTitle = "FormFieldTitle_"; + private static final String getMessage = "UtilProperties.getMessage"; + private static Map> references = null; + + public static Map> getLabelReferences() throws GeneralException { + references = new TreeMap>(); + + // 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(); + + return references; + } + + private static void getLabelsFromFtlFiles() throws GeneralException { + try { + List 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(); + } + } + } + } + } catch(IOException ioe) { + throw new GeneralException(ioe.getMessage()); + } + } + + private static void getLabelsFromJavaFiles() throws GeneralException { + try { + List 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 getLabelsFromSimpleMethodFiles() throws GeneralException { + try { + List 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); + // property-to-field labels + } else if ("property-to-field".equals(elem.getTagName())) { + getPropertyToFieldTag(elem, fileNameURI); + } + } + + private static void getLabelsFromFormWidgets() throws GeneralException { + try { + List 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)) { + checkFormsTag(elem1, fileNameURI); + for (Element elem2: UtilXml.childElementList(elem1)) { + checkFormsTag(elem2, fileNameURI); + for (Element elem3: UtilXml.childElementList(elem2)) { + checkFormsTag(elem3, fileNameURI); + for (Element elem4: UtilXml.childElementList(elem3)) { + checkFormsTag(elem4, fileNameURI); + for (Element elem5: UtilXml.childElementList(elem4)) { + checkFormsTag(elem5, 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) throws GeneralException { + // auto fields entity labels + if ("auto-fields-entity".equals(elem.getTagName())) { + getAutoFieldsEntityTag(elem, fileNameURI); + // auto fields service labels + } else if ("auto-fields-service".equals(elem.getTagName())) { + getAutoFieldsServiceTag(elem, fileNameURI); + // field labels + } else if ("field".equals(elem.getTagName())) { + getFieldTag(elem, fileNameURI); + // 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); + } + } + + private static void getLabelsFromScreenWidgets() throws GeneralException { + try { + List 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 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 setLabelReference(String labelKey, String fileNameURI) { + Map reference = references.get(labelKey); + if (UtilValidate.isEmpty(reference)) { + reference = new TreeMap(); + reference.put(fileNameURI, new Integer(1)); + references.put(labelKey, reference); + } else { + Integer labelsInFile = reference.get(fileNameURI); + + if (UtilValidate.isEmpty(labelsInFile)) { + labelsInFile = new Integer(1); + } + else { + labelsInFile = new Integer(labelsInFile.intValue() + 1); + } + 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); + stringFound = true; + pos = graph; + } + pos += 1; + } + } + } + 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 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);; + } + } + } + + private static void getAutoFieldsEntityTag(Element element, String fileNameURI) 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); + + for (Iterator f = entity.getFieldsIterator(); f.hasNext();) { + ModelField field = f.next(); + setLabelReference(formFieldTitle + field.getName(), fileNameURI); + } + } + } catch(Exception e) { + throw new GeneralException(e.getMessage()); + } + } + + private static void getAutoFieldsServiceTag(Element element, String fileNameURI) 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); + List modelParams = modelService.getInModelParamList(); + Iterator 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); + + if (modelEntity != null) { + ModelField modelField = modelEntity.getField(modelParam.fieldName); + + if (modelField != null) { + setLabelReference(formFieldTitle + modelField.getName(), fileNameURI); + } + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + } + + setLabelReference(formFieldTitle + modelParam.name, fileNameURI); + } + } + } + } catch(Exception e) { + 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);; + } + } + } + + 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; + + for (Element fieldTypeElem: UtilXml.childElementList(element)) { + if ("hidden".equals(fieldTypeElem.getTagName())) { + escludeField = true; + } else if ("ignore".equals(fieldTypeElem.getTagName())) { + escludeField = true; + } + } + + 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);; + } + } + + if (UtilValidate.isNotEmpty(tooltip)) { + // tooltip with hardcoded labels + if (!getLabelFromTag(element, fileNameURI, tooltip, uiLabelMap)) { + 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);; + } + // 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 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 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 static void getPropertyToFieldTag(Element element, String fileNameURI) { + String property = UtilFormatOut.checkNull(element.getAttribute("property")); + + // property-to-field labels + if (UtilValidate.isNotEmpty(property)) { + setLabelReference(property, fileNameURI); + } + } +} + + diff --git a/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/LabelManager.groovy b/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/LabelManager.groovy index 9d5460875e..198032a4ae 100644 --- a/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/LabelManager.groovy +++ b/framework/webtools/webapp/webtools/WEB-INF/actions/labelmanager/LabelManager.groovy @@ -26,4 +26,7 @@ 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.keySeparator = LabelManagerFactory.keySeparator; diff --git a/framework/webtools/webapp/webtools/labelmanager/ViewHardcodedLabels.ftl b/framework/webtools/webapp/webtools/labelmanager/ViewHardcodedLabels.ftl new file mode 100644 index 0000000000..2764b31caa --- /dev/null +++ b/framework/webtools/webapp/webtools/labelmanager/ViewHardcodedLabels.ftl @@ -0,0 +1,24 @@ +
+ <#if parameters.searchLabels?exists> + + + + + + + <#assign rowNum = 1> + <#list referencesList as reference> + <#assign labelFound = 'N'> + <#assign refNum = Static["org.ofbiz.webtools.labelmanager.LabelManagerFactory"].getLabelReferenceFile(reference)> + <#if (refNum > 0)> + + + + + + <#assign rowNum = rowNum + 1> + + +
${uiLabelMap.WebtoolsLabelManagerRow}${uiLabelMap.WebtoolsLabelManagerKey}${uiLabelMap.WebtoolsLabelManagerReferences}
${rowNum}${reference}${refNum}
+ +
diff --git a/framework/webtools/webapp/webtools/labelmanager/ViewLabels.ftl b/framework/webtools/webapp/webtools/labelmanager/ViewLabels.ftl index b6f140c016..70395616e4 100644 --- a/framework/webtools/webapp/webtools/labelmanager/ViewLabels.ftl +++ b/framework/webtools/webapp/webtools/labelmanager/ViewLabels.ftl @@ -25,6 +25,7 @@ under the License. ${uiLabelMap.WebtoolsLabelManagerKey} ${uiLabelMap.WebtoolsLabelManagerFileName} + ${uiLabelMap.WebtoolsLabelManagerReferences} <#list localesFound as localeFound> <#assign showLocale = true> <#if parameters.labelLocaleName?exists && parameters.labelLocaleName != "" && parameters.labelLocaleName != localeFound> @@ -63,9 +64,16 @@ under the License. <#assign showLabel = false> <#if showLabel == true> + <#assign labelKey = label.labelKey> class="alternate-row"> - class="submenutext">${label.labelKey} + class="submenutext">${label.labelKey} ${label.fileName} + <#assign referenceNum = 0> + <#assign reference = references.get(labelKey)?if_exists> + <#if reference?exists && reference?has_content> + <#assign referenceNum = reference.size()> + + ${referenceNum} <#list localesFound as localeFound> <#assign labelVal = label.getLabelValue(localeFound)?if_exists> <#assign showLocale = true> @@ -86,7 +94,7 @@ under the License. <#else> <#assign rowNum = "2"> - <#assign previousKey = label.labelKey> + <#assign previousKey = labelKey> diff --git a/framework/webtools/widget/LabelManagerScreens.xml b/framework/webtools/widget/LabelManagerScreens.xml index f1c5bb4759..fb197134a8 100644 --- a/framework/webtools/widget/LabelManagerScreens.xml +++ b/framework/webtools/widget/LabelManagerScreens.xml @@ -37,7 +37,10 @@ under the License. - + + + +