Title: XML-XSL Wrapper f
1XML-XSL Wrapper für Javader Prototyp
- XXWrapper
- ParserTest
- PicOut
- xslFile.xsl
- xmlFile.xml
2- public class XXWrapper
-
- private final static String PARSER_CLASS
"com.jclark.xml.sax.Driver" - StringWriter XMLWriternull
- String stylesheet""
-
- public XXWrapper(String stylesheet, StringWriter
XMLWriter) - this.stylesheetstylesheet
- this.XMLWriterXMLWriter
-
-
- public String parse() throws ServletException,
IOException -
- XSLProcessor xslProcessor createXSLProcessor(
stylesheet) - StringReader reader new StringReader(XMLWrite
r.toString()) - File temp transformAndWrite(xslProcessor,read
er) - return setFileToString(temp)
-
-
- XXWrapper
- ParserTest
- PicOut
- xslFile.xsl
- xmlFile.xml
3 protected XSLProcessor createXSLProcessor(Stri
ng url) throws ServletException,
IOException Parser parser null
try Class clasz
Class.forName(PARSER_CLASS) parser
(Parser)clasz.newInstance()
catch(ClassNotFoundException e)
throw new ServletException(e.toString())
catch(InstantiationException e)
throw new ServletException(e.toString())
catch(IllegalAccessException e)
throw new ServletException(e.toString(
)) XSLProcessor xslProcessor new
XSLProcessorImpl() xslProcessor.setParse
r(parser) Reader XSLReader new
FileReader(url) InputSource inputSource new
InputSource(XSLReader) try
xslProcessor.loadStylesheet(inputSource)
catch (SAXException e)
throw new ServletException(e.toString())
return xslProcessor
- XXWrapper
- ParserTest
- PicOut
- xslFile.xsl
- xmlFile.xml
4protected File transformAndWrite(XSLProcessor
xslProcessor, Reader reader) throws
ServletException, IOException
OutputMethodHandlerImpl outputMethodHandler new
OutputMethodHandlerImpl(xslProcessor)
xslProcessor.setOutputMethodHandler(outputMethodHa
ndler) File temp File.createTempFile("xxw
rapper", ".tmp") outputMethodHandler.setDes
tination(new FileDestination(temp)) try
xslProcessor.parse(new
InputSource(reader)) catch (Exception
e) throw new ServletException(e.toS
tring()) return temp
- XXWrapper
- ParserTest
- PicOut
- xslFile.xsl
- xmlFile.xml
5- public class ParserTest extends HttpServlet
-
- StringWriter XMLWriternull
- String output ""
-
- public void doGet(HttpServletRequest request,
HttpServletResponse response) - throws ServletException, IOException
-
- response.setContentType("text/html")
- PrintWriter writer
response.getWriter() - XMLWriter new StringWriter()
- try
-
- setXMLData(new File("/home/httpd/htdocs/servle
ts/" - "de/wpp/xml/xmlFile.xml"), XMLWriter)
-
- catch (Exception ioe)
-
- log(ioe.toString())
- XXWrapper
- ParserTest
- PicOut
- xslFile.xsl
- xmlFile.xml
6public class PicOut extends HttpServlet
protected void doGet(HttpServletRequest
request,HttpServletResponse response) throws
ServletException,IOException
PrintWriter writerresponse.getWriter()
response.setContentType("image/gif") try
int bufferSize65535 File
pic new File(request.getParameter("filename"))
InputStreamReader picStream
new InputStreamReader(new FileInputStream(pic))
char buf new charbufferSize
long sizepic.length() while (sizegt0)
if (sizeltbufferSize) bufferSize(int)siz
e int bpicStream.read(buf,0,bufferSize)
writer.write(buf,0,bufferSize)
sizesize-bufferSize
picStream.close()
catch (IOException e)
writer.println("Bild nicht gefunden")
writer.close()
- XXWrapper
- ParserTest
- PicOut
- xslFile.xsl
- xmlFile.xml
7lt?xml version"1.0" encoding"ISO-8859-1"?gt ltxsls
tylesheet xmlnsxsl"http//www.w3.org/1999/XSL/Tr
ansform" version"1.0"
xmlns"http//www.w3.org/TR/REC-html40"
result-ns""gt ltxsloutput method"html"/gt ltxsltem
plate match"/"gt ltHTMLgtltHEADgt
ltTITLEgtXML/XSL-Testseitelt/TITLEgt ltlink
rel"stylesheet" type"text/css"
href"http//139.6.67.191/hebtyp/hebtyp.css"/gt
lt/HEADgt ltBODY bgcolor"ffffff"gt ltdiv
align"center"gtltfont size"6"gtXML/XSL
Testlt/fontgtltbr/gtltbr/gt lttable width"90"
border"0"gt lttrgtlttd colspan"5"gtHier
werden einige Daten mit Hilfe der
XSL/XML-Technologie dargestellt. Etwas Text und
dann auch einige GIFs.ltbr/gt ltbr/gt
lt/tdgtlt/trgt ltxslfor-each
select"liste/item"gt ltTRgt
ltTD bgcolor"dddddd"gtltxslvalue-of
select"vorname"/gt lt/TDgt ltTD
bgcolor"dddddd"gtltxslvalue-of select"name"/gt
lt/TDgt ltTD bgcolor"dddddd"gtltagtltxslat
tribute name"href"gtmailtoltxslvalue-of
select"email"/gt lt/xslattributegt
ltxslvalue-of select"email"/gt lt/agtlt/TDgt
ltTD bgcolor"dddddd"gtltagtltxslattribute
name"href"gt ltxslvalue-of select"homepage"/gt
lt/xslattributegt ltxslvalue-of
select"homepage"/gt lt/agtlt/TDgt ltTD
bgcolor"dddddd"gtltimggtltxslattribute name"src"gt
http//139.6.67.191/servlets/de.wpp.xml.PicOut?fi
lenameltxslvalue-of select"image"/gt
lt/xslattributegtlt/imggtlt/TDgt lt/TRgt
lt/xslfor-eachgt lt/tablegtltbr/gtltbr/gt(c)
SoeBa Inc.lt/divgtlt/BODYgtlt/HTMLgt lt/xsltemplategt lt/x
slstylesheetgt
- XXWrapper
- ParserTest
- PicOut
- xslFile.xsl
- xmlFile.xml
8lt?xml version"1.0" encoding"ISO-8859-1"?gt ltliste
gt ltitem id"1"gt ltvornamegtNicolelt/vornamegt ltnamegt
Bachnerlt/namegt ltemailgtbachner_at_at12.delt/emailgt
lthomepagegthttp//www.need-speed.delt/homepag
egt ltimagegt/home/httpd/htdocs/chet.giflt/imagegt lt/i
temgt ltitem id"2"gt ltvornamegtMichaellt/vornamegt ltn
amegtSoemerslt/namegt ltemailgtmichael_at_soemers.delt/ema
ilgt lthomepagegthttp//www.soemers.delt/home
pagegt ltimagegt/home/httpd/htdocs/bet.giflt/imagegt lt
/itemgt ltitem id"3"gt ltvornamegtMagnuslt/vornamegt lt
namegtPaprottalt/namegt ltemailgtmagnus_paprotta_at_gmx.d
elt/emailgt lthomepagegthttp//www.gm.fh-koel
n.de/ia194lt/homepagegt ltimagegt/home/httpd/htdocs/
ajin.giflt/imagegt lt/itemgt lt/listegt
- XXWrapper
- ParserTest
- PicOut
- xslFile.xsl
- xmlFile.xml