private Object getMySQLConnection() throws SQLException {
    String vcap_services = System.getenv("VCAP_SERVICES");

    String hostname = NULL_STRING;
    String dbname = NULL_STRING;
    String user = NULL_STRING;
    String password = NULL_STRING;
    String port = NULL_STRING;

    if (vcap_services != null && vcap_services.length() > 0) {
      try {
        JsonRootNode root = new JdomParser().parse(vcap_services);

        JsonNode mysqlNode = root.getNode("mysql-5.1");
        JsonNode credentials = mysqlNode.getNode(0).getNode("credentials");

        dbname = credentials.getStringValue("name");
        hostname = credentials.getStringValue("hostname");
        user = credentials.getStringValue("user");
        password = credentials.getStringValue("password");
        port = credentials.getNumberValue("port");

        String dbUrl = "jdbc:mysql://" + hostname + ":" + port + "/" + dbname;

        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection(dbUrl, user, password);
        return connection;
      } catch (Exception e) {
        throw new SQLException(e);
      }
    }

    return null;
  }
  public static WorldTemplateList func_110735_a(String par0Str) {
    WorldTemplateList worldtemplatelist = new WorldTemplateList();
    worldtemplatelist.field_110736_a = new ArrayList();

    try {
      JsonRootNode jsonrootnode = (new JdomParser()).parse(par0Str);

      if (jsonrootnode.isArrayNode(new Object[] {"templates"})) {
        Iterator iterator = jsonrootnode.getArrayNode(new Object[] {"templates"}).iterator();

        while (iterator.hasNext()) {
          JsonNode jsonnode = (JsonNode) iterator.next();
          worldtemplatelist.field_110736_a.add(WorldTemplate.func_110730_a(jsonnode));
        }
      }
    } catch (InvalidSyntaxException invalidsyntaxexception) {;
    } catch (IllegalArgumentException illegalargumentexception) {;
    }

    return worldtemplatelist;
  }
Example #3
0
  private void processJsonDataItems(
      List<EmployeePlan> employeePlans,
      List<EmployeeProjectPlan> employeeProjectPlans,
      JsonRootNode rootNode,
      Integer year,
      Integer month) {
    Integer employeeId;

    for (JsonNode jsonNode : rootNode.getArrayNode(JSON_DATA_ITEMS)) {
      employeeId = JsonUtil.getDecNumberValue(jsonNode, EMPLOYEE_ID);

      final Employee employee = employeeService.find(employeeId);

      addEmployeePlans(employeePlans, year, month, employee, jsonNode);

      addEmployeeProjectPlans(employeeProjectPlans, year, month, employee, jsonNode);
    }
  }
Example #4
0
 @Override
 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
   Path relativePath = rootPath.relativize(file);
   String downloadURL =
       urlBase + "/" + relativePath.toString().replace("\\", "/").replace(" ", "%20");
   InputStream is = Files.newInputStream(file);
   byte[] hash = DigestUtils.md5(is);
   String md5 = new String(Hex.encodeHex(hash));
   String name = file.getFileName().toString();
   String id;
   name = name.substring(0, name.length() - 4);
   id = name.replace(" ", "");
   String depends = "";
   Boolean required = true;
   Boolean inJar = false;
   Boolean extract = false;
   Boolean inRoot = false;
   Boolean isDefault = true;
   Boolean coreMod = false;
   System.out.println(relativePath.toString());
   if (relativePath.toString().contains(".DS_Store")) {
     return FileVisitResult.CONTINUE;
   }
   if (relativePath.toString().indexOf(sep) >= 0) {
     switch (relativePath.toString().substring(0, relativePath.toString().indexOf(sep))) {
         // Ignore these folders
       case "bin":
       case "lib":
       case "resources":
       case "saves":
       case "screenshots":
       case "stats":
       case "texturepacks":
       case "texturepacks-mp-cache":
         return FileVisitResult.CONTINUE;
         //
       case "instMods":
       case "jar":
         {
           inJar = true;
           break;
         }
       case "coremods":
         {
           coreMod = true;
           break;
         }
       case "config":
         {
           String newPath = relativePath.toString();
           if (sep.equals("\\")) {
             newPath = newPath.replace("\\", "/");
           }
           ConfigFile newConfig = new ConfigFile(downloadURL, newPath, false, md5);
           parent.AddConfig(new ConfigFileWrapper("", newConfig));
           return FileVisitResult.CONTINUE;
         }
       default:
     }
   }
   try {
     ZipFile zf = new ZipFile(file.toFile());
     System.out.println(zf.size() + " entries in file.");
     JdomParser parser = new JdomParser();
     JsonRootNode modInfo =
         parser.parse(new InputStreamReader(zf.getInputStream(zf.getEntry("mcmod.info"))));
     JsonNode subnode;
     if (modInfo.hasElements()) {
       subnode = modInfo.getElements().get(0);
     } else {
       subnode = modInfo.getNode("modlist").getElements().get(0);
     }
     id = subnode.getStringValue("modid");
     name = subnode.getStringValue("name");
     zf.close();
   } catch (NullPointerException e) {
   } catch (ZipException e) {
     System.out.println("Not an archive.");
   } catch (IOException e) {
     e.printStackTrace();
   } catch (InvalidSyntaxException e) {
     e.printStackTrace();
   } finally {
     Module newMod =
         new Module(
             name,
             id,
             downloadURL,
             depends,
             required,
             inJar,
             0,
             true,
             extract,
             inRoot,
             isDefault,
             coreMod,
             md5,
             null,
             "both",
             null);
     parent.AddModule(newMod);
   }
   return FileVisitResult.CONTINUE;
 }