List of usage examples for java.io StringWriter append
public StringWriter append(char c)
From source file:nl.b3p.viewer.admin.stripes.GeoServiceActionBean.java
@DontValidate public Resolution cqlToFilter() throws JSONException { JSONObject json = new JSONObject(); json.put("success", Boolean.FALSE); try {/*from w w w. j a v a 2s. c om*/ List<Filter> filters = CQL.toFilterList(cql); FilterTransformer filterTransformer = new FilterTransformer(); filterTransformer.setIndentation(4); filterTransformer.setOmitXMLDeclaration(true); filterTransformer.setNamespaceDeclarationEnabled(false); StringWriter sw = new StringWriter(); for (Filter filter : filters) { sw.append('\n'); filterTransformer.transform(filter, sw); } json.put("filter", sw.toString()); json.put("success", Boolean.TRUE); } catch (Exception e) { String error = ExceptionUtils.getMessage(e); if (e.getCause() != null) { error += "; cause: " + ExceptionUtils.getMessage(e.getCause()); } json.put("error", error); } return new StreamingResolution("application/json", new StringReader(json.toString())); }
From source file:org.netbeans.nbbuild.MakeJnlp2.java
private void generateVersionXMLFiles() throws IOException { FileSet fs = new FileSet(); fs.setIncludes("**/*.jar"); for (File directory : jarDirectories) { fs.setDir(directory);// ww w.ja va 2 s . co m DirectoryScanner scan = fs.getDirectoryScanner(getProject()); StringWriter writeVersionXML = new StringWriter(); writeVersionXML.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); writeVersionXML.append("<jnlp-versions>\n"); for (String jarName : scan.getIncludedFiles()) { File jar = new File(scan.getBasedir(), jarName); JarFile jarFile = new JarFile(jar); String version = getJarVersion(jarFile); if (version != null) { writeVersionXML.append(" <resource>\n <pattern>\n <name>"); writeVersionXML.append(jar.getName()); writeVersionXML.append("</name>\n <version-id>"); writeVersionXML.append(version); writeVersionXML.append("</version-id>\n </pattern>\n <file>"); writeVersionXML.append(jar.getName()); writeVersionXML.append("</file>\n </resource>\n"); } else { writeVersionXML.append(" <!-- No version found for "); writeVersionXML.append(jar.getName()); writeVersionXML.append(" -->\n"); } } writeVersionXML.append("</jnlp-versions>\n"); writeVersionXML.close(); File versionXML = new File(directory, "version.xml"); FileWriter w = new FileWriter(versionXML); w.write(writeVersionXML.toString()); w.close(); } }
From source file:ch.algotrader.esper.EngineImpl.java
private Module getModule(String moduleName) { try {/*w ww.ja va2 s .c om*/ String fileName = "module-" + moduleName + ".epl"; InputStream stream = getClass().getResourceAsStream("/" + fileName); if (stream == null) { throw new IllegalArgumentException(fileName + " does not exist"); } // process loads try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) { StringWriter buffer = new StringWriter(); String strLine; while ((strLine = reader.readLine()) != null) { if (!strLine.startsWith("load")) { buffer.append(strLine); buffer.append(newline); } else { String argument = StringUtils.substringAfter(strLine, "load").trim(); String moduleBaseName = argument.split("\\.")[0]; String statementName = argument.split("\\.")[1].split(";")[0]; Module module = EPLModuleUtil.readResource("module-" + moduleBaseName + ".epl"); for (ModuleItem item : module.getItems()) { if (item.getExpression().contains("@Name('" + statementName + "')")) { buffer.append(item.getExpression()); buffer.append(";"); buffer.append(newline); break; } } } } return EPLModuleUtil.parseInternal(buffer.toString(), fileName); } } catch (ParseException | IOException ex) { throw new InternalEngineException(moduleName + " could not be deployed", ex); } }
From source file:com.espertech.esper.dataflow.core.DataFlowServiceImpl.java
private void writeType(GraphOperatorOutputItemType type, StringWriter writer) { if (type.isWildcard()) { writer.append('?'); return;//from w w w . j a v a 2s .c o m } writer.append(type.getTypeOrClassname()); writeTypes(type.getTypeParameters(), writer); }
From source file:eu.sisob.uma.restserver.TaskManager.java
/** * Create a new folder for a new task if is possible to launch new task * Note:/*from ww w.j av a 2 s. c o m*/ * use MAX_TASKS_PER_USER and validateAccess() * Is possible that use thee locker of AuthorizationManager * @param user * @param pass * @param status * @param message * @return */ public static String prepareNewTask(String user, String pass, StringWriter status, StringWriter message) { String new_folder_name = ""; if (message == null) return ""; message.getBuffer().setLength(0); if (user != null && pass != null) { if (AuthorizationManager.validateAccess(user, pass, message)) { message.getBuffer().setLength(0); List<String> task_code_list = TaskManager.listTasks(user, pass); int num_tasks_alive = 0; int max = -1; if (task_code_list.size() > 0) { for (String task_code : task_code_list) { OutputTaskStatus task_status = TaskManager.getTaskStatus(user, pass, task_code, false, false, false); if (task_status.status.equals(OutputTaskStatus.TASK_STATUS_EXECUTED)) { } else { //Think about it num_tasks_alive++; } try { int act = Integer.parseInt(task_code); if (max < act) { max = act; } } catch (Exception ex) { } } } if (num_tasks_alive < AuthorizationManager.MAX_TASKS_PER_USER) { new_folder_name = String.valueOf(max + 1); String code_task_folder = TASKS_USERS_PATH + File.separator + user + File.separator + new_folder_name; File task_dir = new File(code_task_folder); if (!task_dir.exists()) { task_dir.mkdir(); status.append(OutputTaskStatus.TASK_STATUS_TO_EXECUTE); if (message != null) message.append("A new task has been created successfully."); //FIXME } else { new_folder_name = ""; status.append(OutputTaskStatus.TASK_STATUS_NO_ACCESS); if (message != null) message.append("Error creating place for the new task."); //FIXME } } else { new_folder_name = ""; status.append(OutputTaskStatus.TASK_STATUS_EXECUTING); if (message != null) message.append( "There are still tasks running or there are a task created ready to be launched."); //FIXME } } else { new_folder_name = ""; status.append(OutputTaskStatus.TASK_STATUS_NO_AUTH); } } else { new_folder_name = ""; status.write(OutputTaskStatus.TASK_STATUS_NO_AUTH); if (message != null) message.write(TheResourceBundle.getString("Jsp Params Invalid Msg")); } return new_folder_name; }
From source file:com.dotmarketing.portlets.workflows.business.WorkflowFactoryImpl.java
public int countTasks(WorkflowSearcher searcher) throws DotDataException { final DotConnect dc = new DotConnect(); final StringWriter sw = new StringWriter(); sw.append("select count(*) as mycount from workflow_task "); sw.append(this.getWorkflowSqlQuery(searcher, true)); dc.setSQL(sw.toString());/*from www. ja v a2 s . c o m*/ return dc.getInt("mycount"); }
From source file:com.dotmarketing.portlets.workflows.business.WorkflowFactoryImpl.java
public List<WorkflowTask> searchTasks(WorkflowSearcher searcher) throws DotDataException { final HibernateUtil hu = new HibernateUtil(WorkflowTask.class); final StringWriter sw = new StringWriter(); sw.append("select {workflow_task.*} from workflow_task "); sw.append(this.getWorkflowSqlQuery(searcher, false)); hu.setSQLQuery(sw.toString());//from w w w . j av a 2 s . c om hu.setMaxResults(searcher.getCount()); hu.setFirstResult(searcher.getCount() * searcher.getPage()); return (List<WorkflowTask>) hu.list(); }
From source file:edu.harvard.i2b2.adminTool.dataModel.PDORequestMessageModel.java
protected String generateMessageId() { StringWriter strWriter = new StringWriter(); for (int i = 0; i < 20; i++) { int num = getValidAcsiiValue(); strWriter.append((char) num); }/*from ww w.j a v a2 s . c o m*/ return strWriter.toString(); }
From source file:com.dotmarketing.portlets.workflows.business.WorkflowFactoryImpl.java
public List<WorkflowTask> searchAllTasks(WorkflowSearcher searcher) throws DotDataException { final HibernateUtil hu = new HibernateUtil(WorkflowTask.class); final StringWriter sw = new StringWriter(); sw.append("select {workflow_task.*} from workflow_task "); hu.setSQLQuery(sw.toString());//from w w w . j av a 2s.c om if (searcher != null) { hu.setMaxResults(searcher.getCount()); hu.setFirstResult(searcher.getCount() * searcher.getPage()); } return (List<WorkflowTask>) hu.list(); }
From source file:com.yaon.NewServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w .j a v a 2 s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text"); PrintWriter out = response.getWriter(); String ip = request.getParameter("ip"); String port = request.getParameter("port"); String uname = request.getParameter("uname"); String pass = request.getParameter("pass"); StringWriter sw = new StringWriter(); if ("null".equals(ip) && "null".equals(port) && "null".equals(uname) && "null".equals(pass)) { out.println("Null Argument Passed !!"); } else { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost("http://" + ip + ":" + port + "/Yaon/GetInfo"); postRequest.addHeader( BasicScheme.authenticate(new UsernamePasswordCredentials(uname, pass), "UTF-8", false)); HttpResponse res = httpClient.execute(postRequest); if (res.getStatusLine().getStatusCode() == 401) { throw new Exception("Http Authentication Failed !"); } BufferedReader br = new BufferedReader(new InputStreamReader((res.getEntity().getContent()))); String output; System.out.println("Output from Server.... \n"); while ((output = br.readLine()) != null) { System.out.println(output); sw.append(output); sw.append("\n"); } httpClient.getConnectionManager().shutdown(); } catch (HttpHostConnectException e) { out.println(e.getMessage()); } catch (Exception e) { out.println(e.getMessage()); } out.println(sw.toString()); } }