1 28 29 30 package com.opencms.workplace; 31 32 import org.opencms.file.CmsFile; 33 import org.opencms.file.CmsFolder; 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsResource; 36 import org.opencms.main.CmsException; 37 import org.opencms.main.CmsLog; 38 import org.opencms.workplace.CmsWorkplace; 39 40 import com.opencms.template.A_CmsXmlContent; 41 42 import java.util.ArrayList ; 43 import java.util.List ; 44 45 59 public class CmsXmlLanguageFileContent extends A_CmsXmlContent { 60 61 71 public CmsXmlLanguageFileContent(CmsObject cms, String locale) throws CmsException { 72 super(); 73 try { 74 mergeLanguageFiles(cms, locale); 75 } 76 catch(Exception e) { 77 throwException("Error while merging language files in folder " + CmsWorkplace.VFS_PATH_LOCALES + locale + "/."); 78 } 79 } 80 81 85 public String getContentDescription() { 86 return "Language definition file"; 87 } 88 89 94 public String getLanguageValue(String tag) throws CmsException { 95 String result = null; 96 if(hasData(tag)) { 97 result = getDataValue(tag); 98 } 99 return result; 100 } 101 102 106 public String getXmlDocumentTagName() { 107 return "LANGUAGE"; 108 } 109 110 115 public boolean hasLanguageValue(String tag) { 116 return hasData(tag); 117 } 118 119 128 private void mergeLanguageFiles(CmsObject cms, String language) throws CmsException { 129 List langFiles = (List ) new ArrayList (); 130 131 if ("uk".equals(language)) language = "en"; 133 134 try { 135 langFiles = cms.getFilesInFolder(CmsWorkplace.VFS_PATH_LOCALES + language + "/"); 136 } catch (CmsException e) { 137 } 139 140 List modules = (List ) new ArrayList (); 142 modules = cms.getSubFolders(CmsWorkplace.VFS_PATH_MODULES); 143 String lang = CmsWorkplaceDefault.C_VFS_DIR_LOCALES + language + "/"; 144 String oldLang = "language/" + language + "/"; 146 for(int i = 0;i < modules.size();i++) { 147 List moduleLangFiles = (List ) new ArrayList (); 148 try { 149 moduleLangFiles = cms.getFilesInFolder(cms.getSitePath((CmsFolder)modules.get(i)) + lang); 150 } catch (CmsException e) { 151 try { 153 moduleLangFiles = cms.getFilesInFolder(cms.getSitePath((CmsFolder)modules.get(i)) + oldLang); 154 if(CmsLog.getLog(this).isWarnEnabled() ) { 155 CmsLog.getLog(this).warn("Old module 'locales' path used: " + cms.getSitePath((CmsFolder)modules.get(i)) + oldLang); 156 } 157 } catch (CmsException ex) { 158 } 160 } 161 for(int j = 0;j < moduleLangFiles.size();j++) { 162 langFiles.add(moduleLangFiles.get(j)); 163 } 164 } 165 CmsFile file = null; 166 for(int i = 0;i < langFiles.size();i++) { 167 file = (CmsFile)langFiles.get(i); 168 if(! file.getName().toLowerCase().endsWith(".txt") && file.getState() != CmsResource.STATE_DELETED) { 169 try { 170 init(cms, cms.getSitePath(file)); 171 } catch(Exception exc) { 172 if(CmsLog.getLog(this).isErrorEnabled() ) { 173 CmsLog.getLog(this).error("Error merging language file: " + cms.getSitePath(file), exc); 174 } 175 } 176 } 177 } 178 } 179 }
| Popular Tags
|