[Yanel-commits] rev 27115 -
public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources
michi at wyona.com
michi at wyona.com
Mon Sep 3 11:13:27 CEST 2007
Author: michi
Date: 2007-09-03 11:13:27 +0200 (Mon, 03 Sep 2007)
New Revision: 27115
Added:
public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/YanelURIResolver.java
Modified:
public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/PDFResource.java
Log:
get images by using the yanel scheme
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-03 08:56:24 UTC (rev 27114)
+++ public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/PDFResource.java 2007-09-03 09:13:27 UTC (rev 27115)
@@ -25,16 +25,11 @@
import org.wyona.yarep.core.RepositoryException;
import org.wyona.yarep.core.Repository;
-//import org.apache.avalon.framework.logger.Logger;
-//import org.apache.avalon.framework.logger.ConsoleLogger;
-
import org.apache.log4j.Category;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.MimeConstants;
-//import org.apache.fop.configuration.Configuration;
-//import org.apache.fop.messaging.MessageHandler;
import java.io.File;
import java.io.InputStream;
@@ -53,7 +48,6 @@
public class PDFResource extends Resource implements ViewableV2 {
private static Category log = Category.getInstance(PDFResource.class);
-
/**
*
@@ -93,7 +87,10 @@
// Step 2: Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, getResponse().getOutputStream());
-
+
+ YanelURIResolver yanelURIResolver = new YanelURIResolver(this);
+ fopFactory.setURIResolver(yanelURIResolver); // yanelURIResolver is a javax.xml.transform.URIResolver
+
/* Only for debugging ...
java.io.FileOutputStream fout = new java.io.FileOutputStream("/home/michi/Desktop/yanel.pdf");
driver.setOutputStream(fout);
@@ -138,20 +135,20 @@
return getRealm().getRepository().getSize(new Path(getPath()));
}
- /**
- *
- */
- private StreamSource getXSLTStreamSource(String path, Repository repo) throws Exception {
- String xsltPath = getXSLTPath(path);
- if(xsltPath != null) {
- return new StreamSource(repo.getInputStream(new Path(xsltPath)));
- } else {
- File xsltFile = org.wyona.commons.io.FileUtil.file(
- rtd.getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "xml2fo.xsl");
- log.debug("XSLT file: " + xsltFile);
- return new StreamSource(xsltFile);
- }
- }
+ /**
+ *
+ */
+ private StreamSource getXSLTStreamSource(String path, Repository repo) throws Exception {
+ String xsltPath = getXSLTPath(path);
+ if(xsltPath != null) {
+ return new StreamSource(repo.getInputStream(new Path(xsltPath)));
+ } else {
+ File xsltFile = org.wyona.commons.io.FileUtil.file(
+ rtd.getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "xml2fo.xsl");
+ log.debug("XSLT file: " + xsltFile);
+ return new StreamSource(xsltFile);
+ }
+ }
/**
*
Added: public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/YanelURIResolver.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/YanelURIResolver.java (rev 0)
+++ public/yanel/trunk/src/contributions/resources/pdf/src/java/org/wyona/yanel/impl/resources/YanelURIResolver.java 2007-09-03 09:13:27 UTC (rev 27115)
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2007 Wyona
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.wyona.org/licenses/APACHE-LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import java.net.URL;
+import java.io.InputStream;
+import java.util.StringTokenizer;
+
+import org.apache.log4j.Category;
+
+import org.wyona.yanel.core.Resource;
+
+import org.wyona.yarep.core.RepositoryException;
+import org.wyona.yarep.core.Repository;
+
+/**
+ * URI resolver for the scheme "yanel"
+ */
+public class YanelURIResolver implements URIResolver {
+ private static Category log = Category.getInstance(YanelURIResolver.class);
+
+ private static final String SCHEME = "yanel";
+
+ private Resource resource;
+
+ public YanelURIResolver(Resource resource) {
+ this.resource = resource;
+ }
+
+ public Source resolve(String href, String base) {
+ if (log.isDebugEnabled()) {
+ log.debug("resolving: " + href);
+ }
+
+ String prefix = SCHEME + ":/";
+
+ // only accept 'yanel:/' URIs
+ if (href == null || !href.startsWith(prefix)){
+ return null;
+ }
+
+ // we can't resolve to a Collection (indicated by a trailing '/')
+ if (href.charAt(href.length() - 1) == '/'){
+ return null;
+ }
+
+ StringTokenizer tokens = new StringTokenizer(href.substring(7), "/");
+ if (!tokens.hasMoreTokens()){
+ return null; // nothing after the 'yanel:/'
+ }
+
+ try {
+ String path = href.substring(7); // truncate yanel:/
+ Repository repo = resource.getRealm().getRepository();
+ InputStream in = repo.getNode(path).getInputStream();
+ return new StreamSource(in);
+ } catch (Exception e) {
+ String errorMsg = "Could not resolve URI: " + href + ": " + e.toString();
+ log.error(errorMsg, e);
+ }
+ return null;
+ }
+}
More information about the Yanel-commits
mailing list