示例#1
0
  public static void main(final String[] args) {
    if (args.length >= 2) {
      final String localeSetting = args[0];
      System.out.println("Setting Locale to " + localeSetting + "\n");
      Locale.setDefault(new Locale(localeSetting));

      final String timezoneSetting = args[1];
      System.out.println("Setting TimeZone to " + timezoneSetting + "\n");
      TimeZone.setDefault(TimeZone.getTimeZone(timezoneSetting));
    }

    final Locale locale = Locale.getDefault();
    System.out.println("Locale");
    System.out.println("Code: " + locale.toString());
    try {
      System.out.println("Country: " + locale.getISO3Country());
    } catch (final MissingResourceException e) {
      System.out.println("Country: " + e.getMessage());
    }
    try {
      System.out.println("Language: " + locale.getISO3Language());
    } catch (final MissingResourceException e) {
      System.out.println("Language: " + e.getMessage());
    }

    System.out.println("\nTimezone");
    final TimeZone timezone = TimeZone.getDefault();
    System.out.println("Code: " + timezone.getID());
    System.out.println("Name: " + timezone.getDisplayName());
    System.out.println("Offset: " + timezone.getRawOffset() / (1000 * 60 * 60));
    System.out.println("DST: " + timezone.getDSTSavings() / (1000 * 60 * 60));
  }
示例#2
0
  private static String getMessageFromResourceBundle(String key, Locale locale) {
    ResourceBundle bundle;
    String message = "";

    if (locale == null) {
      locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    }

    try {
      bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale, getCurrentLoader(BUNDLE_NAME));
      if (bundle == null) {
        return NOT_FOUND;
      }
    } catch (MissingResourceException e) {
      LOGGER.log(Level.INFO, e.getMessage(), e);
      return NOT_FOUND;
    }

    try {
      message = bundle.getString(key);
    } catch (Exception e) {
      LOGGER.log(Level.INFO, e.getMessage(), e);
    }
    return message;
  }
 static {
   try {
     resources = ResourceBundle.getBundle("org.apache.ws.security.conversation.errors");
   } catch (MissingResourceException e) {
     throw new RuntimeException(e.getMessage(), e);
   }
 }
