001 /*
002 * Copyright 2007 - 2007 JEuclid, http://jeuclid.sf.net
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 /* $Id: ODFReader.java 321 2007-05-21 19:20:35Z maxberger $ */
018
019 /*
020 * Please note: This file was originally taken from the Apache FOP project,
021 * available at http://xmlgraphics.apache.org/fop/ It is therefore
022 * partially copyright (c) 1999-2007 The Apache Software Foundation.
023 *
024 * Parts of the contents are heavily inspired by work done for Barcode4J by
025 * Jeremias Maerki, available at http://barcode4j.sf.net/
026 */
027
028 package net.sourceforge.jeuclid.fop;
029
030 import java.io.IOException;
031 import java.io.InputStream;
032
033 import net.sourceforge.jeuclid.MathMLParserSupport;
034
035 import org.apache.fop.apps.FOUserAgent;
036 import org.apache.fop.image.FopImage;
037 import org.apache.fop.image.analyser.XMLReader;
038 import org.w3c.dom.Document;
039 import org.xml.sax.SAXException;
040
041 /**
042 * Reader plugin for the ODF Format.
043 *
044 * @author Max Berger
045 * @version $Revision: 321 $
046 */
047 public class ODFReader extends XMLReader {
048
049 /**
050 * Default constructor.
051 */
052 public ODFReader() {
053 }
054
055 /** {@inheritDoc} */
056 @Override
057 protected FopImage.ImageInfo loadImage(final String uri,
058 final InputStream bis, final FOUserAgent ua) {
059
060 Document doc;
061 try {
062 doc = MathMLParserSupport.parseInputStreamODF(bis);
063 return new JEuclidElementMapping.MathMLConverter().convert(doc);
064 } catch (final SAXException e) {
065 // ignore
066 } catch (final IOException e) {
067 // ignore
068 }
069 return null;
070 }
071
072 }