Skip to content

Commit

Permalink
get source document refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Mar 30, 2013
1 parent 548af2e commit 82c48ee
Showing 1 changed file with 23 additions and 4 deletions.
Expand Up @@ -51,7 +51,6 @@ public class PDFResource extends Resource implements ViewableV2 {
*
*/
public PDFResource() {

}

/**
Expand All @@ -62,7 +61,7 @@ public ViewDescriptor[] getViewDescriptors() {
}

/**
*
* @see org.wyona.yanel.core.api.attributes.ViewableV2#getView(String)
*/
public View getView(String viewId) throws Exception {
if (!exists()) {
Expand All @@ -75,8 +74,9 @@ public View getView(String viewId) throws Exception {
defaultView.setResponse(false); // This resource writes directly into the response output stream (because of memory it's better to stream large documents)

try {
String yanelPath = getDataPath();
Repository repo = getRealm().getRepository();
/*
String yanelPath = getDataPath();
InputStream docSource = null;
if (yanelPath.startsWith("yanelrepo:") || yanelPath.startsWith("yanelresource:")) {
SourceResolver resolver = new SourceResolver(this);
Expand All @@ -85,6 +85,7 @@ public View getView(String viewId) throws Exception {
} else {
docSource = repo.getNode(yanelPath).getInputStream();
}
*/

// Step 1: Construct a FopFactory
// (reuse if you plan to render multiple documents!)
Expand All @@ -109,7 +110,8 @@ public View getView(String viewId) throws Exception {

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));
Source src = new SAXSource(xmlReader, new org.xml.sax.InputSource(getSourceDocument()));
//Source src = new SAXSource(xmlReader, new org.xml.sax.InputSource(docSource));

Result res = new SAXResult(fop.getDefaultHandler());

Expand Down Expand Up @@ -184,4 +186,21 @@ private String getXSLTPath(String path) throws Exception {
public String getMimeType(String viewId) {
return "application/pdf";
}

/**
* Get source document
*/
private InputStream getSourceDocument() throws Exception {
String yanelPath = getDataPath();
Repository repo = getRealm().getRepository();
InputStream docSource = 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();
}
return docSource;
}
}

0 comments on commit 82c48ee

Please sign in to comment.