示例#4
0
 public void setLocale(Locale locale) {
   this.locale = locale;
   getLogger().debug("Locale changed to " + locale);
   try {
     getPack(locale);
   } catch (MissingResourceException ex) {
     getLogger().error(ex.getMessage(), ex);
   }
 }
 /**
  * Return the value against the given key if found, else an empty String.
  *
  * @param bundle the bundle that the string is in.
  * @param key the key to get the value for.
  * @return String, the associated value.
  */
 public static String getString(int bundle, String key) {
   String value = "";
   try {
     switch (bundle) {
       case UI_GENERAL_BUNDLE:
         value = uiBundle.getString(key);
         break;
       case MENUS_BUNDLE:
         value = menusBundle.getString(key);
         break;
       case POPUPS_BUNDLE:
         value = popupsBundle.getString(key);
         break;
       case TOOLBARS_BUNDLE:
         value = toolbarsBundle.getString(key);
         break;
       case DIALOGS_BUNDLE:
         value = dialogsBundle.getString(key);
         break;
       case PANELS_BUNDLE:
         value = panelsBundle.getString(key);
         break;
       case TAGS_BUNDLE:
         value = tagsBundle.getString(key);
         break;
       case STENCILS_BUNDLE:
         value = stencilsBundle.getString(key);
         break;
       case EDITS_BUNDLE:
         value = editsBundle.getString(key);
         break;
       case LINKGROUPS_BUNDLE:
         value = linkgroupsBundle.getString(key);
         break;
       case MEETING_BUNDLE:
         value = meetingBundle.getString(key);
         break;
       case IO_BUNDLE:
         value = ioBundle.getString(key);
         break;
       case MOVIE_BUNDLE:
         value = movieBundle.getString(key);
         break;
     }
   } catch (MissingResourceException mre) {
     log.info(mre.getMessage());
     value = "UNKNOWN STRING";
   }
   return value;
 }
 protected String getText(String key, Locale locale, String defaultValue) {
   String result = null;
   ResourceBundle bundle = getBundle(locale);
   if (bundle != null) {
     try {
       result = bundle.getString(key);
     } catch (MissingResourceException e) {
       LOG.debug(e.getMessage());
     }
   }
   if (result == null) {
     result = defaultValue;
   }
   return result;
 }
  /**
   * Returns the current value for the data source.
   *
   * @param runtime the expression runtime that is used to evaluate formulas and expressions when
   *     computing the value of this filter.
   * @param element
   * @return the value.
   */
  public Object getValue(final ExpressionRuntime runtime, final ReportElement element) {
    if (runtime == null) {
      return null;
    }
    final String resourceId;
    if (resourceIdentifier != null) {
      resourceId = resourceIdentifier;
    } else {
      resourceId =
          runtime
              .getConfiguration()
              .getConfigProperty(ResourceBundleFactory.DEFAULT_RESOURCE_BUNDLE_CONFIG_KEY);
    }

    if (resourceId == null) {
      return null;
    }

    try {
      final ResourceBundleFactory resourceBundleFactory = runtime.getResourceBundleFactory();
      final ResourceBundle bundle = resourceBundleFactory.getResourceBundle(resourceId);

      // update the format string, if neccessary ...
      if (ObjectUtilities.equal(formatKey, appliedFormatKey) == false) {
        final String newFormatString = bundle.getString(formatKey);
        messageFormatSupport.setFormatString(newFormatString);
        appliedFormatKey = formatKey;
      }

      messageFormatSupport.setLocale(resourceBundleFactory.getLocale());
      return messageFormatSupport.performFormat(runtime.getDataRow());
    } catch (MissingResourceException mre) {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Failed to format the value for resource-id "
                + resourceId
                + ", was '"
                + mre.getMessage()
                + "'");
      }
      return null;
    } catch (Exception e) {
      if (logger.isDebugEnabled()) {
        logger.debug("Failed to format the value for resource-id " + resourceId, e);
      }
      return null;
    }
  }
 /**
  * Return a MessageFormat for the given bundle basename, message code, and Locale.
  *
  * @param basename the basename of the bundle
  * @param code the message code to retrieve
  * @param locale the Locale to resolve for
  * @return the resulting MessageFormat
  */
 protected MessageFormat resolve(String basename, String code, Locale locale) {
   try {
     ResourceBundle bundle =
         ResourceBundle.getBundle(
             basename, locale, Thread.currentThread().getContextClassLoader());
     try {
       return getMessageFormat(bundle, code);
     } catch (MissingResourceException ex) {
       // assume key not found
       // -> do NOT throw the exception to allow for checking parent message source
       return null;
     }
   } catch (MissingResourceException ex) {
     logger.warn(
         "ResourceBundle [" + basename + "] not found for MessageSource: " + ex.getMessage());
     // assume bundle not found
     // -> do NOT throw the exception to allow for checking parent message source
     return null;
   }
 }
示例#9
0
 public ImageIcon getIcon(String key) throws MissingResourceException {
   String iconfile;
   try {
     iconfile = getString(key);
   } catch (MissingResourceException ex) {
     getLogger().debug(ex.getMessage()); // BJO
     throw ex;
   }
   try {
     ImageIcon icon = (ImageIcon) iconCache.get(iconfile);
     if (icon == null) {
       icon = new ImageIcon(loadResource(iconfile), key);
       iconCache.put(iconfile, icon);
     } // end of if ()
     return icon;
   } catch (Exception ex) {
     String message = "Icon " + iconfile + " can't be created: " + ex.getMessage();
     getLogger().error(message);
     throw new MissingResourceException(message, className, key);
   }
 }
