/*     */ public SerializationHandler openOutputHandler(String filename, boolean append)
     /*     */ throws TransletException
       /*     */ {
   /*     */ try
   /*     */ {
     /* 552 */ TransletOutputHandlerFactory factory = TransletOutputHandlerFactory.newInstance();
     /*     */
     /* 555 */ String dirStr = new File(filename).getParent();
     /* 556 */ if ((null != dirStr) && (dirStr.length() > 0)) {
       /* 557 */ File dir = new File(dirStr);
       /* 558 */ dir.mkdirs();
       /*     */ }
     /*     */
     /* 561 */ factory.setEncoding(this._encoding);
     /* 562 */ factory.setOutputMethod(this._method);
     /* 563 */ factory.setOutputStream(
         new BufferedOutputStream(new FileOutputStream(filename, append)));
     /* 564 */ factory.setOutputType(0);
     /*     */
     /* 566 */ SerializationHandler handler = factory.getSerializationHandler();
     /*     */
     /* 569 */ transferOutputSettings(handler);
     /* 570 */ handler.startDocument();
     /* 571 */ return handler;
     /*     */ }
   /*     */ catch (Exception e) {
     /* 574 */ throw new TransletException(e);
     /*     */ }
   /*     */ }
예제 #2
0
 /*     */ private void doTransform() {
   /*     */ try {
     /* 101 */ Class clazz = ObjectFactory.findProviderClass(this._className, true);
     /* 102 */ AbstractTranslet translet = (AbstractTranslet) clazz.newInstance();
     /* 103 */ translet.postInitialization();
     /*     */
     /* 106 */ SAXParserFactory factory = SAXParserFactory.newInstance();
     /*     */ try {
       /* 108 */ factory.setFeature("http://xml.org/sax/features/namespaces", true);
       /*     */ }
     /*     */ catch (Exception e) {
       /* 111 */ factory.setNamespaceAware(true);
       /*     */ }
     /* 113 */ SAXParser parser = factory.newSAXParser();
     /* 114 */ XMLReader reader = parser.getXMLReader();
     /*     */
     /* 117 */ XSLTCDTMManager dtmManager =
         (XSLTCDTMManager) XSLTCDTMManager.getDTMManagerClass().newInstance();
     /*     */ DTMWSFilter wsfilter;
     /*     */ DTMWSFilter wsfilter;
     /* 122 */ if ((translet != null) && ((translet instanceof StripFilter)))
       /* 123 */ wsfilter = new DOMWSFilter(translet);
     /*     */ else {
       /* 125 */ wsfilter = null;
       /*     */ }
     /*     */
     /* 128 */ DOMEnhancedForDTM dom =
         (DOMEnhancedForDTM)
             dtmManager.getDTM(
                 new SAXSource(reader, new InputSource(this._fileName)),
                 false,
                 wsfilter,
                 true,
                 false,
                 translet.hasIdCall());
     /*     */
     /* 133 */ dom.setDocumentURI(this._fileName);
     /* 134 */ translet.prepassDocument(dom);
     /*     */
     /* 137 */ int n = this._params.size();
     /* 138 */ for (int i = 0; i < n; i++) {
       /* 139 */ Parameter param = (Parameter) this._params.elementAt(i);
       /* 140 */ translet.addParameter(param._name, param._value);
       /*     */ }
     /*     */
     /* 144 */ TransletOutputHandlerFactory tohFactory =
         TransletOutputHandlerFactory.newInstance();
     /*     */
     /* 146 */ tohFactory.setOutputType(0);
     /* 147 */ tohFactory.setEncoding(translet._encoding);
     /* 148 */ tohFactory.setOutputMethod(translet._method);
     /*     */
     /* 150 */ if (this._iterations == -1) {
       /* 151 */ translet.transform(dom, tohFactory.getSerializationHandler());
       /*     */ }
     /* 153 */ else if (this._iterations > 0) {
       /* 154 */ long mm = System.currentTimeMillis();
       /* 155 */ for (int i = 0; i < this._iterations; i++) {
         /* 156 */ translet.transform(dom, tohFactory.getSerializationHandler());
         /*     */ }
       /*     */
       /* 159 */ mm = System.currentTimeMillis() - mm;
       /*     */
       /* 161 */ System.err.println("\n<!--");
       /* 162 */ System.err.println("  transform  = " + mm / this._iterations + " ms");
       /*     */
       /* 165 */ System.err.println(
           "  throughput = " + 1000.0D / (mm / this._iterations) + " tps");
       /*     */
       /* 169 */ System.err.println("-->");
       /*     */ }
     /*     */ }
   /*     */ catch (TransletException e) {
     /* 173 */ if (this._debug) e.printStackTrace();
     /* 174 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + e.getMessage());
     /*     */ }
   /*     */ catch (RuntimeException e)
   /*     */ {
     /* 178 */ if (this._debug) e.printStackTrace();
     /* 179 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + e.getMessage());
     /*     */ }
   /*     */ catch (FileNotFoundException e)
   /*     */ {
     /* 183 */ if (this._debug) e.printStackTrace();
     /* 184 */ ErrorMsg err = new ErrorMsg("FILE_NOT_FOUND_ERR", this._fileName);
     /* 185 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + err.toString());
     /*     */ }
   /*     */ catch (MalformedURLException e)
   /*     */ {
     /* 189 */ if (this._debug) e.printStackTrace();
     /* 190 */ ErrorMsg err = new ErrorMsg("INVALID_URI_ERR", this._fileName);
     /* 191 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + err.toString());
     /*     */ }
   /*     */ catch (ClassNotFoundException e)
   /*     */ {
     /* 195 */ if (this._debug) e.printStackTrace();
     /* 196 */ ErrorMsg err = new ErrorMsg("CLASS_NOT_FOUND_ERR", this._className);
     /* 197 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + err.toString());
     /*     */ }
   /*     */ catch (UnknownHostException e)
   /*     */ {
     /* 201 */ if (this._debug) e.printStackTrace();
     /* 202 */ ErrorMsg err = new ErrorMsg("INVALID_URI_ERR", this._fileName);
     /* 203 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + err.toString());
     /*     */ }
   /*     */ catch (SAXException e)
   /*     */ {
     /* 207 */ Exception ex = e.getException();
     /* 208 */ if (this._debug) {
       /* 209 */ if (ex != null) ex.printStackTrace();
       /* 210 */ e.printStackTrace();
       /*     */ }
     /* 212 */ System.err.print(new ErrorMsg("RUNTIME_ERROR_KEY"));
     /* 213 */ if (ex != null) /* 214 */ System.err.println(ex.getMessage());
     /*     */ else /* 216 */ System.err.println(e.getMessage());
     /*     */ }
   /*     */ catch (Exception e) {
     /* 219 */ if (this._debug) e.printStackTrace();
     /* 220 */ System.err.println(new ErrorMsg("RUNTIME_ERROR_KEY") + e.getMessage());
     /*     */ }
   /*     */ }