Esempio n. 1
0
  @Override
  public AnchorHtmlData getInquiryUrlForPrimaryKeys(
      Class clazz, Object businessObject, List<String> primaryKeys, String displayText) {
    if (businessObject == null) {
      return new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING);
    }

    OleLoadSumRecords oleLoadSumRecords = (OleLoadSumRecords) businessObject;
    Properties parameters = new Properties();
    Map<String, String> fieldList = new HashMap<String, String>();
    parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "docHandler");
    parameters.put(OLEConstants.DOCUMENT_TYPE_NAME, "OLE_ACQBTHUPLOAD");
    parameters.put(OLEConstants.PARAMETER_COMMAND, "displayDocSearchView");
    parameters.put("docId", oleLoadSumRecords.getDocumentNumber().toString());
    fieldList.put("docId", oleLoadSumRecords.getDocumentNumber().toString());
    if (StringUtils.isEmpty(displayText)) {
      return getHyperLink(
          clazz,
          fieldList,
          UrlFactory.parameterizeUrl(OLEConstants.BATCH_UPLOAD_ACTION_PATH, parameters));
    } else {
      return getHyperLink(
          clazz,
          fieldList,
          UrlFactory.parameterizeUrl(OLEConstants.BATCH_UPLOAD_ACTION_PATH, parameters),
          displayText);
    }
  }
Esempio n. 2
0
 static {
   nameToColumnMap.put("id", "ID");
   nameToColumnMap.put("dataTypeId", "DATA_TYPE_ID");
   nameToColumnMap.put("uomId", "UOM_ID");
   nameToColumnMap.put("dataValue", "DATA_VALUE");
   nameToColumnMap.put("dataLabel", "DATA_LABEL");
 }
Esempio n. 3
0
  /**
   * Get the set of properties that match a specified pattern. The match pattern accepts a single
   * '*' char anywhere in the pattern. If the '*' is placed somewhere in the middle of the pattern,
   * then then the subset will contain properties that startWith everything before the '*' and end
   * with everything after the '*'.
   *
   * <p>Sample property patterns:
   *
   * <table>
   * <tr><td>*.bar<td>   returns the subset of properties that end with '.bar'
   * <tr><td>bar.*<td>   returns the subset of properties that begin with 'bar.'
   * <tr><td>foo*bar<td> returns the subset of properties that begin with 'foo' and end with 'bar'
   * </table>
   *
   * @param propPattern a pattern with 0 or 1 '*' chars.
   * @return the subset of properties that match the specified pattern. Note that changing the
   *     properties in the returned subset will not affect this object.
   */
  public Properties getProperties(String propPattern) {
    Properties props = new Properties();
    int index = propPattern.indexOf("*");
    if (index == -1) {
      String value = getProperty(propPattern);
      if (value != null) {
        props.put(propPattern, value);
      }
    } else {
      String startsWith = propPattern.substring(0, index);
      String endsWith;
      if (index == propPattern.length() - 1) {
        endsWith = null;
      } else {
        endsWith = propPattern.substring(index + 1);
      }

      Enumeration names = propertyNames();
      while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (name.startsWith(startsWith)) {
          if (endsWith == null) {
            props.put(name, getProperty(name));
          } else if (name.endsWith(endsWith)) {
            props.put(name, getProperty(name));
          }
        }
      }
    }
    return props;
  }
  @Test
  public void testState() throws IOException {
    final File fcontent = File.createTempFile("foo", "bar");
    final Properties properties = new Properties();
    final Date dt = new Date();

    properties.put("int", 10453);
    properties.put("long", 1000000L);
    properties.put("date", dt);

    final OutputStream out = new FileOutputStream(fcontent);
    properties.store(out);

    final Properties loadProperties = new Properties();

    final InputStream in = new FileInputStream(fcontent);
    loadProperties.load(in);

    assertNotNull(properties.get("int"));
    assertNotNull(properties.get("long"));
    assertNotNull(properties.get("date"));

    assertEquals(10453, properties.get("int"));
    assertEquals(1000000L, properties.get("long"));
    assertEquals(dt, properties.get("date"));
  }
