List of usage examples for java.util ResourceBundle clearCache
@CallerSensitive public static final void clearCache()
From source file:de.kaiserpfalzEdv.commons.HandleI18NImpl.java
/** * Clears our resource bundle cache. */ private void resetMessageBundle() { ResourceBundle.clearCache(); messageBundle = null; }
From source file:edu.cornell.mannlib.vitro.webapp.i18n.I18n.java
/** Only clear the cache one time per request. */ private void clearCacheOnRequest(HttpServletRequest req) { if (req.getAttribute(ATTRIBUTE_CACHE_CLEARED) != null) { log.debug("Cache was already cleared on this request."); } else {//from w w w . ja v a 2 s . c o m ResourceBundle.clearCache(); log.debug("Cache cleared."); req.setAttribute(ATTRIBUTE_CACHE_CLEARED, Boolean.TRUE); } }
From source file:org.jahia.ajax.gwt.helper.GWTResourceBundleUtils.java
public static boolean store(GWTJahiaNode gwtNode, GWTResourceBundle bundle, JCRSessionWrapper session) throws GWTJahiaServiceException { boolean needPermissionReload = false; try {//from w w w . java 2 s .co m JCRNodeWrapper node = session.getNode( gwtNode.isFile() ? StringUtils.substringBeforeLast(gwtNode.getPath(), "/") : gwtNode.getPath()); Map<String, JCRNodeWrapper> nodesByLanguage = new HashMap<String, JCRNodeWrapper>(); for (JCRNodeWrapper rbFileNode : JCRContentUtils.getChildrenOfType(node, "jnt:propertiesFile")) { nodesByLanguage.put(getLanguageCode(rbFileNode.getName()), rbFileNode); } for (String lang : bundle.getLanguages()) { JCRNodeWrapper current = nodesByLanguage.remove(lang); InputStream is = null; try { is = new ByteArrayInputStream(getAsString(lang, bundle).getBytes("ISO-8859-1")); if (current == null) { // new language logger.debug("Processing new resource bundle for language '{}'", lang); String bundleName; if (StringUtils.equals(lang, GWTResourceBundle.DEFAULT_LANG)) { bundleName = bundle.getName() + ".properties"; } else { bundleName = bundle.getName() + "_" + lang + ".properties"; } node.uploadFile(bundleName, is, "text/plain"); } else { // updating existing language logger.debug("Processing resource bundle {} for language '{}'", current.getPath(), lang); current.getFileContent().uploadFile(is, "text/plain"); } } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e.getMessage(), e); } finally { IOUtils.closeQuietly(is); } } // removing deleted languages if any for (Iterator<JCRNodeWrapper> iterator = nodesByLanguage.values().iterator(); iterator.hasNext();) { JCRNodeWrapper toDelete = iterator.next(); logger.debug("Removing resource bundle node {}", toDelete.getPath()); toDelete.remove(); } ResourceBundle.clearCache(); NodeTypeRegistry.getInstance().flushLabels(); needPermissionReload = !node.getResolveSite().getLanguages().containsAll(bundle.getLanguages()); node.getResolveSite().setLanguages(bundle.getLanguages()); } catch (RepositoryException e) { logger.error(e.getMessage(), e); throw new GWTJahiaServiceException(e.getMessage()); } return needPermissionReload; }
From source file:com.aurel.track.admin.customize.localize.LocalizeBL.java
/** * Saves a localization entry//from w w w . ja va2 s . c o m * @param newLocalizedText * @param fieldName * @param primaryKey * @param originalLocalizedResources * @param localeStr */ public static void save(String newLocalizedText, String fieldName, Integer primaryKey, List<TLocalizedResourcesBean> originalLocalizedResources, String localeStr) { String oldLocalizedText = null; TLocalizedResourcesBean localizedResourceBean = null; if (originalLocalizedResources != null && !originalLocalizedResources.isEmpty()) { if (originalLocalizedResources.size() > 1) { //theoretically the list should contain maximal 1 TLocalizedResourcesBean, //but it can be that (previous buggy import) there are more than one. The duplicates should be removed localizedResourcesDAO.deleteLocalizedResourcesForFieldNameAndKeyAndLocale(fieldName, primaryKey, localeStr); } else { localizedResourceBean = originalLocalizedResources.get(0); if (localizedResourceBean != null) { oldLocalizedText = localizedResourceBean.getLocalizedText(); } } } boolean newSpecified = newLocalizedText != null && !"".equals(newLocalizedText.trim()); boolean oldSpecified = oldLocalizedText != null && !"".equals(oldLocalizedText.trim()); boolean saveNeeded = false; if (newSpecified && oldSpecified) { //both exist if (EqualUtils.notEqual(newLocalizedText, oldLocalizedText)) { localizedResourceBean.setLocalizedText(newLocalizedText); localizedResourceBean.setTextChangedBool(true); localizedResourcesDAO.save(localizedResourceBean); saveNeeded = true; } } else { if (newSpecified && !oldSpecified) { //not existed before or it was empty string if (localizedResourceBean == null) { //not existed localizedResourceBean = new TLocalizedResourcesBean(); localizedResourceBean.setPrimaryKeyValue(primaryKey); localizedResourceBean.setFieldName(fieldName); localizedResourceBean.setTextChangedBool(true); localizedResourceBean.setLocale(localeStr); } localizedResourceBean.setLocalizedText(newLocalizedText); localizedResourceBean.setTextChangedBool(true); localizedResourcesDAO.save(localizedResourceBean); saveNeeded = true; } else { if (!newSpecified && oldSpecified) { if (localizedResourceBean != null) { //remove if new is null or empty localizedResourcesDAO.delete(localizedResourceBean.getObjectID()); saveNeeded = true; } } } } if (saveNeeded) { //FIXME: clear cache? ResourceBundle.clearCache(); if (primaryKey != null) { //actualize the lucene index with the changed localization if (fieldName.startsWith(LocalizationKeyPrefixes.FIELD_SYSTEMSELECT_KEY_PREFIX)) { int beginIndex = LocalizationKeyPrefixes.FIELD_SYSTEMSELECT_KEY_PREFIX.length(); String fieldIDStr = fieldName.substring(beginIndex, beginIndex + 1); Integer fieldID = null; try { fieldID = Integer.valueOf(fieldIDStr); } catch (Exception e) { } if (fieldID != null) { int luceneField = 0; ILocalizedLabelBean localizedLabelBean = null; switch (fieldID.intValue()) { case SystemFields.ISSUETYPE: luceneField = LuceneUtil.LOOKUPENTITYTYPES.LISTTYPE; localizedLabelBean = LookupContainer.getItemTypeBean(primaryKey); break; case SystemFields.STATE: luceneField = LuceneUtil.LOOKUPENTITYTYPES.STATE; localizedLabelBean = LookupContainer.getStatusBean(primaryKey); break; case SystemFields.PRIORITY: luceneField = LuceneUtil.LOOKUPENTITYTYPES.PRIORITY; localizedLabelBean = LookupContainer.getPriorityBean(primaryKey); break; case SystemFields.SEVERITY: luceneField = LuceneUtil.LOOKUPENTITYTYPES.SEVERITY; localizedLabelBean = LookupContainer.getSeverityBean(primaryKey); break; } if (localizedLabelBean != null) { LocalizedListIndexer.getInstance().updateLabelBean(localizedLabelBean, luceneField); } } } else { if (fieldName.startsWith(LocalizationKeyPrefixes.FIELD_CUSTOMSELECT_KEY_PREFIX)) { TOptionBean optionBean = OptionBL.loadByPrimaryKey(primaryKey); if (optionBean != null) { LocalizedListIndexer.getInstance().updateLabelBean(optionBean, LuceneUtil.LOOKUPENTITYTYPES.CUSTOMOPTION); } } } } } }
From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java
/** * Create the application.// w w w . ja v a 2 s.co m * * @throws ConfigReadWriteException * @throws IOException */ public MainCommGUI() throws IOException, ConfigReadWriteException { lg = SpxPcloggerProgramConfig.LOGGER; setDefaultLookAndFeelDecorated(isDefaultLookAndFeelDecorated()); // Konfiguration aus der Datei einlesen // bercksichtigt schon per CLI angegebene Werte als gesetzt new ReadConfig(); makeLogger(); // // gib ein paar informationen // lg.info("Operating System: <" + OperatingSystemDetector.getOsName() + ">"); lg.info("Java VM Datamodel: " + OperatingSystemDetector.getDataModel() + " bits"); lg.info("Java VM Datamodel: <" + OperatingSystemDetector.getArch() + ">"); // // Grundstzliche Sachen einstellen // try { ResourceBundle.clearCache(); if (SpxPcloggerProgramConfig.langCode != null) { lg.info("try make locale from cmd options <" + SpxPcloggerProgramConfig.langCode + ">..."); programLocale = new Locale(SpxPcloggerProgramConfig.langCode); } else { lg.debug("try get locale from system..."); programLocale = Locale.getDefault(); } LangStrings.setLocale(programLocale); lg.debug(String.format("getLocale says: Display Language :<%s>, lang: <%s>", programLocale.getDisplayLanguage(), programLocale.getLanguage())); stringsBundle = ResourceBundle.getBundle("de.dmarcini.submatix.pclogger.lang.messages", programLocale); if (stringsBundle.getLocale().equals(programLocale)) { lg.debug("language accepted.."); } else { lg.debug("language fallback default..."); programLocale = Locale.ENGLISH; Locale.setDefault(programLocale); stringsBundle = ResourceBundle.getBundle("de.dmarcini.submatix.pclogger.lang.messages", programLocale); } checkDatabaseDirectory(); } catch (MissingResourceException ex) { lg.error("ERROR get resources <" + ex.getMessage() + "> try standart Strings..."); System.err.println("ERROR get resources <" + ex.getMessage() + "> try standart Strings..."); try { lg.debug("try get default english locale from system..."); programLocale = Locale.ENGLISH; Locale.setDefault(programLocale); stringsBundle = ResourceBundle.getBundle("de.dmarcini.submatix.pclogger.lang.messages_en"); } catch (Exception ex1) { lg.error("ERROR get resources <" + ex1.getMessage() + "> give up..."); System.exit(-1); } } catch (NoDatabaseException ex) { showErrorDialog(ex.getLocalizedMessage()); System.exit(-1); } // // jetzt die wichtigen anderen Sachen, die dauern. // prepareDatabase(); currentConfig.setLogger(lg); btComm = new BTCommunication(databaseUtil); btComm.addActionListener(this); try { initializeGUI(); } catch (SQLException ex) { lg.error("SQL ERROR <" + ex.getMessage() + "> give up..."); System.err.println("ERROR while create GUI: <" + ex.getLocalizedMessage() + ">"); ex.printStackTrace(); System.exit(-1); } catch (ClassNotFoundException ex) { lg.error("CLASS NOT FOUND EXCEPTION <" + ex.getMessage() + "> give up..."); System.err.println("ERROR while create GUI: <" + ex.getLocalizedMessage() + ">"); ex.printStackTrace(); System.exit(-1); } // Listener setzen (braucht auch die Maps) setGlobalChangeListener(); // initLanuageMenu(programLocale); if (!SpxPcloggerProgramConfig.developDebug) { configPanel.setAllConfigPanlelsEnabled(false); logListPanel.setAllLogPanelsEnabled(false); setElementsConnected(false); } if (setLanguageStrings() < 1) { lg.error("setLanguageStrings() faild. give up..."); System.exit(-1); } connectionPanel.setVirtDevicesBoxEnabled(false); startVirtualPortFinder(null); waitForMessage = 0; }
From source file:com.aurel.track.admin.customize.localize.LocalizeBL.java
/** * Update the resources based on the properties * @param properties//from ww w .ja v a 2s. c o m * @param strLocale * @param overwrite whether to overwrite the edited resources * @param withPrimaryKey whether the used to be BoxResources are imported or the ApplicationResources */ static synchronized void uploadResources(Properties properties, String strLocale, boolean overwrite, boolean withPrimaryKey, boolean initBoxResources) { List<TLocalizedResourcesBean> resourceBeans = getResourcesForLocale(strLocale, withPrimaryKey); SortedMap<String, List<TLocalizedResourcesBean>> existingLabels = new TreeMap<String, List<TLocalizedResourcesBean>>(); for (TLocalizedResourcesBean localizedResourcesBean : resourceBeans) { String key = localizedResourcesBean.getFieldName(); if (withPrimaryKey) { if (key.startsWith(LocalizationKeyPrefixes.FIELD_LABEL_KEY_PREFIX) || key.startsWith(LocalizationKeyPrefixes.FIELD_TOOLTIP_KEY_PREFIX)) { key += "."; } key = key + localizedResourcesBean.getPrimaryKeyValue(); } List<TLocalizedResourcesBean> localizedResources = existingLabels.get(key); if (localizedResources == null) { localizedResources = new LinkedList<TLocalizedResourcesBean>(); existingLabels.put(key, localizedResources); } localizedResources.add(localizedResourcesBean); } Enumeration propertyNames = properties.keys(); Connection connection = null; try { connection = Transaction.begin(); connection.setAutoCommit(false); while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); String localizedText = LocalizeBL.correctString(properties.getProperty(key)); Integer primaryKey = null; String fieldName = null; if (withPrimaryKey) { int primaryKeyIndex = key.lastIndexOf("."); if (primaryKeyIndex != -1) { try { primaryKey = Integer.valueOf(key.substring(primaryKeyIndex + 1)); } catch (Exception e) { LOGGER.warn("The last part after . can't be converted to integer " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } fieldName = key.substring(0, primaryKeyIndex + 1); if (fieldName.startsWith(LocalizationKeyPrefixes.FIELD_LABEL_KEY_PREFIX) || fieldName.startsWith(LocalizationKeyPrefixes.FIELD_TOOLTIP_KEY_PREFIX)) { //do not have . at the end (legacy) fieldName = fieldName.substring(0, fieldName.length() - 1); } } } else { fieldName = key; } List<TLocalizedResourcesBean> localizedResources = existingLabels.get(key); if (localizedResources != null && localizedResources.size() > 1) { //remove all duplicates (as a consequence of previous erroneous imports) localizedResourcesDAO.deleteLocalizedResourcesForFieldNameAndKeyAndLocale(fieldName, primaryKey, strLocale); localizedResources = null; } if (localizedResources == null || localizedResources.isEmpty()) { //new resource TLocalizedResourcesBean localizedResourcesBean = new TLocalizedResourcesBean(); localizedResourcesBean.setFieldName(fieldName); localizedResourcesBean.setPrimaryKeyValue(primaryKey); localizedResourcesBean.setLocalizedText(localizedText); localizedResourcesBean.setLocale(strLocale); localizedResourcesDAO.insert(localizedResourcesBean); } else { //existing resource if (localizedResources.size() == 1) { TLocalizedResourcesBean localizedResourcesBean = localizedResources.get(0); if (EqualUtils.notEqual(localizedText, localizedResourcesBean .getLocalizedText()) /*&& locale.equals(localizedResourcesBean.getLocale())*/) { //text changed locally by the customer boolean textChanged = localizedResourcesBean.getTextChangedBool(); if ((textChanged == false && !initBoxResources) || (textChanged && overwrite)) { localizedResourcesBean.setLocalizedText(localizedText); localizedResourcesDAO.save(localizedResourcesBean); } } else { } } } } Transaction.commit(connection); if (!connection.isClosed()) { connection.close(); } } catch (Exception e) { LOGGER.error("Problem filling locales: " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); if (connection != null) { Transaction.safeRollback(connection); } } //delete the existing ones not found in the properties Locale locale; if (strLocale != null) { locale = LocaleHandler.getLocaleFromString(strLocale); } else { locale = Locale.getDefault(); } if (withPrimaryKey) { //not sure that all is needed but to be sure we do not miss imported localizations LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_ISSUETYPE, locale); LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_STATE, locale); LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_PRIORITY, locale); LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_SEVERITY, locale); } ResourceBundle.clearCache(); }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
private void saveProperties(ExternalData data) throws RepositoryException { OutputStream outputStream = null; try {//from www. ja v a 2s .com ExtendedNodeType propertiesType = NodeTypeRegistry.getInstance() .getNodeType(Constants.JAHIAMIX_VIEWPROPERTIES); Map<String, ExtendedPropertyDefinition> propertyDefinitionMap = propertiesType .getDeclaredPropertyDefinitionsAsMap(); Properties properties = new SortedProperties(); for (Map.Entry<String, String[]> property : data.getProperties().entrySet()) { if (propertyDefinitionMap.containsKey(property.getKey())) { String[] v = property.getValue(); if (v != null) { String propertyValue = StringUtils.join(v, ","); if (propertyDefinitionMap.get(property.getKey()).getRequiredType() != PropertyType.BOOLEAN || !propertyValue.equals("false")) { properties.put(property.getKey(), propertyValue); } } } } FileObject file = getFile(StringUtils.substringBeforeLast(data.getPath(), ".") + PROPERTIES_EXTENSION); Properties original = new Properties(); if (file.exists()) { original.load(file.getContent().getInputStream()); for (String s : propertyDefinitionMap.keySet()) { original.remove(s); } } properties.putAll(original); if (!properties.isEmpty()) { outputStream = file.getContent().getOutputStream(); properties.store(outputStream, data.getPath()); } else { if (file.exists()) { file.delete(); } } ResourceBundle.clearCache(); } catch (FileSystemException e) { logger.error(e.getMessage(), e); throw new RepositoryException("Failed to write source code", e); } catch (IOException e) { logger.error(e.getMessage(), e); throw new RepositoryException("Failed to write source code", e); } catch (NoSuchNodeTypeException e) { logger.error("Unable to find type : " + data.getType() + " for node " + data.getPath(), e); throw e; } finally { IOUtils.closeQuietly(outputStream); } }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
private void saveCndResourceBundle(ExternalData data, String key) throws RepositoryException { String resourceBundleName = module.getResourceBundleName(); if (resourceBundleName == null) { resourceBundleName = "resources." + module.getId(); }//from w w w .j ava 2s . co m String rbBasePath = "/src/main/resources/resources/" + StringUtils.substringAfterLast(resourceBundleName, "."); Map<String, Map<String, String[]>> i18nProperties = data.getI18nProperties(); if (i18nProperties != null) { List<File> newFiles = new ArrayList<File>(); for (Map.Entry<String, Map<String, String[]>> entry : i18nProperties.entrySet()) { String lang = entry.getKey(); Map<String, String[]> properties = entry.getValue(); String[] values = properties.get(Constants.JCR_TITLE); String title = ArrayUtils.isEmpty(values) ? null : values[0]; values = properties.get(Constants.JCR_DESCRIPTION); String description = ArrayUtils.isEmpty(values) ? null : values[0]; String rbPath = rbBasePath + "_" + lang + PROPERTIES_EXTENSION; InputStream is = null; InputStreamReader isr = null; OutputStream os = null; OutputStreamWriter osw = null; try { FileObject file = getFile(rbPath); FileContent content = file.getContent(); Properties p = new SortedProperties(); if (file.exists()) { is = content.getInputStream(); isr = new InputStreamReader(is, Charsets.ISO_8859_1); p.load(isr); isr.close(); is.close(); } else if (StringUtils.isBlank(title) && StringUtils.isBlank(description)) { continue; } else { newFiles.add(new File(file.getName().getPath())); } if (!StringUtils.isEmpty(title)) { p.setProperty(key, title); } if (!StringUtils.isEmpty(description)) { p.setProperty(key + "_description", description); } os = content.getOutputStream(); osw = new OutputStreamWriter(os, Charsets.ISO_8859_1); p.store(osw, rbPath); ResourceBundle.clearCache(); } catch (FileSystemException e) { logger.error("Failed to save resourceBundle", e); throw new RepositoryException("Failed to save resourceBundle", e); } catch (IOException e) { logger.error("Failed to save resourceBundle", e); throw new RepositoryException("Failed to save resourceBundle", e); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(isr); IOUtils.closeQuietly(os); IOUtils.closeQuietly(osw); } } SourceControlManagement sourceControl = module.getSourceControl(); if (sourceControl != null) { try { sourceControl.add(newFiles); } catch (IOException e) { logger.error("Failed to add files to source control", e); throw new RepositoryException("Failed to add new files to source control: " + newFiles, e); } } } }