private void validateDTD() throws InvalidWorkflowDescriptorException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); StringWriter sw = new StringWriter(); PrintWriter writer = new PrintWriter(sw); writer.println(XML_HEADER); writer.println(DOCTYPE_DECL); writeXML(writer, 0); WorkflowLoader.AllExceptionsErrorHandler errorHandler = new WorkflowLoader.AllExceptionsErrorHandler(); try { DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver(new DTDEntityResolver()); db.setErrorHandler(errorHandler); db.parse(new InputSource(new StringReader(sw.toString()))); if (errorHandler.getExceptions().size() > 0) { throw new InvalidWorkflowDescriptorException(errorHandler.getExceptions().toString()); } } catch (InvalidWorkflowDescriptorException e) { throw e; } catch (Exception e) { throw new InvalidWorkflowDescriptorException(e.toString()); } }
public boolean save(File file, String options) { PrintWriter writer = PApplet.createWriter(file); boolean result = write(writer); writer.flush(); writer.close(); return result; }
/** Utility method to serialize an exception and its stack trace to simple HTML. */ private final void serializeException(PrintWriter osw, Throwable t) { osw.write("<b>Exception</b>: " + t.toString() + "\n<br/><br/>"); osw.write("<b>Stack trace:</b>"); osw.write( "<pre style=\"margin: 1px solid red; padding: 3px; font-family: sans-serif; font-size: small;\">"); t.printStackTrace(osw); osw.write("</pre>"); }
/** * ** Encodes the specified DBRecordKyes into XML and writes it to ** a specified PrintWriter * ** @param out The PrintWriter ** @param dbrk The list of DBRecordKeys */ public static void printXML(PrintWriter out, DBRecordKey... dbrk) { if (out != null) { out.write("<" + DBFactory.TAG_RecordKeys + ">\n"); for (int i = 0; i < dbrk.length; i++) { dbrk[i].printXML(out, 4); } out.write("</" + DBFactory.TAG_RecordKeys + ">\n"); out.flush(); } }
/** * Attempts to send an internal server error HTTP error, if possible. Otherwise simply pushes the * exception message to the output stream. * * @param message Message to be printed to the logger and to the output stream. * @param t Exception that caused the error. */ protected void filterError(String message, Throwable t) { log.error("XSLT filter error: " + message, t); if (false == origResponse.isCommitted()) { // Reset the buffer and previous status code. origResponse.reset(); origResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); origResponse.setContentType("text/html; charset=UTF-8"); } // Response committed. Just push the error to the output stream. try { final OutputStream os = origResponse.getOutputStream(); final PrintWriter osw = new PrintWriter(new OutputStreamWriter(os, "iso8859-1")); osw.write("<html><body><!-- " + XSLTFilterConstants.ERROR_TOKEN + " -->"); osw.write("<h1 style=\"color: red; margin-top: 1em;\">"); osw.write("Internal server exception"); osw.write("</h1>"); osw.write("<b>URI</b>: " + origRequest.getRequestURI() + "\n<br/><br/>"); serializeException(osw, t); if (t instanceof ServletException && ((ServletException) t).getRootCause() != null) { osw.write("<br/><br/><h2>ServletException root cause:</h2>"); serializeException(osw, ((ServletException) t).getRootCause()); } osw.write("</body></html>"); osw.flush(); } catch (IOException e) { // Not much to do in such case (connection broken most likely). log.debug("Filter error could not be returned to client."); } }
/** * Makes a XML text representation. * * @param buffer */ public void makeTextElement(PrintWriter buffer) { int size; String prefix = rNSContext_.getPrefixByUri("http://www.asahi-net.or.jp/~cs8k-cyu/bulletml"); buffer.print("<"); URelaxer.makeQName(prefix, "direction", buffer); rNSContext_.makeNSMappings(buffer); if (type_ != null) { buffer.print(" "); buffer.print("type"); buffer.print("=\""); buffer.print(URelaxer.escapeAttrQuot(getType())); buffer.print("\""); } buffer.print(">"); buffer.print("</"); URelaxer.makeQName(prefix, "direction", buffer); buffer.print(">"); }
/** * This method must be invoked at the end of processing. The streams are closed and their content * is analyzed. Actual XSLT processing takes place here. */ @SuppressWarnings("unchecked") void finishResponse() throws IOException { if (writer != null) { writer.close(); } else { if (stream != null) stream.close(); } /* * If we're not in passthrough mode, then we need to finalize XSLT transformation. */ if (false == passthrough) { if (stream != null) { final byte[] bytes = ((DeferredOutputStream) stream).getBytes(); final boolean processingSuppressed = (origRequest.getAttribute(XSLTFilterConstants.NO_XSLT_PROCESSING) != null) | (origRequest.getParameter(XSLTFilterConstants.NO_XSLT_PROCESSING) != null); if (processingSuppressed) { // Just copy the buffered data to the output directly. final OutputStream os = origResponse.getOutputStream(); os.write(bytes); os.close(); } else { // Otherwise apply XSLT transformation to it. try { processWithXslt( bytes, (Map<String, Object>) origRequest.getAttribute(XSLTFilterConstants.XSLT_PARAMS_MAP), origResponse); } catch (TransformerException e) { final Throwable t = unwrapCause(e); if (t instanceof IOException) { throw (IOException) t; } filterError("Error applying stylesheet.", e); } } } } }
private void saveStartProjects(File file) throws IOException { Calendar cal = Calendar.getInstance(); try (PrintWriter out = new PrintWriter(file, "windows-1251")) { for (Region region : this.regions) { cal.setTime(region.start); out.write("\""); out.write(region.filial + " " + region.name); out.write("\";;;"); int skeepCells = (cal.get(Calendar.YEAR) - 2017) * 5 + (cal.get(Calendar.MONDAY) % 4); for (int i = 0; i < skeepCells; i++) { out.write(";"); } out.println("X"); } } }
/** * ** Encodes this DBRecordKey into XML and writes it to a specified PrintWriter ** @param out The * PrintWriter ** @param indent The number of spaces to indent ** @param sequence Optional * sequence value ** @param soapXML True for SOAP XML */ public void printXML(PrintWriter out, int indent, int sequence, boolean soapXML) { if (out != null) { out.write(this.toXML(null, indent, sequence, soapXML).toString()); out.flush(); } }
public void writeXML(PrintWriter out, int indent) { XMLUtil.printIndent(out, indent++); out.println("<workflow>"); Iterator iter = metaAttributes.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); XMLUtil.printIndent(out, indent); out.print("<meta name=\""); out.print(XMLUtil.encode(entry.getKey())); out.print("\">"); out.print(XMLUtil.encode(entry.getValue())); out.println("</meta>"); } if (registers.size() > 0) { XMLUtil.printIndent(out, indent++); out.println("<registers>"); for (int i = 0; i < registers.size(); i++) { RegisterDescriptor register = (RegisterDescriptor) registers.get(i); register.writeXML(out, indent); } XMLUtil.printIndent(out, --indent); out.println("</registers>"); } if (timerFunctions.size() > 0) { XMLUtil.printIndent(out, indent++); out.println("<trigger-functions>"); Iterator iterator = timerFunctions.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry) iterator.next(); XMLUtil.printIndent(out, indent++); out.println("<trigger-function id=\"" + entry.getKey() + "\">"); FunctionDescriptor trigger = (FunctionDescriptor) entry.getValue(); trigger.writeXML(out, indent); XMLUtil.printIndent(out, --indent); out.println("</trigger-function>"); } while (iterator.hasNext()) {} XMLUtil.printIndent(out, --indent); out.println("</trigger-functions>"); } if (getGlobalConditions() != null) { XMLUtil.printIndent(out, indent++); out.println("<global-conditions>"); getGlobalConditions().writeXML(out, indent); out.println("</global-conditions>"); } XMLUtil.printIndent(out, indent++); out.println("<initial-actions>"); for (int i = 0; i < initialActions.size(); i++) { ActionDescriptor action = (ActionDescriptor) initialActions.get(i); action.writeXML(out, indent); } XMLUtil.printIndent(out, --indent); out.println("</initial-actions>"); if (globalActions.size() > 0) { XMLUtil.printIndent(out, indent++); out.println("<global-actions>"); for (int i = 0; i < globalActions.size(); i++) { ActionDescriptor action = (ActionDescriptor) globalActions.get(i); action.writeXML(out, indent); } XMLUtil.printIndent(out, --indent); out.println("</global-actions>"); } if (commonActions.size() > 0) { XMLUtil.printIndent(out, indent++); out.println("<common-actions>"); Iterator iterator = getCommonActions().values().iterator(); while (iterator.hasNext()) { ActionDescriptor action = (ActionDescriptor) iterator.next(); action.writeXML(out, indent); } XMLUtil.printIndent(out, --indent); out.println("</common-actions>"); } XMLUtil.printIndent(out, indent++); out.println("<steps>"); for (int i = 0; i < steps.size(); i++) { StepDescriptor step = (StepDescriptor) steps.get(i); step.writeXML(out, indent); } XMLUtil.printIndent(out, --indent); out.println("</steps>"); if (splits.size() > 0) { XMLUtil.printIndent(out, indent++); out.println("<splits>"); for (int i = 0; i < splits.size(); i++) { SplitDescriptor split = (SplitDescriptor) splits.get(i); split.writeXML(out, indent); } XMLUtil.printIndent(out, --indent); out.println("</splits>"); } if (joins.size() > 0) { XMLUtil.printIndent(out, indent++); out.println("<joins>"); for (int i = 0; i < joins.size(); i++) { JoinDescriptor join = (JoinDescriptor) joins.get(i); join.writeXML(out, indent); } XMLUtil.printIndent(out, --indent); out.println("</joins>"); } XMLUtil.printIndent(out, --indent); out.println("</workflow>"); }
// Sends this object and its kids to a Writer with an indent of 2 spaces, // including the declaration at the top so that the output will be valid XML. public boolean write(PrintWriter output) { output.print(format(2)); output.flush(); return true; }