Esempio n. 5
0
  public void mail(String toAddress, String subject, String body) {
    Properties props = new Properties();
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", port);
    props.put("mail.smtp.ssl.enable", true);
    Authenticator authenticator = null;
    if (login) {
      props.put("mail.smtp.auth", true);
      authenticator =
          new Authenticator() {
            private PasswordAuthentication pa = new PasswordAuthentication(username, password);

            @Override
            public PasswordAuthentication getPasswordAuthentication() {
              return pa;
            }
          };
    }

    Session s = Session.getInstance(props, authenticator);
    s.setDebug(debug);
    MimeMessage email = new MimeMessage(s);
    try {
      email.setFrom(new InternetAddress(from));
      email.setRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
      email.setSubject(subject);
      email.setSentDate(new Date());
      email.setText(body);
      Transport.send(email);
    } catch (MessagingException ex) {
      ex.printStackTrace();
    }
  }
Esempio n. 6
0
  /** store the given RenderingHints to a Properties object */
  public static void formatRenderingHints(RenderingHints rh, Properties preferences) {

    if (rh.get(RenderingHints.KEY_ANTIALIASING).equals(RenderingHints.VALUE_ANTIALIAS_ON))
      preferences.put("rendering.antialiasing", "on");
    else if (rh.get(RenderingHints.KEY_ANTIALIASING).equals(RenderingHints.VALUE_ANTIALIAS_OFF))
      preferences.put("rendering.antialiasing", "off");

    if (rh.get(RenderingHints.KEY_TEXT_ANTIALIASING).equals(RenderingHints.VALUE_TEXT_ANTIALIAS_ON))
      preferences.put("rendering.text-antialiasing", "on");
    else if (rh.get(RenderingHints.KEY_TEXT_ANTIALIASING)
        .equals(RenderingHints.VALUE_TEXT_ANTIALIAS_OFF))
      preferences.put("rendering.text-antialiasing", "off");

    if (rh.get(RenderingHints.KEY_RENDERING).equals(RenderingHints.VALUE_RENDER_SPEED))
      preferences.put("rendering.render", "speed");
    else if (rh.get(RenderingHints.KEY_RENDERING).equals(RenderingHints.VALUE_RENDER_QUALITY))
      preferences.put("rendering.render", "quality");

    if (rh.get(RenderingHints.KEY_DITHERING).equals(RenderingHints.VALUE_DITHER_ENABLE))
      preferences.put("rendering.dither", "on");
    else if (rh.get(RenderingHints.KEY_DITHERING).equals(RenderingHints.VALUE_DITHER_DISABLE))
      preferences.put("rendering.dither", "off");

    if (rh.get(RenderingHints.KEY_FRACTIONALMETRICS)
        .equals(RenderingHints.VALUE_FRACTIONALMETRICS_ON))
      preferences.put("rendering.fractional-metrics", "on");
    else if (rh.get(RenderingHints.KEY_FRACTIONALMETRICS)
        .equals(RenderingHints.VALUE_FRACTIONALMETRICS_OFF))
      preferences.put("rendering.fractional-metrics", "off");
  }
  private static ConsumerConfig createConsumerConfig(
      String zookeeper, String groupId, String optionalConfigs) {
    try {
      Properties props = new Properties();
      props.put(KafkaEventAdapterConstants.ADAPTOR_SUSCRIBER_ZOOKEEPER_CONNECT, zookeeper);
      props.put(KafkaEventAdapterConstants.ADAPTOR_SUSCRIBER_GROUP_ID, groupId);

      if (optionalConfigs != null) {
        String[] optionalProperties = optionalConfigs.split(",");

        if (optionalProperties != null && optionalProperties.length > 0) {
          for (String header : optionalProperties) {
            String[] configPropertyWithValue = header.split(":", 2);
            if (configPropertyWithValue.length == 2) {
              props.put(configPropertyWithValue[0], configPropertyWithValue[1]);
            } else {
              log.warn(
                  "Optional configuration property not defined in the correct format.\nRequired - property_name1:property_value1,property_name2:property_value2\nFound - "
                      + optionalConfigs);
            }
          }
        }
      }
      return new ConsumerConfig(props);
    } catch (NoClassDefFoundError e) {
      throw new InputEventAdapterRuntimeException(
          "Cannot access kafka context due to missing jars", e);
    }
  }
 private XmlUIElement getXmlUIElementFor(String typeArg) {
   if (typeToClassMappingProp == null) {
     setUpMappingsHM();
   }
   String clsName = (String) typeToClassMappingProp.get(typeArg);
   if ((clsName != null) && !(clsName.equals("*NOTFOUND*")) && !(clsName.equals("*EXCEPTION*"))) {
     try {
       Class cls = Class.forName(clsName);
       return (XmlUIElement) cls.newInstance();
     } catch (Throwable th) {
       typeToClassMappingProp.put(typeArg, "*EXCEPTION*");
       showErrorMessage(
           MessageFormat.format(
               ProvClientUtils.getString(
                   "{0} occurred when trying to get the XmlUIElement for type : {1}"),
               new Object[] {th.getClass().getName(), typeArg}));
       th.printStackTrace();
       return null;
     }
   } else if (clsName == null) {
     typeToClassMappingProp.put(typeArg, "*NOTFOUND*");
     showErrorMessage(
         MessageFormat.format(
             ProvClientUtils.getString(
                 "The type {0} does not have the corresponding XMLUIElement specified in the TypeToUIElementMapping.txt file"),
             new Object[] {typeArg}));
   }
   return null;
 }
