Methods Summary |
---|
private void | convert()
try {
/* xsl */
final InputStream xslStream = getXslStream();
final StreamSource xsl = new StreamSource(xslStream);
/* domain xml */
final File domainXmlFile = new File(domainXmlPath);
System.out.println("The source xml = " + domainXmlFile.getAbsolutePath());
final StreamSource xml = new StreamSource(domainXmlFile);
/* server xml */
final File serverXmlFile = new File(serverXmlPath);
final StreamResult out = new StreamResult(serverXmlFile);
final Transformer transformer = tFactory.newTransformer(xsl);
transformer.transform(xml, out);
}
catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
|
private void | createFactory()
try {
tFactory = TransformerFactory.newInstance();
System.out.println("Created xform factory = " + tFactory);
}
catch(Exception e) {
System.out.println("Exception while creating transformer factory");
e.printStackTrace();
throw new RuntimeException(e);
}
|
private java.lang.String | getDtdPathForServerXml()
/* unfortunately, this has to be formed
* by the standard technique of the string concat!
*/
String PREFIX = "file://";
if (OS.isWindows()) {
PREFIX = PREFIX+"/";
}
return ( PREFIX + SERVER_DTD_PATH );
/*
BufferedInputStream bis = null;
String dtd = null;
try {
final String PREFIX = "file:///";
final String DTD_EXT = ".dtd";
final File f = new File(serverXmlPath);
bis = new BufferedInputStream
(new FileInputStream(f));
byte[] bytes = new byte[1024];
int bytesRead = 0;
while((bytesRead = bis.read(bytes)) != -1) {
final String line = new String(bytes);
final int start = line.indexOf(PREFIX);
if (start != -1) {
final int end = line.lastIndexOf(DTD_EXT);
dtd = line.substring(start, end);
dtd = dtd + DTD_EXT;
break;
}
}
}
catch(Exception e) {
throw new RuntimeException(e);
}
finally {
try {
if (bis != null)
bis.close();
}
catch(Exception e) {}
}
return ( dtd );
*/
|
private java.io.InputStream | getXslStream()
return ( new FileInputStream(XSL_PATH) );
/*
final Class thisClass = Domain2ServerTransformer.class;
final String packageName =
thisClass.getPackage().getName();
final String modifiedName = packageName.replace('.', '/');
final String xslStreamName = modifiedName + "/" + XSL_NAME;
System.out.println("The xslStreamName = " + xslStreamName);
return (thisClass.getClassLoader().getResourceAsStream(xslStreamName));
*/
|
private void | replaceDocTypePath(java.lang.String dtdPath)
try {
final File tmpFile = File.createTempFile("temp", ".xml");
final String tmpFilePath = tmpFile.getAbsolutePath();
FileUtils.copy(serverXmlPath, tmpFilePath);
final TokenValue tv = new TokenValue(DOCTYPE_TOKEN, dtdPath);
System.out.println("TV = " + tv);
final TokenValueSet ts = new TokenValueSet();
ts.add(tv);
final LineTokenReplacer replacer = new LineTokenReplacer(ts);
replacer.replace(tmpFilePath, serverXmlPath);
tmpFile.delete();
}
catch (Exception e) {
throw new RuntimeException(e);
}
|
public final void | transform()
this.transform(true);
|
public final void | transform(boolean backup)
if (backup) {
try {
if (new File(serverXmlPath).exists()) {
FileUtils.copy(serverXmlPath, origServerXmlPath);
}
System.out.println("ServerXmlPath = " + serverXmlPath);
System.out.println("DomainXmlPath = " + domainXmlPath);
System.out.println("ServerDtdPath = " + SERVER_DTD_PATH);
System.out.println("XslPath = " + XSL_PATH);
}
catch (Exception e) {
System.out.println("Could not backup server.xml before xform");
throw new RuntimeException(e);
}
}
final String dtdPath = getDtdPathForServerXml();
convert();
replaceDocTypePath(dtdPath);
|