You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by me...@apache.org on 2012/07/03 11:47:25 UTC
svn commit: r1356646 [5/12] - in /xmlgraphics/fop/trunk: ./
examples/embedding/java/embedding/ examples/embedding/java/embedding/atxml/
examples/embedding/java/embedding/events/
examples/embedding/java/embedding/intermediate/ src/java/org/apache/fop/af...
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/hyphenation/Hyphenator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/hyphenation/Hyphenator.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/hyphenation/Hyphenator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/hyphenation/Hyphenator.java Tue Jul 3 09:46:41 2012
@@ -20,21 +20,20 @@
package org.apache.fop.hyphenation;
import java.io.BufferedInputStream;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
+import java.net.URISyntaxException;
import java.util.Map;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
import org.xml.sax.InputSource;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.apps.io.InternalResourceResolver;
+
/**
* <p>This class is the main entry point to the hyphenation package.
* You can use only the static methods or create an instance.</p>
@@ -75,7 +74,7 @@ public final class Hyphenator {
* @return the hyphenation tree
*/
public static HyphenationTree getHyphenationTree(String lang,
- String country, HyphenationTreeResolver resolver, Map hyphPatNames) {
+ String country, InternalResourceResolver resolver, Map hyphPatNames) {
String llccKey = HyphenationTreeCache.constructLlccKey(lang, country);
HyphenationTreeCache cache = getHyphenationTreeCache();
@@ -126,12 +125,12 @@ public final class Hyphenator {
* The hyphenation trees are cached.
* @param lang the language
* @param country the country (may be null or "none")
- * @param resolver resolver to find the hyphenation files
+ * @param resourceResolver resolver to find the hyphenation files
* @param hyphPatNames the map with user-configured hyphenation pattern file names
* @return the hyphenation tree
*/
- private static HyphenationTree getHyphenationTree2(String lang,
- String country, HyphenationTreeResolver resolver, Map hyphPatNames) {
+ public static HyphenationTree getHyphenationTree2(String lang,
+ String country, InternalResourceResolver resourceResolver, Map hyphPatNames) {
String llccKey = HyphenationTreeCache.constructLlccKey(lang, country);
HyphenationTreeCache cache = getHyphenationTreeCache();
@@ -147,8 +146,8 @@ public final class Hyphenator {
key = llccKey;
}
- if (resolver != null) {
- hTree = getUserHyphenationTree(key, resolver);
+ if (resourceResolver != null) {
+ hTree = getUserHyphenationTree(key, resourceResolver);
}
if (hTree == null) {
hTree = getFopHyphenationTree(key);
@@ -230,30 +229,11 @@ public final class Hyphenator {
* Load tree from serialized file or xml file
* using configuration settings
* @param key language key for the requested hyphenation file
- * @param hyphenDir base directory to find hyphenation files in
- * @return the requested HypenationTree or null if it is not available
- */
- public static HyphenationTree getUserHyphenationTree(String key,
- String hyphenDir) {
- final File baseDir = new File(hyphenDir);
- HyphenationTreeResolver resolver = new HyphenationTreeResolver() {
- public Source resolve(String href) {
- File f = new File(baseDir, href);
- return new StreamSource(f);
- }
- };
- return getUserHyphenationTree(key, resolver);
- }
-
- /**
- * Load tree from serialized file or xml file
- * using configuration settings
- * @param key language key for the requested hyphenation file
- * @param resolver resolver to find the hyphenation files
+ * @param resourceResolver resource resolver to find the hyphenation files
* @return the requested HypenationTree or null if it is not available
*/
public static HyphenationTree getUserHyphenationTree(String key,
- HyphenationTreeResolver resolver) {
+ InternalResourceResolver resourceResolver) {
HyphenationTree hTree = null;
// I use here the following convention. The file name specified in
// the configuration is taken as the base name. First we try
@@ -262,93 +242,63 @@ public final class Hyphenator {
// first try serialized object
String name = key + ".hyp";
- Source source = resolver.resolve(name);
- if (source != null) {
+ try {
+ InputStream in = getHyphenationTreeStream(name, resourceResolver);
try {
- InputStream in = null;
- if (source instanceof StreamSource) {
- in = ((StreamSource) source).getInputStream();
- }
- if (in == null) {
- if (source.getSystemId() != null) {
- in = new java.net.URL(source.getSystemId()).openStream();
- } else {
- throw new UnsupportedOperationException
- ("Cannot load hyphenation pattern file"
- + " with the supplied Source object: " + source);
- }
- }
- in = new BufferedInputStream(in);
- try {
- hTree = readHyphenationTree(in);
- } finally {
- IOUtils.closeQuietly(in);
- }
- return hTree;
- } catch (IOException ioe) {
- if (log.isDebugEnabled()) {
- log.debug("I/O problem while trying to load " + name, ioe);
- }
+ hTree = readHyphenationTree(in);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ return hTree;
+ } catch (IOException ioe) {
+ if (log.isDebugEnabled()) {
+ log.debug("I/O problem while trying to load " + name, ioe);
}
}
// try the raw XML file
name = key + ".xml";
- source = resolver.resolve(name);
- if (source != null) {
- hTree = new HyphenationTree();
+ hTree = new HyphenationTree();
+ try {
+ InputStream in = getHyphenationTreeStream(name, resourceResolver);
try {
- InputStream in = null;
- if (source instanceof StreamSource) {
- in = ((StreamSource) source).getInputStream();
- }
- if (in == null) {
- if (source.getSystemId() != null) {
- in = new java.net.URL(source.getSystemId()).openStream();
- } else {
- throw new UnsupportedOperationException(
- "Cannot load hyphenation pattern file"
- + " with the supplied Source object: " + source);
- }
- }
- if (!(in instanceof BufferedInputStream)) {
- in = new BufferedInputStream(in);
- }
- try {
- InputSource src = new InputSource(in);
- src.setSystemId(source.getSystemId());
- hTree.loadPatterns(src);
- } finally {
- IOUtils.closeQuietly(in);
- }
- if (statisticsDump) {
- System.out.println("Stats: ");
- hTree.printStats();
- }
- return hTree;
- } catch (HyphenationException ex) {
- log.error("Can't load user patterns from XML file " + source.getSystemId()
- + ": " + ex.getMessage());
- return null;
- } catch (IOException ioe) {
- if (log.isDebugEnabled()) {
- log.debug("I/O problem while trying to load " + name, ioe);
- }
- return null;
+ InputSource src = new InputSource(in);
+ src.setSystemId(name);
+ hTree.loadPatterns(src);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ if (statisticsDump) {
+ System.out.println("Stats: ");
+ hTree.printStats();
}
- } else {
+ return hTree;
+ } catch (HyphenationException ex) {
+ log.error("Can't load user patterns from XML file " + name + ": " + ex.getMessage());
+ return null;
+ } catch (IOException ioe) {
if (log.isDebugEnabled()) {
- log.debug("Could not load user hyphenation file for '" + key + "'.");
+ log.debug("I/O problem while trying to load " + name, ioe);
}
return null;
}
}
+ private static InputStream getHyphenationTreeStream(String name,
+ InternalResourceResolver resourceResolver) throws IOException {
+ try {
+ return new BufferedInputStream(resourceResolver.getResource(name));
+ } catch (URISyntaxException use) {
+ log.debug("An exception was thrown while attempting to load " + name, use);
+ }
+ return null;
+ }
+
/**
* Hyphenates a word.
* @param lang the language
* @param country the optional country code (may be null or "none")
- * @param resolver resolver to find the hyphenation files
+ * @param resourceResolver resolver to find the hyphenation files
* @param hyphPatNames the map with user-configured hyphenation pattern file names
* @param word the word to hyphenate
* @param leftMin the minimum number of characters before the hyphenation point
@@ -356,15 +306,12 @@ public final class Hyphenator {
* @return the hyphenation result
*/
public static Hyphenation hyphenate(String lang, String country,
- HyphenationTreeResolver resolver,
- Map hyphPatNames,
- String word,
- int leftMin, int rightMin) {
- HyphenationTree hTree = getHyphenationTree(lang, country, resolver, hyphPatNames);
+ InternalResourceResolver resourceResolver, Map hyphPatNames, String word, int leftMin,
+ int rightMin) {
+ HyphenationTree hTree = getHyphenationTree(lang, country, resourceResolver, hyphPatNames);
if (hTree == null) {
return null;
}
return hTree.hyphenate(word, leftMin, rightMin);
}
-
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java Tue Jul 3 09:46:41 2012
@@ -91,7 +91,7 @@ public class ExternalDocumentLayoutManag
initialize();
FOUserAgent userAgent = pageSeq.getUserAgent();
- ImageManager imageManager = userAgent.getFactory().getImageManager();
+ ImageManager imageManager = userAgent.getImageManager();
String uri = URISpecification.getURL(getExternalDocument().getSrc());
Integer firstPageIndex = ImageUtil.getPageIndexFromURI(uri);
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java Tue Jul 3 09:46:41 2012
@@ -1396,11 +1396,10 @@ public class LineLayoutManager extends I
// TextLM which generate the hyphenation buffer,
// since these properties inherit and could be specified
// on an inline or wrapper below the block level.
- Hyphenation hyph
- = Hyphenator.hyphenate(hyphenationProperties.language.getString(),
+ Hyphenation hyph = Hyphenator.hyphenate(hyphenationProperties.language.getString(),
hyphenationProperties.country.getString(),
- getFObj().getUserAgent().getFactory().getHyphenationTreeResolver(),
- getFObj().getUserAgent().getFactory().getHyphPatNames(),
+ getFObj().getUserAgent().getResourceResolver(),
+ getFObj().getUserAgent().getHyphPatNames(),
sbChars.toString(),
hyphenationProperties.hyphenationRemainCharacterCount.getValue(),
hyphenationProperties.hyphenationPushCharacterCount.getValue());
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFAMode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFAMode.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFAMode.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFAMode.java Tue Jul 3 09:46:41 2012
@@ -20,14 +20,14 @@
package org.apache.fop.pdf;
/** Enum class for PDF/A modes. */
-public final class PDFAMode {
+public enum PDFAMode {
/** PDF/A disabled */
- public static final PDFAMode DISABLED = new PDFAMode("PDF/A disabled");
+ DISABLED("PDF/A disabled"),
/** PDF/A-1a enabled */
- public static final PDFAMode PDFA_1A = new PDFAMode("PDF/A-1a");
+ PDFA_1A("PDF/A-1a"),
/** PDF/A-1b enabled */
- public static final PDFAMode PDFA_1B = new PDFAMode("PDF/A-1b");
+ PDFA_1B("PDF/A-1b");
private String name;
@@ -66,7 +66,7 @@ public final class PDFAMode {
* @param s the string
* @return the PDFAMode enum object (DISABLED will be returned if no match is found)
*/
- public static PDFAMode valueOf(String s) {
+ public static PDFAMode getValueOf(String s) {
if (PDFA_1A.getName().equalsIgnoreCase(s)) {
return PDFA_1A;
} else if (PDFA_1B.getName().equalsIgnoreCase(s)) {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFDocument.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFDocument.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFDocument.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFDocument.java Tue Jul 3 09:46:41 2012
@@ -21,7 +21,6 @@ package org.apache.fop.pdf;
// Java
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
@@ -719,24 +718,6 @@ public class PDFDocument {
}
/**
- * Resolve a URI.
- *
- * @param uri the uri to resolve
- * @throws java.io.FileNotFoundException if the URI could not be resolved
- * @return the InputStream from the URI.
- */
- protected InputStream resolveURI(String uri)
- throws java.io.FileNotFoundException {
- try {
- /* TODO: Temporary hack to compile, improve later */
- return new java.net.URL(uri).openStream();
- } catch (Exception e) {
- throw new java.io.FileNotFoundException(
- "URI could not be resolved (" + e.getMessage() + "): " + uri);
- }
- }
-
- /**
* Get an image from the image map.
*
* @param key the image key to look for
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFEncryptionParams.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFEncryptionParams.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFEncryptionParams.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFEncryptionParams.java Tue Jul 3 09:46:41 2012
@@ -273,4 +273,17 @@ public class PDFEncryptionParams {
this.encryptionLengthInBits = encryptionLength;
}
+ public String toString() {
+ return "userPassword = " + userPassword + "\n"
+ + "ownerPassword = " + ownerPassword + "\n"
+ + "allowPrint = " + allowPrint + "\n"
+ + "allowCopyContent = " + allowCopyContent + "\n"
+ + "allowEditContent = " + allowEditContent + "\n"
+ + "allowEditAnnotations = " + allowEditAnnotations + "\n"
+ + "allowFillInForms = " + allowFillInForms + "\n"
+ + "allowAccessContent = " + allowAccessContent + "\n"
+ + "allowAssembleDocument = " + allowAssembleDocument + "\n"
+ + "allowPrintHq = " + allowPrintHq;
+ }
+
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFFactory.java Tue Jul 3 09:46:41 2012
@@ -23,10 +23,8 @@ package org.apache.fop.pdf;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -35,9 +33,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.logging.Log;
@@ -1637,79 +1632,48 @@ public class PDFFactory {
InputStream in = null;
try {
- Source source = font.getEmbedFileSource();
- if (source == null && font.getEmbedResourceName() != null) {
- source = new StreamSource(this.getClass()
- .getResourceAsStream(font.getEmbedResourceName()));
- }
- if (source == null) {
- return null;
- }
- if (source instanceof StreamSource) {
- in = ((StreamSource) source).getInputStream();
- }
- if (in == null && source.getSystemId() != null) {
- try {
- in = new java.net.URL(source.getSystemId()).openStream();
- } catch (MalformedURLException e) {
- //TODO: Why construct a new exception here, when it is not thrown?
- new FileNotFoundException(
- "File not found. URL could not be resolved: "
- + e.getMessage());
- }
- }
- if (in == null) {
- return null;
- }
- //Make sure the InputStream is decorated with a BufferedInputStream
- if (!(in instanceof java.io.BufferedInputStream)) {
- in = new java.io.BufferedInputStream(in);
- }
+ in = font.getInputStream();
if (in == null) {
return null;
} else {
- try {
- AbstractPDFStream embeddedFont;
- if (desc.getFontType() == FontType.TYPE0) {
- MultiByteFont mbfont = (MultiByteFont)font;
- FontFileReader reader = new FontFileReader(in);
-
- TTFSubSetFile subset = new TTFSubSetFile();
- subset.readFont(reader, mbfont.getTTCName(), mbfont.getUsedGlyphs());
- byte[] subsetFont = subset.getFontSubset();
- // Only TrueType CID fonts are supported now
-
- embeddedFont = new PDFTTFStream(subsetFont.length);
- ((PDFTTFStream)embeddedFont).setData(subsetFont, subsetFont.length);
- } else if (desc.getFontType() == FontType.TYPE1) {
- PFBParser parser = new PFBParser();
- PFBData pfb = parser.parsePFB(in);
- embeddedFont = new PDFT1Stream();
- ((PDFT1Stream)embeddedFont).setData(pfb);
- } else {
- byte[] file = IOUtils.toByteArray(in);
- embeddedFont = new PDFTTFStream(file.length);
- ((PDFTTFStream)embeddedFont).setData(file, file.length);
- }
+ AbstractPDFStream embeddedFont;
+ if (desc.getFontType() == FontType.TYPE0) {
+ MultiByteFont mbfont = (MultiByteFont) font;
+ FontFileReader reader = new FontFileReader(in);
+
+ TTFSubSetFile subset = new TTFSubSetFile();
+ subset.readFont(reader, mbfont.getTTCName(), mbfont.getUsedGlyphs());
+ byte[] subsetFont = subset.getFontSubset();
+ // Only TrueType CID fonts are supported now
+
+ embeddedFont = new PDFTTFStream(subsetFont.length);
+ ((PDFTTFStream) embeddedFont).setData(subsetFont, subsetFont.length);
+ } else if (desc.getFontType() == FontType.TYPE1) {
+ PFBParser parser = new PFBParser();
+ PFBData pfb = parser.parsePFB(in);
+ embeddedFont = new PDFT1Stream();
+ ((PDFT1Stream) embeddedFont).setData(pfb);
+ } else {
+ byte[] file = IOUtils.toByteArray(in);
+ embeddedFont = new PDFTTFStream(file.length);
+ ((PDFTTFStream) embeddedFont).setData(file, file.length);
+ }
- /*
- embeddedFont.getFilterList().addFilter("flate");
- if (getDocument().isEncryptionActive()) {
- getDocument().applyEncryption(embeddedFont);
- } else {
- embeddedFont.getFilterList().addFilter("ascii-85");
- }*/
+ /*
+ embeddedFont.getFilterList().addFilter("flate");
+ if (getDocument().isEncryptionActive()) {
+ getDocument().applyEncryption(embeddedFont);
+ } else {
+ embeddedFont.getFilterList().addFilter("ascii-85");
+ }*/
- return embeddedFont;
- } finally {
- in.close();
- }
+ return embeddedFont;
}
} catch (IOException ioe) {
- log.error(
- "Failed to embed font [" + desc + "] "
- + desc.getEmbedFontName(), ioe);
+ log.error("Failed to embed font [" + desc + "] " + desc.getEmbedFontName(), ioe);
return null;
+ } finally {
+ IOUtils.closeQuietly(in);
}
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFXMode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFXMode.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFXMode.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFXMode.java Tue Jul 3 09:46:41 2012
@@ -20,12 +20,12 @@
package org.apache.fop.pdf;
/** Enum class for PDF/X modes. */
-public final class PDFXMode {
+public enum PDFXMode {
/** PDF/X disabled */
- public static final PDFXMode DISABLED = new PDFXMode("PDF/X disabled");
+ DISABLED("PDF/X disabled"),
/** PDF/X-3:2003 enabled */
- public static final PDFXMode PDFX_3_2003 = new PDFXMode("PDF/X-3:2003");
+ PDFX_3_2003("PDF/X-3:2003");
private String name;
@@ -47,7 +47,7 @@ public final class PDFXMode {
* @param s the string
* @return the PDFAMode enum object (DISABLED will be returned if no match is found)
*/
- public static PDFXMode valueOf(String s) {
+ public static PDFXMode getValueOf(String s) {
if (PDFX_3_2003.getName().equalsIgnoreCase(s)) {
return PDFX_3_2003;
} else {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/StreamCacheFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/StreamCacheFactory.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/StreamCacheFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/StreamCacheFactory.java Tue Jul 3 09:46:41 2012
@@ -24,56 +24,24 @@ import java.io.IOException;
/**
* This class is serves as a factory from
*/
-public class StreamCacheFactory {
+public final class StreamCacheFactory {
- private static boolean defaultCacheToFile = false;
- private static StreamCacheFactory fileInstance = null;
- private static StreamCacheFactory memoryInstance = null;
-
- private boolean cacheToFile = false;
+ private static StreamCacheFactory memoryInstance = new StreamCacheFactory();
/**
* Returns an instance of a StreamCacheFactory with the requested features.
* @param cacheToFile True if file shall be cached using a temporary file
* @return StreamCacheFactory the requested factory
*/
- public static StreamCacheFactory getInstance(boolean cacheToFile) {
- if (cacheToFile) {
- if (fileInstance == null) {
- fileInstance = new StreamCacheFactory(true);
- }
- return fileInstance;
- } else {
- if (memoryInstance == null) {
- memoryInstance = new StreamCacheFactory(false);
- }
- return memoryInstance;
- }
- }
-
- /**
- * Returns an instance of a StreamCacheFactory depending on the default
- * setting for cacheToFile.
- * @return StreamCacheFactory the requested factory
- */
public static StreamCacheFactory getInstance() {
- return getInstance(defaultCacheToFile);
- }
-
- /**
- * Sets the global default for cacheToFile
- * @param cacheToFile True if stream caches should be held in files.
- */
- public static void setDefaultCacheToFile(boolean cacheToFile) {
- defaultCacheToFile = cacheToFile;
+ return memoryInstance;
}
/**
* Creates a new StreamCacheFactory.
* @param cacheToFile True if file shall be cached using a temporary file
*/
- public StreamCacheFactory(boolean cacheToFile) {
- this.cacheToFile = cacheToFile;
+ private StreamCacheFactory() {
}
/**
@@ -83,11 +51,7 @@ public class StreamCacheFactory {
* @return a new StreamCache for caching streams
*/
public StreamCache createStreamCache() throws IOException {
- if (this.cacheToFile) {
- return new TempFileStreamCache();
- } else {
- return new InMemoryStreamCache();
- }
+ return new InMemoryStreamCache();
}
/**
@@ -98,20 +62,6 @@ public class StreamCacheFactory {
* @return a new StreamCache for caching streams
*/
public StreamCache createStreamCache(int hintSize) throws IOException {
- if (this.cacheToFile) {
- return new TempFileStreamCache();
- } else {
- return new InMemoryStreamCache(hintSize);
- }
- }
-
- /**
- * Get the value of the global cacheToFile flag.
- * @return the current cache to file flag
- */
- public boolean getCacheToFile() {
- return this.cacheToFile;
+ return new InMemoryStreamCache(hintSize);
}
-
-
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractConfigurator.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractConfigurator.java Tue Jul 3 09:46:41 2012
@@ -19,9 +19,6 @@
package org.apache.fop.render;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -49,41 +46,6 @@ public abstract class AbstractConfigurat
}
/**
- * Returns the configuration subtree for a specific renderer.
- * @param mimeType the MIME type of the renderer
- * @return the requested configuration subtree, null if there's no configuration
- */
- protected Configuration getConfig(String mimeType) {
- Configuration cfg = userAgent.getFactory().getUserConfig();
- if (cfg == null) {
- if (log.isDebugEnabled()) {
- log.debug("userconfig is null");
- }
- return null;
- }
-
- Configuration userConfig = null;
-
- String type = getType();
- Configuration[] cfgs
- = cfg.getChild(type + "s").getChildren(type);
- for (int i = 0; i < cfgs.length; ++i) {
- Configuration child = cfgs[i];
- try {
- if (child.getAttribute(MIME).equals(mimeType)) {
- userConfig = child;
- break;
- }
- } catch (ConfigurationException e) {
- // silently pass over configurations without mime type
- }
- }
- log.debug((userConfig == null ? "No u" : "U")
- + "ser configuration found for MIME type " + mimeType);
- return userConfig;
- }
-
- /**
* Returns the configurator type
* @return the configurator type
*/
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererConfigurator.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererConfigurator.java Tue Jul 3 09:46:41 2012
@@ -19,49 +19,30 @@
package org.apache.fop.render;
-import org.apache.avalon.framework.configuration.Configuration;
-
import org.apache.fop.apps.FOUserAgent;
/**
* Abstract base classes for renderer-related configurator classes. This class basically just
* provides an accessor to the specific renderer configuration object.
*/
-public abstract class AbstractRendererConfigurator extends AbstractConfigurator {
+public abstract class AbstractRendererConfigurator {
- private static final String TYPE = "renderer";
+ /** fop factory configuration */
+ protected final FOUserAgent userAgent;
/**
* Default constructor
* @param userAgent user agent
*/
public AbstractRendererConfigurator(FOUserAgent userAgent) {
- super(userAgent);
- }
-
- /**
- * Returns the configuration subtree for a specific renderer.
- * @param renderer the renderer
- * @return the requested configuration subtree, null if there's no configuration
- */
- protected Configuration getRendererConfig(Renderer renderer) {
- return super.getConfig(renderer.getMimeType());
+ this.userAgent = userAgent;
}
/**
- * Returns the configuration subtree for a specific renderer.
- * @param mimeType the MIME type of the renderer
- * @return the requested configuration subtree, null if there's no configuration
+ * Returns the configurator type
+ * @return the configurator type
*/
- protected Configuration getRendererConfig(String mimeType) {
- return super.getConfig(mimeType);
+ public static String getType() {
+ return "renderer";
}
-
- /**
- * {@inheritDoc}
- */
- public String getType() {
- return TYPE;
- }
-
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererMaker.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererMaker.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/AbstractRendererMaker.java Tue Jul 3 09:46:41 2012
@@ -19,6 +19,7 @@
package org.apache.fop.render;
+import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
/**
@@ -50,9 +51,8 @@ public abstract class AbstractRendererMa
* @param userAgent user agent
* @return a config object that can be used to configure the renderer
*/
- public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
- return null;
- }
+ public abstract void configureRenderer(FOUserAgent userAgent, Renderer renderer)
+ throws FOPException;
/**
* Indicates whether a specific MIME type is supported by this renderer.
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java Tue Jul 3 09:46:41 2012
@@ -36,10 +36,11 @@ import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontCollection;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontManager;
-import org.apache.fop.fonts.FontResolver;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.base14.Base14FontCollection;
+import sun.font.FontResolver;
+
/** Abstract base class of "Print" type renderers. */
public abstract class PrintRenderer extends AbstractRenderer {
@@ -88,11 +89,11 @@ public abstract class PrintRenderer exte
/** {@inheritDoc} */
public void setupFontInfo(FontInfo inFontInfo) throws FOPException {
this.fontInfo = inFontInfo;
- FontManager fontManager = userAgent.getFactory().getFontManager();
+ FontManager fontManager = userAgent.getFontManager();
FontCollection[] fontCollections = new FontCollection[] {
new Base14FontCollection(fontManager.isBase14KerningEnabled()),
- new CustomFontCollection(getFontResolver(), getFontList(),
- userAgent.isComplexScriptFeaturesEnabled())
+ new CustomFontCollection(fontManager.getResourceResolver(), getFontList(),
+ userAgent.isComplexScriptFeaturesEnabled())
};
fontManager.setup(getFontInfo(), fontCollections);
}
@@ -180,18 +181,6 @@ public abstract class PrintRenderer exte
}
/**
- * Get FontResolver
- *
- * @return FontResolver
- */
- public FontResolver getFontResolver() {
- if (this.fontResolver == null) {
- this.fontResolver = new DefaultFontResolver(super.userAgent);
- }
- return this.fontResolver;
- }
-
- /**
* @return the font info
*/
public FontInfo getFontInfo() {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRendererConfigurator.java Tue Jul 3 09:46:41 2012
@@ -19,124 +19,155 @@
package org.apache.fop.render;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import org.apache.avalon.framework.configuration.Configuration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.io.InternalResourceResolver;
import org.apache.fop.fonts.CustomFontCollection;
+import org.apache.fop.fonts.DefaultFontConfigurator;
import org.apache.fop.fonts.EmbedFontInfo;
import org.apache.fop.fonts.FontCollection;
+import org.apache.fop.fonts.FontConfigurator;
import org.apache.fop.fonts.FontEventAdapter;
-import org.apache.fop.fonts.FontEventListener;
import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontInfoConfigurator;
import org.apache.fop.fonts.FontManager;
-import org.apache.fop.fonts.FontResolver;
-import org.apache.fop.fonts.base14.Base14FontCollection;
+import org.apache.fop.render.RendererConfig.RendererConfigParser;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/**
* Base Print renderer configurator (mostly handles font configuration)
*/
-public class PrintRendererConfigurator extends AbstractRendererConfigurator
- implements RendererConfigurator, IFDocumentHandlerConfigurator {
+public abstract class PrintRendererConfigurator extends AbstractRendererConfigurator
+ implements IFDocumentHandlerConfigurator {
/** logger instance */
- protected static final Log log = LogFactory.getLog(PrintRendererConfigurator.class);
+ private static Log LOG = LogFactory.getLog(PrintRendererConfigurator.class);
+
+ private final RendererConfigParser rendererConfigParser;
+
+ private final FontConfigurator<EmbedFontInfo> fontInfoConfigurator;
/**
* Default constructor
* @param userAgent user agent
*/
- public PrintRendererConfigurator(FOUserAgent userAgent) {
+ public PrintRendererConfigurator(FOUserAgent userAgent, RendererConfigParser rendererConfigParser) {
+ this(userAgent, rendererConfigParser,
+ new DefaultFontConfigurator(userAgent.getFontManager(), new FontEventAdapter(
+ userAgent.getEventBroadcaster()), userAgent.validateUserConfigStrictly()));
+ }
+
+ /**
+ * Default constructor
+ * @param userAgent user agent
+ */
+ public PrintRendererConfigurator(FOUserAgent userAgent, RendererConfigParser rendererConfigParser,
+ FontConfigurator<EmbedFontInfo> fontInfoConfigurator) {
super(userAgent);
+ this.rendererConfigParser = rendererConfigParser;
+ this.fontInfoConfigurator = fontInfoConfigurator;
}
/**
- * Builds a list of EmbedFontInfo objects for use with the setup() method.
+ * Returns the renderer configuration data for a specific renderer.
*
- * @param renderer print renderer
- * @throws FOPException if something's wrong with the config data
+ * @param documentHandler the document handler
+ * @return the renderer configuration data
+ * @throws FOPException if an error occurs
*/
- public void configure(Renderer renderer) throws FOPException {
- Configuration cfg = getRendererConfig(renderer);
- if (cfg == null) {
- log.trace("no configuration found for " + renderer);
- return;
- }
-
- PrintRenderer printRenderer = (PrintRenderer)renderer;
- FontResolver fontResolver = printRenderer.getFontResolver();
+ protected RendererConfig getRendererConfig(IFDocumentHandler documentHandler) throws FOPException {
+ return getRendererConfig(documentHandler.getMimeType());
+ }
- FontEventListener listener = new FontEventAdapter(
- renderer.getUserAgent().getEventBroadcaster());
- List<EmbedFontInfo> embedFontInfoList = buildFontList(cfg, fontResolver, listener);
- printRenderer.addFontList(embedFontInfoList);
+ /**
+ * gets the renderer configuration data for a specific renderer.
+ *
+ * @param mimeType the MIME type
+ * @return the renderer configuration data
+ * @throws FOPException if an error occurs
+ */
+ protected RendererConfig getRendererConfig(String mimeType) throws FOPException {
+ return userAgent.getRendererConfig(mimeType, rendererConfigParser);
}
/**
- * Builds the font list from configuration.
- * @param cfg the configuration object
- * @param fontResolver a font resolver
- * @param listener the font event listener
- * @return the list of {@link EmbedFontInfo} objects
- * @throws FOPException if an error occurs while processing the configuration
- */
- protected List<EmbedFontInfo> buildFontList(Configuration cfg, FontResolver fontResolver,
- FontEventListener listener) throws FOPException {
- FopFactory factory = userAgent.getFactory();
- FontManager fontManager = factory.getFontManager();
- if (fontResolver == null) {
- //Ensure that we have minimal font resolution capabilities
- fontResolver
- = FontManager.createMinimalFontResolver
- ( userAgent.isComplexScriptFeaturesEnabled() );
- }
+ * gets the renderer configuration data for a specific renderer.
+ *
+ * @param renderer the renderer
+ * @return the renderer configuration data
+ * @throws FOPException if an error occurs
+ */
+ protected RendererConfig getRendererConfig(Renderer renderer) throws FOPException {
+ return getRendererConfig(renderer.getMimeType());
+ }
- boolean strict = factory.validateUserConfigStrictly();
- //Read font configuration
- FontInfoConfigurator fontInfoConfigurator
- = new FontInfoConfigurator(cfg, fontManager, fontResolver, listener, strict);
- List<EmbedFontInfo> fontInfoList = new ArrayList<EmbedFontInfo>();
- fontInfoConfigurator.configure(fontInfoList);
- return fontInfoList;
+ /**
+ * Builds a list of EmbedFontInfo objects for use with the setup() method.
+ *
+ * @param renderer print renderer
+ * @throws FOPException if something's wrong with the config data
+ */
+ public void configure(Renderer renderer) throws FOPException {
+ PrintRenderer printRenderer = (PrintRenderer) renderer;
+ List<EmbedFontInfo> embedFontInfoList = buildFontList(renderer.getMimeType());
+ printRenderer.addFontList(embedFontInfoList);
}
- // ---=== IFDocumentHandler configuration ===---
-
/** {@inheritDoc} */
public void configure(IFDocumentHandler documentHandler) throws FOPException {
//nop
}
/** {@inheritDoc} */
- public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
- throws FOPException {
- FontManager fontManager = userAgent.getFactory().getFontManager();
- List<FontCollection> fontCollections = new ArrayList<FontCollection>();
- fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
-
- Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
- if (cfg != null) {
- FontResolver fontResolver = new DefaultFontResolver(userAgent);
- FontEventListener listener = new FontEventAdapter(
- userAgent.getEventBroadcaster());
- List<EmbedFontInfo> fontList = buildFontList(cfg, fontResolver, listener);
- fontCollections.add(new CustomFontCollection(fontResolver, fontList,
- userAgent.isComplexScriptFeaturesEnabled()));
+ public void setupFontInfo(String mimeType, FontInfo fontInfo) throws FOPException {
+ FontManager fontManager = userAgent.getFontManager();
+ List<FontCollection> fontCollections = getDefaultFontCollection();
+ fontCollections.add(getCustomFontCollection(fontManager.getResourceResolver(), mimeType));
+ fontManager.setup(fontInfo, fontCollections.toArray(new FontCollection[fontCollections.size()]));
+ }
+
+ protected abstract List<FontCollection> getDefaultFontCollection();
+
+ /**
+ * Returns the font collection for custom configured fonts.
+ *
+ * @param resolver the resource resolver
+ * @param mimeType the renderer MIME type
+ * @return the font collection
+ * @throws FOPException if an error occurs
+ */
+ protected FontCollection getCustomFontCollection(InternalResourceResolver resolver, String mimeType)
+ throws FOPException {
+ List<EmbedFontInfo> fontList;
+ if (rendererConfigParser == null) {
+ fontList = Collections.<EmbedFontInfo>emptyList();
+ } else {
+ fontList = fontInfoConfigurator.configure(getRendererConfig(mimeType).getFontInfoConfig());
}
+ return createCollectionFromFontList(resolver, fontList);
+ }
+
+ /***
+ * Creates the font collection given a list of embedded font infomation.
+ *
+ * @param resolver the resource resolver
+ * @param fontList the embedded font infomation
+ * @return the font collection
+ */
+ protected FontCollection createCollectionFromFontList(InternalResourceResolver resolver,
+ List<EmbedFontInfo> fontList) {
+ return new CustomFontCollection(resolver, fontList,
+ userAgent.isComplexScriptFeaturesEnabled());
+ }
- fontManager.setup(fontInfo,
- (FontCollection[])fontCollections.toArray(
- new FontCollection[fontCollections.size()]));
- documentHandler.setFontInfo(fontInfo);
+ private List<EmbedFontInfo> buildFontList(String mimeType) throws FOPException {
+ return fontInfoConfigurator.configure(getRendererConfig(mimeType).getFontInfoConfig());
}
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java Tue Jul 3 09:46:41 2012
@@ -36,6 +36,7 @@ import org.apache.fop.area.AreaTreeHandl
import org.apache.fop.fo.FOEventHandler;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
import org.apache.fop.render.intermediate.EventProducingFilter;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.render.intermediate.IFRenderer;
@@ -52,25 +53,19 @@ public class RendererFactory {
private Map eventHandlerMakerMapping = new java.util.HashMap();
private Map documentHandlerMakerMapping = new java.util.HashMap();
- private boolean rendererPreferred = false;
+ private final boolean rendererPreferred;
/**
* Main constructor.
+ * @param rendererPreferred Controls whether a {@link Renderer} is preferred over a
+ * {@link IFDocumentHandler} if both are available for the same MIME type. True to prefer the
+ * {@link Renderer}, false to prefer the {@link IFDocumentHandler}.
*/
- public RendererFactory() {
+ public RendererFactory(boolean rendererPreferred) {
discoverRenderers();
discoverFOEventHandlers();
discoverDocumentHandlers();
- }
-
- /**
- * Controls whether a {@link Renderer} is preferred over a {@link IFDocumentHandler} if
- * both are available for the same MIME type.
- * @param value true to prefer the {@link Renderer},
- * false to prefer the {@link IFDocumentHandler}.
- */
- public void setRendererPreferred(boolean value) {
- this.rendererPreferred = value;
+ this.rendererPreferred = rendererPreferred;
}
/**
@@ -239,7 +234,7 @@ public class RendererFactory {
* @param mime the requested output format
* @return the requested RendererMaker or null if none is available
*/
- public AbstractIFDocumentHandlerMaker getDocumentHandlerMaker(String mime) {
+ private AbstractIFDocumentHandlerMaker getDocumentHandlerMaker(String mime) {
AbstractIFDocumentHandlerMaker maker
= (AbstractIFDocumentHandlerMaker)documentHandlerMakerMapping.get(mime);
return maker;
@@ -299,10 +294,7 @@ public class RendererFactory {
AbstractRendererMaker maker = getRendererMaker(outputFormat);
if (maker != null) {
Renderer rend = maker.makeRenderer(userAgent);
- RendererConfigurator configurator = maker.getConfigurator(userAgent);
- if (configurator != null) {
- configurator.configure(rend);
- }
+ maker.configureRenderer(userAgent, rend);
return rend;
} else {
return null;
@@ -383,7 +375,10 @@ public class RendererFactory {
throw new UnsupportedOperationException(
"No IF document handler for the requested format available: " + outputFormat);
}
- IFDocumentHandler documentHandler = maker.makeIFDocumentHandler(userAgent);
+ IFDocumentHandler documentHandler = maker.makeIFDocumentHandler(new IFContext(userAgent));
+ // TODO: do all the configuration in the makeIfDocumentHandler method, that would beam when
+ // you ask for a document handler, a configured one is returned to you. Getting it and
+ // configuring it in two steps doesn't make sense.
IFDocumentHandlerConfigurator configurator = documentHandler.getConfigurator();
if (configurator != null) {
configurator.configure(documentHandler);
@@ -398,15 +393,15 @@ public class RendererFactory {
List lst = new java.util.ArrayList();
Iterator iter = this.rendererMakerMapping.keySet().iterator();
while (iter.hasNext()) {
- lst.add(((String)iter.next()));
+ lst.add(iter.next());
}
iter = this.eventHandlerMakerMapping.keySet().iterator();
while (iter.hasNext()) {
- lst.add(((String)iter.next()));
+ lst.add(iter.next());
}
iter = this.documentHandlerMakerMapping.keySet().iterator();
while (iter.hasNext()) {
- lst.add(((String)iter.next()));
+ lst.add(iter.next());
}
Collections.sort(lst);
return (String[])lst.toArray(new String[lst.size()]);
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/XMLHandlerConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/XMLHandlerConfigurator.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/XMLHandlerConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/XMLHandlerConfigurator.java Tue Jul 3 09:46:41 2012
@@ -83,7 +83,7 @@ public class XMLHandlerConfigurator exte
*/
public void configure(RendererContext context, String ns) throws FOPException {
//Optional XML handler configuration
- Configuration cfg = getRendererConfig(context.getRenderer());
+ Configuration cfg = userAgent.getRendererConfiguration(context.getRenderer().getMimeType());
if (cfg != null) {
cfg = getHandlerConfig(cfg, ns);
if (cfg != null) {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java Tue Jul 3 09:46:41 2012
@@ -19,6 +19,8 @@
package org.apache.fop.render.afp;
+import java.net.URI;
+
import org.apache.fop.afp.AFPResourceLevelDefaults;
/**
@@ -152,10 +154,10 @@ public interface AFPCustomizable {
boolean isStrokeGOCAText();
/**
- * Sets the default resource group file path
- * @param filePath the default resource group file path
+ * Sets the default resource group URI
+ * @param uri the default resource group URI
*/
- void setDefaultResourceGroupFilePath(String filePath);
+ void setDefaultResourceGroupUri(URI uri);
/**
* Sets the resource level defaults. The object passed in provides information which resource
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java Tue Jul 3 09:46:41 2012
@@ -23,6 +23,7 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.geom.AffineTransform;
import java.io.IOException;
+import java.net.URI;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -38,13 +39,13 @@ import org.apache.fop.afp.DataStream;
import org.apache.fop.afp.fonts.AFPFontCollection;
import org.apache.fop.afp.fonts.AFPPageFonts;
import org.apache.fop.afp.modca.ResourceObject;
-import org.apache.fop.afp.util.DefaultFOPResourceAccessor;
-import org.apache.fop.afp.util.ResourceAccessor;
+import org.apache.fop.afp.util.AFPResourceAccessor;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.fonts.FontCollection;
import org.apache.fop.fonts.FontEventAdapter;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontManager;
+import org.apache.fop.render.afp.AFPRendererConfig.AFPRendererConfigParser;
import org.apache.fop.render.afp.extensions.AFPElementMapping;
import org.apache.fop.render.afp.extensions.AFPIncludeFormMap;
import org.apache.fop.render.afp.extensions.AFPInvokeMediumMap;
@@ -53,6 +54,8 @@ import org.apache.fop.render.afp.extensi
import org.apache.fop.render.afp.extensions.AFPPageSetup;
import org.apache.fop.render.afp.extensions.ExtensionPlacement;
import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
+import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
@@ -99,8 +102,9 @@ public class AFPDocumentHandler extends
/**
* Default constructor.
*/
- public AFPDocumentHandler() {
- this.resourceManager = new AFPResourceManager();
+ public AFPDocumentHandler(IFContext context) {
+ super(context);
+ this.resourceManager = new AFPResourceManager(context.getUserAgent().getResourceResolver());
this.paintingState = new AFPPaintingState();
this.unitConv = paintingState.getUnitConverter();
}
@@ -117,13 +121,13 @@ public class AFPDocumentHandler extends
/** {@inheritDoc} */
public IFDocumentHandlerConfigurator getConfigurator() {
- return new AFPRendererConfigurator(getUserAgent());
+ return new AFPRendererConfigurator(getUserAgent(), new AFPRendererConfigParser());
}
/** {@inheritDoc} */
@Override
public void setDefaultFontInfo(FontInfo fontInfo) {
- FontManager fontManager = getUserAgent().getFactory().getFontManager();
+ FontManager fontManager = getUserAgent().getFontManager();
FontCollection[] fontCollections = new FontCollection[] {
new AFPFontCollection(getUserAgent().getEventBroadcaster(), null)
};
@@ -381,8 +385,8 @@ public class AFPDocumentHandler extends
}
} else if (extension instanceof AFPIncludeFormMap) {
AFPIncludeFormMap formMap = (AFPIncludeFormMap)extension;
- ResourceAccessor accessor = new DefaultFOPResourceAccessor(
- getUserAgent(), null, null);
+ AFPResourceAccessor accessor = new AFPResourceAccessor(
+ getUserAgent().getResourceResolver());
try {
getResourceManager().createIncludedResource(formMap.getName(),
formMap.getSrc(), accessor,
@@ -493,9 +497,8 @@ public class AFPDocumentHandler extends
return paintingState.getFS45();
}
- /** {@inheritDoc} */
- public void setDefaultResourceGroupFilePath(String filePath) {
- resourceManager.setDefaultResourceGroupFilePath(filePath);
+ public void setDefaultResourceGroupUri(URI uri) {
+ resourceManager.setDefaultResourceGroupUri(uri);
}
/** {@inheritDoc} */
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java Tue Jul 3 09:46:41 2012
@@ -19,7 +19,6 @@
package org.apache.fop.render.afp;
-import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
import org.apache.fop.render.intermediate.IFContext;
@@ -36,10 +35,8 @@ public class AFPDocumentHandlerMaker ext
};
/** {@inheritDoc} */
- public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
- AFPDocumentHandler handler = new AFPDocumentHandler();
- handler.setContext(new IFContext(ua));
- return handler;
+ public IFDocumentHandler makeIFDocumentHandler(IFContext ifContext) {
+ return new AFPDocumentHandler(ifContext);
}
/** {@inheritDoc} */
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPForeignAttributeReader.java Tue Jul 3 09:46:41 2012
@@ -19,7 +19,7 @@
package org.apache.fop.render.afp;
-import java.io.File;
+import java.net.URI;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -46,7 +46,7 @@ public class AFPForeignAttributeReader {
AFPElementMapping.NAMESPACE, "afp:resource-level");
/** the resource-group-file attribute */
- public static final QName RESOURCE_GROUP_FILE = new QName(
+ public static final QName RESOURCE_GROUP_URI = new QName(
AFPElementMapping.NAMESPACE, "afp:resource-group-file");
/**
@@ -64,7 +64,7 @@ public class AFPForeignAttributeReader {
public AFPResourceInfo getResourceInfo(Map/*<QName, String>*/ foreignAttributes) {
AFPResourceInfo resourceInfo = new AFPResourceInfo();
if (foreignAttributes != null && !foreignAttributes.isEmpty()) {
- String resourceName = (String)foreignAttributes.get(RESOURCE_NAME);
+ String resourceName = (String) foreignAttributes.get(RESOURCE_NAME);
if (resourceName != null) {
resourceInfo.setName(resourceName);
}
@@ -82,45 +82,20 @@ public class AFPForeignAttributeReader {
* @param foreignAttributes the foreign attributes
* @return the resource level
*/
- public AFPResourceLevel getResourceLevel(Map/*<QName, String>*/ foreignAttributes) {
+ public AFPResourceLevel getResourceLevel(Map<QName, String> foreignAttributes) {
AFPResourceLevel resourceLevel = null;
if (foreignAttributes != null && !foreignAttributes.isEmpty()) {
if (foreignAttributes.containsKey(RESOURCE_LEVEL)) {
- String levelString = (String)foreignAttributes.get(RESOURCE_LEVEL);
+ String levelString = foreignAttributes.get(RESOURCE_LEVEL);
resourceLevel = AFPResourceLevel.valueOf(levelString);
// if external get resource group file attributes
if (resourceLevel != null && resourceLevel.isExternal()) {
- String resourceGroupFile
- = (String)foreignAttributes.get(RESOURCE_GROUP_FILE);
- if (resourceGroupFile == null) {
- String msg = RESOURCE_GROUP_FILE + " not specified";
- LOG.error(msg);
+ String resourceGroupUri = foreignAttributes.get(RESOURCE_GROUP_URI);
+ if (resourceGroupUri == null) {
+ String msg = RESOURCE_GROUP_URI + " not specified";
throw new UnsupportedOperationException(msg);
}
- File resourceExternalGroupFile = new File(resourceGroupFile);
- SecurityManager security = System.getSecurityManager();
- try {
- if (security != null) {
- security.checkWrite(resourceExternalGroupFile.getPath());
- }
- } catch (SecurityException ex) {
- String msg = "unable to gain write access to external resource file: "
- + resourceGroupFile;
- LOG.error(msg);
- }
-
- try {
- boolean exists = resourceExternalGroupFile.exists();
- if (exists) {
- LOG.warn("overwriting external resource file: "
- + resourceGroupFile);
- }
- resourceLevel.setExternalFilePath(resourceGroupFile);
- } catch (SecurityException ex) {
- String msg = "unable to gain read access to external resource file: "
- + resourceGroupFile;
- LOG.error(msg);
- }
+ resourceLevel.setExternalUri(URI.create(resourceGroupUri));
}
}
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerSVG.java Tue Jul 3 09:46:41 2012
@@ -42,6 +42,7 @@ import org.apache.fop.afp.AFPObjectAreaI
import org.apache.fop.afp.AFPPaintingState;
import org.apache.fop.afp.AFPResourceInfo;
import org.apache.fop.afp.AFPResourceLevel;
+import org.apache.fop.afp.AFPResourceLevel.ResourceType;
import org.apache.fop.afp.AFPResourceManager;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.image.loader.batik.BatikImageFlavors;
@@ -142,7 +143,7 @@ public class AFPImageHandlerSVG implemen
//level not explicitly set/changed so default to inline for GOCA graphic objects
// (due to a bug in the IBM AFP Workbench Viewer (2.04.01.07), hard copy works just fine)
if (!resourceInfo.levelChanged()) {
- resourceInfo.setLevel(new AFPResourceLevel(AFPResourceLevel.INLINE));
+ resourceInfo.setLevel(new AFPResourceLevel(ResourceType.INLINE));
}
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPPainter.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPPainter.java Tue Jul 3 09:46:41 2012
@@ -51,8 +51,7 @@ import org.apache.fop.afp.modca.Abstract
import org.apache.fop.afp.modca.PresentationTextObject;
import org.apache.fop.afp.ptoca.PtocaBuilder;
import org.apache.fop.afp.ptoca.PtocaProducer;
-import org.apache.fop.afp.util.DefaultFOPResourceAccessor;
-import org.apache.fop.afp.util.ResourceAccessor;
+import org.apache.fop.afp.util.AFPResourceAccessor;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.Typeface;
@@ -204,8 +203,8 @@ public class AFPPainter extends Abstract
//Do we need to embed an external page segment?
if (pageSegment.getURI() != null) {
- ResourceAccessor accessor = new DefaultFOPResourceAccessor (
- getUserAgent(), null, null);
+ AFPResourceAccessor accessor = new AFPResourceAccessor(
+ getDocumentHandler().getUserAgent().getResourceResolver());
try {
URI resourceUri = new URI(pageSegment.getURI());
getDocumentHandler().getResourceManager().createIncludedResourceFromExternal(
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org