Esempio n. 9
0
  public static void main(String[] args) {
    // set up environment to access the server
    Properties env = new Properties();

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://" + ldapServerName + "/" + rootContext);
    env.put(Context.SECURITY_PRINCIPAL, rootdn);
    env.put(Context.SECURITY_CREDENTIALS, rootpass);

    try {
      // obtain initial directory context using the environment
      DirContext ctx = new InitialDirContext(env);

      // create some random number to add to the directory
      Integer i = new Integer(28420);

      System.out.println("Adding " + i + " to directory...");
      ctx.bind("cn=myRandomInt", i);

      i = new Integer(98765);
      System.out.println("i is now: " + i);

      i = (Integer) ctx.lookup("cn=myRandomInt");
      System.out.println("Retrieved i from directory with value: " + i);

    } catch (NameAlreadyBoundException nabe) {
      System.err.println("value has already been bound!");
    } catch (Exception e) {
      System.err.println(e);
    }
  }
Esempio n. 10
0
 @BeforeClass
 public static void setUpClass() throws Exception {
   Properties props = new Properties();
   props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
   props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
   props.put(Context.PROVIDER_URL, "localhost:1099");
   ic = new InitialContext(props);
 }
Esempio n. 11
0
 /** Gets the system properties explicitly set in the Maven command line (the "-D" option.) */
 public Properties getMavenProperties() {
   Properties props = new Properties();
   for (String arg : getMavenArgument("-D", "--define")) {
     int idx = arg.indexOf('=');
     if (idx < 0) props.put(arg, "true");
     else props.put(arg.substring(0, idx), arg.substring(idx + 1));
   }
   return props;
 }
 //	----------------------------------------------------------------------------------------------------------------
 //       Method:    getConnection
 //       Inputs:	database URL, username, password
 //      Outputs:	connection to DB
 //  Description:    Connects to MySql database
 //	----------------------------------------------------------------------------------------------------------------
 private static Connection getConnection(String dbURL, String user, String password)
     throws SQLException, ClassNotFoundException {
   Class.forName("com.mysql.jdbc.Driver"); // Setup for the MySql JDBC Driver
   Properties props = new Properties(); // Build the properties
   props.put("user", user);
   props.put("password", password);
   props.put("autoReconnect", "true"); // Enabled auto-reconnection
   return DriverManager.getConnection(dbURL, props); // Return the connection to the database
 }
