List of usage examples for java.lang String replaceAll
public String replaceAll(String regex, String replacement)
From source file:eu.interedition.collatex.http.Server.java
public static void main(String... args) { try {//from w w w . j av a 2 s . c o m final CommandLine commandLine = new GnuParser().parse(OPTIONS, args); if (commandLine.hasOption("h")) { new HelpFormatter().printHelp("collatex-server [<options> ...]\n", OPTIONS); return; } final Collator collator = new Collator(Integer.parseInt(commandLine.getOptionValue("mpc", "2")), Integer.parseInt(commandLine.getOptionValue("mcs", "0")), commandLine.getOptionValue("dot", null)); final String staticPath = System.getProperty("collatex.static.path", ""); final HttpHandler httpHandler = staticPath.isEmpty() ? new CLStaticHttpHandler(Server.class.getClassLoader(), "/static/") { @Override protected void onMissingResource(Request request, Response response) throws Exception { collator.service(request, response); } } : new StaticHttpHandler(staticPath.replaceAll("/+$", "") + "/") { @Override protected void onMissingResource(Request request, Response response) throws Exception { collator.service(request, response); } }; final NetworkListener httpListener = new NetworkListener("http", "0.0.0.0", Integer.parseInt(commandLine.getOptionValue("p", "7369"))); final CompressionConfig compressionConfig = httpListener.getCompressionConfig(); compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON); compressionConfig.setCompressionMinSize(860); // http://webmasters.stackexchange.com/questions/31750/what-is-recommended-minimum-object-size-for-gzip-performance-benefits compressionConfig.setCompressableMimeTypes("application/javascript", "application/json", "application/xml", "text/css", "text/html", "text/javascript", "text/plain", "text/xml"); final HttpServer httpServer = new HttpServer(); httpServer.addListener(httpListener); httpServer.getServerConfiguration().addHttpHandler(httpHandler, commandLine.getOptionValue("cp", "").replaceAll("/+$", "") + "/*"); Runtime.getRuntime().addShutdownHook(new Thread(() -> { if (LOG.isLoggable(Level.INFO)) { LOG.info("Stopping HTTP server"); } httpServer.shutdown(); })); httpServer.start(); Thread.sleep(Long.MAX_VALUE); } catch (Throwable t) { LOG.log(Level.SEVERE, "Error while parsing command line", t); System.exit(1); } }
From source file:com.googlecode.dex2jar.bin_gen.BinGen.java
/** * @param args/*w w w. j a v a 2 s. co m*/ * @throws IOException */ public static void main(String[] args) throws IOException { Properties p = new Properties(); p.load(BinGen.class.getResourceAsStream("class.cfg")); String bat = FileUtils.readFileToString( new File("src/main/resources/com/googlecode/dex2jar/bin_gen/bat_template"), "UTF-8"); String sh = FileUtils.readFileToString( new File("src/main/resources/com/googlecode/dex2jar/bin_gen/sh_template"), "UTF-8"); File binDir = new File("src/main/bin"); String setclasspath = FileUtils.readFileToString( new File("src/main/resources/com/googlecode/dex2jar/bin_gen/setclasspath.bat"), "UTF-8"); FileUtils.writeStringToFile(new File(binDir, "setclasspath.bat"), setclasspath, "UTF-8"); for (Object key : p.keySet()) { String name = key.toString(); FileUtils.writeStringToFile(new File(binDir, key.toString() + ".sh"), sh.replaceAll("__@class_name@__", p.getProperty(name)), "UTF-8"); FileUtils.writeStringToFile(new File(binDir, key.toString() + ".bat"), bat.replaceAll("__@class_name@__", p.getProperty(name)), "UTF-8"); } }
From source file:kendzi.kendzi3d.service.viewer.service.OverpassService.java
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, XPathExpressionException { String q = "<osm-script>" // + "<union>"// + "<query type=\"node\"> "// + " <bbox-query {{bbox}}/>"// + "</query>"// + "<query type=\"way\"> "// + " <bbox-query {{bbox}}/>"// + "</query>"// + "<query type=\"relation\"> "// + " <bbox-query {{bbox}}/>"// + "</query>"// + "</union>" // + " <print limit=\"\" mode=\"meta\" order=\"id\"/>" // + " </osm-script>"; q = q.replaceAll("\\{\\{bbox}}", " s=\"52.105892353376625\" w=\"15.670173168182371\" n=\"52.10792193310275\" e=\"15.675639510154724\" "); String xml = new OverpassService().findQuery(q); System.out.println(xml);/*from www . ja v a 2 s. c om*/ }
From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveSet.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0]; //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions String T = args[2];/* w w w .j av a 2s . c o m*/ String tCls = T; if (tCls.equals("byte[]")) { tCls = "BytesArray"; } String CLASS_NAME = tCls + "Set"; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString( new File(root.getAbsolutePath() + "/src/main/resources/PrimitiveSetTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#T#", T); program = program.replaceAll("#TCLS#", tCls); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:com.axiomine.largecollections.generator.GeneratorWritableSet.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0]; //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions String T = args[2];//w w w.j ava2s. c o m String tCls = T; if (tCls.equals("byte[]")) { tCls = "BytesArray"; } String CLASS_NAME = tCls + "Set"; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString( new File(root.getAbsolutePath() + "/src/main/resources/WritableSetTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#T#", T); program = program.replaceAll("#TCLS#", tCls); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveList.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0]; //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions String T = args[2];//from w w w .j a v a2s.c o m String tCls = T; if (tCls.equals("byte[]")) { tCls = "BytesArray"; } String CLASS_NAME = tCls + "List"; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString( new File(root.getAbsolutePath() + "/src/main/resources/PrimitiveListTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#T#", T); program = program.replaceAll("#TCLS#", tCls); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:com.axiomine.largecollections.generator.GeneratorWritableList.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0]; //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions String T = args[2];//from w w w . j a v a2 s . c om String tCls = T; if (tCls.equals("byte[]")) { tCls = "BytesArray"; } String CLASS_NAME = tCls + "List"; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString( new File(root.getAbsolutePath() + "/src/main/resources/WritableListTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#T#", T); program = program.replaceAll("#TCLS#", tCls); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:io.anserini.index.UpdateIndex.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(HELP_OPTION, "show help")); options.addOption(new Option(OPTIMIZE_OPTION, "merge indexes into a single segment")); options.addOption(new Option(STORE_TERM_VECTORS_OPTION, "store term vectors")); options.addOption(//from w ww .j a va 2s . com OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("file with deleted tweetids") .create(DELETES_OPTION)); options.addOption(OptionBuilder.withArgName("id").hasArg().withDescription("max id").create(MAX_ID_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (cmdline.hasOption(HELP_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(UpdateIndex.class.getName(), options); System.exit(-1); } String indexPath = cmdline.getOptionValue(INDEX_OPTION); final FieldType textOptions = new FieldType(); textOptions.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); textOptions.setStored(true); textOptions.setTokenized(true); textOptions.setStoreTermVectors(true); LOG.info("index: " + indexPath); File file = new File("PittsburghUserTimeline"); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } final StatusStream stream = new JsonStatusCorpusReader(file); Status status; String s; HashMap<Long, String> hm = new HashMap<Long, String>(); try { while ((s = stream.nextRaw()) != null) { try { status = DataObjectFactory.createStatus(s); if (status.getText() == null) { continue; } hm.put(status.getUser().getId(), hm.get(status.getUser().getId()) + status.getText().replaceAll("[\\r\\n]+", " ")); } catch (Exception e) { } } } catch (Exception e) { e.printStackTrace(); } finally { stream.close(); } ArrayList<String> userIDList = new ArrayList<String>(); try (BufferedReader br = new BufferedReader(new FileReader(new File("userID")))) { String line; while ((line = br.readLine()) != null) { userIDList.add(line.replaceAll("[\\r\\n]+", "")); // process the line. } } try { reader = DirectoryReader .open(FSDirectory.open(new File(cmdline.getOptionValue(INDEX_OPTION)).toPath())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } final Directory dir = new SimpleFSDirectory(Paths.get(cmdline.getOptionValue(INDEX_OPTION))); final IndexWriterConfig config = new IndexWriterConfig(ANALYZER); config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); final IndexWriter writer = new IndexWriter(dir, config); IndexSearcher searcher = new IndexSearcher(reader); System.out.println("The total number of docs indexed " + searcher.collectionStatistics(TweetStreamReader.StatusField.TEXT.name).docCount()); for (int city = 0; city < cityName.length; city++) { // Pittsburgh's coordinate -79.976389, 40.439722 Query q_long = NumericRangeQuery.newDoubleRange(TweetStreamReader.StatusField.LONGITUDE.name, new Double(longitude[city] - 0.05), new Double(longitude[city] + 0.05), true, true); Query q_lat = NumericRangeQuery.newDoubleRange(TweetStreamReader.StatusField.LATITUDE.name, new Double(latitude[city] - 0.05), new Double(latitude[city] + 0.05), true, true); BooleanQuery bqCityName = new BooleanQuery(); Term t = new Term("place", cityName[city]); TermQuery query = new TermQuery(t); bqCityName.add(query, BooleanClause.Occur.SHOULD); System.out.println(query.toString()); for (int i = 0; i < cityNameAlias[city].length; i++) { t = new Term("place", cityNameAlias[city][i]); query = new TermQuery(t); bqCityName.add(query, BooleanClause.Occur.SHOULD); System.out.println(query.toString()); } BooleanQuery bq = new BooleanQuery(); BooleanQuery finalQuery = new BooleanQuery(); // either a coordinate match bq.add(q_long, BooleanClause.Occur.MUST); bq.add(q_lat, BooleanClause.Occur.MUST); finalQuery.add(bq, BooleanClause.Occur.SHOULD); // or a place city name match finalQuery.add(bqCityName, BooleanClause.Occur.SHOULD); TotalHitCountCollector totalHitCollector = new TotalHitCountCollector(); // Query hasFieldQuery = new ConstantScoreQuery(new // FieldValueFilter("timeline")); // // searcher.search(hasFieldQuery, totalHitCollector); // // if (totalHitCollector.getTotalHits() > 0) { // TopScoreDocCollector collector = // TopScoreDocCollector.create(Math.max(0, // totalHitCollector.getTotalHits())); // searcher.search(finalQuery, collector); // ScoreDoc[] hits = collector.topDocs().scoreDocs; // // // HashMap<String, Integer> hasHit = new HashMap<String, Integer>(); // int dupcount = 0; // for (int i = 0; i < hits.length; ++i) { // int docId = hits[i].doc; // Document d; // // d = searcher.doc(docId); // // System.out.println(d.getFields()); // } // } // totalHitCollector = new TotalHitCountCollector(); searcher.search(finalQuery, totalHitCollector); if (totalHitCollector.getTotalHits() > 0) { TopScoreDocCollector collector = TopScoreDocCollector .create(Math.max(0, totalHitCollector.getTotalHits())); searcher.search(finalQuery, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; System.out.println("City " + cityName[city] + " " + collector.getTotalHits() + " hits."); HashMap<String, Integer> hasHit = new HashMap<String, Integer>(); int dupcount = 0; for (int i = 0; i < hits.length; ++i) { int docId = hits[i].doc; Document d; d = searcher.doc(docId); if (userIDList.contains(d.get(IndexTweets.StatusField.USER_ID.name)) && hm.containsKey(Long.parseLong(d.get(IndexTweets.StatusField.USER_ID.name)))) { // System.out.println("Has timeline field?" + (d.get("timeline") != null)); // System.out.println(reader.getDocCount("timeline")); // d.add(new Field("timeline", hm.get(Long.parseLong(d.get(IndexTweets.StatusField.USER_ID.name))), // textOptions)); System.out.println("Found a user hit"); BytesRefBuilder brb = new BytesRefBuilder(); NumericUtils.longToPrefixCodedBytes(Long.parseLong(d.get(IndexTweets.StatusField.ID.name)), 0, brb); Term term = new Term(IndexTweets.StatusField.ID.name, brb.get()); // System.out.println(reader.getDocCount("timeline")); Document d_new = new Document(); // for (IndexableField field : d.getFields()) { // d_new.add(field); // } // System.out.println(d_new.getFields()); d_new.add(new StringField("userBackground", d.get(IndexTweets.StatusField.USER_ID.name), Store.YES)); d_new.add(new Field("timeline", hm.get(Long.parseLong(d.get(IndexTweets.StatusField.USER_ID.name))), textOptions)); // System.out.println(d_new.get()); writer.addDocument(d_new); writer.commit(); // t = new Term("label", "why"); // TermQuery tqnew = new TermQuery(t); // // totalHitCollector = new TotalHitCountCollector(); // // searcher.search(tqnew, totalHitCollector); // // if (totalHitCollector.getTotalHits() > 0) { // collector = TopScoreDocCollector.create(Math.max(0, totalHitCollector.getTotalHits())); // searcher.search(tqnew, collector); // hits = collector.topDocs().scoreDocs; // // System.out.println("City " + cityName[city] + " " + collector.getTotalHits() + " hits."); // // for (int k = 0; k < hits.length; k++) { // docId = hits[k].doc; // d = searcher.doc(docId); // System.out.println(d.get(IndexTweets.StatusField.ID.name)); // System.out.println(d.get(IndexTweets.StatusField.PLACE.name)); // } // } // writer.deleteDocuments(term); // writer.commit(); // writer.addDocument(d); // writer.commit(); // System.out.println(reader.getDocCount("timeline")); // writer.updateDocument(term, d); // writer.commit(); } } } } reader.close(); writer.close(); }
From source file:ValidateLicenseHeaders.java
/** * ValidateLicenseHeaders jboss-src-root * //from www . j ava 2s . c o m * @param args */ public static void main(String[] args) throws Exception { if (args.length == 0 || args[0].startsWith("-h")) { log.info("Usage: ValidateLicenseHeaders [-addheader] jboss-src-root"); System.exit(1); } int rootArg = 0; if (args.length == 2) { if (args[0].startsWith("-add")) addDefaultHeader = true; else { log.severe("Uknown argument: " + args[0]); log.info("Usage: ValidateLicenseHeaders [-addheader] jboss-src-root"); System.exit(1); } rootArg = 1; } File jbossSrcRoot = new File(args[rootArg]); if (jbossSrcRoot.exists() == false) { log.info("Src root does not exist, check " + jbossSrcRoot.getAbsolutePath()); System.exit(1); } URL u = Thread.currentThread().getContextClassLoader() .getResource("META-INF/services/javax.xml.parsers.DocumentBuilderFactory"); System.err.println(u); // Load the valid copyright statements for the licenses File licenseInfo = new File(jbossSrcRoot, "varia/src/etc/license-info.xml"); if (licenseInfo.exists() == false) { log.severe("Failed to find the varia/src/etc/license-info.xml under the src root"); System.exit(1); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); Document doc = db.parse(licenseInfo); NodeList licenses = doc.getElementsByTagName("license"); for (int i = 0; i < licenses.getLength(); i++) { Element license = (Element) licenses.item(i); String key = license.getAttribute("id"); ArrayList headers = new ArrayList(); licenseHeaders.put(key, headers); NodeList copyrights = license.getElementsByTagName("terms-header"); for (int j = 0; j < copyrights.getLength(); j++) { Element copyright = (Element) copyrights.item(j); copyright.normalize(); String id = copyright.getAttribute("id"); // The id will be blank if there is no id attribute if (id.length() == 0) continue; String text = getElementContent(copyright); if (text == null) continue; // Replace all duplicate whitespace and '*' with a single space text = text.replaceAll("[\\s*]+", " "); if (text.length() == 1) continue; text = text.toLowerCase().trim(); // Replace any copyright date0-date1,date2 with copyright ... text = text.replaceAll(COPYRIGHT_REGEX, "..."); LicenseHeader lh = new LicenseHeader(id, text); headers.add(lh); } } log.fine(licenseHeaders.toString()); File[] files = jbossSrcRoot.listFiles(dotJavaFilter); log.info("Root files count: " + files.length); processSourceFiles(files, 0); log.info("Processed " + totalCount); log.info("Updated jboss headers: " + jbossCount); // Files with no headers details log.info("Files with no headers: " + noheaders.size()); FileWriter fw = new FileWriter("NoHeaders.txt"); for (Iterator iter = noheaders.iterator(); iter.hasNext();) { File f = (File) iter.next(); fw.write(f.getAbsolutePath()); fw.write('\n'); } fw.close(); // Files with unknown headers details log.info("Files with invalid headers: " + invalidheaders.size()); fw = new FileWriter("InvalidHeaders.txt"); for (Iterator iter = invalidheaders.iterator(); iter.hasNext();) { File f = (File) iter.next(); fw.write(f.getAbsolutePath()); fw.write('\n'); } fw.close(); // License usage summary log.info("Creating HeadersSummary.txt"); fw = new FileWriter("HeadersSummary.txt"); for (Iterator iter = licenseHeaders.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String key = (String) entry.getKey(); fw.write("+++ License type=" + key); fw.write('\n'); List list = (List) entry.getValue(); Iterator jiter = list.iterator(); while (jiter.hasNext()) { LicenseHeader lh = (LicenseHeader) jiter.next(); fw.write('\t'); fw.write(lh.id); fw.write(", count="); fw.write("" + lh.count); fw.write('\n'); } } fw.close(); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwingHttpCLI.CFAsteriskSwingHttpCLI.java
public static void main(String args[]) { final String S_ProcName = "CFAsteriskSwingHttpCLI.main() "; initConsoleLog();//from w w w .j a v a 2 s .c om boolean fastExit = false; 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; } CFAsteriskClientConfigurationFile cFAsteriskClientConfig = new CFAsteriskClientConfigurationFile(); String cFAsteriskClientConfigFileName = homeDir.getPath() + File.separator + ".cfasteriskclientrc"; cFAsteriskClientConfig.setFileName(cFAsteriskClientConfigFileName); File cFAsteriskClientConfigFile = new File(cFAsteriskClientConfigFileName); if (!cFAsteriskClientConfigFile.exists()) { String cFAsteriskKeyStoreFileName = homeDir.getPath() + File.separator + ".msscfjceks"; cFAsteriskClientConfig.setKeyStore(cFAsteriskKeyStoreFileName); 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(); cFAsteriskClientConfig.setDeviceName(deviceName); cFAsteriskClientConfig.save(); log.message(S_ProcName + "INFO: Created CFAsterisk client configuration file " + cFAsteriskClientConfigFileName); fastExit = true; } if (!cFAsteriskClientConfigFile.isFile()) { log.message(S_ProcName + "ERROR: Proposed client configuration file " + cFAsteriskClientConfigFileName + " is not a file."); fastExit = true; } if (!cFAsteriskClientConfigFile.canRead()) { log.message(S_ProcName + "ERROR: Permission denied attempting to read client configuration file " + cFAsteriskClientConfigFileName); fastExit = true; } cFAsteriskClientConfig.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); // The Invoker and it's implementation CFAsteriskXMsgClientHttpSchema invoker = new CFAsteriskXMsgClientHttpSchema(); // And now for the client side cache implementation that invokes it ICFAsteriskSchemaObj clientSchemaObj = new CFAsteriskSchemaObj() { public void logout() { CFAsteriskXMsgClientHttpSchema invoker = (CFAsteriskXMsgClientHttpSchema) getBackingStore(); try { invoker.logout(getAuthorization()); } catch (RuntimeException e) { } setAuthorization(null); } }; clientSchemaObj.setBackingStore(invoker); // And stitch the response handler to reference our client instance invoker.setResponseHandlerSchemaObj(clientSchemaObj); // And now we can stitch together the CLI to the SAX loader code CFAsteriskSwingHttpCLI cli = new CFAsteriskSwingHttpCLI(); cli.setXMsgClientHttpSchema(invoker); cli.setSchema(clientSchemaObj); ICFAsteriskSwingSchema swing = cli.getSwingSchema(); swing.setClientConfigurationFile(cFAsteriskClientConfig); swing.setSchema(clientSchemaObj); swing.setClusterName("system"); swing.setTenantName("system"); swing.setSecUserName("system"); JFrame jframe = cli.getDesktop(); jframe.setVisible(true); jframe.toFront(); }