33 |
33 |
import java.io.IOException;
|
34 |
34 |
import java.io.OutputStreamWriter;
|
35 |
35 |
import java.io.StringReader;
|
36 |
|
import java.io.StringWriter;
|
37 |
36 |
import java.io.Writer;
|
38 |
37 |
import java.sql.SQLException;
|
39 |
38 |
import java.util.Enumeration;
|
... | ... | |
66 |
65 |
*/
|
67 |
66 |
public class DBTransform {
|
68 |
67 |
|
69 |
|
// private Connection conn = null;
|
70 |
|
// private MetacatUtil util = null;
|
|
68 |
|
71 |
69 |
private String configDir = null;
|
72 |
70 |
private String defaultStyle = null;
|
73 |
71 |
private Logger logMetacat = Logger.getLogger(DBTransform.class);
|
... | ... | |
143 |
141 |
}
|
144 |
142 |
|
145 |
143 |
}
|
146 |
|
|
147 |
|
/**
|
148 |
|
* Transform an XML document to StringWriter using the stylesheet reference
|
149 |
|
* from the db
|
150 |
|
* @param doc the document to be transformed
|
151 |
|
* @param sourceType the document type of the source
|
152 |
|
* @param targetType the target document type
|
153 |
|
* @param qFormat the name of the style set to use
|
154 |
|
* @param pw the StringWriter to which output will be stored
|
155 |
|
*/
|
156 |
|
public void transformXMLDocument(String doc, String sourceType,
|
157 |
|
String targetType, String qFormat, StringWriter pw,
|
158 |
|
Hashtable<String, String[]> param, String sessionid)
|
159 |
|
{
|
160 |
144 |
|
161 |
|
// Look up the stylesheet for this type combination
|
162 |
|
String xslSystemId = getStyleSystemId(qFormat, sourceType, targetType);
|
163 |
|
if (xslSystemId != null)
|
164 |
|
{
|
165 |
|
// Create a stylesheet from the system id that was found
|
166 |
|
try
|
167 |
|
{
|
168 |
|
doc = removeDOCTYPE(doc);
|
169 |
|
StringReader xml = new StringReader(doc);
|
170 |
|
StreamResult result = new StreamResult(pw);
|
171 |
|
doTransform(xml, result, xslSystemId, param, qFormat, sessionid);
|
172 |
|
}
|
173 |
|
catch (Exception e)
|
174 |
|
{
|
175 |
|
logMetacat.error("DBTransform.transformXMLDocument - " + xslSystemId + ": Error transforming document in " +
|
176 |
|
"DBTransform.transformXMLDocument: " +
|
177 |
|
e.getMessage());
|
178 |
145 |
|
179 |
|
}
|
180 |
|
}
|
181 |
|
else
|
182 |
|
{
|
183 |
|
// No stylesheet registered form this document type, so just return the
|
184 |
|
// XML stream we were passed
|
185 |
|
pw.write(doc);
|
186 |
|
}
|
187 |
|
}
|
188 |
|
|
189 |
|
|
190 |
146 |
/**
|
191 |
147 |
* Reads skin's config file if it exists, and populates Transformer paramaters
|
192 |
148 |
* with its contents.
|
clean up DBTransform in preparation for "view" service. https://projects.ecoinformatics.org/ecoinfo/issues/6019