List of usage examples for java.io PrintWriter append
public PrintWriter append(char c)
From source file:org.jahia.bin.errors.ErrorFileDumper.java
public static void outputSystemInfo(PrintWriter strOut, boolean systemProperties, boolean environmentVariables, boolean jahiaSettings, boolean memory, boolean caches, boolean threads, boolean deadlocks, boolean loadAverage) { if (systemProperties) { // now let's output the system properties. strOut.println();/*from w ww. jav a2s. c om*/ strOut.println("System properties:"); strOut.println("-------------------"); Map<Object, Object> orderedProperties = new TreeMap<Object, Object>(System.getProperties()); Iterator<Map.Entry<Object, Object>> entrySetIter = orderedProperties.entrySet().iterator(); while (entrySetIter.hasNext()) { Map.Entry<Object, Object> curEntry = entrySetIter.next(); String curPropertyName = (String) curEntry.getKey(); String curPropertyValue = (String) curEntry.getValue(); strOut.println(" " + curPropertyName + " : " + curPropertyValue); } } if (environmentVariables) { // now let's output the environment variables. strOut.println(); strOut.println("Environment variables:"); strOut.println("-------------------"); Map<String, String> orderedProperties = new TreeMap<String, String>(System.getenv()); Iterator<Map.Entry<String, String>> entrySetIter = orderedProperties.entrySet().iterator(); while (entrySetIter.hasNext()) { Map.Entry<String, String> curEntry = entrySetIter.next(); String curPropertyName = curEntry.getKey(); String curPropertyValue = curEntry.getValue(); strOut.println(" " + curPropertyName + " : " + curPropertyValue); } } if (jahiaSettings) { strOut.println(); if (SettingsBean.getInstance() != null) { strOut.append("Server configuration (").append(Jahia.getFullProductVersion()).append(" - ") .append(Jahia.getBuildDate()).append("):"); strOut.println(); strOut.println("---------------------"); SettingsBean settings = SettingsBean.getInstance(); Map<Object, Object> jahiaOrderedProperties = new TreeMap<Object, Object>( settings.getPropertiesFile()); Iterator<Map.Entry<Object, Object>> jahiaEntrySetIter = jahiaOrderedProperties.entrySet() .iterator(); while (jahiaEntrySetIter.hasNext()) { Map.Entry<Object, Object> curEntry = jahiaEntrySetIter.next(); String curPropertyName = (String) curEntry.getKey(); String curPropertyValue = null; if (curEntry.getValue() == null) { curPropertyValue = null; } else if (curEntry.getValue() instanceof String) { curPropertyValue = (String) curEntry.getValue(); } else { curPropertyValue = curEntry.getValue().toString(); } if (curPropertyName.toLowerCase().indexOf("password") == -1 && (!"mail_server".equals(curPropertyName) || !StringUtils.contains(curPropertyValue, "&password=") && !StringUtils.contains(curPropertyValue, "?password="))) { strOut.println(" " + curPropertyName + " = " + curPropertyValue); } } } } if (memory) { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage(); printMemoryUsage(MemoryType.HEAP.toString(), memoryUsage, strOut); memoryUsage = memoryMXBean.getNonHeapMemoryUsage(); printMemoryUsage(MemoryType.NON_HEAP.toString(), memoryUsage, strOut); strOut.println("--------------"); strOut.println("Memory pool details"); strOut.println("--------------"); List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean bean : memoryPoolMXBeans) { printMemoryUsage("Memory Pool \"" + bean.getName() + "\" (" + bean.getType().toString() + ")", bean.getUsage(), strOut); } } if (caches) { strOut.println(); DecimalFormat percentFormat = new DecimalFormat("###.##"); if (SpringContextSingleton.getInstance().isInitialized() && (ServicesRegistry.getInstance().getCacheService() != null)) { strOut.println("Cache status:"); strOut.println("--------------"); // non Ehcaches SortedSet<String> sortedCacheNames = new TreeSet<>( ServicesRegistry.getInstance().getCacheService().getNames()); for (String sortedCacheName : sortedCacheNames) { final Cache<Object, Object> objectCache = ServicesRegistry.getInstance().getCacheService() .getCache(sortedCacheName); if (objectCache != null && !(((Cache<?, ?>) objectCache).getCacheImplementation() instanceof EhCacheImpl)) { String efficiencyStr = "0"; if (!Double.isNaN(objectCache.getCacheEfficiency())) { efficiencyStr = percentFormat.format(objectCache.getCacheEfficiency()); } strOut.println(sortedCacheName + ": size=" + objectCache.size() + ", successful hits=" + objectCache.getSuccessHits() + ", total hits=" + objectCache.getTotalHits() + ", efficiency=" + efficiencyStr + "%"); } } } // Ehcaches List<CacheManager> cacheManagers = CacheManager.ALL_CACHE_MANAGERS; for (CacheManager ehcacheManager : cacheManagers) { String[] ehcacheNames = ehcacheManager.getCacheNames(); java.util.Arrays.sort(ehcacheNames); for (String ehcacheName : ehcacheNames) { Ehcache ehcache = ehcacheManager.getEhcache(ehcacheName); strOut.append(ehcacheName).append(": "); if (ehcache != null) { StatisticsGateway ehcacheStats = ehcache.getStatistics(); String efficiencyStr = "0"; if (ehcacheStats.cacheHitCount() + ehcacheStats.cacheMissCount() > 0) { efficiencyStr = percentFormat.format(ehcacheStats.cacheHitCount() * 100f / (ehcacheStats.cacheHitCount() + ehcacheStats.cacheMissCount())); } strOut.append("size=" + ehcacheStats.getSize() + ", successful hits=" + ehcacheStats.cacheHitCount() + ", total hits=" + (ehcacheStats.cacheHitCount() + ehcacheStats.cacheMissCount()) + ", efficiency=" + efficiencyStr + "%"); strOut.println(); } } } } ThreadMonitor threadMonitor = null; if (threads) { strOut.println(); strOut.println("Thread status:"); strOut.println("--------------"); threadMonitor = ThreadMonitor.getInstance(); threadMonitor.generateThreadInfo(strOut); } if (deadlocks) { strOut.println(); strOut.println("Deadlock status:"); threadMonitor = threadMonitor != null ? threadMonitor : ThreadMonitor.getInstance(); ; String deadlock = threadMonitor.findDeadlock(); strOut.println(deadlock != null ? deadlock : "none"); } if (loadAverage) { strOut.println(); strOut.println("Request load average:"); strOut.println("---------------------"); RequestLoadAverage info = RequestLoadAverage.getInstance(); if (info != null) { strOut.println("Over one minute=" + info.getOneMinuteLoad() + " Over five minute=" + info.getFiveMinuteLoad() + " Over fifteen minute=" + info.getFifteenMinuteLoad()); } else { strOut.println("not available"); } strOut.println(); } strOut.flush(); }
From source file:com.ephesoft.dcma.gwt.customworkflow.server.ImportPluginUploadServlet.java
private void attachFile(HttpServletRequest req, HttpServletResponse resp) throws IOException { String errorMessageString = EMPTY_STRING; PrintWriter printWriter = null; printWriter = resp.getWriter();// w ww. ja v a 2 s.c o m File tempZipFile = null; if (ServletFileUpload.isMultipartContent(req)) { String exportSerailizationFolderPath = EMPTY_STRING; try { Properties allProperties = ApplicationConfigProperties.getApplicationConfigProperties() .getAllProperties(META_INF_APPLICATION_PROPERTIES); exportSerailizationFolderPath = allProperties.getProperty(PLUGIN_UPLOAD_PROPERTY_NAME); } catch (IOException e) { LOG.error("Error retreiving plugin upload path ", e); } File exportSerailizationFolder = new File(exportSerailizationFolderPath); if (!exportSerailizationFolder.exists()) { exportSerailizationFolder.mkdir(); } tempZipFile = readAndParseAttachedFile(req, exportSerailizationFolderPath, printWriter); errorMessageString = processZipFileEntries(tempZipFile, exportSerailizationFolderPath, printWriter); } else { LOG.error("Request contents type is not supported."); printWriter.write("Request contents type is not supported."); } if (tempZipFile != null) { tempZipFile.delete(); } if (validZipContent) { String zipFileNameWithoutExtension = tempOutputUnZipDir.substring(0, tempOutputUnZipDir.lastIndexOf('.')); printWriter.write(CustomWorkflowConstants.PLUGIN_NAME + zipFileNameWithoutExtension); printWriter.append(RESULT_SEPERATOR); printWriter.append(CustomWorkflowConstants.JAR_FILE_PATH).append(jarFilePath); printWriter.append(RESULT_SEPERATOR); printWriter.append(CustomWorkflowConstants.XML_FILE_PATH).append(xmlFilePath); printWriter.append(RESULT_SEPERATOR); printWriter.flush(); } else { printWriter.write("Error while importing.Please try again." + CAUSE + errorMessageString); } }
From source file:com.stratio.qa.specs.CommonG.java
/** * Capture a snapshot or an evidence in the driver * * @param driver driver used for testing * @param type type/*from ww w.j a v a 2s. c o m*/ * @param suffix suffix * @return String */ public String captureEvidence(WebDriver driver, String type, String suffix) { String testSuffix = System.getProperty("TESTSUFFIX"); String dir = "./target/executions/"; if (testSuffix != null) { dir = dir + testSuffix + "/"; } String clazz = ThreadProperty.get("class"); String currentBrowser = ThreadProperty.get("browser"); String currentData = ThreadProperty.get("dataSet"); if (!currentData.equals("")) { currentData = currentData.replaceAll("[\\\\|\\/|\\|\\s|:|\\*]", "_"); } if (!"".equals(currentData)) { currentData = "-" + HashUtils.doHash(currentData); } Timestamp ts = new Timestamp(new java.util.Date().getTime()); String outputFile = dir + clazz + "/" + ThreadProperty.get("feature") + "." + ThreadProperty.get("scenario") + "/" + currentBrowser + currentData + ts.toString() + suffix; outputFile = outputFile.replaceAll(" ", "_"); if (type.endsWith("htmlSource")) { if (type.equals("framehtmlSource")) { boolean isFrame = (Boolean) ((JavascriptExecutor) driver) .executeScript("return window.top != window.self"); if (isFrame) { outputFile = outputFile + "frame.html"; } else { outputFile = ""; } } else if (type.equals("htmlSource")) { driver.switchTo().defaultContent(); outputFile = outputFile + ".html"; } if (!outputFile.equals("")) { String source = ((RemoteWebDriver) driver).getPageSource(); File fout = new File(outputFile); boolean dirs = fout.getParentFile().mkdirs(); FileOutputStream fos; try { fos = new FileOutputStream(fout, true); Writer out = new OutputStreamWriter(fos, "UTF8"); PrintWriter writer = new PrintWriter(out, false); writer.append(source); writer.close(); out.close(); } catch (IOException e) { logger.error("Exception on evidence capture", e); } } } else if ("screenCapture".equals(type)) { outputFile = outputFile + ".png"; File file = null; driver.switchTo().defaultContent(); ((Locatable) driver.findElement(By.tagName("body"))).getCoordinates().inViewPort(); if (currentBrowser.startsWith("chrome") || currentBrowser.startsWith("droidemu")) { Actions actions = new Actions(driver); actions.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).perform(); actions.keyUp(Keys.CONTROL).perform(); file = chromeFullScreenCapture(driver); } else { file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); } try { FileUtils.copyFile(file, new File(outputFile)); } catch (IOException e) { logger.error("Exception on copying browser screen capture", e); } } return outputFile; }
From source file:org.bdval.modelselection.CandidateModelSelection.java
private void dump(final ModelSelectionArguments toolsArgs) { if (toolsArgs.dumpFilename != null) { System.out.println("Writing integrated dataset to " + toolsArgs.dumpFilename); try {// ww w .ja v a2 s . c o m final PrintWriter writer = new PrintWriter(new FileWriter(toolsArgs.dumpFilename)); final ObjectList<String> modelConditionColumnNames = getModelConditionColumnNames( toolsArgs.modelConditions); writer.append(String.format("dataset\tendpoint\tmodelId\tnumFeaturesInModel\t" + "MCC_CV\tACC_CV\tSens_CV\tSpec_CV\tAUC_CV\t" + "norm_MCC_CV\tnorm_ACC_CV\tnorm_Sens_CV\tnorm_Spec_CV\tnorm_AUC_CV\tT&T_accuracy_bias\t" + "MCC_CVCF\tACC_CVCF\tSens_CVCF\tSpec_CVCF\tAUC_CVCF\t" + // "max_MCC_CVCF\tmax_ACC_CVCF\tmax_Sens_CVCF\tmax_Spec_CVCF\tmax_AUC_CVCF\t" + "norm_MCC_CVCF\tnorm_ACC_CVCF\tnorm_Sens_CVCF\tnorm_Spec_CVCF\tnorm_AUC_CVCF\t" + "MCC_validation\tACC_validation\tSens_validation\tSpec_validation\tAUC_validation\t" + // "max_MCC_validation\tmax_ACC_validation\tmax_Sens_validation\tmax_Spec_validation\tmax_AUC_validation\t" + "norm_MCC_validation\tnorm_ACC_validation\tnorm_Sens_validation\tnorm_Spec_validation\tnorm_AUC_validation\t" + "delta_MCC_CVCF_CV\tdelta_ACC_CVCF_CV\tdelta_Sens_CVCF_CV\tdelta_Spec_CVCF_CV\tdelta_AUC_CVCF_CV\t" + "MCC_CV_stdev\tACC_CV_stdev\tSens_CV_stdev\tSpec_CV_stdev\tAUC_CV_stdev\tmodel-name\tpair-wise-cal-AUC" + // no tab intended getModelConditionHeaders(toolsArgs.modelConditions, modelConditionColumnNames) + "\n")); for (final String modelId : modelIds) { final ModelPerformance cvPerf = this.cvResults.get(modelId); final ModelPerformance cvcfPerf = this.cvcfResults.get(modelId); final String datasetName = cvPerf == null ? "unknown" : cvPerf.dataset; final String endpointCode = cvPerf == null ? "unknown" : cvPerf.endpoint; int numActualFeatures = cvPerf == null ? 0 : cvPerf.actualNumberOfFeaturesInModel; if (numActualFeatures == -1) { // get it from CVCF instead: numActualFeatures = this.cvcfResults.get(modelId).actualNumberOfFeaturesInModel; } // modelId CV(MCC, Sens, Spec, AUC) CVCF() validation() final double deltaCVCF_CV_mcc = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.MCC) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.MCC); final double deltaCVCF_CV_acc = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.ACC) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.ACC); final double deltaCVCF_CV_sens = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.SENS) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.SENS); final double deltaCVCF_CV_spec = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.SPEC) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.SPEC); final double deltaCVCF_CV_auc = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.AUC) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.AUC); final double pairWiseCal_auc = getModelRankingPerformance(toolsArgs, cvPerf, cvcfPerf); writer.append(String.format( "%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\t%f\t%f\t%f\t%f\t%f\t%s\t%s\t%f%s\n", datasetName, endpointCode, modelId, numActualFeatures, formatStats(modelId, this.cvResults, this.cvNormFactorPerfs), formatBias(cvPerf), formatStats(modelId, this.cvcfResults, this.cvcfNormFactorPerfs), formatStats(modelId, this.testResults, this.testNormFactorPerfs), deltaCVCF_CV_mcc, deltaCVCF_CV_acc, deltaCVCF_CV_sens, deltaCVCF_CV_spec, deltaCVCF_CV_auc, formatStdev(modelId, this.cvResults), toolsArgs.modelNameString, pairWiseCal_auc, getModelConditionColumns(modelId, modelConditionColumnNames, toolsArgs.modelConditions))); } writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } System.exit(0); } }
From source file:hudson.plugins.dimensionsscm.DimensionsChangeLogWriter.java
private void write(List<DimensionsChangeSet> changeSets, Writer logFile, boolean appendFile) { Logger.Debug("Writing logfile in append mode = " + appendFile); String logStr = ""; PrintWriter writer = new PrintWriter(logFile); if (!appendFile) { writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); writer.println("<changelog>"); }//from w w w .j av a 2s .c om if (changeSets != null) { for (DimensionsChangeSet changeSet : changeSets) { logStr += String.format("\t<changeset version=\"%s\">\n", escapeXML(changeSet.getVersion())); logStr += String.format("\t\t<date>%s</date>\n", Util.XS_DATETIME_FORMATTER.format(changeSet.getDate())); logStr += String.format("\t\t<user>%s</user>\n", escapeXML(changeSet.getDeveloper())); logStr += String.format("\t\t<comment>%s</comment>\n", escapeXML(changeSet.getSCMComment())); logStr += "\t\t<items>\n"; for (DimensionsChangeSet.DmFiles item : changeSet.getFiles()) { logStr += String.format("\t\t\t<item operation=\"%s\" url=\"%s\">%s</item>\n", item.getOperation(), escapeHTML(item.getUrl()), escapeXML(item.getFile())); } logStr += "\t\t</items>\n"; logStr += "\t\t<requests>\n"; for (DimensionsChangeSet.DmRequests req : changeSet.getRequests()) { logStr += String.format("\t\t\t<request url=\"%s\" title=\"%s\">%s</request>\n", escapeHTML(req.getUrl()), escapeXML(req.getTitle()), escapeXML(req.getIdentifier())); } logStr += "\t\t</requests>\n"; logStr += "\t</changeset>\n"; } } Logger.Debug("Writing to logfile '" + logStr + "'"); if (appendFile) { writer.append(logStr); } else { writer.print(logStr); } return; }
From source file:com.francelabs.datafari.servlets.admin.FieldWeight.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) Used to free a semaphore on an other select without any * confirl Checks if the files still exist Gets the list of the fields * Gets the weight of a field in a type of query *///from w w w.ja va2 s. c om @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final PrintWriter out = response.getWriter(); usingCustom = false; // Reinit the usingCustom value to false in order // to check again if the // custom_search_handler.xml file is used try { if (request.getParameter("sem") != null) { // If it's called just to // clean the semaphore return; } if ((config == null) || !new File(env + "/solrconfig.xml").exists()) {// If // the // files // did // not // existed // when // the // constructor // was // run // Checks if they exist now if (!new File(env + "/solrconfig.xml").exists()) { LOGGER.error( "Error while opening the configuration files, solrconfig.xml and/or schema.xml, in FieldWeight doGet, please make sure those files exist at " + env + " . Error 69025"); // If // not // an // error // is // printed out.append( "Error while opening the configuration files, please retry, if the problem persists contact your system administrator. Error Code : 69025"); out.close(); return; } else { config = new File(env + "/solrconfig.xml"); } } if (customFields == null) { if (new File(env + "/customs_schema/custom_fields.incl").exists()) { customFields = new File(env + "/customs_schema/custom_fields.incl"); } } if (customSearchHandler == null) { if (new File(env + "/customs_solrconfig/custom_search_handler.incl").exists()) { customSearchHandler = new File(env + "/customs_solrconfig/custom_search_handler.incl"); } } if (request.getParameter("type") == null) { // If called at the // creation of the HTML // ==> retrieve the // fields list try { // Define the Solr hostname, port and protocol final String solrserver = "localhost"; final String solrport = "8983"; final String protocol = "http"; // Use Solr Schema REST API to get the list of fields final HttpClient httpClient = HttpClientBuilder.create().build(); final HttpHost httpHost = new HttpHost(solrserver, Integer.parseInt(solrport), protocol); final HttpGet httpGet = new HttpGet("/solr/FileShare/schema/fields"); final HttpResponse httpResponse = httpClient.execute(httpHost, httpGet); // Construct the jsonResponse final JSONObject jsonResponse = new JSONObject(); if (httpResponse.getStatusLine().getStatusCode() == 200) { // Status of the API response is OK final JSONObject json = new JSONObject(EntityUtils.toString(httpResponse.getEntity())); final JSONArray fieldsJson = json.getJSONArray("fields"); jsonResponse.put("field", fieldsJson); response.getWriter().write(jsonResponse.toString()); // Answer // to // the // request response.setStatus(200); response.setContentType("text/json;charset=UTF-8"); } else { // Status of the API response is an error LOGGER.error("Error while retrieving the fields from the Schema API of Solr: " + httpResponse.getStatusLine().toString()); out.append( "Error while retrieving the fields from the Schema API of Solr, please retry, if the problem persists contact your system administrator. Error Code : 69026"); } out.close(); } catch (final IOException e) { LOGGER.error("Error while retrieving the fields from the Schema API of Solr", e); out.append( "Error while retrieving the fields from the Schema API of Solr, please retry, if the problem persists contact your system administrator. Error Code : 69026"); out.close(); } } else { // If the weight of a field has been requested try { final String type = request.getParameter("type"); final String field = request.getParameter("field").toString(); findSearchHandler(); // if (searchHandler == null && customSearchHandler != null // && customSearchHandler.exists()) { // search // // handler // // not // // found // // in // // the // // standard solrconfig.xml find, try // // to find it in the // // custom_search_handler.xml file // usingCustom = true; // doc = dBuilder.parse(customSearchHandler); // searchHandler = // getSearchHandler(doc.getElementsByTagName("requestHandler")); // } if (searchHandler != null) { final Node n = run(searchHandler.getChildNodes(), type); childList = n.getParentNode().getChildNodes(); final String elemValue = n.getTextContent(); // Get the // text // content // of // the // node int index = elemValue.indexOf(field + "^"); if (index != -1) { // If the field is weighted index += field.length() + 1; // Gets the number of // the // char that is the // first figure of // the // number final String elemValueCut = elemValue.substring(index);// Get // the // text // content // cutting // everything // before // the // requested // field if (elemValueCut.indexOf(" ") != -1) { // the // last // field, // returns // what's // between // the // "^" and // the // next // whitespace response.getWriter() .write(elemValue.substring(index, index + elemValueCut.indexOf(" "))); } else { // that // is after the "field^" response.getWriter().write(elemValue.substring(index)); } } else { response.getWriter().write("0"); } response.setStatus(200); response.setContentType("text;charset=UTF-8"); return; } else { LOGGER.error( "No searchHandler found either in solrconfig.xml or in custom_search_handler.xml ! Make sure your files are valid. Error 69028"); out.append( "Something bad happened, please retry, if the problem persists contact your system administrator. Error code : 69028"); out.close(); return; } } catch (SAXException | ParserConfigurationException e) { LOGGER.error( "Error while parsing the solrconfig.xml, in FieldWeight doGet, make sure the file is valid. Error 69028", e); out.append( "Something bad happened, please retry, if the problem persists contact your system administrator. Error code : 69028"); out.close(); return; } } } catch (final Exception e) { out.append( "Something bad happened, please retry, if the problem persists contact your system administrator. Error code : 69510"); out.close(); LOGGER.error("Unindentified error in FieldWeight doGet. Error 69510", e); } }
From source file:org.bdval.modelselection.CandidateModelSelectionAllTeams.java
private void dump(final arguments toolsArgs) { if (toolsArgs.dumpFilename != null) { System.out.println("Writing integrated dataset to " + toolsArgs.dumpFilename); try {/*w ww.j a v a2s . com*/ final PrintWriter writer = new PrintWriter(new FileWriter(toolsArgs.dumpFilename)); final ObjectList<String> modelConditionColumnNames = getModelConditionColumnNames( toolsArgs.modelConditions); writer.append(String.format("dataset\tendpoint\tmodelId\tnumFeaturesInModel\t" + "MCC_CV\tACC_CV\tSens_CV\tSpec_CV\tAUC_CV\t" + // "max_MCC_CV\tmax_ACC_CV\tmax_Sens_CV\tmax_Spec_CV\tmax_AUC_CV\t" + "norm_MCC_CV\tnorm_ACC_CV\tnorm_Sens_CV\tnorm_Spec_CV\tnorm_AUC_CV\t" + "MCC_CVCF\tACC_CVCF\tSens_CVCF\tSpec_CVCF\tAUC_CVCF\t" + // "max_MCC_CVCF\tmax_ACC_CVCF\tmax_Sens_CVCF\tmax_Spec_CVCF\tmax_AUC_CVCF\t" + "norm_MCC_CVCF\tnorm_ACC_CVCF\tnorm_Sens_CVCF\tnorm_Spec_CVCF\tnorm_AUC_CVCF\t" + "MCC_validation\tACC_validation\tSens_validation\tSpec_validation\tAUC_validation\t" + // "max_MCC_validation\tmax_ACC_validation\tmax_Sens_validation\tmax_Spec_validation\tmax_AUC_validation\t" + "norm_MCC_validation\tnorm_ACC_validation\tnorm_Sens_validation\tnorm_Spec_validation\tnorm_AUC_validation\t" + "delta_MCC_CVCF_CV\tdelta_ACC_CVCF_CV\tdelta_Sens_CVCF_CV\tdelta_Spec_CVCF_CV\tdelta_AUC_CVCF_CV" + // no tab intended getModelConditionHeaders(toolsArgs.modelConditions, modelConditionColumnNames) + "\n")); for (final String modelId : modelIds) { final ModelPerformance cvPerf = this.cvResults.get(modelId); final ModelPerformance cvcfPerf = this.cvcfResults.get(modelId); final String datasetName = cvPerf == null ? "unknown" : cvPerf.dataset; final String endpointCode = cvPerf == null ? "unknown" : cvPerf.endpoint; int numActualFeatures = cvPerf == null ? 0 : cvPerf.actualNumberOfFeaturesInModel; if (numActualFeatures == -1) { // get it from CVCF instead: numActualFeatures = this.cvcfResults.get(modelId).actualNumberOfFeaturesInModel; } // modelId CV(MCC, Sens, Spec, AUC) CVCF() validation() final double deltaCVCF_CV_mcc = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.MCC) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.MCC); final double deltaCVCF_CV_acc = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.ACC) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.ACC); final double deltaCVCF_CV_sens = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.SENS) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.SENS); final double deltaCVCF_CV_spec = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.SPEC) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.SPEC); final double deltaCVCF_CV_auc = getNormalizedMeasure(modelId, cvcfResults, cvcfNormFactorPerfs, MeasureName.AUC) - getNormalizedMeasure(modelId, cvResults, cvNormFactorPerfs, MeasureName.AUC); writer.append(String.format("%s\t%s\t%s\t%d\t%s\t%s\t%s\t%f\t%f\t%f\t%f\t%f%s\n", datasetName, endpointCode, modelId, numActualFeatures, formatStats(modelId, this.cvResults, this.cvNormFactorPerfs), formatStats(modelId, this.cvcfResults, this.cvcfNormFactorPerfs), formatStats(modelId, this.testResults, this.testNormFactorPerfs), deltaCVCF_CV_mcc, deltaCVCF_CV_acc, deltaCVCF_CV_sens, deltaCVCF_CV_spec, deltaCVCF_CV_auc, getModelConditionColumns(modelId, modelConditionColumnNames, toolsArgs.modelConditions))); } writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } System.exit(0); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgSrvWar.CFAsteriskXMsgSrvWarRequestXml.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */// ww w . j a v a 2 s . c om protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String S_ProcName = "doPost"; ICFAsteriskSchemaObj schemaObj; HttpSession sess = request.getSession(false); if (sess == null) { sess = request.getSession(true); schemaObj = new CFAsteriskSchemaPooledObj(); sess.setAttribute("SchemaObj", schemaObj); } else { schemaObj = (ICFAsteriskSchemaObj) sess.getAttribute("SchemaObj"); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "SchemaObj"); } } CFTipServerInfo serverInfo = CFAsteriskXMsgSrvWarApplicationListener.getServerInfo(); CFTipEnvelopeHandler envelopeHandler = (CFTipEnvelopeHandler) sess.getAttribute("CFTipEnvelopeHandler"); if (envelopeHandler == null) { envelopeHandler = new CFTipEnvelopeHandler(); envelopeHandler.setLog(log); CFAsteriskXMsgRqstHandler requestHandler = new CFAsteriskXMsgRqstHandler(); requestHandler.setSchemaObj(schemaObj); envelopeHandler.setRequestHandler(requestHandler); envelopeHandler.setServerInfo(serverInfo); sess.setAttribute("CFTipEnvelopeHandler", envelopeHandler); } String clusterDescription = ""; ICFAsteriskSchema dbSchema = null; try { dbSchema = (ICFAsteriskSchema) CFAsteriskSchemaPool.getSchemaPool().getInstance(); schemaObj.setBackingStore(dbSchema); schemaObj.beginTransaction(); ICFSecuritySysClusterObj sysCluster = schemaObj.getSysClusterTableObj().readSysClusterByIdIdx(1, false); if (sysCluster == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "SysCluster"); } ICFSecurityClusterObj secCluster = sysCluster.getRequiredContainerCluster(); if (secCluster == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "SysCluster.Cluster"); } if (serverInfo.getClusterDescr() == null) { serverInfo.setClusterDescr(secCluster.getRequiredDescription()); serverInfo.setClusterURL(secCluster.getRequiredFullDomainName()); } clusterDescription = serverInfo.getClusterDescr(); // envelopeHandler.setLog( log ); String messageBody = request.getParameter("MessageBody"); if ((messageBody == null) || (messageBody.length() <= 0)) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">"); out.println("<HTML>"); out.println("<BODY>"); out.println("<form method=\"post\" formaction=\"CFAsteriskXMsgSrvWarRequestXml\">"); out.println("<H1 style=\"text-align:center\">" + clusterDescription + " XMsg Server</H1>"); out.println( "<H2 style=\"text-align:center\"> Enter a CFTipEnvelope XML request message to process</H2>"); out.println("<p>"); out.println("<table style=\"width:90%\">"); out.println( "<tr><th style=\"text-align:left\">Message Body:</th><td><textarea name=\"MessageBody\" cols=\"60\" rows=\"10\"></textarea></td></tr>"); out.println("</table>"); out.println( "<p style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Submit Request</button> <button type=\"button\" name=\"Cancel\"\" onclick=\"window.location.href='CFAsteriskXMsgSrvWarRequestXml'\">Cancel;</button>"); out.println("</form>"); out.println("</BODY>"); out.println("</HTML>"); return; } PrintWriter out = response.getWriter(); log.setPrintWriter(out); envelopeHandler.parseStringContents(messageBody); response.setContentType("text/plain"); String rspnBase64EncodedEncryptedSessionBlock = envelopeHandler.getResponse(); out.append(rspnBase64EncodedEncryptedSessionBlock); out.flush(); } finally { if (dbSchema != null) { try { if (schemaObj.isTransactionOpen()) { schemaObj.rollback(); } schemaObj.minimizeMemory(); } catch (RuntimeException e) { } schemaObj.setBackingStore(null); CFAsteriskSchemaPool.getSchemaPool().releaseInstance(dbSchema); } } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstXMsgSrvWar.CFAstXMsgSrvWarRequestXml.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */// ww w . java 2s.c o m protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String S_ProcName = "doPost"; ICFAstSchemaObj schemaObj; HttpSession sess = request.getSession(false); if (sess == null) { sess = request.getSession(true); schemaObj = new CFAstSchemaObj(); sess.setAttribute("SchemaObj", schemaObj); } else { schemaObj = (ICFAstSchemaObj) sess.getAttribute("SchemaObj"); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "SchemaObj"); } } CFTipEnvelopeHandler envelopeHandler = (CFTipEnvelopeHandler) sess.getAttribute("CFTipEnvelopeHandler"); if (envelopeHandler == null) { envelopeHandler = new CFTipEnvelopeHandler(); envelopeHandler.setLog(log); CFAstXMsgRqstHandler requestHandler = new CFAstXMsgRqstHandler(); requestHandler.setSchemaObj(schemaObj); envelopeHandler.setRequestHandler(requestHandler); sess.setAttribute("CFTipEnvelopeHandler", envelopeHandler); } String clusterDescription = ""; ICFAstSchema dbSchema = null; try { dbSchema = CFAstSchemaPool.getSchemaPool().getInstance(); schemaObj.setBackingStore(dbSchema); schemaObj.beginTransaction(); ICFAstSysClusterObj sysCluster = schemaObj.getSysClusterTableObj().readSysClusterByIdIdx(1, false); if (sysCluster == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "SysCluster"); } ICFAstClusterObj secCluster = sysCluster.getRequiredContainerCluster(); if (secCluster == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "SysCluster.Cluster"); } CFTipServerInfo serverInfo = CFAstXMsgSrvWarApplicationListener.getServerInfo(); if (serverInfo == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "ServerInfo"); } if (null == envelopeHandler.getServerInfo()) { serverInfo.setClusterDescr(secCluster.getRequiredDescription()); serverInfo.setClusterURL(secCluster.getRequiredFullDomainName()); envelopeHandler.setServerInfo(serverInfo); envelopeHandler.initServerKeys(); } clusterDescription = serverInfo.getClusterDescr(); // envelopeHandler.setLog( log ); String messageBody = request.getParameter("MessageBody"); if ((messageBody == null) || (messageBody.length() <= 0)) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">"); out.println("<HTML>"); out.println("<BODY>"); out.println("<form method=\"post\" formaction=\"CFAstXMsgSrvWarRequestXml\">"); out.println("<H1 style=\"text-align:center\">" + clusterDescription + " XMsg Server</H1>"); out.println( "<H2 style=\"text-align:center\"> Enter a CFTipEnvelope XML request message to process</H2>"); out.println("<p>"); out.println("<table style=\"width:90%\">"); out.println( "<tr><th style=\"text-align:left\">Message Body:</th><td><textarea name=\"MessageBody\" cols=\"60\" rows=\"10\"></textarea></td></tr>"); out.println("</table>"); out.println( "<p style=\"text-align:center\"><button type=\"submit\" name=\"Ok\"\">Submit Request</button> <button type=\"button\" name=\"Cancel\"\" onclick=\"window.location.href='CFAstXMsgSrvWarRequestXml'\">Cancel;</button>"); out.println("</form>"); out.println("</BODY>"); out.println("</HTML>"); return; } PrintWriter out = response.getWriter(); log.setPrintWriter(out); envelopeHandler.parseStringContents(messageBody); response.setContentType("text/plain"); String rspnBase64EncodedEncryptedSessionBlock = envelopeHandler.getResponse(); out.append(rspnBase64EncodedEncryptedSessionBlock); out.flush(); } catch (RuntimeException | InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Caught " + e.getClass().getName() + " -- " + e.getMessage(), e); } finally { if (dbSchema != null) { try { if (schemaObj.isTransactionOpen()) { schemaObj.rollback(); } } catch (RuntimeException e) { } schemaObj.setBackingStore(null); CFAstSchemaPool.getSchemaPool().releaseInstance(dbSchema); } } }
From source file:org.auraframework.http.resource.InlineJs.java
private void appendLocaleDataJavascripts(PrintWriter out) { AuraLocale auraLocale = localizationAdapter.getAuraLocale(); // Refer to the locale in LocaleValueProvider Locale langLocale = auraLocale.getLanguageLocale(); Locale userLocale = auraLocale.getLocale(); // This is for backward compatibility. At this moment, there are three locales // in Locale Value Provider. Keep them all available for now to avoid breaking consumers. String langMomentLocale = this.getMomentLocale(langLocale.toString()); String userMomentLocale = this.getMomentLocale(userLocale.toString()); String ltngMomentLocale = this.getMomentLocale(langLocale.getLanguage() + "_" + userLocale.getCountry()); StringBuilder defineLocaleJs = new StringBuilder(); // "en" data has been included in moment lib, no need to load locale data if (!"en".equals(langMomentLocale)) { String content = this.localeData.get(langMomentLocale); defineLocaleJs.append(content).append("\n"); }/*from w ww . j a va 2 s. c o m*/ // if user locale is same as language locale, not need to load again if (!"en".equals(userMomentLocale) && userMomentLocale != null && !userMomentLocale.equals(langMomentLocale)) { String content = this.localeData.get(userMomentLocale); defineLocaleJs.append(content); } if (!"en".equals(ltngMomentLocale) && ltngMomentLocale != null && !ltngMomentLocale.equals(langMomentLocale) && !ltngMomentLocale.equals(userMomentLocale)) { String content = this.localeData.get(ltngMomentLocale); defineLocaleJs.append(content); } if (defineLocaleJs.length() > 0) { String loadLocaleDataJs = String.format("\n(function(){\n" + " function loadLocaleData(){\n%s}\n" + " window.moment? loadLocaleData() : (window.Aura || (window.Aura = {}), window.Aura.loadLocaleData=loadLocaleData);\n" + "})();\n", defineLocaleJs.toString()); out.append(loadLocaleDataJs); } }