Media Contacts
-John Newton
Alfresco Software Inc.
+44 1628 860639
press@alfresco.com
Chuck Tanowitz
Schwartz Communications
+1 781 684-0770
alfresco@schwartz-pr.com
-
+
- Accessibility | +
- Site Map | +
- Contact Us | +
- Store | +
- RSS
diff --git a/source/java/org/alfresco/web/templating/OutputUtil.java b/source/java/org/alfresco/web/templating/OutputUtil.java index 1cd7f834bb..079ade270d 100644 --- a/source/java/org/alfresco/web/templating/OutputUtil.java +++ b/source/java/org/alfresco/web/templating/OutputUtil.java @@ -27,6 +27,7 @@ import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.web.bean.wcm.AVMConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; @@ -39,8 +40,6 @@ import org.w3c.dom.Document; public class OutputUtil { private static final Log LOGGER = LogFactory.getLog(OutputUtil.class); - private static final String PARENT_AVM_PATH = - "repo-1:/repo-1/alice/appBase/avm_webapps/ROOT"; private static String stripExtension(String s) { @@ -64,6 +63,9 @@ public class OutputUtil OutputStream fileOut = avmService.createFile(parentPath, generatedFileName); String fullAvmPath = parentPath + '/' + generatedFileName; + + String avmStore = parentPath.substring(0, parentPath.indexOf(":/")); + String sandBoxUrl = AVMConstants.buildAVMStoreUrl(avmStore); if (LOGGER.isDebugEnabled()) LOGGER.debug("Created file node for file: " + @@ -71,7 +73,7 @@ public class OutputUtil TemplateOutputMethod tom = tt.getOutputMethods().get(0); OutputStreamWriter out = new OutputStreamWriter(fileOut); - tom.generate(xml, tt, out); + tom.generate(xml, tt, sandBoxUrl, out); out.close(); NodeRef outputNodeRef = AVMNodeConverter.ToNodeRef(-1, fullAvmPath); @@ -117,10 +119,14 @@ public class OutputUtil String generatedFileName = (String) nodeService.getProperty(generatedNodeRef, ContentModel.PROP_NAME); - + String avmPath = (String)AVMNodeConverter.ToAVMVersionPath(nodeRef)[1]; + String avmStore = avmPath.substring(0, avmPath.indexOf(":/")); + String sandBoxUrl = AVMConstants.buildAVMStoreUrl(avmStore); + if (LOGGER.isDebugEnabled()) LOGGER.debug("regenerating file node for : " + fileName + " (" + nodeRef.toString() + ") to " + generatedNodeRef.toString()); + // get a writer for the content and put the file ContentWriter writer = contentService.getWriter(generatedNodeRef, @@ -132,7 +138,7 @@ public class OutputUtil // put a loop to generate all output methods TemplateOutputMethod tom = tt.getOutputMethods().get(0); OutputStreamWriter out = new OutputStreamWriter(writer.getContentOutputStream()); - tom.generate(xml, tt, out); + tom.generate(xml, tt, sandBoxUrl, out); out.close(); LOGGER.debug("generated " + fileName + " using " + tom); diff --git a/source/java/org/alfresco/web/templating/TemplateOutputMethod.java b/source/java/org/alfresco/web/templating/TemplateOutputMethod.java index 545d6f8380..0e1157d653 100644 --- a/source/java/org/alfresco/web/templating/TemplateOutputMethod.java +++ b/source/java/org/alfresco/web/templating/TemplateOutputMethod.java @@ -32,10 +32,12 @@ public interface TemplateOutputMethod * * @param xmlContent the xml content to serialize * @param tt the template type that collected the xml content. + * @param sandBoxUrl the url of the current sandbox * @param out the writer to serialize to. */ public void generate(final Document xmlContent, final TemplateType tt, + final String sandBoxUrl, final Writer out) throws Exception; } diff --git a/source/java/org/alfresco/web/templating/xforms/FreeMarkerOutputMethod.java b/source/java/org/alfresco/web/templating/xforms/FreeMarkerOutputMethod.java index 5e558bda7e..a5a579eb97 100644 --- a/source/java/org/alfresco/web/templating/xforms/FreeMarkerOutputMethod.java +++ b/source/java/org/alfresco/web/templating/xforms/FreeMarkerOutputMethod.java @@ -33,6 +33,7 @@ public class FreeMarkerOutputMethod public void generate(final Document xmlContent, final TemplateType tt, + final String sandBoxUrl, final Writer out) { } diff --git a/source/java/org/alfresco/web/templating/xforms/XSLTOutputMethod.java b/source/java/org/alfresco/web/templating/xforms/XSLTOutputMethod.java index 2202a5d36f..00488d21ac 100644 --- a/source/java/org/alfresco/web/templating/xforms/XSLTOutputMethod.java +++ b/source/java/org/alfresco/web/templating/xforms/XSLTOutputMethod.java @@ -17,6 +17,8 @@ package org.alfresco.web.templating.xforms; import java.io.*; +import java.net.URI; +import java.net.URISyntaxException; import org.alfresco.web.templating.*; import org.chiba.xml.util.DOMUtil; import javax.xml.parsers.ParserConfigurationException; @@ -30,7 +32,10 @@ import javax.xml.transform.URIResolver; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -41,6 +46,8 @@ public class XSLTOutputMethod implements TemplateOutputMethod { + private static final Log LOGGER = LogFactory.getLog(XSLTOutputMethod.class); + private final NodeRef nodeRef; public XSLTOutputMethod(final NodeRef nodeRef) @@ -50,6 +57,7 @@ public class XSLTOutputMethod public void generate(final Document xmlContent, final TemplateType tt, + final String sandBoxUrl, final Writer out) throws ParserConfigurationException, TransformerConfigurationException, @@ -58,11 +66,49 @@ public class XSLTOutputMethod IOException { TransformerFactory tf = TransformerFactory.newInstance(); - TemplatingService ts = TemplatingService.getInstance(); + final TemplatingService ts = TemplatingService.getInstance(); DOMSource source = new DOMSource(ts.parseXML(this.nodeRef)); final Templates templates = tf.newTemplates(source); final Transformer t = templates.newTransformer(); + t.setURIResolver(new URIResolver() + { + public Source resolve(final String href, final String base) + throws TransformerException + { + URI uri = null; + try + { + uri = new URI(sandBoxUrl + href); + } + catch (URISyntaxException e) + { + throw new TransformerException("unable to create uri " + sandBoxUrl + href, e); + } + try + { + LOGGER.debug("loading " + uri); + final Document d = ts.parseXML(uri.toURL().openStream()); + LOGGER.debug("loaded " + ts.writeXMLToString(d)); + return new DOMSource(d); + } + catch (Exception e) + { + LOGGER.warn(e); + throw new TransformerException("unable to load " + uri, e); + } + } + }); + t.setParameter("avm_store_url", sandBoxUrl); + LOGGER.debug("setting parameter avm_store_url=" + sandBoxUrl); final StreamResult result = new StreamResult(out); - t.transform(new DOMSource(xmlContent), result); + try + { + t.transform(new DOMSource(xmlContent), result); + } + catch (TransformerException e) + { + LOGGER.error(e.getMessageAndLocation()); + throw e; + } } } diff --git a/source/test-resources/websites/alfresco.zip b/source/test-resources/websites/alfresco.zip index 816ab66de1..594b81f0e4 100644 Binary files a/source/test-resources/websites/alfresco.zip and b/source/test-resources/websites/alfresco.zip differ diff --git a/source/test-resources/websites/alfresco/ROOT/assets/footer.html b/source/test-resources/websites/alfresco/ROOT/assets/footer.html new file mode 100644 index 0000000000..c112fd2481 --- /dev/null +++ b/source/test-resources/websites/alfresco/ROOT/assets/footer.html @@ -0,0 +1,36 @@ + +
+ + diff --git a/source/test-resources/websites/alfresco/ROOT/assets/header.html b/source/test-resources/websites/alfresco/ROOT/assets/header.html new file mode 100644 index 0000000000..da814bb129 --- /dev/null +++ b/source/test-resources/websites/alfresco/ROOT/assets/header.html @@ -0,0 +1,40 @@ +John Newton
Alfresco Software Inc.
+44 1628 860639
press@alfresco.com
Chuck Tanowitz
Schwartz Communications
+1 781 684-0770
alfresco@schwartz-pr.com