Author: jleroux
Date: Sat Jan 24 15:35:14 2009 New Revision: 737382 URL: http://svn.apache.org/viewvc?rev=737382&view=rev Log: Modified LabelsInfo11.patch from Marco Risaliti "New tool to get labels information" (https://issues.apache.org/jira/browse/OFBIZ-2070) - OFBIZ-2070 Added: ofbiz/trunk/framework/webtools/config/APACHE2_HEADER_FOR_XML Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java ofbiz/trunk/framework/webtools/webapp/webtools/labelmanager/UpdateLabel.ftl Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java?rev=737382&r1=737381&r2=737382&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/FileUtil.java Sat Jan 24 15:35:14 2009 @@ -100,7 +100,16 @@ throw e; } } - + + public static void writeString(String encoding, String s, File outFile) throws IOException { + try { + FileUtils.writeStringToFile(outFile, s, encoding); + } catch (IOException e) { + Debug.logError(e, module); + throw e; + } + } + public static Writer getBufferedWriter(String path, String name) throws IOException { String fileName = getPatchedFileName(path, name); if (UtilValidate.isEmpty(fileName)) { @@ -179,7 +188,18 @@ File file = new File(fileName); return readTextFile(file, newline); } - + + public static String readString(String encoding, File inFile) throws IOException { + String readString = ""; + try { + readString = FileUtils.readFileToString(inFile, encoding); + } catch (IOException e) { + Debug.logError(e, module); + throw e; + } + return readString; + } + public static void searchFiles(List<File> fileList, File path, FilenameFilter filter, boolean includeSubfolders) throws IOException { // Get filtered files in the current path File[] files = path.listFiles(filter); Added: ofbiz/trunk/framework/webtools/config/APACHE2_HEADER_FOR_XML URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/config/APACHE2_HEADER_FOR_XML?rev=737382&view=auto ============================================================================== --- ofbiz/trunk/framework/webtools/config/APACHE2_HEADER_FOR_XML (added) +++ ofbiz/trunk/framework/webtools/config/APACHE2_HEADER_FOR_XML Sat Jan 24 15:35:14 2009 @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. +--> Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java?rev=737382&r1=737381&r2=737382&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java (original) +++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java Sat Jan 24 15:35:14 2009 @@ -49,6 +49,8 @@ public static final String module = LabelManagerFactory.class.getName(); public static final String resource = "WebtoolsUiLabels"; + private static final String keySeparator = ";"; + protected static UtilCache<String, LabelManagerFactory> labelManagerFactoryCache = new UtilCache<String, LabelManagerFactory>("LabelManagerFactory"); protected static Map<String, LabelInfo> labels = null; @@ -106,11 +108,11 @@ for (Element valueElem: UtilXml.childElementList(propertyElem, "value")) { String localeName = valueElem.getAttribute("xml:lang"); String labelValue = UtilXml.elementValue(valueElem); - LabelInfo label = (LabelInfo)labels.get(labelKey + "_" + fileName); + LabelInfo label = (LabelInfo)labels.get(labelKey + keySeparator + fileName); if (UtilValidate.isEmpty(label)) { label = new LabelInfo(labelKey, fileName, componentName, localeName, labelValue); - labels.put(labelKey + "_" + fileName, label); + labels.put(labelKey + keySeparator + fileName, label); } else { if (label.setLabelValue(localeName, labelValue, false)) { duplicatedLocales++; @@ -174,7 +176,7 @@ Locale locale = (Locale) context.get("locale"); if (UtilValidate.isNotEmpty(confirm)) { - LabelInfo label = labels.get(key + "_" + fileName); + LabelInfo label = labels.get(key + keySeparator + fileName); // Update a Label if (update_label.equalsIgnoreCase("Y")) { @@ -213,7 +215,7 @@ try { String componentName = getFileComponent(fileName); label = new LabelInfo(key, fileName, componentName, localeName, localeValue); - labels.put(key + "_" + fileName, label); + labels.put(key + keySeparator + fileName, label); } catch(Exception e) { e.printStackTrace(); } @@ -225,7 +227,7 @@ } if (UtilValidate.isNotEmpty(label) && label.getLabelValueSize() == 0) { - labels.remove(key + "_" + fileName); + labels.remove(key + keySeparator + fileName); } return notEmptyLabels; 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=737382&r1=737381&r2=737382&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 Sat Jan 24 15:35:14 2009 @@ -31,11 +31,11 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.cache.UtilCache; +import org.ofbiz.base.util.FileUtil; 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; @@ -63,8 +63,6 @@ String uri = (String)fileNamesFound.get(fileName); Document resourceDocument = UtilXml.makeEmptyXmlDocument("resource"); Element resourceElem = resourceDocument.getDocumentElement(); - Comment comment = resourceDocument.createComment("A Document Comment"); - resourceElem.getParentNode().insertBefore(comment, resourceElem); resourceElem.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); for (String labelKey : labelsList) { @@ -87,22 +85,41 @@ } } -// if (resourceElem != null && uri != null) { -// File outFile = new File(new URI(uri)); -// FileOutputStream fos = new FileOutputStream(outFile); -// -// try { -// OutputFormat format = new OutputFormat(resourceDocument.getDocumentElement().getOwnerDocument(), "UTF-8", true); -// format.setIndent(4); -// format.setOmitComments(false); -// UtilXml.writeXmlDocument(fos, resourceElem, format); -// } finally { -// if (fos != null) { -// fos.close(); -// } -// } -// } - UtilCache.clearCache("properties.UtilPropertiesBundleCache"); + if (UtilValidate.isNotEmpty(resourceElem) && UtilValidate.isNotEmpty(uri)) { + File outFile = new File(new URI(uri)); + FileOutputStream fos = new FileOutputStream(outFile); + OutputFormat format = new OutputFormat(resourceDocument.getDocumentElement().getOwnerDocument(), "UTF-8", true); + + try { + format.setIndent(4); + format.setOmitXMLDeclaration(true); + UtilXml.writeXmlDocument(fos, resourceElem, format); + } finally { + if (UtilValidate.isNotEmpty(fos)) { + fos.close(); + + // workaround to insert the Apache License Header at top of the file + // because the comment on top the xml file has been not written + String outBuffer = FileUtil.readString("UTF-8", outFile); + String basePath = System.getProperty("ofbiz.home"); + + if (UtilValidate.isNotEmpty(basePath)) { + String apacheHeaderFileName = basePath + "/framework/webtools/config/APACHE2_HEADER_FOR_XML"; + String apacheHeaderBuffer = ""; + File apacheHeaderFile = new File(apacheHeaderFileName); + + if (UtilValidate.isNotEmpty(apacheHeaderFile)) { + apacheHeaderBuffer = FileUtil.readString("UTF-8", apacheHeaderFile); + } + + FileUtil.writeString("UTF-8", apacheHeaderBuffer + outBuffer, outFile); + + // clear cache to see immediately the new labels and translations in OFBiz + UtilCache.clearCache("properties.UtilPropertiesBundleCache"); + } + } + } + } } } catch (Exception e) { Debug.logError(e, "Exception during save labels to xml file:", module); Modified: ofbiz/trunk/framework/webtools/webapp/webtools/labelmanager/UpdateLabel.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/labelmanager/UpdateLabel.ftl?rev=737382&r1=737381&r2=737382&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/webapp/webtools/labelmanager/UpdateLabel.ftl (original) +++ ofbiz/trunk/framework/webtools/webapp/webtools/labelmanager/UpdateLabel.ftl Sat Jan 24 15:35:14 2009 @@ -56,7 +56,7 @@ </tr> <#list localesFound as localeFound> <#if parameters.sourceKey?exists> - <#assign labelVal = label.getLabelValue(localeFound)?if_exists> + <#assign labelVal = (label.getLabelValue(localeFound))?if_exists> <#else> <#assign labelVal = ""> </#if> |
Free forum by Nabble | Edit this page |