Dear Stefano, I wrote a RTF to XSL-FO converter that can embed images in the created XSL-FO file/stream using the data scheme. The JRE gives us the chance to set a stream handler factory handling other protocols. Please have a look at the attached Java files. Compile all and then call (before rendering with FOP):
URL.setURLStreamHandlerFactory( de.dd.net.ExtendableURLStreamHandlerFactory.getDefaultFactory() ); I tested it with FOP and it works fine. After rendering you should probably clear FOPs image cache by calling org.apache.fop.image.FopImageFactory.resetCache(); Cheers, Sascha NORTHBIT Sascha Schmidt [EMAIL PROTECTED] www.northbit.de -----Ursprüngliche Nachricht----- Von: Chizzolini Stefano [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 16. September 2004 14:28 An: [EMAIL PROTECTED] Betreff: [Image embedding] fo:external-graphic - fop support to uri data scheme Hello folks, I'm wondering whether FOP supports real XSL-FO image embedding (not the referencial "embedding" described in the images.fo example). I say: can FOP properly render a fo:external-graphic element whose src attribute contains an inline binary image defined accordingly to the uri data scheme (RFC 2397)? Regards, Stefano Chizzolini --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
package de.dd.io; import java.io.*; /** * <p>Überschrift: </p> * <p>Beschreibung: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Organisation: </p> * @author not attributable * @version 1.0 */ public class Base64InputStream extends InputStream{ //---- Attributes ------------------------------------------------------------ private char[] readBuffer = new char[4]; private int[] buffer = new int[3]; private int bufferPosition = 3; private int preview = -1; private Reader in; private static final byte base64ToInt[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 }; //---- statics --------------------------------------------------------------- //---- Constructors ---------------------------------------------------------- public Base64InputStream(Reader in) { this.in = in; } //---- public --------------------------------------------------------------- public int read() throws IOException{ int rc = getPreview(); preview=-1; return rc; } public int available() throws IOException { if (getPreview()==-1) return 0; else return 1; } //---- protected ------------------------------------------------------------- private final int getIntOfChar(int c){ if (c>=base64ToInt.length) throw new IllegalArgumentException("Invalid character '"+c+"'"); int i = base64ToInt[c]; if (i==-1) throw new IllegalArgumentException("Invalid character '"+c+"'"); return i; } //---- package --------------------------------------------------------------- //---- privat ---------------------------------------------------------------- private int getPreview() throws IOException{ if (preview==-1){ preview = readPreview(); } return preview; } private final int readPreview() throws IOException{ if (bufferPosition>2){ readNextTriple(); } return buffer[bufferPosition++]; } private final void readNextTriple() throws IOException{ bufferPosition=0; int size = in.read(readBuffer); if (size<4){ buffer[0] = -1; buffer[1] = -1; buffer[2] = -1; return; } int i0 = getIntOfChar(readBuffer[0]); int i1 = getIntOfChar(readBuffer[1]); buffer[0] = ((i0 << 2) | (i1 >> 4)) & 0xFF; if (readBuffer[2]=='='){ buffer[1] = -1; buffer[2] = -1; } else{ int i2 = getIntOfChar(readBuffer[2]); buffer[1] = ((i1 << 4) | (i2 >> 2)) & 0xFF; if (readBuffer[3]=='=') buffer[2] = -1; else{ int i3 = getIntOfChar(readBuffer[3]); buffer[2] = ((i2 << 6) | i3) & 0xFF; } } return; } }
package de.dd.net; import java.net.*; import de.dd.net.protocol.DataURLStreamHandler; import java.util.HashMap; public class ExtendableURLStreamHandlerFactory implements URLStreamHandlerFactory{ //---- Attributes ------------------------------------------------------------ private HashMap protocol2Handler = new HashMap(); private static ExtendableURLStreamHandlerFactory instance; //---- statics --------------------------------------------------------------- public final static ExtendableURLStreamHandlerFactory getDefaultFactory(){ if (instance==null) instance=new ExtendableURLStreamHandlerFactory(); return instance; } //---- Constructors ---------------------------------------------------------- public ExtendableURLStreamHandlerFactory() { putHandler(DataURLStreamHandler.PROTOCOL, new DataURLStreamHandler()); } //---- public --------------------------------------------------------------- public URLStreamHandler createURLStreamHandler(String string) { return (URLStreamHandler) protocol2Handler.get(string); } public void putHandler(String protocol, URLStreamHandler handler){ this.protocol2Handler.put(protocol, handler); } public boolean handlesProtocol(String protocol){ return protocol2Handler.containsKey(protocol); } //---- protected ------------------------------------------------------------- //---- package --------------------------------------------------------------- //---- privat ---------------------------------------------------------------- }
package de.dd.net.protocol; import java.io.*; import java.net.*; import java.util.*; import de.dd.io.Base64InputStream; import java.io.CharArrayReader; /** * <p>Überschrift: </p> * <p>Beschreibung: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Organisation: </p> * @author not attributable * @version 1.0 */ public class DataURLConnection extends URLConnection { //---- Attributes ------------------------------------------------------------ private boolean base64 = false; private boolean connected = false; private String data; private String mediaType; private HashMap headerFields = new HashMap(); //---- statics --------------------------------------------------------------- //---- Constructors ---------------------------------------------------------- public DataURLConnection(URL url) { super(url); } //---- public --------------------------------------------------------------- public void connect() throws IOException{ if( connected ) return; connected = true; String data = getURL().getPath(); int dataStart = data.indexOf(','); if (dataStart==-1) throw new IOException("Expecting ',' introducing data"); String prefix = data.substring(0, dataStart); if (prefix.trim().endsWith(";base64")){ base64 = true; mediaType = prefix.substring(0, prefix.length()-7).trim(); } else{ mediaType = prefix.trim(); } this.data = data.substring(dataStart+1); if (mediaType==null || mediaType.length()==0) mediaType="text/plain"; headerFields.put("content-type", mediaType); } public String getHeaderField(String name) { return (String) headerFields.get(name); } public Map getHeaderFields() { return headerFields; } public InputStream getInputStream() throws IOException { connect(); return base64 ? (InputStream) new Base64InputStream( new CharArrayReader( data.toCharArray() ) ) : (InputStream) new DefaultInputStream(); } //---- protected ------------------------------------------------------------- //---- package --------------------------------------------------------------- //---- privat ---------------------------------------------------------------- private class DefaultInputStream extends InputStream{ int dataIdx = 0; public int available() throws IOException{ return dataIdx+1<data.length() ? 1 : 0; } public int read() throws IOException { try { char c = data.charAt(dataIdx++); if (c != '%') { return c; } else { char h1 = data.charAt(dataIdx++); char h2 = data.charAt(dataIdx++); int value = Character.digit(h1, 16) * 16 + Character.digit(h2, 16); return (char) value; } } catch (IndexOutOfBoundsException ex) { return -1; } } } }
package de.dd.net.protocol; import java.net.URLStreamHandler; import java.net.URLConnection; import java.net.URL; /** * <p>Überschrift: </p> * <p>Beschreibung: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Organisation: </p> * @author not attributable * @version 1.0 */ public class DataURLStreamHandler extends URLStreamHandler { //---- Attributes ------------------------------------------------------------ public final static String PROTOCOL="data"; //---- statics --------------------------------------------------------------- //---- Constructors ---------------------------------------------------------- public DataURLStreamHandler() { } //---- public --------------------------------------------------------------- //---- protected ------------------------------------------------------------- protected URLConnection openConnection(URL url) { return new DataURLConnection(url); } //---- package --------------------------------------------------------------- //---- privat ---------------------------------------------------------------- }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]