Esempio n. 13
0
 protected Properties getProperties() {
   Properties properties = new Properties();
   properties.put("resource.loader", "jar");
   properties.put(
       "jar.resource.loader.class",
       "org.apache.velocity.runtime.resource.loader.JarResourceLoader");
   String jarPath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
   properties.put("jar.resource.loader.path", "jar:file:" + jarPath);
   properties.put("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
   return properties;
 }
Esempio n. 14
0
 private void setTarget(Info info) {
   String factionInfo = info.getMessage().substring(11);
   String[] splitInfo = factionInfo.split("/");
   if (splitInfo.length != 2) {
     info.sendMessage("usage for !setTarget is !setTarget <faction>/<location>");
   } else {
     raidTarget.put(info.getChannel(), splitInfo[0]);
     raidLocation.put(info.getChannel(), splitInfo[1]);
     target(info);
   }
 }
  protected AnchorHtmlData getPrintLink(String proposalNumber) {
    AnchorHtmlData htmlData = new AnchorHtmlData();
    htmlData.setDisplayText(PRINT_LINK);
    Properties parameters = new Properties();
    parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, PRINT_PROPOSAL_LOG);
    parameters.put(PROPOSAL_NUMBER, proposalNumber);
    String href = UrlFactory.parameterizeUrl(PRINT_PROPOSAL_LOG_ACTION, parameters);

    htmlData.setHref(href);
    return htmlData;
  }
Esempio n. 16
0
 public Email() {
   props = new Properties();
   toList = new ArrayList<InternetAddress>();
   ccList = new ArrayList<InternetAddress>();
   bccList = new ArrayList<InternetAddress>();
   props.put("mail.smtp.host", mailSmtpHost);
   // props.put("mail.smtp.host", "mcadlx01.servers.mc.franklin.edu");
   props.put("mail.user", "*****@*****.**");
   Session session = Session.getInstance(props, null);
   msg = new MimeMessage(session);
 }
Esempio n. 17
0
 private static Properties addDeserializerToConfig(
     Properties properties, Deserializer<?> keyDeserializer, Deserializer<?> valueDeserializer) {
   Properties newProperties = new Properties();
   newProperties.putAll(properties);
   if (keyDeserializer != null)
     newProperties.put(
         ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializer.getClass().getName());
   if (keyDeserializer != null)
     newProperties.put(
         ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializer.getClass().getName());
   return newProperties;
 }
