예제 #1
0
 /**
  * Get a connection to MySQL database named in madaap.xml file
  *
  * @return
  */
 static Connection getMySQLconnection() {
   Connection mysqlconn = null;
   try {
     Class.forName("com.mysql.jdbc.Driver").newInstance();
   } catch (Exception e) {
     System.out.println(e.getMessage() + "\nCannot register MySQL to DriverManager");
   }
   try {
     XMLConfiguration config = new XMLConfiguration("config/madaap.xml");
     Properties connectionProp = new Properties();
     System.out.println(config.getString("database.username"));
     connectionProp.put("user", config.getString("database.username"));
     connectionProp.put("password", config.getString("database.password"));
     mysqlconn =
         DriverManager.getConnection(
             "jdbc:mysql"
                 + "://"
                 + config.getString("database.url")
                 + ":"
                 + config.getString("database.port")
                 + "/madaap",
             connectionProp);
   } catch (SQLException e) {
     System.out.println(e.getMessage() + "\nCannot connect to MySQL. Check if MySQL is running.");
     System.exit(0);
   } catch (ConfigurationException e) {
     e.printStackTrace();
   }
   System.out.println("Connection made to MySQL");
   return mysqlconn;
 }
  @Test
  public void testDownloadPeopleJdo() {

    ClientFactory cf = null;
    try {
      cf = new ClientFactory(new File(configfilepath));
    } catch (ConfigurationException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (cf == null) {
      fail("no client factory");
    }

    String kind = "PeopleJdo";
    EntityStat es = cf.getAppEngineUtils().getStat(kind);
    long offset = 0;
    int limit = 10;
    Long finish = 100l;
    Long total = es.getCount();

    // download 100 of
    DownloadKind dk = new DownloadKind(cf);
    dk.setLimit(offset, limit, finish, total);
    dk.setKind(kind);
    dk.run();

    System.out.println("finished test");
  }
예제 #3
0
  public static void main(String[] args) {
    try {
      String corpusFile = args[0];
      String goldSet = args[1];
      File outputDir = new File(args[2]);

      SystemConfig systemConfig = DriverUtils.configure(args);
      systemConfig.setAnnotationSetName(Constants.GS_NP, goldSet);

      Trainer trainer = new Trainer(systemConfig);
      FeatureGenerator featureGenerator = new FeatureGenerator(systemConfig);

      // get corpus
      Corpus c = DriverUtils.loadFiles(corpusFile);

      Preprocessor preprocessor = new Preprocessor(systemConfig);
      preprocessor.preprocess(c, false);

      // generate features
      String featureSetName = featureGenerator.generateFeatures(c, true);

      // train classifier
      Classifier classifier = trainer.runLearner(c, outputDir, featureSetName);
      System.out.println("classifier trained: " + classifier.getName());

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ConfigurationException e) {
      e.printStackTrace();
    }
  }
예제 #4
0
파일: TestSetup.java 프로젝트: dzzh/in4150
  public void init() {

    // read network configuration
    Configuration config = null;
    try {
      config = new PropertiesConfiguration("network.cfg");
    } catch (ConfigurationException e) {
      e.printStackTrace();
    }

    urls = config.getStringArray("node.url");
    processes = new ArrayList<DA_Schiper_Eggli_Sandoz_RMI>();

    // locate processes
    for (String url : urls) {
      try {
        DA_Schiper_Eggli_Sandoz_RMI process = (DA_Schiper_Eggli_Sandoz_RMI) Naming.lookup(url);
        process.reset();
        processes.add(process);

      } catch (RemoteException e1) {
        e1.printStackTrace();
      } catch (NotBoundException e2) {
        e2.printStackTrace();
      } catch (MalformedURLException e3) {
        e3.printStackTrace();
      }
    }
  }
예제 #5
0
파일: AssetTag.java 프로젝트: tauren/zipper
  static {
    try {
      _configuration = new PropertiesConfiguration("zipper.properties");

    } catch (ConfigurationException e) {
      e.printStackTrace();
    }
  }
예제 #6
0
  public void loadConfig(String file) {
    try {
      xml = new XMLConfiguration();
      xml.load(file);

    } catch (ConfigurationException cex) {
      cex.printStackTrace();
      System.exit(1);
    }
  }
예제 #7
0
  public void write(String filename) {
    if (!filename.endsWith(".xml")) filename += ".xml";
    log.info("write vrp: " + filename);
    XMLConf xmlConfig = new XMLConf();
    xmlConfig.setFileName(filename);
    xmlConfig.setRootElementName("problem");
    xmlConfig.setAttributeSplittingDisabled(true);
    xmlConfig.setDelimiterParsingDisabled(true);

    writeProblemType(xmlConfig);
    writeVehiclesAndTheirTypes(xmlConfig);

    // might be sorted?
    List<Job> jobs = new ArrayList<Job>();
    jobs.addAll(vrp.getJobs().values());
    for (VehicleRoute r : vrp.getInitialVehicleRoutes()) {
      jobs.addAll(r.getTourActivities().getJobs());
    }

    writeServices(xmlConfig, jobs);
    writeShipments(xmlConfig, jobs);

    writeInitialRoutes(xmlConfig);
    writeSolutions(xmlConfig);

    OutputFormat format = new OutputFormat();
    format.setIndenting(true);
    format.setIndent(5);

    try {
      Document document = xmlConfig.createDoc();

      Element element = document.getDocumentElement();
      element.setAttribute("xmlns", "http://www.w3schools.com");
      element.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
      element.setAttribute("xsi:schemaLocation", "http://www.w3schools.com vrp_xml_schema.xsd");

    } catch (ConfigurationException e) {
      logger.error("Exception:", e);
      e.printStackTrace();
      System.exit(1);
    }

    try {
      Writer out = new FileWriter(filename);
      XMLSerializer serializer = new XMLSerializer(out, format);
      serializer.serialize(xmlConfig.getDocument());
      out.close();
    } catch (IOException e) {
      logger.error("Exception:", e);
      e.printStackTrace();
      System.exit(1);
    }
  }
예제 #8
0
  public static GitRepositoryState getGitRepositoryState() {

    if (gitRepositoryState == null) {
      PropertiesConfiguration config;
      try {
        config = new PropertiesConfiguration("git.properties");
        gitRepositoryState = new GitRepositoryState(config);
      } catch (ConfigurationException e) {
        e.printStackTrace();
      }
    }
    return gitRepositoryState;
  }
예제 #9
0
  // Saves the settings to config file.
  public static void saveSettings(Settings settings) {
    config.setProperty("vlclocation", settings.getVlcLocation());
    config.setProperty("thumbnailcount", settings.getThumbnailCount());
    config.setProperty("thumbnailwidth", settings.getThumbnailWidth());
    config.setProperty("thumbnailhighlightcolor", settings.getThumbnailHighlightColor());
    config.setProperty("folders", String.join("|", settings.getFolders()));

    try {
      config.save("vidor.config");
    } catch (ConfigurationException ex) {
      ex.printStackTrace();
    }
  }
예제 #10
0
 @Test
 public void testConfigObject() throws JSONException {
   ProjectConfig cp = ProjectConfig.getInstance().init();
   cp.setProperties("aaaa", RoundingMode.HALF_EVEN);
   try {
     cp.save();
   } catch (ConfigurationException e) {
     e.printStackTrace();
   }
   Object property = cp.getReadOnlyConfiguration().getProperty("aaaa");
   System.out.println(
       property + ": instanceof of RoundingMode:" + (property instanceof RoundingMode));
   System.out.println(JSONUtil.serialize(cp.getReadOnlyConfiguration()));
 }
예제 #11
0
  private BaiduDriver() {
    Configuration config = null;
    try {
      config = new XMLConfiguration(BaiduDriver.class.getClassLoader().getResource("Cloud.xml"));
    } catch (ConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    this.ACCESS_KEY_ID = config.getString("Baidu.ACCESS_KEY_ID");
    this.SECRET_ACCESS_KEY = config.getString("Baidu.SECRET_ACCESS_KEY");

    BosClientConfiguration bosconfig = new BosClientConfiguration();
    bosconfig.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
    baiduClient = new BosClient(bosconfig);
  }
예제 #12
0
  public void read(String filename) {
    logger.info("read vrp from file " + filename);
    XMLConfiguration xmlConfig = new XMLConfiguration();
    xmlConfig.setFileName(filename);
    xmlConfig.setAttributeSplittingDisabled(true);
    xmlConfig.setDelimiterParsingDisabled(true);

    if (schemaValidation) {
      final InputStream resource = Resource.getAsInputStream("vrp_xml_schema.xsd");
      if (resource != null) {
        EntityResolver resolver =
            new EntityResolver() {

              @Override
              public InputSource resolveEntity(String publicId, String systemId)
                  throws SAXException, IOException {
                {
                  InputSource is = new InputSource(resource);
                  return is;
                }
              }
            };
        xmlConfig.setEntityResolver(resolver);
        xmlConfig.setSchemaValidation(true);
        logger.info("validating " + filename + " with xsd-schema");
      } else {
        logger.warn(
            "cannot find schema-xsd file (vrp_xml_schema.xsd). try to read xml without xml-file-validation.");
      }
    }
    try {
      xmlConfig.load();
    } catch (ConfigurationException e) {
      logger.error(e);
      e.printStackTrace();
      System.exit(1);
    }
    readProblemType(xmlConfig);
    readVehiclesAndTheirTypes(xmlConfig);

    readShipments(xmlConfig);
    readServices(xmlConfig);

    readInitialRoutes(xmlConfig);
    readSolutions(xmlConfig);

    addJobsAndTheirLocationsToVrp();
  }
예제 #13
0
 static {
   if (config == null) {
     synchronized (ApiConf.class) {
       if (config == null)
         try {
           entity = new HashMap();
           config = new XMLConfiguration("entity.xml");
           String[] nrs = config.getStringArray("entities.entity.nr");
           String[] ids = config.getStringArray("entities.entity.id");
           for (int i = 0; i < nrs.length; i++) {
             entity.put(nrs[i], ids[i]);
           }
         } catch (ConfigurationException e) {
           e.printStackTrace();
         }
     }
   }
 }
예제 #14
0
  private TestData() {
    try {
      // Load the configuration file
      config = new PropertiesConfiguration("./config/config.properties");

      // Make sure the test data folder exists
      dataFolder = new File(config.getString("test.folder"));
      //            if (!dataFolder.exists())
      //                dataFolder.createNewFile();

    } catch (ConfigurationException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
      //        } catch (IOException e) {
      //            e.printStackTrace();  //To change body of catch statement use File | Settings |
      // File Templates.
    }
  }
예제 #15
0
  @Test
  public void testPropertiesConfiguration() {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    try {
      System.out.println(builder.getConfigurationBasePath());
      System.out.println(
          FileSystem.getDefaultFileSystem().getFileName("pss-settings.properties").toString());
      URL locate =
          ConfigurationUtils.locate(
              "E:/study/jelyworkspace/jelypss/pss-core/target/test-classes/conf",
              "pss-settings.properties");
      builder.load(locate);
      Configuration config = builder.getConfiguration();
      config.setProperty("1123", "asdf");

    } catch (ConfigurationException e) {
      e.printStackTrace();
    }
  }
예제 #16
0
  // Loads the settings from config file. If no values defined, the deafult values are returned.
  public static Settings loadSettings() {
    config.setListDelimiter('|');
    Settings s = new Settings();
    try {
      config.load("vidor.config");
    } catch (ConfigurationException ex) {
      ex.printStackTrace();
    }

    s.setVlcLocation(config.getString("vlclocation", ""));
    s.setThumbnailCount(config.getInt("thumbnailcount", 10));
    s.setThumbnailWidth(config.getInt("thumbnailwidth", 200));
    s.setThumbnailHighlightColor(config.getString("thumbnailhighlightcolor", ""));

    List<String> f = new ArrayList(Arrays.asList(config.getStringArray("folders")));
    if (!f.get(0).trim().isEmpty()) { // Bug fix - Empty folder check
      s.setFolders(f);
    }

    return s;
  }
예제 #17
0
  /**
   * @return the height of the camera stored at the ImageJ preferences.
   * @throws ConfigurationException
   */
  public static int getFullHeight() {
    EFTEMj_Configuration config;
    try {
      config = EFTEMj_ConfigurationManager.getConfiguration();

      int height = config.getInt(heightKey);
      if (height <= 0) {
        height =
            (int)
                IJ.getNumber(
                    "The height of the used camera is not saved. Please enter the height in Pixel:",
                    4096);
        config.setProperty(heightKey, height);
        config.save();
      }
      return height;
    } catch (ConfigurationException e) {
      e.printStackTrace();
    }
    return 1;
  }
예제 #18
0
 /**
  * @return the width of the camera stored at the ImageJ preferences.
  * @throws ConfigurationException
  */
 public static int getFullWidth() {
   EFTEMj_Configuration config;
   try {
     config = EFTEMj_ConfigurationManager.getConfiguration();
     int width = config.getInt(widthKey);
     if (width <= 0) {
       width =
           (int)
               IJ.getNumber(
                   "The width of the used camera is not saved. Please enter the width in Pixel:",
                   4096);
       config.setProperty(widthKey, width);
       config.save();
     }
     return width;
   } catch (ConfigurationException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return 1;
 }
예제 #19
0
 @Test
 public void testCompositeConfiguration() throws URISyntaxException {
   CompositeConfiguration configuration = new CompositeConfiguration();
   try {
     PropertiesConfiguration propertiesConfiguration =
         new PropertiesConfiguration("conf/pss-settings.properties");
     //
     //	propertiesConfiguration.setFileName("E:/study/jelyworkspace/jelypss/pss-core/target/test-classes/conf/pss-settings.properties");
     propertiesConfiguration.load(
         "E:/study/jelyworkspace/jelypss/pss-core/target/test-classes/conf/pss-settings.properties");
     configuration.addConfiguration(propertiesConfiguration);
     //			propertiesConfiguration.setProperty("haha", 1235);
     configuration.setProperty("asdf", "aaaaaaaaa");
     System.out.println(configuration.getInt("haha"));
     System.out.println(this.getClass().getClassLoader().getResource("").toURI().toString());
     System.out.println(this.getClass().getClassLoader().getResource("").toString());
     propertiesConfiguration.save();
   } catch (ConfigurationException e) {
     e.printStackTrace();
   }
 }
예제 #20
0
  public static void main(String... args) {
    if (args == null || args.length == 0) {
      System.out.println("Please provide the configuration file");
      return;
    }

    String filename = args[0];

    List<String> scenariosToRun = new ArrayList<String>();
    for (int i = 1; i < args.length; i++) {
      scenariosToRun.add(args[i]);
    }

    // load all scenarios from configuration file
    ConfigurationLoader configurationLoader = new ConfigurationLoader();
    Map<String, PostageConfiguration> configurations;
    try {
      // TODO allow different (non-xml) configs - as Common-Configuration supports it
      XMLConfiguration xmlConfiguration = new XMLConfiguration(filename);
      // xmlConfiguration.setThrowExceptionOnMissing(false);
      configurations = configurationLoader.create(xmlConfiguration);
    } catch (ConfigurationException e) {
      e.printStackTrace();
      return;
    }

    // register shutdown hook if this app is terminated from outside
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {
                shutdown();
              }
            });

    // run all scenarios
    runScenarios(configurations, scenariosToRun);
  }
  /** 静态读入属性文件到Properties p变量中. */
  protected static void init(String propertyFileName) {
    InputStream in = null;
    try {
      in = ConfigurableConstants.class.getClassLoader().getResourceAsStream(propertyFileName);
      if (in != null) {
        p.load(in);
        String path = p.getProperty("config_file");
        if ("".equals(StringUtils.trimToEmpty(path))) {
          // 引用当前文件
          URL url = ConfigurableConstants.class.getClassLoader().getResource(propertyFileName);
          path = url.getPath();
        }

        File f = new File(path);
        pc = new XMLConfiguration();
        pc.setDelimiterParsingDisabled(true);

        // 注册 修改生新加载
        pc.setReloadingStrategy(new FileChangedReloadingStrategy());

        pc.load(f);
      }
    } catch (IOException e) {
      logger.error("load " + propertyFileName + " into Constants error!");
    } catch (ConfigurationException e) {
      e.printStackTrace();
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {
          logger.error("close " + propertyFileName + " error!");
        }
      }
    }
  }
  protected void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {

    res.setContentType("text/html");
    try {
      if (config == null) {
        config = new PropertiesConfiguration("pnengine.properties");
      }
    } catch (ConfigurationException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    String postVariable = config.getString("pnengine.post_variable");
    String engineURL = config.getString("pnengine.url") + "/petrinets";
    String engineURL_host = config.getString("pnengine.url");
    String modelURL = config.getString("pnengine.default_model_url");
    String formURL = null;
    String bindingsURL = null;

    String rdf = req.getParameter("data");
    String diagramTitle = req.getParameter("title");

    DocumentBuilder builder;
    BPMNDiagram diagram;
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      builder = factory.newDocumentBuilder();
      Document document = builder.parse(new ByteArrayInputStream(rdf.getBytes()));
      BPMNRDFImporter importer = new BPMNRDFImporter(document);
      diagram = (BPMNDiagram) importer.loadBPMN();

      String basefilename = String.valueOf(System.currentTimeMillis());
      String tmpPNMLFile =
          this.getServletContext().getRealPath("/")
              + "tmp"
              + File.separator
              + basefilename
              + ".pnml";
      BufferedWriter out1 = new BufferedWriter(new FileWriter(tmpPNMLFile));

      // URL only for testing purposes...
      ExecConverter converter =
          new ExecConverter(diagram, modelURL, this.getServletContext().getRealPath("/"));
      converter.setBaseFileName(
          this.getServletContext().getRealPath("/") + "tmp" + File.separator + basefilename);
      PetriNet net = converter.convert();
      ExecPetriNet execnet = (ExecPetriNet) net;
      Document pnmlDoc = builder.newDocument();

      ExecPNPNMLExporter exp = new ExecPNPNMLExporter();
      execnet.setName(diagramTitle);
      exp.savePetriNet(pnmlDoc, execnet);

      OutputFormat format = new OutputFormat(pnmlDoc);
      XMLSerializer serial = new XMLSerializer(out1, format);
      serial.asDOMSerializer();
      serial.serialize(pnmlDoc.getDocumentElement());
      out1.close();

      StringWriter stringOut = new StringWriter();
      XMLSerializer serial2 = new XMLSerializer(stringOut, format);
      serial2.asDOMSerializer();

      serial2.serialize(pnmlDoc.getDocumentElement());

      URL url_engine = new URL(engineURL);
      HttpURLConnection connection_engine = (HttpURLConnection) url_engine.openConnection();
      connection_engine.setRequestMethod("POST");

      String encoding = new sun.misc.BASE64Encoder().encode("testuser:"******"Authorization", "Basic " + encoding);

      connection_engine.setUseCaches(false);
      connection_engine.setDoInput(true);
      connection_engine.setDoOutput(true);

      String escaped_content =
          postVariable + "=" + URLEncoder.encode(stringOut.toString(), "UTF-8");

      connection_engine.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      connection_engine.setRequestProperty(
          "Accept",
          "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");

      // connection_engine.setRequestProperty("Content-Length",
      // ""+escaped_content.getBytes().length);
      String errorMessage = null;
      try {
        connection_engine.getOutputStream().write(escaped_content.getBytes());
        connection_engine.connect();
      } catch (ConnectException e) {
        errorMessage = e.getMessage();
      }

      // output link address
      res.getWriter().print("tmp/" + basefilename + ".pnml" + "\">View PNML</a><br/><br/>");
      if (errorMessage == null && connection_engine.getResponseCode() == 200) {
        res.getWriter()
            .println(
                "Deployment to Engine <a href=\""
                    + engineURL_host
                    + "/worklist\" target=\"_blank\">"
                    + engineURL_host
                    + "</a><br/><b>successful</b>!");
      } else {
        res.getWriter()
            .println(
                "Deployment to Engine <a href=\""
                    + engineURL
                    + "\" target=\"_blank\">"
                    + engineURL
                    + "</a><br/><b>failed</b> with message: \n"
                    + errorMessage
                    + "!");
      }

    } catch (ParserConfigurationException e1) {
      res.getWriter().println(e1.getMessage());
    } catch (SAXException e1) {
      res.getWriter().println(e1.getMessage());
    }
  }