[Yanel-commits] rev 27601 -
public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources
jon at wyona.com
jon at wyona.com
Mon Sep 24 17:32:58 CEST 2007
Author: jon
Date: 2007-09-24 17:32:58 +0200 (Mon, 24 Sep 2007)
New Revision: 27601
Modified:
public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/PDFResource.java
Log:
added getDataPath() method to PDF resource, thanks to Simon.
Modified: public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/PDFResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/PDFResource.java 2007-09-24 14:08:02 UTC (rev 27600)
+++ public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/PDFResource.java 2007-09-24 15:32:58 UTC (rev 27601)
@@ -47,23 +47,23 @@
*
*/
public class PDFResource extends Resource implements ViewableV2 {
-
+
private static Category log = Category.getInstance(PDFResource.class);
-
+
/**
*
*/
public PDFResource() {
-
+
}
-
+
/**
*
*/
public ViewDescriptor[] getViewDescriptors() {
return null;
- }
-
+ }
+
/**
*
*/
@@ -71,23 +71,19 @@
View defaultView = new View();
defaultView.setMimeType(getMimeType(viewId));
defaultView.setResponse(false); // This resource writes directly into the response output stream
-
+
try {
- String yanelPath = getResourceConfigProperty("yanel-path");
+ String yanelPath = getDataPath();
Repository repo = getRealm().getRepository();
InputStream docSource = null;
- if (yanelPath != null) {
- if (yanelPath.startsWith("yanelrepo:") || yanelPath.startsWith("yanelresource:")) {
- SourceResolver resolver = new SourceResolver(this);
- Source source = resolver.resolve(yanelPath, null);
- docSource = ((StreamSource) source).getInputStream();
- } else {
- docSource = repo.getNode(yanelPath).getInputStream();
- }
+ if (yanelPath.startsWith("yanelrepo:") || yanelPath.startsWith("yanelresource:")) {
+ SourceResolver resolver = new SourceResolver(this);
+ Source source = resolver.resolve(yanelPath, null);
+ docSource = ((StreamSource) source).getInputStream();
} else {
- docSource = repo.getNode(getPath()).getInputStream();
+ docSource = repo.getNode(yanelPath).getInputStream();
}
-
+
// Step 1: Construct a FopFactory
// (reuse if you plan to render multiple documents!)
FopFactory fopFactory = FopFactory.newInstance();
@@ -97,7 +93,7 @@
SourceResolver srcResolver = new SourceResolver(this);
fopFactory.setURIResolver(srcResolver);
-
+
/* Only for debugging ...
java.io.FileOutputStream fout = new java.io.FileOutputStream("/home/michi/Desktop/yanel.pdf");
driver.setOutputStream(fout);
@@ -106,42 +102,52 @@
// TODO: This doesn't seem to work properly (see below)
//java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
//driver.setOutputStream(baos);
-
- Transformer transformer = TransformerFactory.newInstance().newTransformer(getXSLTStreamSource(getPath(),repo));
-
+
+ Transformer transformer = TransformerFactory.newInstance().newTransformer(getXSLTStreamSource(getPath(),repo));
+
org.xml.sax.XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
xmlReader.setEntityResolver(new org.apache.xml.resolver.tools.CatalogResolver());
Source src = new SAXSource(xmlReader, new org.xml.sax.InputSource(docSource));
-
+
Result res = new SAXResult(fop.getDefaultHandler());
-
+
transformer.transform(src,res);
-
+
// TODO: For some strange reason the stream seems to be truncated after a certain length ...!
//log.debug("Result Size"+ baos.size());
//defaultView.setInputStream(new java.io.ByteArrayInputStream(baos.toByteArray()));
} catch(Exception e) {
log.error(e, e);
- }
+ }
- return defaultView;
+ return defaultView;
}
-
+
/**
+ * convenient method to allow easy overriding of how the dataPath is generated
+ * @return String datapath
+ */
+ public String getDataPath() throws Exception {
+ String yanelPath = getResourceConfigProperty("yanel-path");
+ if (yanelPath != null) return yanelPath;
+ return getPath();
+ }
+
+ /**
*
*/
public boolean exists() throws Exception {
log.warn("Not implemented yet!");
- return true;
+ return true;
}
-
+
/**
- *
+ *
*/
public long getSize() throws Exception {
return getRealm().getRepository().getSize(new Path(getPath()));
}
-
+
/**
*
*/
@@ -158,7 +164,7 @@
}
/**
- *
+ *
*/
private String getXSLTPath(String path) throws Exception {
String xsltPath = getResourceConfigProperty("xslt");
More information about the Yanel-commits
mailing list