Пример #1
0
  /**
   * This method adds a choose file field to the panel.
   *
   * @param panel to which the choose file field should be added
   */
  private void addChooseFileField(JPanel panel) {

    filePathField = new JTextField();

    final FileDialog fileDialog = new FileDialog(this);
    fileDialog.setModal(true);
    fileDialog.addComponentListener(
        new ComponentAdapter() {
          public void componentHidden(ComponentEvent e) {
            if (fileDialog.getFile() != null) {
              filePathField.setText(fileDialog.getDirectory() + fileDialog.getFile());
            }
          }
        });

    final JButton chooseFileButton = new JButton(guiText.getString("ChooseFileButtonLabel"));
    chooseFileButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fileDialog.setVisible(true);
          }
        });

    JPanel chooseFileButtonPanel = new JPanel();
    chooseFileButtonPanel.setLayout(new GridLayout(1, 3));
    chooseFileButtonPanel.add(new JPanel());
    chooseFileButtonPanel.add(chooseFileButton);
    chooseFileButtonPanel.add(new JPanel());

    panel.add(new JLabel(guiText.getString("FilePathLabel")));
    panel.add(filePathField);
    panel.add(chooseFileButtonPanel);
  }
Пример #2
0
 private void initConfigDecorator() {
   InputStream in =
       Q2.class
           .getClassLoader()
           .getResourceAsStream("META-INF/org/jpos/config/Q2-decorator.properties");
   try {
     if (in != null) {
       PropertyResourceBundle bundle = new PropertyResourceBundle(in);
       String ccdClass = bundle.getString("config-decorator-class");
       if (log != null) log.info("Initializing config decoration provider: " + ccdClass);
       decorator =
           (ConfigDecorationProvider) Q2.class.getClassLoader().loadClass(ccdClass).newInstance();
       decorator.initialize(getDeployDir());
     }
   } catch (IOException e) {
   } catch (Exception e) {
     if (log != null) log.error(e);
     else {
       e.printStackTrace();
     }
   } finally {
     if (in != null) {
       try {
         in.close();
       } catch (IOException e) {
       }
     }
   }
 }
Пример #3
0
  private static List<String> match(
      PropertyResourceBundle sourceBundle, PropertyResourceBundle targetBundle) {

    List<String> remaining = new ArrayList<String>();

    Enumeration<String> targetKeys = targetBundle.getKeys();
    while (targetKeys.hasMoreElements()) {
      String targetKey = targetKeys.nextElement();
      Enumeration<String> sourceKeys = sourceBundle.getKeys();
      boolean matched = false;
      while (sourceKeys.hasMoreElements()) {
        if (sourceKeys.nextElement().equals(targetKey)) {
          matched = true;
          break;
        }
      }

      if (!matched && !remaining.contains(targetKey)) remaining.add(targetKey);
    }

    System.out.println("Source keys: " + sourceBundle.keySet().size());
    System.out.println("Target keys: " + targetBundle.keySet().size());
    System.out.println("Remaining: " + remaining.size());

    return remaining;
  }
  @SuppressWarnings({"HardCodedStringLiteral"})
  @Nullable
  public static String getPropertyFromLaxFile(
      @NotNull final File file, @NotNull final String propertyName) {
    if (file.getName().endsWith(".properties")) {
      try {
        PropertyResourceBundle bundle;
        InputStream fis = new BufferedInputStream(new FileInputStream(file));
        try {
          bundle = new PropertyResourceBundle(fis);
        } finally {
          fis.close();
        }
        if (bundle.containsKey(propertyName)) {
          return bundle.getString(propertyName);
        }
        return null;
      } catch (IOException e) {
        return null;
      }
    }

    final String fileContent = getContent(file);

    // try to find custom config path
    final String propertyValue = findProperty(propertyName, fileContent);
    if (!StringUtil.isEmpty(propertyValue)) {
      return propertyValue;
    }

    return null;
  }