Esempio n. 18
0
 public void koneksiDatabase() {
   try {
     String url = "jdbc:mysql://localhost:3306/payroll_db";
     Properties prop = new Properties();
     prop.put("user", "root");
     prop.put("password", "admin");
     konek = DriverManager.getConnection(url, prop);
     status_Proses(true, "Sukses!!!Berhasil Terhubung dengan Database...", 20);
   } catch (SQLException se) {
     status_Proses(false, "Gagal!!!Tidak terhubung \nKarena : " + se, 20);
   }
 }
  /** {@inheritDoc} */
  public SynapseConfiguration createSynapseConfiguration() {

    String synapseXMLLocation = serverConfigurationInformation.getSynapseXMLLocation();
    Properties properties = SynapsePropertiesLoader.loadSynapseProperties();
    if (serverConfigurationInformation.getResolveRoot() != null) {
      properties.put(
          SynapseConstants.RESOLVE_ROOT, serverConfigurationInformation.getResolveRoot());
    }

    if (serverConfigurationInformation.getSynapseHome() != null) {
      properties.put(
          SynapseConstants.SYNAPSE_HOME, serverConfigurationInformation.getSynapseHome());
    }

    if (synapseXMLLocation != null) {
      synapseConfiguration =
          SynapseConfigurationBuilder.getConfiguration(synapseXMLLocation, properties);
    } else {
      log.warn(
          "System property or init-parameter '"
              + SynapseConstants.SYNAPSE_XML
              + "' is not specified. Using default configuration..");
      synapseConfiguration = SynapseConfigurationBuilder.getDefaultConfiguration();
    }

    Enumeration keys = properties.keys();
    while (keys.hasMoreElements()) {
      String key = (String) keys.nextElement();
      synapseConfiguration.setProperty(key, properties.getProperty(key));
    }

    // Set the Axis2 ConfigurationContext to the SynapseConfiguration
    synapseConfiguration.setAxisConfiguration(configurationContext.getAxisConfiguration());
    MessageContextCreatorForAxis2.setSynConfig(synapseConfiguration);

    // set the Synapse configuration into the Axis2 configuration
    Parameter synapseConfigurationParameter =
        new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration);
    try {
      configurationContext.getAxisConfiguration().addParameter(synapseConfigurationParameter);
    } catch (AxisFault e) {
      handleFatal(
          "Could not set parameters '"
              + SynapseConstants.SYNAPSE_CONFIG
              + "' to the Axis2 configuration : "
              + e.getMessage(),
          e);
    }

    addServerIPAndHostEntries();

    return synapseConfiguration;
  }
  public Properties getProperties() {
    Properties prop = new Properties();
    String name = saName.getText();
    String interval = saInt.getText();
    boolean opt = saYes.isSelected();

    prop.put("name", name);
    prop.put("suppressInt", interval);
    prop.put("suppressAll", opt + "");

    return prop;
  }
Esempio n. 21
0
  public boolean sendEmail(
      String senderEmail,
      String senderPassword,
      String recipientEmail,
      String recipientName,
      String newPassword) {
    boolean success = false;
    final String username = senderEmail;
    final String password = senderPassword;
    // Properties is used to maintain lists of values in which
    // the key is a String and the value is also a String.
    // .put is used to map the specified key to the specified value in this hashtable.
    // Neither the key nor the value can be null.
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    // Session object is a single-threaded context for producing and consuming messages.
    // Authenticator represents an object that knows how to obtain authentication for a network
    // connection.
    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
              }
            });

    try {
      // Message models an email message.
      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(recipientEmail));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail));
      message.setSubject("Replacement Password.");
      message.setText(
          "Dear "
              + recipientName
              + ","
              + "\n\nYour new password is: "
              + newPassword
              + "\n\nRegards, \nsimplyTECH");
      // Transport models an message transport
      Transport.send(message);
      success = true;
    } catch (MessagingException e) {
      success = false;
    }
    return success;
  }
Esempio n. 22
0
  /** This method creates a properties object containing the definition of the data store. */
  public Properties getProperties() {

    Properties p = super.getProperties();
    String desc = "base.";

    p.put(desc + "updateMethod", getIntProperty(_updateMethod));
    p.put(desc + "checkConcurrency", getBoolProperty(_checkConcurrency));
    p.put(desc + "useBind", getBoolProperty(_useBind));
    p.put(desc + "maxRows", getIntProperty(_maxRows));
    p.put(desc + "remoteID", getStringProperty(_remoteID));

    return p;
  }
