Source Code Cross Referenced for XMLReader.java in  » Graphic-Library » fop » org » apache » fop » image » analyser » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Graphic Library » fop » org.apache.fop.image.analyser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        /* $Id: XMLReader.java 542447 2007-05-29 07:51:52Z vhennebert $ */
019:
020:        package org.apache.fop.image.analyser;
021:
022:        // Java
023:        import java.io.InputStream;
024:        import java.io.IOException;
025:        import java.util.Map;
026:
027:        // XML
028:        import javax.xml.parsers.DocumentBuilderFactory;
029:        import org.w3c.dom.Document;
030:        import org.w3c.dom.Element;
031:
032:        // FOP
033:        import org.apache.fop.image.FopImage;
034:        import org.apache.fop.util.UnclosableInputStream;
035:        import org.apache.fop.apps.FOUserAgent;
036:
037:        // Commons-Logging
038:        import org.apache.commons.io.IOUtils;
039:        import org.apache.commons.logging.Log;
040:        import org.apache.commons.logging.LogFactory;
041:
042:        /** ImageReader object for XML document image type. */
043:        public class XMLReader implements  ImageReader {
044:
045:            /**
046:             * logging instance
047:             */
048:            private Log log = LogFactory.getLog(XMLReader.class);
049:
050:            private static Map converters = new java.util.HashMap();
051:
052:            /**
053:             * Registers a Converter implementation with XMLReader.
054:             *
055:             * @param ns    The namespace to associate with this converter
056:             * @param conv  The actual Converter implementation
057:             */
058:            public static void setConverter(String ns, Converter conv) {
059:                converters.put(ns, conv);
060:            }
061:
062:            /** @see org.apache.fop.image.analyser.ImageReader */
063:            public FopImage.ImageInfo verifySignature(String uri,
064:                    InputStream fis, FOUserAgent ua) throws IOException {
065:                FopImage.ImageInfo info = loadImage(uri, fis, ua);
066:                if (info != null) {
067:                    info.originalURI = uri;
068:                    IOUtils.closeQuietly(fis);
069:                }
070:                return info;
071:            }
072:
073:            /**
074:             * Returns the MIME type supported by this implementation.
075:             *
076:             * @return   The MIME type
077:             */
078:            public String getMimeType() {
079:                return "text/xml";
080:            }
081:
082:            /**
083:             * Creates an ImageInfo object from an XML image read from a stream.
084:             *
085:             * (todo) This means the external svg document will be loaded twice. Possibly need
086:             * a slightly different design for the image stuff.
087:             *
088:             * @param uri  The URI to the image
089:             * @param bis  The InputStream
090:             * @param ua   The user agent
091:             * @return     An ImageInfo object describing the image
092:             */
093:            protected FopImage.ImageInfo loadImage(String uri, InputStream bis,
094:                    FOUserAgent ua) {
095:                return createDocument(bis, ua);
096:            }
097:
098:            /**
099:             * Creates an ImageInfo object from an XML image read from a stream.
100:             *
101:             * @param input  The InputStream
102:             * @param ua  The user agent
103:             * @return    An ImageInfo object describing the image
104:             */
105:            public FopImage.ImageInfo createDocument(final InputStream input,
106:                    final FOUserAgent ua) {
107:                Document doc = null;
108:                FopImage.ImageInfo info = new FopImage.ImageInfo();
109:                info.mimeType = getMimeType();
110:
111:                try {
112:                    final InputStream is = new UnclosableInputStream(input);
113:                    int length = is.available();
114:                    is.mark(length);
115:
116:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
117:                            .newInstance();
118:                    doc = dbf.newDocumentBuilder().parse(is);
119:                    info.data = doc;
120:
121:                    Element root = doc.getDocumentElement();
122:                    log.debug("XML image namespace: "
123:                            + root.getAttribute("xmlns"));
124:                    String ns = root.getAttribute("xmlns");
125:                    info.str = ns;
126:
127:                    Converter conv = (Converter) converters.get(ns);
128:                    if (conv != null) {
129:                        FopImage.ImageInfo i = conv.convert(doc);
130:                        if (i != null) {
131:                            info = i;
132:                        }
133:                    }
134:                } catch (Exception e) {
135:                    log.debug("Error while constructing image from XML", e);
136:                    try {
137:                        input.reset();
138:                    } catch (IOException ioe) {
139:                        // throw the original exception, not this one
140:                    }
141:                    return null;
142:                }
143:                if (info != null) {
144:                    try {
145:                        input.close();
146:                    } catch (IOException io) {
147:                        // ignore
148:                    }
149:                }
150:                return info;
151:            }
152:
153:            /**
154:             * This interface is to be implemented for XML to image converters.
155:             */
156:            public static interface Converter {
157:
158:                /**
159:                 * This method is called for a DOM document to be converted into an
160:                 * ImageInfo object.
161:                 *
162:                 * @param doc   The DOM document to convert
163:                 * @return      An ImageInfo object describing the image
164:                 */
165:                FopImage.ImageInfo convert(Document doc);
166:            }
167:
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.