Пример #5
0
  /**
   * Formats a message with the specified arguments using the given locale information.
   *
   * @param locale The locale of the message.
   * @param key The message key.
   * @param arguments The message replacement text arguments. The order of the arguments must match
   *     that of the placeholders in the actual message.
   * @return Returns the formatted message.
   * @throws MissingResourceException Thrown if the message with the specified key cannot be found.
   */
  public String formatMessage(Locale locale, String key, Object[] arguments)
      throws MissingResourceException {

    if (fResourceBundle == null || locale != fLocale) {
      if (locale != null) {
        fResourceBundle =
            PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XIncludeMessages", locale);
        // memorize the most-recent locale
        fLocale = locale;
      }
      if (fResourceBundle == null)
        fResourceBundle =
            PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XIncludeMessages");
    }

    String msg = fResourceBundle.getString(key);
    if (arguments != null) {
      try {
        msg = java.text.MessageFormat.format(msg, arguments);
      } catch (Exception e) {
        msg = fResourceBundle.getString("FormatFailed");
        msg += " " + fResourceBundle.getString(key);
      }
    }

    if (msg == null) {
      msg = fResourceBundle.getString("BadMessageKey");
      throw new MissingResourceException(msg, "org.apache.xerces.impl.msg.XIncludeMessages", key);
    }

    return msg;
  }
Пример #6
0
  @Override
  public User getUserByLoginId(String loginid) throws SQLException {
    User user = null;
    PropertyResourceBundle prop = (PropertyResourceBundle) ResourceBundle.getBundle("kujosa");

    Connection connection = null;
    PreparedStatement stmt = null;
    try {
      connection = Database.getConnection();

      stmt = connection.prepareStatement(UserDAOQuery.GET_USER_BY_USERNAME);
      stmt.setString(1, loginid);

      ResultSet rs = stmt.executeQuery();
      if (rs.next()) {
        user = new User();
        user.setId(rs.getString("id"));
        user.setLoginid(rs.getString("loginid"));
        user.setEmail(rs.getString("email"));
        user.setFullname(rs.getString("fullname"));
        user.setFilename(rs.getString("image") + ".png");
        user.setImageURL(prop.getString("imgBaseURL") + user.getFilename());
      }
    } catch (SQLException e) {
      throw e;
    } finally {
      if (stmt != null) stmt.close();
      if (connection != null) connection.close();
    }

    return user;
  }
Пример #7
0
  /**
   * This method displays the result in the result text area.
   *
   * @param result to display
   */
  private void showResult(Object result) {

    resultTextArea.setText(null);
    if (result instanceof String) {
      resultTextArea.append((String) result);
    } else if (result instanceof String[]) {
      String[] resultStringArray = (String[]) result;
      if (resultStringArray.length == 0) {
        resultTextArea.append(guiText.getString("EmptyArray"));
      } else {
        Arrays.sort(resultStringArray, String.CASE_INSENSITIVE_ORDER);
        for (String s : (String[]) resultStringArray) {
          resultTextArea.append(s);
          resultTextArea.append("\n");
        }
      }
    } else if (result instanceof ECSpec) {
      CharArrayWriter writer = new CharArrayWriter();
      try {
        SerializerUtil.serializeECSpecPretty((ECSpec) result, writer);
      } catch (IOException e) {
        showExcpetionDialog(guiText.getString("SerializationExceptionMessage"));
      }
      resultTextArea.append(writer.toString());
    } else if (result instanceof ECReports) {
      CharArrayWriter writer = new CharArrayWriter();
      try {
        SerializerUtil.serializeECReportsPretty((ECReports) result, writer);
      } catch (IOException e) {
        showExcpetionDialog(guiText.getString("SerializationExceptionMessage"));
      }
      resultTextArea.append(writer.toString());
    }
  }
Пример #8
0
 private Config mockConfigMessages() {
   PropertyResourceBundle bundle = mock(PropertyResourceBundle.class);
   when(bundle.handleGetObject("Feedback.validated-mail-text")).thenReturn(validationMessage);
   when(bundle.handleGetObject("Feedback.mail-title")).thenReturn(title);
   Config config = mock(Config.class);
   when(config.getMessages(any(Locale.class))).thenReturn(bundle);
   return config;
 }