Esempio n. 23
0
  static {
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.host", "smtp.gmail.com");
    properties.put("mail.smtp.port", "587");

    //    	try {
    //			properties.load( new FileInputStream("mail.properties"));
    //		} catch (IOException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}
  }
  protected AnchorHtmlData getSelectLinkForProposalCreation(ProposalLog proposalLog) {
    AnchorHtmlData htmlData = new AnchorHtmlData();
    htmlData.setDisplayText(DISPLAY_TEXT);
    Properties parameters = new Properties();
    parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, DOC_HANDLER);
    parameters.put(KRADConstants.PARAMETER_COMMAND, INITIATE);
    parameters.put(KRADConstants.DOCUMENT_TYPE_NAME, INST_PROP_DOC_NAME);
    parameters.put(PROPOSAL_NUMBER, proposalLog.getProposalNumber());
    String href = UrlFactory.parameterizeUrl(INSTITUTIONAL_PROPOSAL_HOME_ACTION, parameters);

    htmlData.setHref(href);
    return htmlData;
  }
 private DirContext bindUser(AdCredentials credentials) throws AuthenticationException {
   Properties properties = new Properties();
   properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
   // See: http://docs.oracle.com/javase/jndi/tutorial/ldap/connect/create.html#TIMEOUT
   properties.put(
       "com.sun.jndi.ldap.read.timeout",
       configuration.getReadTimeout() + ""); // How long to wait for a read response
   properties.put(
       "com.sun.jndi.ldap.connect.timeout",
       configuration.getConnectionTimeout() + ""); // How long to wait for a network connection
   properties.put(Context.PROVIDER_URL, configuration.getLdapUrl());
   properties.put(
       Context.SECURITY_PRINCIPAL, credentials.getUserPrincipalName(configuration.getDomain()));
   properties.put(Context.SECURITY_CREDENTIALS, credentials.getPassword());
   properties.put(Context.REFERRAL, "ignore");
   if (configuration.getBinaryAttributeNames().length > 0) {
     properties.put(
         "java.naming.ldap.attributes.binary",
         Joiner.on(" ").join(configuration.getBinaryAttributeNames()));
   }
   try {
     return new InitialDirContext(properties);
   } catch (javax.naming.AuthenticationException e) {
     LOG.warn(
         String.format(
             "User: %s failed to authenticate. Bad Credentials", credentials.getUsername()),
         e);
     return null;
   } catch (NamingException e) {
     throw new AuthenticationException("Could not bind with AD", e);
   }
 }
Esempio n. 26
0
  public static void testSpecialConversions() throws URISyntaxException {
    Properties p = new Properties();
    p.put("enumv", "A");
    p.put("pattern", ".*");
    p.put("clazz", "java.lang.Object");
    p.put("constructor", "http://www.aQute.biz");

    SpecialConversions trt =
        Configurable.createConfigurable(SpecialConversions.class, (Map<Object, Object>) p);
    assertEquals(SpecialConversions.X.A, trt.enumv());
    assertEquals(".*", trt.pattern().pattern());
    assertEquals(Object.class, trt.clazz());
    assertEquals(new URI("http://www.aQute.biz"), trt.constructor());
  }
Esempio n. 27
0
 public void testCreateIllProv() throws Exception {
   File dir = getTempDir();
   File file = new File(dir, "test.ks");
   Properties p = initProps();
   p.put(KeyStoreUtil.PROP_KEYSTORE_FILE, file.toString());
   p.put(KeyStoreUtil.PROP_KEYSTORE_TYPE, "JKS");
   p.put(KeyStoreUtil.PROP_KEYSTORE_PROVIDER, "not_a_provider");
   assertFalse(file.exists());
   try {
     KeyStoreUtil.createKeyStore(p);
     fail("Illegal keystore type should throw");
   } catch (NoSuchProviderException e) {
   }
   assertFalse(file.exists());
 }
