List of usage examples for java.io File separator
String separator
To view the source code for java.io File separator.
Click Source Link
From source file:com.ibm.jaql.MiniCluster.java
/** * @param args/* w w w .j av a2 s. c o m*/ */ public static void main(String[] args) throws IOException { String clusterHome = System.getProperty("hadoop.minicluster.dir"); if (clusterHome == null) { clusterHome = "./minicluster"; System.setProperty("hadoop.minicluster.dir", clusterHome); } LOG.info("hadoop.minicluster.dir=" + clusterHome); File clusterFile = new File(clusterHome); if (!clusterFile.exists()) { clusterFile.mkdirs(); } if (!clusterFile.isDirectory()) { throw new IOException("minicluster home directory must be a directory: " + clusterHome); } if (!clusterFile.canRead() || !clusterFile.canWrite()) { throw new IOException("minicluster home directory must be readable and writable: " + clusterHome); } String logDir = System.getProperty("hadoop.log.dir"); if (logDir == null) { logDir = clusterHome + File.separator + "logs"; System.setProperty("hadoop.log.dir", logDir); } File logFile = new File(logDir); if (!logFile.exists()) { logFile.mkdirs(); } String confDir = System.getProperty("hadoop.conf.override"); if (confDir == null) { confDir = clusterHome + File.separator + "conf"; System.setProperty("hadoop.conf.override", confDir); } File confFile = new File(confDir); if (!confFile.exists()) { confFile.mkdirs(); } System.out.println("starting minicluster in " + clusterHome); MiniCluster mc = new MiniCluster(args); // To find the ports in the // hdfs: search for: Web-server up at: localhost:#### // mapred: search for: mapred.JobTracker: JobTracker webserver: #### Configuration conf = mc.getConf(); System.out.println("fs.default.name: " + conf.get("fs.default.name")); System.out.println("dfs.http.address: " + conf.get("dfs.http.address")); System.out.println("mapred.job.tracker.http.address: " + conf.get("mapred.job.tracker.http.address")); boolean waitForInterrupt; try { System.out.println("press enter to end minicluster (or eof to run forever)..."); waitForInterrupt = System.in.read() < 0; // wait for any input or eof } catch (Exception e) { // something odd happened. Just shutdown. LOG.error("error reading from stdin", e); waitForInterrupt = false; } // eof means that we will wait for a kill signal while (waitForInterrupt) { System.out.println("minicluster is running until interrupted..."); try { Thread.sleep(60 * 60 * 1000); } catch (InterruptedException e) { waitForInterrupt = false; } } System.out.println("shutting down minicluster..."); try { mc.tearDown(); } catch (Exception e) { LOG.error("error while shutting down minicluster", e); } }
From source file:com.adobe.aem.demomachine.Updates.java
public static void main(String[] args) { String rootFolder = null;//w w w . jav a 2s .c o m // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { rootFolder = cmd.getOptionValue("f"); } } catch (Exception e) { System.exit(-1); } Properties md5properties = new Properties(); try { URL url = new URL( "https://raw.githubusercontent.com/Adobe-Marketing-Cloud/aem-demo-machine/master/conf/checksums.properties"); InputStream in = url.openStream(); Reader reader = new InputStreamReader(in, "UTF-8"); md5properties.load(reader); reader.close(); } catch (Exception e) { System.out.println("Error: Cannot connect to GitHub.com to check for updates"); System.exit(-1); } System.out.println(AemDemoConstants.HR); int nbUpdateAvailable = 0; List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths); for (String[] path : listPaths) { if (path.length == 5) { logger.debug(path[1]); File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : "")); if (pathFolder.exists()) { String newMd5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false); logger.debug("MD5 is: " + newMd5); String oldMd5 = md5properties.getProperty("demo.md5." + path[0]); if (oldMd5 == null || oldMd5.length() == 0) { logger.error("Cannot find MD5 for " + path[0]); System.out.println(path[2] + " : Cannot find M5 checksum"); continue; } if (newMd5.equals(oldMd5)) { continue; } else { System.out.println(path[2] + " : New update available" + (path[0].equals("0") ? " (use 'git pull' to get the latest changes)" : "")); nbUpdateAvailable++; } } else { System.out.println(path[2] + " : Not installed"); } } } if (nbUpdateAvailable == 0) { System.out.println("Your AEM Demo Machine is up to date!"); } System.out.println(AemDemoConstants.HR); }
From source file:at.gv.egiz.pdfas.cli.test.SignaturProfileTest.java
public static void main(String[] args) { String user_home = System.getProperty("user.home"); String pdfas_dir = user_home + File.separator + ".pdfas"; PdfAs pdfas = PdfAsFactory.createPdfAs(new File(pdfas_dir)); try {/* w w w .j a va 2s . c om*/ Configuration config = pdfas.getConfiguration(); ISettings settings = (ISettings) config; List<String> signatureProfiles = new ArrayList<String>(); List<String> signaturePDFAProfiles = new ArrayList<String>(); Iterator<String> itKeys = settings.getFirstLevelKeys("sig_obj.types.").iterator(); while (itKeys.hasNext()) { String key = itKeys.next(); String profile = key.substring("sig_obj.types.".length()); System.out.println("[" + profile + "]: " + settings.getValue(key)); if (settings.getValue(key).equals("on")) { signatureProfiles.add(profile); if (profile.contains("PDFA")) { signaturePDFAProfiles.add(profile); } } } byte[] input = IOUtils.toByteArray(new FileInputStream(sourcePDF)); IPlainSigner signer = new PAdESSignerKeystore(KS_FILE, KS_ALIAS, KS_PASS, KS_KEY_PASS, KS_TYPE); Iterator<String> itProfiles = signatureProfiles.iterator(); while (itProfiles.hasNext()) { String profile = itProfiles.next(); System.out.println("Testing " + profile); DataSource source = new ByteArrayDataSource(input); FileOutputStream fos = new FileOutputStream(targetFolder + profile + ".pdf"); SignParameter signParameter = PdfAsFactory.createSignParameter(config, source, fos); signParameter.setPlainSigner(signer); signParameter.setSignatureProfileId(profile); SignResult result = pdfas.sign(signParameter); fos.close(); } byte[] inputPDFA = IOUtils.toByteArray(new FileInputStream(sourcePDFA)); Iterator<String> itPDFAProfiles = signaturePDFAProfiles.iterator(); while (itPDFAProfiles.hasNext()) { String profile = itPDFAProfiles.next(); System.out.println("Testing " + profile); DataSource source = new ByteArrayDataSource(inputPDFA); FileOutputStream fos = new FileOutputStream(targetFolder + "PDFA_" + profile + ".pdf"); SignParameter signParameter = PdfAsFactory.createSignParameter(config, source, fos); signParameter.setPlainSigner(signer); signParameter.setSignatureProfileId(profile); SignResult result = pdfas.sign(signParameter); fos.close(); } } catch (Throwable e) { e.printStackTrace(); } }
From source file:com.sishuok.es.generate.Generate.java
public static void main(String[] args) throws Exception { // ========== ?? ==================== // ??????/*from www . j a v a 2s . c o m*/ // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className} // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4? String packageName = "com.sishuok.es"; String sysName = "sys"; // ??sys?showcase?maintain?personal?shop String moduleName = "xxs"; // ???? String tableName = "sys_xxs_attribute"; // user String className = "XxsAttribute"; // ??User String permissionName = "sys:xxsAttribute";//?????????? String folderName = "xxs";//?? String classAuthor = "xxs"; // ThinkGem String functionName = "??????"; // ?? // ??? //Boolean isEnable = false; Boolean isEnable = true; // ========== ?? ==================== if (!isEnable) { logger.error("????isEnable = true"); return; } if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className) || StringUtils.isBlank(functionName)) { logger.error("??????????????"); return; } // ? String separator = File.separator; // ? File projectPath = new DefaultResourceLoader().getResource("").getFile(); while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) { projectPath = projectPath.getParentFile(); } logger.info("Project Path: {}", projectPath); // ? String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/sishuok/es/generate/template", "/", separator); logger.info("Template Path: {}", tplPath); // Java String javaPath = StringUtils.replaceEach( projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." }, new String[] { separator, separator }); logger.info("Java Path: {}", javaPath); // String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/jsp/admin", "/", separator); logger.info("View Path: {}", viewPath); // ??? Configuration cfg = new Configuration(); cfg.setDefaultEncoding("UTF-8"); cfg.setDirectoryForTemplateLoading(new File(tplPath)); // ??? Map<String, String> model = Maps.newHashMap(); model.put("packageName", StringUtils.lowerCase(packageName)); // model.put("sysName", StringUtils.lowerCase(sysName)); //??? model.put("moduleName", StringUtils.lowerCase(moduleName)); //??? model.put("tableName", StringUtils.lowerCase(tableName)); // model.put("className", StringUtils.uncapitalize(className)); //??? model.put("permissionName", permissionName); //???? model.put("ClassName", StringUtils.capitalize(className)); //?? model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools"); // model.put("classVersion", DateUtils.getDate()); // model.put("functionName", functionName); //??? model.put("folderName", folderName); //?? model.put("urlPrefix", model.get("moduleName") + "_" + model.get("className")); //jsp?? model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+ model.get("urlPrefix")); model.put("permissionPrefix", model.get("sysName") + ":" + model.get("moduleName")); //?? // ? Entity Template template = cfg.getTemplate("entity.ftl"); String content = FreeMarkers.renderTemplate(template, model); String filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "entity" + separator + model.get("ClassName") + ".java"; System.out.println("Entity filePath" + filePath); writeFile(content, filePath); logger.info("Entity: {}", filePath); // ? Repository template = cfg.getTemplate("repository.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "repository" + separator + separator + model.get("ClassName") + "Repository.java"; System.out.println("repository filePath" + filePath); writeFile(content, filePath); logger.info("Dao: {}", filePath); // ? Service template = cfg.getTemplate("service.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "service" + separator + separator + model.get("ClassName") + "Service.java"; System.out.println("Service filePath" + filePath); writeFile(content, filePath); logger.info("Service: {}", filePath); // ? ??Controller template = cfg.getTemplate("frontController.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "web" + separator + "controller" + separator + "front" + separator + model.get("ClassName") + "Controller.java"; System.out.println("Controller filePath" + filePath); writeFile(content, filePath); logger.info("Controller: {}", filePath); // ? ??Controller template = cfg.getTemplate("adminController.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "web" + separator + "controller" + separator + "admin" + separator + model.get("ClassName") + "Controller.java"; System.out.println("Controller filePath" + filePath); writeFile(content, filePath); logger.info("Controller: {}", filePath); // ? editForm template = cfg.getTemplate("editForm.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator + "editForm.jsp"; System.out.println("---------------------------------------------------"); System.out.println("ViewForm filePath" + filePath); writeFile(content, filePath); logger.info("ViewForm: {}", filePath); // ? list template = cfg.getTemplate("list.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator + "list.jsp"; writeFile(content, filePath); System.out.println("ViewListfilePath" + filePath); logger.info("ViewList: {}", filePath); // ? searcheForm template = cfg.getTemplate("searchForm.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator + "searchForm.jsp"; writeFile(content, filePath); System.out.println("searcheForm filePath" + filePath); logger.info("ViewList: {}", filePath); // ? listTable template = cfg.getTemplate("listTable.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator + "listTable.jsp"; writeFile(content, filePath); System.out.println("listTable filePath" + filePath); logger.info("ViewList: {}", filePath); logger.info("Generate Success."); }
From source file:de.uzk.hki.da.main.SIPBuilder.java
public static void main(String[] args) { TTCCLayout layout = new TTCCLayout(); layout.setDateFormat("yyyy'-'MM'-'dd' 'HH':'mm':'ss"); layout.setThreadPrinting(false);/*from w w w .j ava 2 s. c om*/ ConsoleAppender consoleAppender = new ConsoleAppender(layout); logger.addAppender(consoleAppender); logger.setLevel(Level.DEBUG); properties = new Properties(); try { properties.load(new InputStreamReader( (ClassLoader.getSystemResourceAsStream("configuration/config.properties")))); } catch (FileNotFoundException e1) { System.exit(Feedback.GUI_ERROR.toInt()); } catch (IOException e2) { System.exit(Feedback.GUI_ERROR.toInt()); } try { if (SystemUtils.IS_OS_WINDOWS) System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "CP850")); else System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "UTF-8")); } catch (UnsupportedEncodingException e) { return; } String mainFolderPath = SIPBuilder.class.getProtectionDomain().getCodeSource().getLocation().getPath(); String confFolderPath, dataFolderPath; try { mainFolderPath = URLDecoder.decode(mainFolderPath, "UTF-8"); confFolderPath = new File(mainFolderPath).getParent() + File.separator + "conf"; dataFolderPath = new File(mainFolderPath).getParent() + File.separator + "data"; } catch (UnsupportedEncodingException e) { confFolderPath = "conf"; dataFolderPath = "data"; } System.out.println("ConfFolderPath:" + confFolderPath); if (args.length == 0) startGUIMode(confFolderPath, dataFolderPath); else startCLIMode(confFolderPath, dataFolderPath, args); }
From source file:DruidThroughput.java
@SuppressWarnings("InfiniteLoopStatement") public static void main(String[] args) throws Exception { final int numQueries = QUERIES.length; final Random random = new Random(RANDOM_SEED); final AtomicInteger counter = new AtomicInteger(0); final AtomicLong totalResponseTime = new AtomicLong(0L); final ExecutorService executorService = Executors.newFixedThreadPool(NUM_CLIENTS); for (int i = 0; i < NUM_CLIENTS; i++) { executorService.submit(new Runnable() { @Override/*from w w w . ja va 2 s .co m*/ public void run() { try (CloseableHttpClient client = HttpClients.createDefault()) { HttpPost post = new HttpPost("http://localhost:8082/druid/v2/?pretty"); post.addHeader("content-type", "application/json"); CloseableHttpResponse res; while (true) { try (BufferedReader reader = new BufferedReader(new FileReader( QUERY_FILE_DIR + File.separator + random.nextInt(numQueries) + ".json"))) { int length = reader.read(BUFFER); post.setEntity(new StringEntity(new String(BUFFER, 0, length))); } long start = System.currentTimeMillis(); res = client.execute(post); res.close(); counter.getAndIncrement(); totalResponseTime.getAndAdd(System.currentTimeMillis() - start); } } catch (IOException e) { e.printStackTrace(); } } }); } long startTime = System.currentTimeMillis(); while (true) { Thread.sleep(REPORT_INTERVAL_MILLIS); double timePassedSeconds = ((double) (System.currentTimeMillis() - startTime)) / MILLIS_PER_SECOND; int count = counter.get(); double avgResponseTime = ((double) totalResponseTime.get()) / count; System.out.println("Time Passed: " + timePassedSeconds + "s, Query Executed: " + count + ", QPS: " + count / timePassedSeconds + ", Avg Response Time: " + avgResponseTime + "ms"); } }
From source file:com.sccl.attech.generate.Generate.java
/** * The main method.//w w w.j av a 2s. c o m * * @param args the arguments * @throws Exception the exception */ public static void main(String[] args) throws Exception { // ========== ?? ====================1412914 // ?????? // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className} // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4? String packageName = "com.sccl.attech.modules"; String moduleName = "mobil"; // ???sys String subModuleName = ""; // ????? String className = "updateApp"; // ??user List<GenerateField> fields = Lists.newArrayList(); fields.add(new GenerateField("name", "??")); fields.add(new GenerateField("type", "")); fields.add(new GenerateField("version", "")); fields.add(new GenerateField("path", "")); String classAuthor = "zzz"; // zhaozz String functionName = "App?"; // ?? // ??? //Boolean isEnable = false; Boolean isEnable = true; // ========== ?? ==================== if (!isEnable) { logger.error("????isEnable = true"); return; } if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className) || StringUtils.isBlank(functionName)) { logger.error("??????????????"); return; } // ? String separator = File.separator; // ? File projectPath = new DefaultResourceLoader().getResource("").getFile(); while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) { projectPath = projectPath.getParentFile(); } logger.info("Project Path: {}", projectPath); // ? String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/sccl/attech/generate/template", "/", separator); logger.info("Template Path: {}", tplPath); // Java String javaPath = StringUtils.replaceEach( projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." }, new String[] { separator, separator }); logger.info("Java Path: {}", javaPath); // String viewPath = StringUtils.replace(projectPath + "/WebRoot/pages", "/", separator); logger.info("View Path: {}", viewPath); String resPath = StringUtils.replace(projectPath + "/WebRoot/assets/js", "/", separator); logger.info("Res Path: {}", resPath); // ??? Configuration cfg = new Configuration(); cfg.setDefaultEncoding("UTF-8"); cfg.setDirectoryForTemplateLoading(new File(tplPath)); // ??? Map<String, Object> model = Maps.newHashMap(); model.put("packageName", StringUtils.lowerCase(packageName)); model.put("moduleName", StringUtils.lowerCase(moduleName)); model.put("fields", fields); model.put("subModuleName", StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : ""); model.put("className", StringUtils.uncapitalize(className)); model.put("ClassName", StringUtils.capitalize(className)); model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools"); model.put("classVersion", DateUtils.getDate()); model.put("functionName", functionName); model.put("tableName", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "") + "_" + model.get("className")); model.put("urlPrefix", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "") + "/" + model.get("className")); model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+ model.get("urlPrefix")); model.put("permissionPrefix", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "") + ":" + model.get("className")); // ? Entity Template template = cfg.getTemplate("entity.ftl"); String content = FreeMarkers.renderTemplate(template, model); String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java"; writeFile(content, filePath); logger.info("Entity: {}", filePath); // ? Dao template = cfg.getTemplate("dao.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Dao.java"; writeFile(content, filePath); logger.info("Dao: {}", filePath); // ? Service template = cfg.getTemplate("service.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Service.java"; writeFile(content, filePath); logger.info("Service: {}", filePath); // ? Controller createJavaFile(subModuleName, separator, javaPath, cfg, model); // ? ViewForm template = cfg.getTemplate("viewForm.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "Form.html"; writeFile(content, filePath); logger.info("ViewForm: {}", filePath); // ? ViewFormJs template = cfg.getTemplate("viewFormJs.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = resPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "FormCtrl.js"; writeFile(content, filePath); logger.info("ViewFormJs: {}", filePath); // ? ViewList template = cfg.getTemplate("viewList.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "List.html"; writeFile(content, filePath); logger.info("ViewList: {}", filePath); // ? ViewListJs template = cfg.getTemplate("viewListJs.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = resPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "ListCtrl.js"; writeFile(content, filePath); logger.info("ViewList: {}", filePath); // ? ??sql template = cfg.getTemplate("sql.ftl"); model.put("uid", IdGen.uuid()); model.put("uid1", IdGen.uuid()); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + ".sql"; writeFile(content, filePath); logger.info("ViewList: {}", filePath); logger.info("Generate Success."); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxMySqlLoaderCLI.CFAsteriskSaxMySqlLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxMySqlLoaderCLI.main() "; initConsoleLog();//w w w . j av a 2 s . co m int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskmysqlrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(3306); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("root"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskMySqlSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxMySqlLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxDb2LUWLoaderCLI.CFAsteriskSaxDb2LUWLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxDb2LUWLoaderCLI.main() "; initConsoleLog();//from ww w .j a v a 2s. co m int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskdb2luwrc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("127.0.0.1"); cFAsteriskConfig.setDbPort(5432); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("luw"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskDb2LUWSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxDb2LUWLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSaxSybaseLoaderCLI.CFAsteriskSaxSybaseLoaderCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSaxSybaseLoaderCLI.main() "; initConsoleLog();//from www . jav a2 s. c o m int numArgs = args.length; if (numArgs >= 2) { String homeDirName = System.getProperty("HOME"); if (homeDirName == null) { homeDirName = System.getProperty("user.home"); if (homeDirName == null) { log.message(S_ProcName + "ERROR: Home directory not set"); return; } } File homeDir = new File(homeDirName); if (!homeDir.exists()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" does not exist"); return; } if (!homeDir.isDirectory()) { log.message(S_ProcName + "ERROR: Home directory \"" + homeDirName + "\" is not a directory"); return; } CFAsteriskConfigurationFile cFAsteriskConfig = new CFAsteriskConfigurationFile(); String cFAsteriskConfigFileName = homeDir.getPath() + File.separator + ".cfasterisksybaserc"; cFAsteriskConfig.setFileName(cFAsteriskConfigFileName); File cFAsteriskConfigFile = new File(cFAsteriskConfigFileName); if (!cFAsteriskConfigFile.exists()) { cFAsteriskConfig.setDbServer("localhost"); cFAsteriskConfig.setDbPort(2345); cFAsteriskConfig.setDbDatabase("CFAst24"); cFAsteriskConfig.setDbUserName("sa"); cFAsteriskConfig.setDbPassword("edit-me-please"); cFAsteriskConfig.save(); log.message(S_ProcName + "INFO: Created configuration file " + cFAsteriskConfigFileName + ", please edit configuration and restart."); return; } if (!cFAsteriskConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed configuration file " + cFAsteriskConfigFileName + " is not a file."); return; } if (!cFAsteriskConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read configuration file " + cFAsteriskConfigFileName); return; } cFAsteriskConfig.load(); boolean fastExit = false; CFAsteriskClientConfigurationFile cFDbTestClientConfig = new CFAsteriskClientConfigurationFile(); String cFDbTestClientConfigFileName = homeDir.getPath() + File.separator + ".cfdbtestclientrc"; cFDbTestClientConfig.setFileName(cFDbTestClientConfigFileName); File cFDbTestClientConfigFile = new File(cFDbTestClientConfigFileName); if (!cFDbTestClientConfigFile.exists()) { String cFDbTestKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFDbTestClientConfig.setKeyStore(cFDbTestKeyStoreFileName); InetAddress localHost; try { localHost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { localHost = null; } if (localHost == null) { log.message(S_ProcName + "ERROR: LocalHost is null"); return; } String hostName = localHost.getHostName(); if ((hostName == null) || (hostName.length() <= 0)) { log.message("ERROR: LocalHost.HostName is null or empty"); return; } String userName = System.getProperty("user.name"); if ((userName == null) || (userName.length() <= 0)) { log.message("ERROR: user.name is null or empty"); return; } String deviceName = hostName.replaceAll("[^\\w]", "_").toLowerCase() + "-" + userName.replaceAll("[^\\w]", "_").toLowerCase(); cFDbTestClientConfig.setDeviceName(deviceName); cFDbTestClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } if (!cFDbTestClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFDbTestClientConfigFileName + " is not a file."); fastExit = true; } if (!cFDbTestClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFDbTestClientConfigFileName); fastExit = true; } cFDbTestClientConfig.load(); if (fastExit) { return; } // Configure logging Properties sysProps = System.getProperties(); sysProps.setProperty("log4j.rootCategory", "WARN"); sysProps.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); Logger httpLogger = Logger.getLogger("org.apache.http"); httpLogger.setLevel(Level.WARN); ICFAsteriskSchema cFAsteriskSchema = new CFAsteriskSybaseSchema(); cFAsteriskSchema.setConfigurationFile(cFAsteriskConfig); ICFAsteriskSchemaObj cFAsteriskSchemaObj = new CFAsteriskSchemaObj(); cFAsteriskSchemaObj.setBackingStore(cFAsteriskSchema); CFAsteriskSaxLoaderCLI cli = new CFAsteriskSaxSybaseLoaderCLI(); CFAsteriskSaxLoader loader = cli.getSaxLoader(); loader.setSchemaObj(cFAsteriskSchemaObj); cFAsteriskSchema.connect(); String url = args[1]; if (numArgs >= 5) { cli.setClusterName(args[2]); cli.setTenantName(args[3]); cli.setSecUserName(args[4]); } else { cli.setClusterName("default"); cli.setTenantName("system"); cli.setSecUserName("system"); } loader.setUseCluster(cli.getClusterObj()); loader.setUseTenant(cli.getTenantObj()); try { cFAsteriskSchema.beginTransaction(); cFAsteriskSchemaObj.setSecCluster(cli.getClusterObj()); cFAsteriskSchemaObj.setSecTenant(cli.getTenantObj()); cFAsteriskSchemaObj.setSecUser(cli.getSecUserObj()); cFAsteriskSchemaObj.setSecSession(cli.getSecSessionObj()); CFSecurityAuthorization auth = new CFSecurityAuthorization(); auth.setSecCluster(cFAsteriskSchemaObj.getSecCluster()); auth.setSecTenant(cFAsteriskSchemaObj.getSecTenant()); auth.setSecSession(cFAsteriskSchemaObj.getSecSession()); cFAsteriskSchemaObj.setAuthorization(auth); applyLoaderOptions(loader, args[0]); if (numArgs >= 5) { cli.evaluateRemainingArgs(args, 5); } else { cli.evaluateRemainingArgs(args, 2); } loader.parseFile(url); cFAsteriskSchema.commit(); cFAsteriskSchema.disconnect(true); } catch (Exception e) { log.message(S_ProcName + "EXCEPTION: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } catch (Error e) { log.message(S_ProcName + "ERROR: Could not parse XML file \"" + url + "\": " + e.getMessage()); e.printStackTrace(System.out); } finally { if (cFAsteriskSchema.isConnected()) { cFAsteriskSchema.rollback(); cFAsteriskSchema.disconnect(false); } } } else { log.message(S_ProcName + "ERROR: Expected at least two argument specifying the loader options and the name of the XML file to parse. The first argument may be empty."); } }