Пример #9
0
    /**
     * Checks if at least one of the underlying resource bundles supports the locale assigned to
     * this bundle.
     */
    public boolean isSupported() {
      for (String name : bundleNames) {
        PropertyResourceBundle bundle = getPropertyResourceBundle(name);
        if (bundle != null && bundle.getLocale().equals(locale)) {
          return true;
        }
      }

      return false;
    }
  public static Optional<String> getLocalePrefixForLocateResource(final FacesContext facesContext) {
    String localePrefix = null;
    boolean isResourceRequest =
        facesContext.getApplication().getResourceHandler().isResourceRequest(facesContext);

    if (isResourceRequest) {
      localePrefix =
          facesContext
              .getExternalContext()
              .getRequestParameterMap()
              .get(OsgiResource.REQUEST_PARAM_LOCALE);

      if (localePrefix != null) {
        if (!ResourceValidationUtils.isValidLocalePrefix(localePrefix)) {
          return Optional.empty();
        }
        return Optional.of(localePrefix);
      }
    }

    String bundleName = facesContext.getApplication().getMessageBundle();

    if (null != bundleName) {
      Locale locale = null;

      if (isResourceRequest || facesContext.getViewRoot() == null) {
        locale = facesContext.getApplication().getViewHandler().calculateLocale(facesContext);
      } else {
        locale = facesContext.getViewRoot().getLocale();
      }

      try {
        // load resource via ServletContext because due to Classloader
        ServletContext servletContext =
            (ServletContext) facesContext.getExternalContext().getContext();
        PropertyResourceBundle resourceBundle = null;
        try {
          URL resourceUrl =
              servletContext.getResource(
                  '/' + bundleName.replace('.', '/') + '_' + locale + ".properties");
          if (resourceUrl != null) {
            resourceBundle = new PropertyResourceBundle(resourceUrl.openStream());
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
        if (resourceBundle != null) {
          localePrefix = resourceBundle.getString(ResourceHandler.LOCALE_PREFIX);
        }
      } catch (MissingResourceException e) {
        // Ignore it and return null
      }
    }
    return Optional.ofNullable(localePrefix);
  }
Пример #11
0
  /**
   * Returns the message string with the specified key from the "properties" file in the package
   * containing the class with the specified name.
   */
  protected static final String getString(String className, String key) {
    PropertyResourceBundle bundle = null;
    try {
      InputStream stream = Class.forName(className).getResourceAsStream("properties");
      bundle = new PropertyResourceBundle(stream);
    } catch (Throwable e) {
      throw new RuntimeException(e); // Chain the exception.
    }

    return (String) bundle.handleGetObject(key);
  }
  /**
   * Formats a message with the specified arguments using the given locale information.
   *
   * @param locale The locale of the message.
   * @param key The message key.
   * @param arguments The message replacement text arguments. The order of the arguments must match
   *     that of the placeholders in the actual message.
   * @return Returns the formatted message.
   * @throws MissingResourceException Thrown if the message with the specified key cannot be found.
   */
  public String formatMessage(Locale locale, String key, Object[] arguments)
      throws MissingResourceException {

    if (fResourceBundle == null || locale != fLocale) {
      if (locale != null) {
        fResourceBundle =
            PropertyResourceBundle.getBundle(
                "com.sun.org.apache.xerces.internal.impl.msg.XMLMessages", locale);
        // memorize the most-recent locale
        fLocale = locale;
      }
      if (fResourceBundle == null)
        fResourceBundle =
            PropertyResourceBundle.getBundle(
                "com.sun.org.apache.xerces.internal.impl.msg.XMLMessages");
    }

    // format message
    String msg;
    try {
      msg = fResourceBundle.getString(key);
      if (arguments != null) {
        try {
          msg = java.text.MessageFormat.format(msg, arguments);
        } catch (Exception e) {
          msg = fResourceBundle.getString("FormatFailed");
          msg += " " + fResourceBundle.getString(key);
        }
      }
    }

    // error
    catch (MissingResourceException e) {
      msg = fResourceBundle.getString("BadMessageKey");
      throw new MissingResourceException(key, msg, key);
    }

    // no message
    if (msg == null) {
      msg = key;
      if (arguments.length > 0) {
        StringBuffer str = new StringBuffer(msg);
        str.append('?');
        for (int i = 0; i < arguments.length; i++) {
          if (i > 0) {
            str.append('&');
          }
          str.append(String.valueOf(arguments[i]));
        }
      }
    }

    return msg;
  }
  @Test
  public void testLoadMultipleFilesAndNoLookUps() {

    ResourceBundle bundle1 =
        PropertyResourceBundle.getBundle("propertyServiceImplTest-noLookUps-1");
    ResourceBundle bundle2 =
        PropertyResourceBundle.getBundle("propertyServiceImplTest-noLookUps-2");

    List<ResourceBundle> bundles = new ArrayList<ResourceBundle>();
    bundles.add(bundle1);
    bundles.add(bundle2);

    LookUpKeyResolver resolver =
        new LookUpKeyResolver() {
          @Override
          public LookUpKey resolve(String lookUpKey) {
            return new LookUpKey(null, lookUpKey, lookUpKey);
          }
        };

    PropertyServiceImpl service = new PropertyServiceImpl(resolver);

    Set<ClearProperty> properties = service.load(bundles);

    Assert.assertNotNull(properties);
    Assert.assertEquals(properties.size(), 5);

    for (ClearProperty property : properties) {
      String key = property.getKey();
      String value = property.getValue();
      String lookUp = property.getLookUpKey().getLookUp();

      Assert.assertNotNull(property.getLookUpKey());
      Assert.assertNotNull(property.getValue());
      Assert.assertNotNull(property.getKey());
      Assert.assertNull(lookUp);

      if (!(key.equals("foo")
          || key.equals("baz")
          || key.equals("qix")
          || key.equals("stux")
          || key.equals("flix"))) {
        Assert.fail("Key must either be foo, baz, or qix");
      }
      if (!(value.equals("bar")
          || value.equals("waldo")
          || value.equals("qux")
          || value.equals("flux")
          || value.equals("glux"))) {
        Assert.fail("Key must either be bar, waldo, or qux");
      }
    }
  }
  @Test
  public void testFilterWithMultipleFilesAndMultipleLookUps() {

    String expectedLookUp1 = "lookUp1";
    String expectedLookUp2 = "lookUp2";

    ResourceBundle bundle1 =
        PropertyResourceBundle.getBundle("propertyServiceImplTest-withLookUps-1");
    ResourceBundle bundle2 =
        PropertyResourceBundle.getBundle("propertyServiceImplTest-withLookUps-2");

    List<ResourceBundle> bundles = new ArrayList<ResourceBundle>();
    bundles.add(bundle1);
    bundles.add(bundle2);

    PropertyServiceImpl service = new PropertyServiceImpl(new ParenthesesLookUpKeyResolver());

    Set<ClearProperty> properties = service.load(bundles);

    // test with just one lookUp 'lookUp1'
    List<String> lookUps = new ArrayList<String>();
    lookUps.add(expectedLookUp1);
    lookUps.add(expectedLookUp2);

    Collection<ClearProperty> filteredProperties = service.filter(properties, lookUps);

    Assert.assertNotNull(filteredProperties);
    Assert.assertEquals(filteredProperties.size(), 4);

    for (ClearProperty filteredProperty : filteredProperties) {
      String key = filteredProperty.getKey();
      String value = filteredProperty.getValue();
      String lookUp = filteredProperty.getLookUpKey().getLookUp();

      Assert.assertNotNull(filteredProperty.getLookUpKey());
      Assert.assertNotNull(filteredProperty.getValue());
      Assert.assertNotNull(filteredProperty.getKey());
      Assert.assertNotNull(lookUp);

      if (!(key.equals("foo") || key.equals("stux") || key.equals("flix") || key.equals("baz"))) {
        Assert.fail("Key must either be foo, stux, flix, or baz");
      }
      if (!(value.equals("bar")
          || value.equals("flux")
          || value.equals("glux")
          || value.equals("waldo"))) {
        Assert.fail("Key must either be bar, flux, glux, or waldo");
      }
      if (!(lookUp.equals(expectedLookUp1) || lookUp.equals(expectedLookUp2))) {
        Assert.fail("lookUp either be lookUp1 or lookUp2");
      }
    }
  }
Пример #15
0
    protected Object handleGetObject(String key) {
      for (String name : bundleNames) {
        PropertyResourceBundle bundle = getPropertyResourceBundle(name);
        if (bundle != null) {
          Object value = bundle.handleGetObject(key);
          if (value != null) {
            return value;
          }
        }
      }

      return null;
    }
 public static String getMessage(int i) {
   try {
     String s = ""; // _cs, _de, _pl
     PropertyResourceBundle props =
         new PropertyResourceBundle(
             CodeBaseManifestEntrySignedMatching.class
                 .getClassLoader()
                 .getResourceAsStream(
                     "net/sourceforge/jnlp/resources/Messages" + s + ".properties"));
     return props.getString(keys[i]);
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   }
 }
Пример #17
0
  /** {@inheritDoc} */
  @Override
  protected void update(Object key, Object value) {

    // If top level active collection, or a derive collection that is being actively
    // maintained, then apply the update
    if (!isDerived() || isActive()) {
      synchronized (_list) {
        if (key != null) {
          if (key instanceof Integer) {
            _list.set((Integer) key, value);

            if (getItemExpiration() > 0) {
              _listTimestamps.set((Integer) key, System.currentTimeMillis());
            }

            updated(key, value);
          } else {
            LOG.severe(
                MessageFormat.format(
                    java.util.PropertyResourceBundle.getBundle("active-collection.Messages")
                        .getString("ACTIVE-COLLECTION-8"),
                    key));
          }
        } else {
          // Can only assume that value maintains its own identity
          int index = _list.indexOf(value);

          if (index == -1) {
            // Can't find updated entry, so log error
            LOG.severe(
                MessageFormat.format(
                    java.util.PropertyResourceBundle.getBundle("active-collection.Messages")
                        .getString("ACTIVE-COLLECTION-9"),
                    getName(),
                    value));
          } else {
            _list.set(index, value);

            if (getItemExpiration() > 0) {
              _listTimestamps.set(index, System.currentTimeMillis());
            }

            updated(index, value);
          }
        }

        _readCopy = null;
      }
    }
  }
Пример #18
0
  /**
   * This method creates the file menu.
   *
   * @return file menu
   */
  private Component createFileMenu() {

    JMenu fileMenuItem = new JMenu(guiText.getString("FileMenu"));

    JMenuItem exitMenuItem = new JMenuItem(guiText.getString("QuitMenuItem"));
    exitMenuItem.addMouseListener(
        new MouseAdapter() {
          public void mouseReleased(MouseEvent e) {
            System.exit(0);
          }
        });
    fileMenuItem.add(exitMenuItem);

    return fileMenuItem;
  }
Пример #19
0
 private PropertyResourceBundle getPropertyResourceBundle(String name) {
   try {
     return (PropertyResourceBundle) PropertyResourceBundle.getBundle(name, locale);
   } catch (MissingResourceException e) {
     return null;
   }
 }
Пример #20
0
  /**
   * Loads the language for the GUI window.
   *
   * @throws IOException It can't be loaded the requested File
   */
  public ResourceBundle loadWindowLanguageStringsResource(String fileName, Locale displayLanguage)
      throws LanguageExecption {
    if (localeLang == null) {
      throw new LanguageExecption("It isn't set a display language (No Locale class is set).");
    }

    try {
      // Nur laden, wenn von einem anderen Fenster etwas geladen werden soll
      if (!fileName.equals(guiElement)) {
        languageResource =
            PropertyResourceBundle.getBundle(BUNDLE_BASENANE + fileName, displayLanguage);
      }
    } catch (MissingResourceException e2) {
      System.err.println("Cannot load the file with name: " + BUNDLE_BASENANE + fileName);
      e2.printStackTrace();
      throw new LanguageExecption(
          "(MissingResourceException) Cannot load the file with name: "
              + BUNDLE_BASENANE
              + fileName);
    } catch (NullPointerException e1) {
      System.err.println("The Inputstream is empty");
      e1.printStackTrace();
      throw new LanguageExecption("(NullPointerException) The Inputstream is empty");
    }
    return languageResource;
  }
Пример #21
0
  /**
   * This method adds a notification uri field to the panel.
   *
   * @param panel to which the norification uri field should be added
   */
  private void addNotificationURIField(JPanel panel) {

    notificationUriField = new JTextField();

    panel.add(new JLabel(guiText.getString("NotificationURILabel")));
    panel.add(notificationUriField);
  }
Пример #22
0
  /**
   * This method creates the command selection panel.
   *
   * @return command selection panel
   */
  private JPanel createCommandSelectionPanel() {

    JPanel selectionPanel = new JPanel();
    selectionPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder(guiText.getString("SelectionPanelTitle")),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    commandSelection.setMaximumRowCount(12);

    commandSelection.addItem(null);
    for (String item : getCommands()) {
      commandSelection.addItem(item);
    }

    commandSelection.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if ("comboBoxChanged".equals(e.getActionCommand())) {
              setCommandPanel(commandSelection.getSelectedIndex());
            }
          }
        });

    selectionPanel.add(commandSelection);

    return selectionPanel;
  }
 /**
  * @see
  *     org.eclipse.papyrus.adltool.designer.bundle.AbstractBundleDescriptionDesigner#getBundleValue(java.lang.Object,
  *     java.lang.String)
  * @param bundleProject
  * @param key
  * @return the value that corresponds to the key
  */
 public String getBundleValue(Object bundleProject, String key) {
   String valueFromDescription = null;
   if (bundleProject instanceof IBundleProjectDescription) {
     PropertyResourceBundle propertyResourceBundle =
         getNLSFilesFor((IBundleProjectDescription) bundleProject);
     valueFromDescription = ((IBundleProjectDescription) bundleProject).getHeader(key);
     if (propertyResourceBundle != null && valueFromDescription != null) {
       if (valueFromDescription.startsWith("%")
           && (valueFromDescription.length() > 1)) { // $NON-NLS-1$
         String propertiesKey = valueFromDescription.substring(1);
         valueFromDescription = propertyResourceBundle.getString(propertiesKey);
       }
     }
   }
   return valueFromDescription;
 }
  /**
   * This method validates the supplied model object.
   *
   * @param obj The model object being validated
   * @param logger The logger
   */
  public void validate(ModelObject obj, Journal logger) {
    Recursion elem = (Recursion) obj;
    ModelObject act = elem.getParent();

    if (elem.getLabel() != null) {
      boolean f_found = false;

      while (f_found == false && act != null && (act instanceof Protocol) == false) {

        if (act instanceof RecBlock
            && ((RecBlock) act).getLabel() != null
            && ((RecBlock) act).getLabel().equals(elem.getLabel())) {
          f_found = true;
        }

        act = act.getParent();
      }

      if (f_found == false) {
        logger.error(
            MessageFormat.format(
                java.util.PropertyResourceBundle.getBundle("org.scribble.protocol.Messages")
                    .getString("_NO_ENCLOSING_RECUR"),
                elem.getLabel()),
            obj.getProperties());
      }
    }
  }