Esempio n. 28
0
  private void updateLinuxServiceInstaller() {
    try {
      File dir = new File(directory, "CTP");
      if (suppressFirstPathElement) dir = dir.getParentFile();
      Properties props = new Properties();
      String ctpHome = dir.getAbsolutePath();
      cp.appendln(Color.black, "...CTP_HOME: " + ctpHome);
      ctpHome = ctpHome.replaceAll("\\\\", "\\\\\\\\");
      props.put("CTP_HOME", ctpHome);
      File javaHome = new File(System.getProperty("java.home"));
      String javaBin = (new File(javaHome, "bin")).getAbsolutePath();
      cp.appendln(Color.black, "...JAVA_BIN: " + javaBin);
      javaBin = javaBin.replaceAll("\\\\", "\\\\\\\\");
      props.put("JAVA_BIN", javaBin);

      File linux = new File(dir, "linux");
      File install = new File(linux, "ctpService-ubuntu.sh");
      cp.appendln(Color.black, "Linux service installer:");
      cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
      String bat = getFileText(install);
      bat = replace(bat, props); // do the substitutions
      bat = bat.replace("\r", "");
      setFileText(install, bat);

      // If this is an ISN installation, put the script in the correct place.
      String osName = System.getProperty("os.name").toLowerCase();
      if (programName.equals("ISN") && !osName.contains("windows")) {
        install = new File(linux, "ctpService-red.sh");
        cp.appendln(Color.black, "ISN service installer:");
        cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
        bat = getFileText(install);
        bat = replace(bat, props); // do the substitutions
        bat = bat.replace("\r", "");
        File initDir = new File("/etc/init.d");
        File initFile = new File(initDir, "ctpService");
        if (initDir.exists()) {
          setOwnership(initDir, "edge", "edge");
          setFileText(initFile, bat);
          initFile.setReadable(true, false); // everybody can read //Java 1.6
          initFile.setWritable(true); // only the owner can write //Java 1.6
          initFile.setExecutable(true, false); // everybody can execute //Java 1.6
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println("Unable to update the Linux service ctpService.sh file");
    }
  }
Esempio n. 29
0
 public Bean(String classPackage, String clazz, ClassLoaderStrategy cls, Bean topLevelBean)
     throws Exception {
   // Get the no-arg constructor and create the bean
   try {
     Class classOfBean = ObjectXml.getClassOfBean((ClassLoader) cls, classPackage + "." + clazz);
     Constructor ct = null;
     // check whether this class is an inner class
     if (classOfBean.getEnclosingClass() != null) {
       ct = classOfBean.getConstructor(new Class[] {classOfBean.getEnclosingClass()});
       beanObject = ct.newInstance(new Object[] {topLevelBean.getBeanObject()});
     } else {
       ct = classOfBean.getConstructor((Class[]) null);
       beanObject = ct.newInstance((Object[]) null);
     }
     // Get an array of property descriptors
     beanInfo = Introspector.getBeanInfo(classOfBean);
     PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
     // load property descriptors into hashtable
     propDesc = new Properties();
     for (int i = 0; i < pds.length; i++) {
       propDesc.put(pds[i].getName(), pds[i]);
     }
   } catch (Exception e) {
     System.err.println("Exception creating bean: " + e.getMessage());
     e.printStackTrace();
     throw e;
   }
 }
Esempio n. 30
0
 public static Properties expandPropertyVars(Properties props) {
   // Create a new Properties with variables expanded
   Properties expanded = new Properties();
   for (String str : props.stringPropertyNames()) {
     String value = props.getProperty(str);
     Set<String> vars = new HashSet<String>();
     Matcher m = varPattern.matcher(value);
     while (m.find()) {
       vars.add(m.group(1));
     }
     String expandedValue = value;
     if (vars.size() > 0) {
       String[] expandedValues = new String[] {value};
       for (String var : vars) {
         String varValue = props.getProperty(var);
         String[] varValueExpanded = varValue.split("[,\\s]+");
         String[] unexpandedValues = expandedValues;
         expandedValues = new String[unexpandedValues.length * varValueExpanded.length];
         int i = 0;
         String replaceRegex = Pattern.quote("${" + var + "}");
         for (String v : varValueExpanded) {
           for (String ex : unexpandedValues) {
             expandedValues[i] = ex.replaceAll(replaceRegex, v);
             i++;
           }
         }
       }
       expandedValue = StringUtils.join(expandedValues, ",");
       System.err.println("Expanded property " + str + ": " + value + " to " + expandedValue);
     }
     expanded.put(str, expandedValue);
   }
   return expanded;
 }