示例#10
0
  public void init() throws ServletException {
    // Create the info object that can be used by the entire application.
    info = new Info();

    localInit(); // Typically descendent controller will override this method. Sets the application
                 // name.

    // create the Log4jLog object using the application name just set.
    setLog();

    // get the event values and save them into events
    ResourceBundle bundle = null;
    try {
      bundle = ResourceBundle.getBundle(APPLICATION_NAME);
    } catch (java.util.MissingResourceException mre) {
      log.fatal("Can't get actions from properties file: " + mre.getMessage());
      throw new ServletException("Can't get actions from properties file. Can't start servlet. ");
    }

    Enumeration e = bundle.getKeys();
    log.info("init. Loading events...");
    while (e.hasMoreElements()) {
      String key = (String) e.nextElement();
      String value = bundle.getString(key);

      log.info(key + "=" + value);
      try {
        HandlerBase event = (HandlerBase) Class.forName(value).newInstance();
        if (!events.containsValue(event)) events.put(key, event);
      } catch (Exception exc) {
        log.fatal(":event:" + key + "  NO HANDLER FOUND! " + value);
      }
    }

    // Load URLS into static class for all to access
    // TODO - This may not be right. One instance for the entire JVM!
    DispatchUrls U = DispatchUrls.getInstance();
    U.load(APPLICATION_NAME + "-Urls");
  }
 /**
  * Return a ResourceBundle for the given basename and code, fetching already generated
  * MessageFormats from the cache.
  *
  * @param basename the basename of the ResourceBundle
  * @param locale the Locale to find the ResourceBundle for
  * @return the resulting ResourceBundle, or {@code null} if none found for the given basename and
  *     Locale
  */
 protected ResourceBundle getResourceBundle(String basename, Locale locale) {
   if (getCacheMillis() >= 0) {
     // Fresh ResourceBundle.getBundle call in order to let ResourceBundle
     // do its native caching, at the expense of more extensive lookup steps.
     return doGetBundle(basename, locale);
   } else {
     // Cache forever: prefer locale cache over repeated getBundle calls.
     synchronized (this.cachedResourceBundles) {
       Map<Locale, ResourceBundle> localeMap = this.cachedResourceBundles.get(basename);
       if (localeMap != null) {
         ResourceBundle bundle = localeMap.get(locale);
         if (bundle != null) {
           return bundle;
         }
       }
       try {
         ResourceBundle bundle = doGetBundle(basename, locale);
         if (localeMap == null) {
           localeMap = new HashMap<>();
           this.cachedResourceBundles.put(basename, localeMap);
         }
         localeMap.put(locale, bundle);
         return bundle;
       } catch (MissingResourceException ex) {
         if (logger.isWarnEnabled()) {
           logger.warn(
               "ResourceBundle ["
                   + basename
                   + "] not found for MessageSource: "
                   + ex.getMessage());
         }
         // Assume bundle not found
         // -> do NOT throw the exception to allow for checking parent message source.
         return null;
       }
     }
   }
 }