Пример #25
0
  /** {@inheritDoc} */
  @Override
  protected void insert(Object key, Object value) {

    // If top level active collection, or a derive collection that is being actively
    // maintained, then apply the insertion
    if (!isDerived() || isActive()) {
      synchronized (_list) {
        if (key == null) {
          _list.add(value);

          if (getItemExpiration() > 0) {
            _listTimestamps.add(System.currentTimeMillis());
          }
        } else if (key instanceof Integer) {
          _list.add((Integer) key, value);

          if (getItemExpiration() > 0) {
            _listTimestamps.add((Integer) key, System.currentTimeMillis());
          }
        } else {
          LOG.severe(
              MessageFormat.format(
                  java.util.PropertyResourceBundle.getBundle("active-collection.Messages")
                      .getString("ACTIVE-COLLECTION-7"),
                  key));
        }

        _readCopy = null;
      }

      inserted(key, value);
    }
  }
Пример #26
0
  /**
   * This method hunts down the version recorded in the current product.
   *
   * @throws IOException
   */
  private void loadVersion() {
    IProduct product = Platform.getProduct();
    if (product == null || !(UDIG_PRODUCT_ID.equals(product.getId()))) {
      // chances are someone is using the SDK with their own
      // application or product.
      String message =
          "Unable to parse version from about.mappings file. Defaulting to a blank string."; //$NON-NLS-1$
      this.getLog().log(new Status(IStatus.INFO, ID, 0, message, null));
      this.version = "";
      return;
    }
    Bundle pluginBundle = product.getDefiningBundle();

    URL mappingsURL = FileLocator.find(pluginBundle, new Path(MAPPINGS_FILENAME), null);
    if (mappingsURL != null) {
      try {
        mappingsURL = FileLocator.resolve(mappingsURL);
      } catch (IOException e) {
        mappingsURL = null;
        String message =
            "Unable to find " + mappingsURL + " Defaulting to a blank string."; // $NON-NLS-1$
        this.getLog().log(new Status(IStatus.ERROR, ID, 0, message, e));
      }
    }
    PropertyResourceBundle bundle = null;
    if (mappingsURL != null) {
      InputStream is = null;
      try {
        is = mappingsURL.openStream();
        bundle = new PropertyResourceBundle(is);
      } catch (IOException e) {
        bundle = null;
        String message =
            "Unable to parse version from about.mappings file. Defaulting to a blank string."; //$NON-NLS-1$
        this.getLog().log(new Status(IStatus.ERROR, ID, 0, message, e));
      } finally {
        try {
          if (is != null) is.close();
        } catch (IOException e) {
        }
      }
    }

    if (bundle != null) {
      this.version = bundle.getString(UDIG_VERSION_KEY);
    }
  }
