List of usage examples for java.io StringWriter append
public StringWriter append(char c)
From source file:org.overture.codegen.vdm2java.JavaFormat.java
public String formatOperationBody(SStmCG body) throws AnalysisException { String NEWLINE = "\n"; if (body == null) { return ";"; }//from w w w . j a va2s. c om StringWriter generatedBody = new StringWriter(); generatedBody.append("{" + NEWLINE + NEWLINE); generatedBody.append(handleOpBody(body)); generatedBody.append(NEWLINE + "}"); return generatedBody.toString(); }
From source file:org.overture.codegen.vdm2java.JavaFormat.java
private String formattedTypes(List<STypeCG> types, String typePostFix) throws AnalysisException { STypeCG firstType = types.get(0);//from w w w . ja v a 2 s.co m if (info.getAssistantManager().getTypeAssistant().isBasicType(firstType)) { firstType = info.getAssistantManager().getTypeAssistant().getWrapperType((SBasicTypeCG) firstType); } StringWriter writer = new StringWriter(); writer.append(format(firstType) + typePostFix); for (int i = 1; i < types.size(); i++) { STypeCG currentType = types.get(i); if (info.getAssistantManager().getTypeAssistant().isBasicType(currentType)) { currentType = info.getAssistantManager().getTypeAssistant() .getWrapperType((SBasicTypeCG) currentType); } writer.append(", " + format(currentType) + typePostFix); } String result = writer.toString(); return result; }
From source file:org.kuali.student.myplan.audit.controller.DegreeAuditController.java
/** * Method to copy the audit html report on to the form * * @param report/*from www. j a va2 s. c om*/ * @param form * @throws IOException */ private void copyReportToForm(AuditReportInfo report, DegreeAuditForm form) throws IOException { InputStream in = report.getReport().getDataSource().getInputStream(); StringWriter sw = new StringWriter(); int c = 0; while ((c = in.read()) != -1) { sw.append((char) c); } String html = sw.toString(); form.setAuditHtml(html); }
From source file:org.cloudfoundry.ide.eclipse.server.core.internal.tunnel.LaunchTunnelCommandManager.java
/** * Throws CoreException if an error occurred while launching the external * application./* w w w.ja va2 s. c o m*/ * @param monitor */ public void run(IProgressMonitor monitor) throws CoreException { // For certain OSs, script files are create that contain the application // and options. File scriptFile = null; String appOptions = serviceCommand.getOptions() != null ? serviceCommand.getOptions().getOptions() : null; CommandTerminal terminalCommand = serviceCommand.getCommandTerminal(); final List<String> processArguments = new ArrayList<String>(); final Map<String, String> envVars = getEnvironmentVariables(); try { if (terminalCommand != null) { // Parse the terminal, application, and its options into // separate // process arguments, based on the platform. // First add the terminal as the initial arguments to the // process. // Each terminal component needs // to be added as a separate process argument, and has to be // trimmed // of any leading/trailing whitespaces String terminalCommandValue = terminalCommand.getTerminal(); List<String> terminalElements = parseElement(terminalCommandValue); processArguments.addAll(terminalElements); // If using a terminal, the application that is launched by a // terminal needs to be handled differently for // Mac OS X and Windows. if (Platform.OS_MACOSX.equals(PlatformUtil.getOS())) { // For launching Mac OS Terminal, the Terminal.app does not // take // arguments for the application that is being launched. It // only // takes // in a file name, therefore the external application that // should be // launched in Terminal.app needs to be converted to a // script // file. StringWriter optionsWr = new StringWriter(); // For Mac OS, any environment variables should be // added as part of the script if (serviceCommand.getEnvironmentVariables() != null) { for (EnvironmentVariable var : serviceCommand.getEnvironmentVariables()) { optionsWr.append("export "); //$NON-NLS-1$ optionsWr.append(var.getVariable()); optionsWr.append("="); //$NON-NLS-1$ optionsWr.append(var.getValue()); optionsWr.append('\n'); } } optionsWr.append(serviceCommand.getExternalApplication().getExecutableNameAndPath()); if (appOptions != null) { optionsWr.append(' '); optionsWr.append(appOptions); } scriptFile = getScriptFile(optionsWr.toString()); processArguments.add(scriptFile.getAbsolutePath()); } else if (Platform.OS_WIN32.equals(PlatformUtil.getOS())) { // For Windows, in order for the process launcher to correct // handle the launch argument for the cmd.exe terminal, both // the // application and the // options need to be in ONE argument. StringBuffer windowsArgument = new StringBuffer(); // 1. Surround the application file location with quotes, as // any // path value with spaces needs to be surrounded with quotes // in // Windows // This leading leading space is needed for any process // argument // that starts with a quote. The process launcher // checks whether the process argument starts with a quote, // and // if it does, it expects it to end with a quote. However // The options for the applications are not surrounded by // quotes, therefore to avoid this quote check, start with a // leading whitespace windowsArgument.append(' '); windowsArgument.append('"'); windowsArgument.append(serviceCommand.getExternalApplication().getExecutableNameAndPath()); windowsArgument.append('"'); // 2. The options for the application and the application // location both need to be in ONE argument. However, the // options are not surrounded by quotes, and need to be // separated from the application by a whitespace if (appOptions != null) { windowsArgument.append(' '); windowsArgument.append(appOptions); } processArguments.add(windowsArgument.toString()); } else { // For Linux, pass the application and its options in one // process argument String processArg = serviceCommand.getExternalApplication().getExecutableNameAndPath(); if (appOptions != null) { processArg += " " + appOptions; //$NON-NLS-1$ } processArguments.add(processArg); } } else { // Otherwise no terminal is being used so parse each option // element into separate process arguments processArguments.add(serviceCommand.getExternalApplication().getExecutableNameAndPath()); if (appOptions != null) { List<String> optionElements = parseElement(appOptions); processArguments.addAll(optionElements); } } launch(processArguments, envVars); } finally { if (scriptFile != null && scriptFile.exists()) { scriptFile.deleteOnExit(); } } }
From source file:com.espertech.esper.epl.expression.core.ExprNodeUtility.java
public static void toExpressionString(List<ExprChainedSpec> chainSpec, StringWriter buffer, boolean prefixDot, String functionName) {/*from w ww .j a v a2 s. com*/ String delimiterOuter = ""; if (prefixDot) { delimiterOuter = "."; } boolean isFirst = true; for (ExprChainedSpec element : chainSpec) { buffer.append(delimiterOuter); if (functionName != null) { buffer.append(functionName); } else { buffer.append(element.getName()); } // the first item without dot-prefix and empty parameters should not be appended with parenthesis if (!isFirst || prefixDot || !element.getParameters().isEmpty()) { toExpressionStringIncludeParen(element.getParameters(), buffer); } delimiterOuter = "."; isFirst = false; } }
From source file:de.mpg.mpdl.inge.cone.util.TreeFragment.java
/** * {@inheritDoc}/*w w w. ja v a2s . c o m*/ */ public String toRdf(Model model) { if (size() == 0) { try { return StringEscapeUtils .escapeXml10(PropertyReader.getProperty("escidoc.cone.service.url") + subject); } catch (Exception e) { throw new RuntimeException(e); } } else { StringWriter result = new StringWriter(); Map<String, String> namespaces = new HashMap<String, String>(); ModelList modelList; try { modelList = ModelList.getInstance(); } catch (Exception e) { throw new RuntimeException(e); } int counter = 0; result.append("<" + (model.getRdfAboutTag().getPrefix() != null ? model.getRdfAboutTag().getPrefix() + ":" : "") + model.getRdfAboutTag().getLocalPart()); if (!subject.startsWith("genid:")) { try { result.append(" rdf:about=\""); result.append(PropertyReader.getProperty("escidoc.cone.service.url") + subject); result.append("\""); } catch (Exception e) { throw new RuntimeException(e); } } if (language != null && !"".equals(language)) { result.append(" xml:lang=\""); result.append(language); result.append("\""); } for (String predicate : keySet()) { Matcher matcher = NAMESPACE_PATTERN.matcher(predicate); if (matcher.find()) { String namespace = matcher.group(1) + (matcher.group(3) == null ? "" : matcher.group(3)); if (!namespaces.containsKey(namespace)) { String prefix; if (modelList.getDefaultNamepaces().containsKey(namespace)) { prefix = modelList.getDefaultNamepaces().get(namespace); } else { counter++; prefix = "ns" + counter; } namespaces.put(namespace, prefix); result.append(" xmlns:" + prefix + "=\"" + namespace + "\""); } } } result.append(">\n"); for (String predicate : keySet()) { Matcher matcher = NAMESPACE_PATTERN.matcher(predicate); String namespace = null; String tagName = null; String prefix = null; if (matcher.find()) { namespace = matcher.group(1) + (matcher.group(3) == null ? "" : matcher.group(3)); prefix = namespaces.get(namespace); tagName = matcher.group(4); } else { int lastColon = predicate.lastIndexOf(":"); tagName = predicate.substring(lastColon + 1); } List<LocalizedTripleObject> values = get(predicate); for (LocalizedTripleObject value : values) { result.append("<"); if (namespace != null) { result.append(prefix); result.append(":"); } result.append(tagName); if (value.getLanguage() != null && !"".equals(value.getLanguage())) { result.append(" xml:lang=\""); result.append(value.getLanguage()); result.append("\""); } Predicate p = model.getPredicate(predicate); // display links to other resources as rdf:resource attribute, if includeResource is false if (p != null && p.getResourceModel() != null && !p.isIncludeResource()) { String url = value.toString(); if (!(url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp:"))) { try { if (value.toString().startsWith("/")) { url = PropertyReader.getProperty("escidoc.cone.service.url") + url.substring(0, url.length() - 1); } else { url = PropertyReader.getProperty("escidoc.cone.service.url") + url; } } catch (Exception e) { throw new RuntimeException(e); } } result.append(" rdf:resource=\"" + url + "\"/>"); } else { result.append(">"); result.append(value.toRdf(model)); result.append("</"); if (namespace != null) { result.append(prefix); result.append(":"); } result.append(tagName); result.append(">\n"); } } } result.append("</" + (model.getRdfAboutTag().getPrefix() != null ? model.getRdfAboutTag().getPrefix() + ":" : "") + model.getRdfAboutTag().getLocalPart() + ">\n"); return result.toString(); } }
From source file:de.mpg.escidoc.services.cone.util.TreeFragment.java
/** * {@inheritDoc}//from w ww.ja v a 2s . c o m */ public String toRdf(Model model) { if (size() == 0) { try { return StringEscapeUtils .escapeXml10(PropertyReader.getProperty("escidoc.cone.service.url") + subject); } catch (Exception e) { throw new RuntimeException(e); } } else { StringWriter result = new StringWriter(); Map<String, String> namespaces = new HashMap<String, String>(); ModelList modelList; try { modelList = ModelList.getInstance(); } catch (Exception e) { throw new RuntimeException(e); } int counter = 0; result.append("<" + (model.getRdfAboutTag().getPrefix() != null ? model.getRdfAboutTag().getPrefix() + ":" : "") + model.getRdfAboutTag().getLocalPart()); if (!subject.startsWith("genid:")) { try { result.append(" rdf:about=\""); result.append(PropertyReader.getProperty("escidoc.cone.service.url") + subject); result.append("\""); } catch (Exception e) { throw new RuntimeException(e); } } if (language != null && !"".equals(language)) { result.append(" xml:lang=\""); result.append(language); result.append("\""); } for (String predicate : keySet()) { Matcher matcher = NAMESPACE_PATTERN.matcher(predicate); if (matcher.find()) { String namespace = matcher.group(1) + (matcher.group(3) == null ? "" : matcher.group(3)); if (!namespaces.containsKey(namespace)) { String prefix; if (modelList.getDefaultNamepaces().containsKey(namespace)) { prefix = modelList.getDefaultNamepaces().get(namespace); } else { counter++; prefix = "ns" + counter; } namespaces.put(namespace, prefix); result.append(" xmlns:" + prefix + "=\"" + namespace + "\""); } } } result.append(">\n"); for (String predicate : keySet()) { Matcher matcher = NAMESPACE_PATTERN.matcher(predicate); String namespace = null; String tagName = null; String prefix = null; if (matcher.find()) { namespace = matcher.group(1) + (matcher.group(3) == null ? "" : matcher.group(3)); prefix = namespaces.get(namespace); tagName = matcher.group(4); } else { int lastColon = predicate.lastIndexOf(":"); tagName = predicate.substring(lastColon + 1); } List<LocalizedTripleObject> values = get(predicate); for (LocalizedTripleObject value : values) { result.append("<"); if (namespace != null) { result.append(prefix); result.append(":"); } result.append(tagName); if (value.getLanguage() != null && !"".equals(value.getLanguage())) { result.append(" xml:lang=\""); result.append(value.getLanguage()); result.append("\""); } Predicate p = model.getPredicate(predicate); //display links to other resources as rdf:resource attribute, if includeResource is false if (p != null && p.getResourceModel() != null && !p.isIncludeResource()) { String url = value.toString(); if (!(url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp:"))) { try { if (value.toString().startsWith("/")) { url = PropertyReader.getProperty("escidoc.cone.service.url") + url.substring(0, url.length() - 1); } else { url = PropertyReader.getProperty("escidoc.cone.service.url") + url; } } catch (Exception e) { throw new RuntimeException(e); } } result.append(" rdf:resource=\"" + url + "\"/>"); } else { result.append(">"); result.append(value.toRdf(model)); result.append("</"); if (namespace != null) { result.append(prefix); result.append(":"); } result.append(tagName); result.append(">\n"); } } } result.append("</" + (model.getRdfAboutTag().getPrefix() != null ? model.getRdfAboutTag().getPrefix() + ":" : "") + model.getRdfAboutTag().getLocalPart() + ">\n"); return result.toString(); } }
From source file:uk.ac.liverpool.narrative.SolutionGraph.java
public void validatePlans() throws IOException, InterruptedException, URISyntaxException { int n = 0;//from ww w .j av a 2 s . c o m for (Solution s : solutions) { n++; File tempPlan = File.createTempFile("plan", ".plan"); FileWriter fw = new FileWriter(tempPlan); for (Action a : s.actions) { fw.write("(" + a + ")\n"); } fw.close(); ProcessBuilder pb; File domain = new File(s.domain); File problem = new File(s.problem); File val = new File("validate");// pb = new ProcessBuilder(val.getAbsolutePath(), domain.getAbsolutePath(), problem.getAbsolutePath(), tempPlan.getAbsolutePath()); pb.redirectErrorStream(true); Process p = pb.start(); InputStream io = p.getInputStream(); StringWriter sw = new StringWriter(); int i; while ((i = io.read()) != -1) { sw.append((char) i); } p.waitFor(); if (!sw.toString().contains("Plan valid")) { System.out.println(sw.toString()); } else { System.out.println("Plan valid " + n); } } }
From source file:org.zaproxy.zap.extension.ascan.ScriptsActiveScanner.java
@Override public void scan() { if (this.getExtension() == null) { return;/*from w ww. jav a 2 s . co m*/ } List<ScriptWrapper> scripts = this.getExtension().getScripts(ExtensionActiveScan.SCRIPT_TYPE_ACTIVE); for (Iterator<ScriptWrapper> it = scripts.iterator(); it.hasNext() && !isStop();) { ScriptWrapper script = it.next(); StringWriter writer = new StringWriter(); try { if (script.isEnabled()) { // Note that 'old' scripts may not implement the scan() method, so just ignore them ActiveScript2 s = extension.getInterface(script, ActiveScript2.class); if (s != null) { HttpMessage msg = this.getNewMsg(); logger.debug("Calling script " + script.getName() + " scanNode for " + msg.getRequestHeader().getURI()); s.scanNode(this, msg); } } } catch (Exception e) { writer.append(e.toString()); extension.setError(script, e); extension.setEnabled(script, false); } } if (!isStop()) { super.scan(); } }
From source file:org.overture.codegen.vdm2java.JavaFormat.java
public String formatArgs(List<? extends SExpCG> exps) throws AnalysisException { StringWriter writer = new StringWriter(); if (exps.size() <= 0) { return ""; }/*from www . j av a2s .co m*/ SExpCG firstExp = exps.get(0); writer.append(format(firstExp)); for (int i = 1; i < exps.size(); i++) { SExpCG exp = exps.get(i); writer.append(", " + format(exp)); } return writer.toString(); }