mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
implementing a urlresolver for xsl so that we can include documents properly using the document function.
updates to press release xsds - it's now basically working. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3926 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ public class FreeMarkerOutputMethod
|
||||
|
||||
public void generate(final Document xmlContent,
|
||||
final TemplateType tt,
|
||||
final String sandBoxUrl,
|
||||
final Writer out)
|
||||
{
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user