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 @@ +
+ + + +
+
+ +
+
+
+
+

Company  |  Contact  |  News  |  Events  |  People

+
+
+
diff --git a/source/test-resources/websites/alfresco/ROOT/media/releases/content/about_blurbs/Activiti.xml b/source/test-resources/websites/alfresco/ROOT/media/releases/content/about_blurbs/Activiti.xml new file mode 100644 index 0000000000..c3d4dfc7d9 --- /dev/null +++ b/source/test-resources/websites/alfresco/ROOT/media/releases/content/about_blurbs/Activiti.xml @@ -0,0 +1,5 @@ + + + Activiti + Alfresco used to be called Activiti. See About Alfresco. + diff --git a/source/test-resources/xforms/demos/press-release/about-blurb.xsd b/source/test-resources/xforms/demos/press-release/about-blurb.xsd index cb594c08af..1833a58679 100644 --- a/source/test-resources/xforms/demos/press-release/about-blurb.xsd +++ b/source/test-resources/xforms/demos/press-release/about-blurb.xsd @@ -1,7 +1,7 @@ diff --git a/source/test-resources/xforms/demos/press-release/about-blurb.xsl b/source/test-resources/xforms/demos/press-release/about-blurb.xsl index 0e7af5010f..ffa9fa7d3b 100644 --- a/source/test-resources/xforms/demos/press-release/about-blurb.xsl +++ b/source/test-resources/xforms/demos/press-release/about-blurb.xsl @@ -4,18 +4,12 @@ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:alfresco="http://www.alfresco.org/alfresco" exclude-result-prefixes="xhtml"> - + this template produces no output. the xml is used by press-release.xsl + diff --git a/source/test-resources/xforms/demos/press-release/press-release.xsd b/source/test-resources/xforms/demos/press-release/press-release.xsd index 311c2d0faa..a204b53a17 100644 --- a/source/test-resources/xforms/demos/press-release/press-release.xsd +++ b/source/test-resources/xforms/demos/press-release/press-release.xsd @@ -1,7 +1,7 @@ @@ -14,6 +14,7 @@ + diff --git a/source/test-resources/xforms/demos/press-release/press-release.xsl b/source/test-resources/xforms/demos/press-release/press-release.xsl index 9ed44360a6..788b5d19f0 100644 --- a/source/test-resources/xforms/demos/press-release/press-release.xsl +++ b/source/test-resources/xforms/demos/press-release/press-release.xsl @@ -1,153 +1,142 @@ - - + - - - - - -<xsl:value-of select="/alfresco:press-release/alfresco:title"/> - - - - - - - - - - - - -
-
- - - -
- -
-
-
-

Company  |  Contact  |  News  |  Events  |  People

-
-
-
-
- -
+ + - + + + + + <xsl:value-of select="/alfresco:press-release/alfresco:title"/> + + + + + + + + + + -

-

-

- -

-
- - -

- -

-
-
- -

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

-
- +
+
+ + + +
+ +
+
+
+

Company  |  Contact  |  News  |  Events  |  People

+
+
+
+
 
+ +
-
- -
-
-
-
- - - -
-
-
- - - - + + + +
+ + + +