示例#12
0
  /**
   * @param orgNode Processed node
   * @param propertyName which property used for editing
   * @param inputType input type for editing: TEXT, TEXTAREA, WYSIWYG
   * @param cssClass class name for CSS, should implement: cssClass, [cssClass]Title Edit[cssClass]
   *     as relative css Should create the function:
   *     InlineEditor.presentationRequestChange[cssClass] to request the rest-service
   * @param isGenericProperty set as true to use generic javascript function, other wise, must
   *     create the correctspond function InlineEditor.presentationRequestChange[cssClass]
   * @param arguments Extra parameter for Input component (toolbar, width, height,.. for
   *     CKEditor/TextArea)
   * @return String that can be put on groovy template
   * @throws Exception
   * @author vinh_nguyen
   */
  public static String getInlineEditingField(
      Node orgNode,
      String propertyName,
      String defaultValue,
      String inputType,
      String idGenerator,
      String cssClass,
      boolean isGenericProperty,
      String... arguments)
      throws Exception {
    HashMap<String, String> parsedArguments = parseArguments(arguments);
    String height = parsedArguments.get(HEIGHT);
    String bDirection = parsedArguments.get(BUTTON_DIR);
    String publishLink = parsedArguments.get(FAST_PUBLISH_LINK);

    Locale locale = WebuiRequestContext.getCurrentInstance().getLocale();
    String language = locale.getLanguage();
    ResourceBundleService resourceBundleService =
        WCMCoreUtils.getService(ResourceBundleService.class);
    ResourceBundle resourceBundle;
    resourceBundle = resourceBundleService.getResourceBundle(LOCALE_WEBUI_DMS, locale);

    PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance();
    String draft = INLINE_DRAFT;
    String published = INLINE_PUBLISHED;
    try {
      draft =
          portletRequestContext.getApplicationResourceBundle().getString("PublicationStates.draft");
      published =
          portletRequestContext
              .getApplicationResourceBundle()
              .getString("PublicationStates.published");
    } catch (MissingResourceException ex) {
      if (LOG.isWarnEnabled()) {
        LOG.warn(ex.getMessage());
      }
    }

    String portletRealID =
        org.exoplatform.wcm.webui.Utils.getRealPortletId(
            (PortletRequestContext) WebuiRequestContext.getCurrentInstance());
    StringBuffer sb = new StringBuffer();
    StringBuffer actionsb = new StringBuffer();
    String repo =
        ((ManageableRepository) orgNode.getSession().getRepository()).getConfiguration().getName();
    String workspace = orgNode.getSession().getWorkspace().getName();
    String uuid = orgNode.getUUID();
    String strSuggestion = "";
    String acceptButton = "";
    String cancelButton = "";
    portletRealID = portletRealID.replace('-', '_');
    String showBlockId = "Current" + idGenerator + "_" + portletRealID;
    String editBlockEditorID = "Edit" + idGenerator + "_" + portletRealID;
    String editFormID = "Edit" + idGenerator + "Form_" + portletRealID;
    String newValueInputId = "new" + idGenerator + "_" + portletRealID;
    String currentValueID = "old" + idGenerator + "_" + portletRealID;
    String siteName =
        org.exoplatform.portal.webui.util.Util.getPortalRequestContext().getPortalOwner();
    String currentValue = StringUtils.replace(defaultValue, "{portalName}", siteName);
    try {
      strSuggestion = resourceBundle.getString("UIPresentation.label.EditingSuggestion");
      acceptButton = resourceBundle.getString("UIPresentation.title.AcceptButton");
      cancelButton = resourceBundle.getString("UIPresentation.title.CancelButton");
    } catch (MissingResourceException e) {
      if (LOG.isWarnEnabled()) {
        LOG.warn(e.getMessage());
      }
    }
    actionsb.append(" return InlineEditor.presentationRequestChange");

    if (isGenericProperty) {
      actionsb
          .append("Property")
          .append("('")
          .append("/property?', '")
          .append(propertyName)
          .append("', '");
    } else {
      actionsb.append(cssClass).append("('");
    }
    actionsb
        .append(currentValueID)
        .append("', '")
        .append(newValueInputId)
        .append("', '")
        .append(repo)
        .append("', '")
        .append(workspace)
        .append("', '")
        .append(uuid)
        .append("', '")
        .append(editBlockEditorID)
        .append("', '")
        .append(showBlockId)
        .append("', '")
        .append(siteName)
        .append("', '")
        .append(language);

    if (inputType.equals(INPUT_WYSIWYG)) {
      actionsb.append("', 1);");
    } else {
      actionsb.append("');");
    }
    String strAction = actionsb.toString();

    if (orgNode.hasProperty(propertyName)) {
      try {
        if (propertyName.equals(EXO_TITLE))
          return ContentReader.getXSSCompatibilityContent(
              orgNode.getProperty(propertyName).getString());
        if (org.exoplatform.wcm.webui.Utils.getCurrentMode().equals(WCMComposer.MODE_LIVE))
          return StringUtils.replace(
              orgNode.getProperty(propertyName).getString(), "{portalName}", siteName);
        else
          return "<div class=\"WCMInlineEditable\" contenteditable=\"true\" propertyName=\""
              + propertyName
              + "\" repo=\""
              + repo
              + "\" workspace=\""
              + workspace
              + "\""
              + " uuid=\""
              + uuid
              + "\" siteName=\""
              + siteName
              + "\" publishedMsg=\""
              + published
              + "\" draftMsg=\""
              + draft
              + "\" fastpublishlink=\""
              + publishLink
              + "\" language=\""
              + language
              + "\" >"
              + orgNode.getProperty(propertyName).getString()
              + "</div>";
      } catch (Exception e) {
        if (org.exoplatform.wcm.webui.Utils.getCurrentMode().equals(WCMComposer.MODE_LIVE))
          return currentValue;
        else
          return "<div class=\"WCMInlineEditable\" contenteditable=\"true\" propertyName=\""
              + propertyName
              + "\" repo=\""
              + repo
              + "\" workspace=\""
              + workspace
              + "\" "
              + "uuid=\""
              + uuid
              + "\" siteName=\""
              + siteName
              + "\" publishedMsg=\""
              + published
              + "\" draftMsg=\""
              + draft
              + "\" fastpublishlink=\""
              + publishLink
              + "\" language=\""
              + language
              + "\" >"
              + defaultValue
              + "</div>";
      }
    }

    sb.append("<div class=\"InlineEditing\" >\n");
    sb.append("\n<div rel=\"tooltip\" data-placement=\"bottom\" id=\"")
        .append(showBlockId)
        .append("\" Class=\"")
        .append(cssClass)
        .append("\"");
    sb.append("title=\"").append(strSuggestion).append("\"");
    sb.append(" onClick=\"InlineEditor.presentationSwitchBlock('")
        .append(showBlockId)
        .append("', '")
        .append(editBlockEditorID)
        .append("');\"");

    sb.append("onmouseout=\"this.className='")
        .append(cssClass)
        .append("';\" onblur=\"this.className='")
        .append(cssClass)
        .append("';\" onfocus=\"this.className='")
        .append(cssClass)
        .append("Hover")
        .append("';\" onmouseover=\"this.className='")
        .append(cssClass)
        .append("Hover';\">")
        .append(currentValue)
        .append("</div>\n");
    sb.append("\t<div id=\"")
        .append(editBlockEditorID)
        .append("\" class=\"Edit")
        .append(cssClass)
        .append("\">\n");
    sb.append("\t\t<form name=\"")
        .append(editFormID)
        .append("\" id=\"")
        .append(editFormID)
        .append("\" onSubmit=\"")
        .append(strAction)
        .append("\">\n");
    sb.append("<DIV style=\"display:none; visible:hidden\" id=\"")
        .append(currentValueID)
        .append("\" name=\"")
        .append(currentValueID)
        .append("\">")
        .append(currentValue)
        .append("</DIV>");

    if (bDirection != null && bDirection.equals(LEFT2RIGHT)) {
      sb.append("\t\t<a href=\"#\" rel=\"tooltip\" data-placement=\"bottom\"")
          .append(" class =\"AcceptButton\" style=\"float:left\" onclick=\"")
          .append(strAction)
          .append("\" title=\"" + acceptButton + "\">&nbsp;</a>\n");
      sb.append(
              "\t\t<a href=\"#\" rel=\"tooltip\" data-placement=\"bottom\" class =\"CancelButton\" style=\"float:left\" ")
          .append("onClick=\"InlineEditor.presentationSwitchBlock('");
      sb.append(editBlockEditorID)
          .append("', '")
          .append(showBlockId)
          .append("');\" title=\"" + cancelButton + "\">&nbsp;</a>\n");
    } else {
      sb.append(
              "\t\t<a href=\"#\" rel=\"tooltip\" data-placement=\"bottom\" class =\"CancelButton\" ")
          .append("onClick=\"InlineEditor.presentationSwitchBlock('");
      sb.append(editBlockEditorID)
          .append("', '")
          .append(showBlockId)
          .append("');\" title=\"" + cancelButton + "\">&nbsp;</a>\n");
      sb.append(
              "\t\t<a href=\"#\" rel=\"tooltip\" data-placement=\"bottom\" class =\"AcceptButton\" onclick=\"")
          .append(strAction)
          .append("\" title=\"" + acceptButton + "\">&nbsp;</a>\n");
    }
    sb.append("\t\t<div class=\"Edit").append(cssClass).append("Input\">\n ");

    sb.append("\n\t\t</div>\n\t</form>\n</div>\n\n</div>");
    return sb.toString();
  }
