public class DbXmlXsl extends HttpServlet
DbXmlXsl
provides a server side engine for processing
a variety of XML/XSL tasks based on a SQL db query, or a saved XML file. The XSL processing syntax assumes the Xalan package from xml.apache.org.
All funtional options are accessible via the parameters passed to it.
The db SQL to XML extraction is provided by the GNU DB2XML library of Java classes. This servlet has the following capabilities:
text/xml
http://servername/DbXmlXsl?parameterListwhere parameter list is a list of acceptable servlet parameter name value pairs separated by the & character.
/DbXmlXsl?xslURL=http://yoururl&xmlURL=http://yoururl&xslTransform=true
Modifier and Type | Field and Description |
---|---|
private static String |
db2XmlPropFile_ |
(package private) String |
DEFAULT_XSL_STYLESHEET_URL
The Default XSL template to use (in the form of a URL)
|
private boolean |
dumpDebug_ |
private String |
fileBaseDir_
Description of the Field
|
private db2xml.xml.JDBCXML |
jx_
Description of the Field
|
private static db2xml.util.JDBCXMLProperties |
map_
Description of the Field
|
private String |
myHost_
This Servers Host Internet Address.
|
private String |
myPort_
This Servers Host port.
|
private String |
servletUrlStr_
The URL of this servlet
|
private static String |
SYSTEM_FILE_SEPERATOR
A holder for this Servers System File Separator.
|
String |
usageHtml_ |
private String |
xmlFileOutputDir_
Description of the Field
|
private String |
xmlFileOutputName_
Description of the Field
|
Constructor and Description |
---|
DbXmlXsl() |
Modifier and Type | Method and Description |
---|---|
String |
convertSystemDependantPath(URL url)
Converts the path component of a URL to the native relative file path.
|
static String |
createCurrentTimeStamp()
Creates a timestamp for the current time in the form of 'hour + "-" + min +
"-" + sec + "-" + millis'.
|
static db2xml.xml.XMLDocument |
db2XmlDocument(String sqlStatement)
A method to generate an XML Document based on the result set from an
SQL query on a the default db and username.
|
static db2xml.xml.XMLDocument |
db2XmlDocument(String sqlStatement,
db2xml.util.JDBCXMLProperties map)
A method to generate an XML Document based on the result set from an
SQL query on a the default db and username.
|
static db2xml.xml.XMLDocument |
db2XmlDocument(String jdbcDriverClass,
String jdbcUrl,
String jdbcUser,
String jdbcUserPassword,
String sqlStatement)
A method to generate an XML Document based on the result set from an SQL query
on a db.
|
void |
doGet(HttpServletRequest req,
HttpServletResponse res)
Performs the HTTP GET operation.
|
void |
doPost(HttpServletRequest req,
HttpServletResponse res)
Handles Post Requests by simply calling the doGet Method.
|
static void |
doTransform(InputStream xmlStream,
InputStream xslStream,
OutputStream outStream,
Hashtable params)
Performs the XSL transform on the XML.
|
static void |
doTransform(InputStream xmlStream,
InputStream xslStream,
PrintWriter outWriter,
Hashtable params)
Performs the XSL transform on the XML.
|
static void |
doTransform(URL xmlUrl,
URL xslUrl,
PrintWriter outWriter,
Hashtable params)
Performs the XSL transform on the XML.
|
void |
init(ServletConfig config)
Initializes the servlet and loads some db2xml init data.
|
private URL |
parseIntoUrl(String value)
Parses a String representation of a URL or absolute file path and converts
it into a URL.
|
static void |
writeXmlFile(String xmlFilename,
db2xml.xml.XMLDocument xmlDoc)
Writes the passed in XMLDocument to the specified XML file.
|
static void |
writeXmlFile(String xmlFilename,
db2xml.xml.XMLDocument xmlDoc,
db2xml.util.JDBCXMLProperties map)
Writes the passed in XMLDocument to the specified XML file.
|
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
String DEFAULT_XSL_STYLESHEET_URL
private static final String SYSTEM_FILE_SEPERATOR
private db2xml.xml.JDBCXML jx_
private static db2xml.util.JDBCXMLProperties map_
private static String db2XmlPropFile_
private String xmlFileOutputName_
private String xmlFileOutputDir_
private String fileBaseDir_
private String servletUrlStr_
private boolean dumpDebug_
public String usageHtml_
public DbXmlXsl()
public static String createCurrentTimeStamp()
public void init(ServletConfig config) throws ServletException
db2xml.properties
if an Servlet Init Parm - 'db2XmlPropFile' was not specified. This default
file must be placed in a server config directory or other suitable directory.init
in interface Servlet
init
in class GenericServlet
config
- servlet configuration informationServletException
- if an error occured during initializationpublic static db2xml.xml.XMLDocument db2XmlDocument(String jdbcDriverClass, String jdbcUrl, String jdbcUser, String jdbcUserPassword, String sqlStatement) throws db2xml.util.DB2XMLException
jdbcDriverClass
- the DriverClass name to override the defaultsjdbcUrl
- the URL name to override the defaultsjdbcUser
- the User name to override the defaultsjdbcUserPassword
- the Password to override the defaultssqlStatement
- the SQL to executedb2xml.util.DB2XMLException
public static db2xml.xml.XMLDocument db2XmlDocument(String sqlStatement) throws db2xml.util.DB2XMLException
sqlStatement
- the SQL to executedb2xml.util.DB2XMLException
public static db2xml.xml.XMLDocument db2XmlDocument(String sqlStatement, db2xml.util.JDBCXMLProperties map) throws db2xml.util.DB2XMLException
sqlStatement
- the SQL to executemap
- The properties map to use for this query.db2xml.util.DB2XMLException
public static void writeXmlFile(String xmlFilename, db2xml.xml.XMLDocument xmlDoc) throws IOException, db2xml.util.DB2XMLException
xmlFilename
- the resultant XMLfilenamexmlDoc
- The XML Documewnt to write outIOException
db2xml.util.DB2XMLException
db2XmlDocument(String)
public static void writeXmlFile(String xmlFilename, db2xml.xml.XMLDocument xmlDoc, db2xml.util.JDBCXMLProperties map) throws IOException, db2xml.util.DB2XMLException
xmlFilename
- the resultant XMLfilenamexmlDoc
- The XML Documewnt to write outmap
- The properties map to use for th DB2XML usage.IOException
db2xml.util.DB2XMLException
public static void doTransform(URL xmlUrl, URL xslUrl, PrintWriter outWriter, Hashtable params) throws IOException, TransformerConfigurationException, TransformerException, IOException, ParserConfigurationException, SAXException
xmlUrl
- The URL for the XML dataxslUrl
- The URL for the XSL dataoutWriter
- The output writer to dump the output from the transformparams
- other parameters to pass directly to the transformIOException
TransformerConfigurationException
TransformerException
ParserConfigurationException
SAXException
public static void doTransform(InputStream xmlStream, InputStream xslStream, OutputStream outStream, Hashtable params) throws TransformerConfigurationException, TransformerException, IOException, ParserConfigurationException, SAXException
xmlStream
- The Stream of XML dataxslStream
- The Stream of XSL dataoutStream
- The Stream to dump the output from the transformparams
- other parameters to pass directly to the transformTransformerConfigurationException
TransformerException
IOException
ParserConfigurationException
SAXException
public static void doTransform(InputStream xmlStream, InputStream xslStream, PrintWriter outWriter, Hashtable params) throws TransformerConfigurationException, TransformerException, IOException, ParserConfigurationException, SAXException
xmlStream
- The Stream of XML dataxslStream
- The Stream of XSL dataoutWriter
- The OutputPrinter to dump the output from the transformparams
- other parameters to pass directly to the transformTransformerConfigurationException
TransformerException
IOException
ParserConfigurationException
SAXException
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
doPost
in class HttpServlet
req
- HttpServletRequest that encapsulates the
request to the servletres
- HttpServletResponse that encapsulates the
response from the servletServletException
- if the request could not be handledIOException
- in case of an write error while handling
requestpublic void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
It provides many options for how things are processed:
doGet
in class HttpServlet
req
- HttpServletRequest that encapsulates the
request to the servlet.res
- HttpServletResponse that encapsulates the
response from the servlet.ServletException
- if the request could not be handled.IOException
- in case of an write error while handling
request.private URL parseIntoUrl(String value) throws MalformedURLException
This method is a bit forgiving... if the string is not a correctlty formatted http, ftp, or file URL it will assume it is a file URL and create the returned URL as such.
value
- is the String to convert into a URL.MalformedURLException
- if the passed in String is not a URLpublic String convertSystemDependantPath(URL url)
the
- url to use to convert.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses