Properties oEnvironmentProps, Properties oUserProps)
throws FileNotFoundException, IOException, DOMException, TransformerException,
TransformerConfigurationException, MalformedURLException {
Transformer oTransformer;
StreamResult oStreamResult;
StreamSource oStreamSrcXML;
StringWriter oStrWritter;
File oXMLFile,oXSLFile;
InputStream oXMLStream = null;
String sTransformed;
StringBuffer oPostTransform;
String sKey;
String sMedia;
String sXSLFile;
Object sVal;
Page oCurrentPage;
int iCloseHead, iOpenBody, iCloseBody;
int iReaded;
char CharBuffer[] = new char[8192];
String sCharBuffer;
long lElapsed = 0;
final String sSep = System.getProperty("file.separator");
if (DebugFile.trace) {
lElapsed = System.currentTimeMillis();
DebugFile.writeln("Begin Pageset.buildPageForEdit(" + sBasePath + "," + sOutputPath + "," + sCtrlPath + "," + sMenuPath + ")");
DebugFile.incIdent();
}
FileSystem oFS = new FileSystem();
if (!sBasePath.endsWith(sSep)) sBasePath += sSep;
String sWebServer = oEnvironmentProps.getProperty("webserver", "");
if (DebugFile.trace && sWebServer.length()==0) DebugFile.writeln("WARNING: webserver property not set at EnvironmentProperties");
if (!sWebServer.endsWith("/")) sWebServer+="/";
// Posicionarse en el nodo de contenedores
Node oContainers = oMSite.seekChildByName(oMSite.getRootNode().getFirstChild(), "containers");
if (oContainers==null) {
if (DebugFile.trace)
DebugFile.writeln("ERROR: <containers> node not found.");
throw new DOMException(DOMException.NOT_FOUND_ERR, "<containers> node not found");
}
// Cagar el stream de datos XML una sola vez
if (DebugFile.trace)
DebugFile.writeln("new FileInputStream(" + (sURI.startsWith("file://") ? sURI.substring(7) : sURI) + ")");
// Para cada contenedor (página) realizar la transformación XSLT
oCurrentPage = this.page(sPageGUID);
oXMLFile = new File (sURI.startsWith("file://") ? sURI.substring(7) : sURI);
if (!oXMLFile.exists()) {
if (DebugFile.trace) DebugFile.decIdent();
throw new FileNotFoundException("PageSet.buildPageForEdit() File not found "+sURI);
}
oXMLStream = new FileInputStream(oXMLFile);
oStreamSrcXML = new StreamSource(oXMLStream);
// Asignar cada stream de salida a su stream temporal
oStrWritter = new StringWriter();
oStreamResult = new StreamResult(oStrWritter);
// Transformacion XSLT
try {
// Obtener la hoja de estilo desde el cache
sXSLFile = sBasePath + "xslt" + sSep + "templates" + sSep + oMSite.name() + sSep + oCurrentPage.template();
oXSLFile = new File (sXSLFile);
if (!oXSLFile.exists()) {
if (DebugFile.trace) DebugFile.decIdent();
throw new FileNotFoundException("PageSet.buildPageForEdit() File not found "+sXSLFile+" maybe there is a mismatch between the microsite name and the directory name where it is placed, or between the template name and the actual .xsl file name");
}
oTransformer = StylesheetCache.newTransformer(sXSLFile);
sMedia = oTransformer.getOutputProperty(OutputKeys.MEDIA_TYPE);
if (DebugFile.trace) DebugFile.writeln(OutputKeys.MEDIA_TYPE + "=" + sMedia);
if (null==sMedia)
sMedia = "html";
else
sMedia = sMedia.substring(sMedia.indexOf('/')+1);
if (null==oCurrentPage.getTitle())
throw new NullPointerException("Page title is null");
if (DebugFile.trace)
DebugFile.writeln("Page.filePath(" + sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia + ")");
oCurrentPage.filePath(sOutputPath + oCurrentPage.getTitle().replace(' ','_') + "." + sMedia);
// Set environment parameters for stylesheet
StylesheetCache.setParameters (oTransformer, oEnvironmentProps);
// Set user defined parameters for stylesheet
StylesheetCache.setParameters (oTransformer, oUserProps);
// Paso el title de la pagina como parametro
oTransformer.setParameter ("param_page", oCurrentPage.getTitle());
// Realizar la transformación
oTransformer.transform (oStreamSrcXML, oStreamResult);
}
catch (TransformerConfigurationException e) {
oLastXcpt = e;
sMedia = null;