示例#13
0
  // ------------------------------------------------------------------------
  TextViewer(JFrame inParentFrame) {
    // super(true); //is double buffered - only for panels

    textViewerFrame = this;
    parentFrame = inParentFrame;
    lastViewedDirStr = "";
    lastViewedFileStr = "";

    setTitle(resources.getString("Title"));
    addWindowListener(new AppCloser());
    pack();
    setSize(500, 600);

    warningPopup = new WarningDialog(this);
    okCancelPopup = new WarningDialogOkCancel(this);
    messagePopup = new MessageDialog(this);
    okCancelMessagePopup = new MessageDialogOkCancel(this);

    // Force SwingSet to come up in the Cross Platform L&F
    try {
      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
      // If you want the System L&F instead, comment out the above line and
      // uncomment the following:
      // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception exc) {
      String errstr = "TextViewer:Error loading L&F: " + exc;
      warningPopup.display(errstr);
    }

    Container cf = getContentPane();
    cf.setBackground(Color.lightGray);
    // Border etched=BorderFactory.createEtchedBorder();
    // Border title=BorderFactory.createTitledBorder(etched,"TextViewer");
    // cf.setBorder(title);
    cf.setLayout(new BorderLayout());

    // create the embedded JTextComponent
    editor1 = createEditor();
    editor1.setFont(new Font("monospaced", Font.PLAIN, 12));
    // aa -added next line
    setPlainDocument((PlainDocument) editor1.getDocument()); // sets doc1

    // install the command table
    commands = new Hashtable();
    Action[] actions = getActions();
    for (int i = 0; i < actions.length; i++) {
      Action a = actions[i];
      commands.put(a.getValue(Action.NAME), a);
      // System.out.println("Debug:TextViewer: actionName:"+a.getValue(Action.NAME));
    }
    // editor1.setPreferredSize(new Dimension(,));
    // get setting from user preferences
    if (UserPref.keymapType.equals("Word")) {
      editor1 = updateKeymapForWord(editor1);
    } else {
      editor1 = updateKeymapForEmacs(editor1);
    }

    scroller1 = new JScrollPane();
    viewport1 = scroller1.getViewport();
    viewport1.add(editor1);
    scroller1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scroller1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    try {
      String vpFlag = resources.getString("ViewportBackingStore");
      Boolean bs = new Boolean(vpFlag);
      viewport1.setBackingStoreEnabled(bs.booleanValue());
    } catch (MissingResourceException mre) {
      System.err.println("TextViewer:missing resource:" + mre.getMessage());
      // just use the viewport1 default
    }

    menuItems = new Hashtable();

    menubar = createMenubar();

    lowerPanel = new JPanel(true); // moved double buffering to here
    lowerPanel.setLayout(new BorderLayout());
    lowerPanel.add("North", createToolbar());
    lowerPanel.add("Center", scroller1);

    cf.add("North", menubar);
    cf.add("Center", lowerPanel);
    cf.add("South", createStatusbar());

    // for the find/search utilities
    mySearchDialog = new SearchDialog(this);

    // System.out.println("Debug:TextViewer: end of TextViewer constructor");

  }