Subject: RE: [xsl] SAX Transformation: Servlet returns blank XSL template From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Thu, 10 Oct 2002 09:16:46 +0100 |
Your SAX filter is using lots of updateable static variables. This means it isn't thread-safe. In fact, it probably isn't even serially re-usable: I don't think drvrCount is ever decremented. Sorry, but I haven't the time, nor is this the right place, to teach you about writing servlets. Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Bruce McDougald > Sent: 09 October 2002 22:30 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: [xsl] SAX Transformation: Servlet returns blank > XSL template > > > > There's a bug in your servlet code, but without seeing the code, I > > can't begin to guess what it is. > > > > Sorry, here is my code. > ------------------------------------ > > public class pipeline extends HttpServlet{ > > public void doGet (HttpServletRequest req, > HttpServletResponse res) > throws ServletException,IOException > { > // Set content type for HTML. > res.setContentType("text/html; charset=UTF-8"); > > OutputStream os = res.getOutputStream(); > > try{ > > TransformerFactory tFactory = TransformerFactory.newInstance(); > > if (tFactory.getFeature(SAXSource.FEATURE) && > tFactory.getFeature(SAXResult.FEATURE)) > { > > XMLReader reader = XMLReaderFactory.createXMLReader(); > > SAXTransformerFactory saxTFactory = > ((SAXTransformerFactory) tFactory); > > XMLFilter xmlFilter1 = new SAXParse(); > > xmlFilter1.setParent(reader); > > XMLFilter xmlFilter2 = > saxTFactory.newXMLFilter(new > StreamSource("http://localhost/taymac.nsf/dynitmact.xsl")); > > // xmlFilter1 uses the XMLReader as its reader. > xmlFilter2.setParent(xmlFilter1); > > // xmlFilter2 outputs SAX events to the serializer. > Serializer serializer = SerializerFactory.getSerializer > > (OutputProperties.getDefaultMethodProperties("xml")); > > serializer.setOutputStream(os); > > xmlFilter2.setContentHandler(serializer.asContentHandler()); > xmlFilter2.parse(new > InputSource("http://localhost/cgi-bin/xmlbldr.pl")); > > os.flush(); > os.close(); > } > > }catch (Exception e){ > e.printStackTrace(); > } > } > } > > ////////////////////////////////////////////////////////////// > > public class SAXParse extends XMLFilterImpl > { > > String col; > String row; > String drvr; > String root; > String node; > > static boolean rootFlag = false; > static boolean drvrFlag = false; > static boolean colFlag = false; > static boolean rowFlag = false; > > static int drvrCount = 0; > static int colCount = 0; > static int rowCount = 0; > > static int colStart = 85; > static int rowStart = 0; > > static int colLimit = 13; > static int rowLimit = 25; > static int drvrLimit = 3; > > > > //////////////////////////////////////////////////////////////////// > // Event handlers. > > //////////////////////////////////////////////////////////////////// > > public void startElement (String uri, String name, > String qName, Attributes atts) > throws SAXException > { > boolean printIt = false; > node = qName; > > if ( qName.equals( "ITMACT" ) ) { > rootFlag = true; > rowFlag = false; > colFlag = false; > drvrFlag = false; > root = qName; > printIt = true; > } > > if ( qName.equals( "DRIVER" ) ) { > drvrCount++; > rowCount=0; > rowFlag = false; > colFlag = false; > if (drvrCount == drvrLimit){ > drvrFlag = true; > drvr = qName; > printIt = true; > }else{ > drvrFlag = false; > } > } > > if ( drvrFlag && qName.equals("DRVRKEY") ) { > printIt = true; > } > > if (qName.equals("ROW") && drvrFlag){ > rowCount++; > colCount = 0; > colFlag = false; > if ((rowCount >= rowStart) && > (rowCount <= rowStart + rowLimit)){ > rowFlag = true; > row = qName; > printIt = true; > }else{ > rowFlag = false; > } > > } > > if ( qName.equals("ROWKEY") && rowFlag ) { > printIt = true; > } > > if (qName.equals("COLUMN") && rowFlag){ > colCount++; > if ((colCount >= colStart) && > (colCount <= colStart + colLimit)){ > colFlag = true; > col = qName; > printIt = true; > }else{ > colFlag = false; > } > } > > if (( (qName.equals("COLKEY")) || > (qName.equals("CDATA1")) || > (qName.equals("CDATA2")) || > (qName.equals("CDATA3")) ) && colFlag ) { > printIt = true; > } > > if (printIt){ > super.startElement(uri,name,qName,atts); > printIt = false; > } > > } > > > public void endElement (String uri, String name, String qName) > throws SAXException > { > > boolean printIt = false; > > if ( qName.equals("ITMACT") ) { > printIt = true; > } > > if ( drvrFlag && ( (qName.equals("DRIVER"))|| > (qName.equals("DRVRKEY")) )) { > printIt = true; > } > > if ( ((qName.equals("ROW")) || > (qName.equals("ROWKEY"))) && rowFlag ) { > printIt = true; > } > > if (( (qName.equals("COLUMN")) || > (qName.equals("COLKEY")) || > (qName.equals("CDATA1")) || > (qName.equals("CDATA2")) || > (qName.equals("CDATA3"))) && colFlag ) { > printIt = true; > } > > if (printIt){ > super.endElement(uri,name,qName); > printIt = false; > } > > } > > > public void characters (char[] ch, int start, int length) > throws SAXException > { > boolean wFlag = false; > > if(drvrFlag && ( node.equals("DRIVER") || > node.equals("DRVRKEY"))) { wFlag = true;}; > > if(rowFlag && ( node.equals("ROW") || > node.equals("ROWKEY"))) {wFlag = true;}; > > if(colFlag){ wFlag=true; } > > > if(wFlag) { super.characters (ch, start, length); } > } > } > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] SAX Transformation: Servl, Bruce McDougald | Thread | Re: [xsl] SAX Transformation: Servl, Bruce McDougald |
RE: [xsl] Node renaming problem, Michael Kay | Date | RE: [xsl] Using document(), Michael Kay |
Month |