Пример #27
0
  /**
   * This method sets the command selection panel depending on the command id.
   *
   * @param command id
   */
  private void setCommandPanel(int command) {

    if (command == -1) {
      commandPanel.removeAll();
      commandPanel.setBorder(null);
      this.setVisible(false);
      this.setVisible(true);
      return;
    }

    commandPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder(guiText.getString("Command" + command)),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    commandPanel.removeAll();

    switch (command) {
      case 4: // getECSpecNames
      case 10: // getStandardVersion
      case 11: // getVendorVersion
        commandPanel.setLayout(new GridLayout(1, 1, 5, 0));
        break;

      case 2: // undefine
      case 3: // getECSpec
      case 7: // poll
      case 9: // getSubscribers
        commandPanel.setLayout(new GridLayout(5, 1, 5, 0));
        addECSpecNameComboBox(commandPanel);
        addSeparator(commandPanel);
        break;

      case 5: // subscribe
      case 6: // unsubscribe
        commandPanel.setLayout(new GridLayout(7, 1, 5, 0));
        addECSpecNameComboBox(commandPanel);
        addNotificationURIField(commandPanel);
        addSeparator(commandPanel);
        break;

      case 8: // immediate
        commandPanel.setLayout(new GridLayout(6, 1, 5, 0));
        addChooseFileField(commandPanel);
        addSeparator(commandPanel);
        break;

      case 1: // define
        commandPanel.setLayout(new GridLayout(8, 1, 5, 0));
        addECSpecNameComboBox(commandPanel);
        addChooseFileField(commandPanel);
        addSeparator(commandPanel);
        break;
    }

    addExecuteButton(commandPanel);

    this.setVisible(false);
    this.setVisible(true);
  }
