mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fix for ALF-14746 (SVG mimetype)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@40697 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -17,12 +17,13 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. */
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
package org.alfresco.web.forms;
|
package org.alfresco.web.forms;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.io.OutputStream;
|
||||||
import javax.xml.transform.Result;
|
import java.util.HashMap;
|
||||||
import javax.xml.transform.Source;
|
import java.util.Map;
|
||||||
import javax.xml.transform.dom.DOMSource;
|
|
||||||
import javax.xml.transform.sax.SAXResult;
|
import javax.xml.transform.sax.SAXResult;
|
||||||
|
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -31,97 +32,85 @@ import org.apache.fop.apps.FOUserAgent;
|
|||||||
import org.apache.fop.apps.Fop;
|
import org.apache.fop.apps.Fop;
|
||||||
import org.apache.fop.apps.FopFactory;
|
import org.apache.fop.apps.FopFactory;
|
||||||
import org.apache.fop.apps.MimeConstants;
|
import org.apache.fop.apps.MimeConstants;
|
||||||
import org.w3c.dom.*;
|
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A rendering engine which uses xsl-fo templates to generate renditions of
|
* A rendering engine which uses xsl-fo templates to generate renditions of form
|
||||||
* form instance data.
|
* instance data.
|
||||||
*
|
*
|
||||||
* @author Ariel Backenroth
|
* @author Ariel Backenroth
|
||||||
*/
|
*/
|
||||||
public class XSLFORenderingEngine
|
public class XSLFORenderingEngine extends XSLTRenderingEngine
|
||||||
extends XSLTRenderingEngine
|
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final Log LOGGER = LogFactory.getLog(XSLFORenderingEngine.class);
|
private static final Log LOGGER = LogFactory.getLog(XSLFORenderingEngine.class);
|
||||||
|
|
||||||
private static final Map<String, String> MIME_TYPES =
|
private static final Map<String, String> MIME_TYPES = new HashMap<String, String>();
|
||||||
new HashMap<String, String>();
|
static
|
||||||
static
|
{
|
||||||
{
|
MIME_TYPES.put(MimeConstants.MIME_PDF, MimeConstants.MIME_PDF);
|
||||||
MIME_TYPES.put(MimeConstants.MIME_PDF, MimeConstants.MIME_PDF);
|
|
||||||
|
|
||||||
MIME_TYPES.put(MimeConstants.MIME_POSTSCRIPT, MimeConstants.MIME_POSTSCRIPT);
|
MIME_TYPES.put(MimeConstants.MIME_POSTSCRIPT, MimeConstants.MIME_POSTSCRIPT);
|
||||||
MIME_TYPES.put(MimeConstants.MIME_EPS, MimeConstants.MIME_POSTSCRIPT);
|
MIME_TYPES.put(MimeConstants.MIME_EPS, MimeConstants.MIME_POSTSCRIPT);
|
||||||
|
|
||||||
MIME_TYPES.put(MimeConstants.MIME_PLAIN_TEXT, MimeConstants.MIME_PLAIN_TEXT);
|
MIME_TYPES.put(MimeConstants.MIME_PLAIN_TEXT, MimeConstants.MIME_PLAIN_TEXT);
|
||||||
|
|
||||||
MIME_TYPES.put(MimeConstants.MIME_RTF, MimeConstants.MIME_RTF);
|
MIME_TYPES.put(MimeConstants.MIME_RTF, MimeConstants.MIME_RTF);
|
||||||
MIME_TYPES.put(MimeConstants.MIME_RTF_ALT1, MimeConstants.MIME_RTF);
|
MIME_TYPES.put(MimeConstants.MIME_RTF_ALT1, MimeConstants.MIME_RTF);
|
||||||
MIME_TYPES.put(MimeConstants.MIME_RTF_ALT2, MimeConstants.MIME_RTF);
|
MIME_TYPES.put(MimeConstants.MIME_RTF_ALT2, MimeConstants.MIME_RTF);
|
||||||
|
|
||||||
MIME_TYPES.put(MimeConstants.MIME_MIF, MimeConstants.MIME_MIF);
|
MIME_TYPES.put(MimeConstants.MIME_MIF, MimeConstants.MIME_MIF);
|
||||||
MIME_TYPES.put("application/x-mif", MimeConstants.MIME_MIF);
|
MIME_TYPES.put("application/x-mif", MimeConstants.MIME_MIF);
|
||||||
|
|
||||||
MIME_TYPES.put(MimeConstants.MIME_SVG, MimeConstants.MIME_SVG);
|
MIME_TYPES.put(MimeConstants.MIME_SVG, MimeConstants.MIME_SVG);
|
||||||
MIME_TYPES.put("image/svg", MimeConstants.MIME_SVG);
|
|
||||||
|
|
||||||
//looks like a dependency is missing - removing for now
|
// looks like a dependency is missing - removing for now
|
||||||
//MIME_TYPES.put(MimeConstants.MIME_GIF, MimeConstants.MIME_GIF);
|
// MIME_TYPES.put(MimeConstants.MIME_GIF, MimeConstants.MIME_GIF);
|
||||||
MIME_TYPES.put(MimeConstants.MIME_PNG, MimeConstants.MIME_PNG);
|
MIME_TYPES.put(MimeConstants.MIME_PNG, MimeConstants.MIME_PNG);
|
||||||
MIME_TYPES.put(MimeConstants.MIME_JPEG, MimeConstants.MIME_JPEG);
|
MIME_TYPES.put(MimeConstants.MIME_JPEG, MimeConstants.MIME_JPEG);
|
||||||
MIME_TYPES.put(MimeConstants.MIME_TIFF, MimeConstants.MIME_TIFF);
|
MIME_TYPES.put(MimeConstants.MIME_TIFF, MimeConstants.MIME_TIFF);
|
||||||
};
|
};
|
||||||
|
|
||||||
public XSLFORenderingEngine()
|
public XSLFORenderingEngine()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
return "XSL-FO";
|
return "XSL-FO";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultTemplateFileExtension()
|
public String getDefaultTemplateFileExtension()
|
||||||
{
|
{
|
||||||
return "fo";
|
return "fo";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(final Map<QName, Object> model,
|
public void render(final Map<QName, Object> model, final RenderingEngineTemplate ret, final OutputStream out)
|
||||||
final RenderingEngineTemplate ret,
|
throws IOException, RenderingEngine.RenderingException, SAXException
|
||||||
final OutputStream out)
|
{
|
||||||
throws IOException,
|
|
||||||
RenderingEngine.RenderingException,
|
|
||||||
SAXException
|
|
||||||
{
|
|
||||||
|
|
||||||
String mimetype = MIME_TYPES.get(ret.getMimetypeForRendition());
|
String mimetype = MIME_TYPES.get(ret.getMimetypeForRendition());
|
||||||
if (mimetype == null)
|
if (mimetype == null) { throw new RenderingEngine.RenderingException("mimetype "
|
||||||
{
|
+ ret.getMimetypeForRendition() + " is not supported by " + this.getName()); }
|
||||||
throw new RenderingEngine.RenderingException("mimetype " + ret.getMimetypeForRendition() +
|
try
|
||||||
" is not supported by " + this.getName());
|
{
|
||||||
}
|
final FopFactory fopFactory = FopFactory.newInstance();
|
||||||
try
|
final FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
|
||||||
{
|
final Fop fop = fopFactory.newFop(mimetype, foUserAgent, out);
|
||||||
final FopFactory fopFactory = FopFactory.newInstance();
|
// Resulting SAX events (the generated FO) must be piped through to
|
||||||
final FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
|
// FOP
|
||||||
final Fop fop = fopFactory.newFop(mimetype, foUserAgent, out);
|
super.render(model, ret, new SAXResult(fop.getDefaultHandler()));
|
||||||
// Resulting SAX events (the generated FO) must be piped through to FOP
|
|
||||||
super.render(model,
|
|
||||||
ret,
|
|
||||||
new SAXResult(fop.getDefaultHandler()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (FOPException fope)
|
catch (FOPException fope)
|
||||||
{
|
{
|
||||||
throw new RenderingEngine.RenderingException(fope);
|
throw new RenderingEngine.RenderingException(fope);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user