Пример #28
0
  /**
   * This method returns the names of all commands.
   *
   * @return command names
   */
  private String[] getCommands() {

    String[] commands = new String[11];
    for (int i = 1; i < 12; i++) {
      commands[i - 1] = guiText.getString("Command" + i);
    }
    return commands;
  }
Пример #29
0
  static SQLException createSQLException(
      Locale msgLocale, String messageId, Object[] messageArguments) {
    Locale currentLocale;
    int sqlcode;

    if (msgLocale == null) currentLocale = Locale.getDefault();
    else currentLocale = msgLocale;
    try {
      PropertyResourceBundle messageBundle =
          (PropertyResourceBundle)
              ResourceBundle.getBundle(
                  "SQLMXT2Messages",
                  currentLocale); // R321 changed property file name to
                                  // SQLMXT2Messages_en.properties
      MessageFormat formatter = new MessageFormat("");
      formatter.setLocale(currentLocale);
      formatter.applyPattern(messageBundle.getString(messageId + "_msg"));
      String message = formatter.format(messageArguments);
      String sqlState = messageBundle.getString(messageId + "_sqlstate");
      String sqlcodeStr = messageBundle.getString(messageId + "_sqlcode");
      if (sqlcodeStr != null) {
        try {
          sqlcode = Integer.parseInt(sqlcodeStr);
          sqlcode = -sqlcode;
        } catch (NumberFormatException e1) {
          sqlcode = -1;
        }
      } else sqlcode = -1;
      return new SQLException(message, sqlState, sqlcode);
    } catch (MissingResourceException e) {
      // If the resource bundle is not found, concatenate the messageId and the parameters
      String message;
      int i = 0;

      message = "The message id: " + messageId;
      if (messageArguments != null) {
        message = message.concat(" With parameters: ");
        while (true) {
          message = message.concat(messageArguments[i++].toString());
          if (i >= messageArguments.length) break;
          else message = message.concat(",");
        }
      }
      return new SQLException(message, "HY000", -1);
    }
  }
  /**
   * This method projects a 'global' protocol model to a specified role's 'local' protocol model.
   *
   * @param model The 'global' protocol model
   * @param role The role to project
   * @param journal Journal for reporting issues
   * @param context The protocol context
   * @return The 'local' protocol model
   */
  public ProtocolModel project(
      ProtocolModel model, Role role, Journal journal, ProtocolContext context) {
    ProtocolModel ret = null;

    if (model == null || role == null) {
      throw new IllegalArgumentException("Model and/or role has not bee specified");
    }

    // Check that the supplied role has been defined within the model
    // being projected
    java.util.List<Role> roles = model.getRoles();
    int index = roles.indexOf(role);

    if (index == -1) {
      throw new IllegalArgumentException(
          "Role '" + role.getName() + "' is not defined within the protocol model");
    } else {
      // Obtain the role instance actually defined within the model,
      // as this can be used to locate the appropriate scope to be
      // projected
      role = roles.get(index);
    }

    // Check that role is defined within a role list, and its parent
    // link has not inadvertantly been reset
    if ((role.getParent() instanceof RoleList) == false) {
      throw new IllegalArgumentException(
          "Role is not contained within a role list, " + "and is therefore not the declared role");
    }

    DefaultProjectorContext projectorContext = new DefaultProjectorContext(context);

    ModelObject obj = projectorContext.project(model, role, journal);

    if (obj != null) {
      if (obj instanceof ProtocolModel) {
        ret = (ProtocolModel) obj;
      } else {
        String modelName = model.getProtocol().getName();

        if (model.getProtocol().getRole() != null) {
          modelName += "," + model.getProtocol().getRole();
        }

        journal.error(
            MessageFormat.format(
                java.util.PropertyResourceBundle.getBundle(
                        "org.scribble.protocol.projection.Messages")
                    .getString("_NOT_PROJECTED_MODEL"),
                modelName),
            null);
      }
    }

    return (ret);
  }