Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libGPE-XML / src / org / gvsig / gpe / xml / parser / GPEXmlParserFactory.java @ 27598

History | View | Annotate | Download (5.38 KB)

1
package org.gvsig.gpe.xml.parser;
2

    
3
import java.io.InputStream;
4
import java.io.OutputStream;
5

    
6
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
7
import org.gvsig.gpe.xml.stream.IXmlStreamReaderFactory;
8
import org.gvsig.gpe.xml.stream.IXmlStreamWriter;
9
import org.gvsig.gpe.xml.stream.XmlStreamException;
10
import org.gvsig.gpe.xml.stream.kxml.KxmlXmlParserFactory;
11

    
12

    
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id: GPEXmlParserFactory.java 144 2007-06-07 14:53:59Z jorpiell $
56
 * $Log$
57
 * Revision 1.3  2007/06/07 14:53:30  jorpiell
58
 * Add the schema support
59
 *
60
 * Revision 1.2  2007/04/12 11:47:15  jorpiell
61
 * Add a getParser method
62
 *
63
 * Revision 1.1  2007/04/12 10:23:41  jorpiell
64
 * Add some writers and the GPEXml parser
65
 *
66
 *
67
 */
68
/**
69
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
70
 */
71
public class GPEXmlParserFactory {
72
        //private static ClassLoader classLoader = null;
73
        private static IXmlStreamReaderFactory factory;
74
        private static String parserName;
75
        /**
76
         * Create a new parser from a name
77
         * @param name
78
         * GPEParser name
79
         * @param contenHandler
80
         * Application contenHandler usett to throw the parsing events
81
         * @param errorHandler
82
         * Application errror handler used to put errors and warnings
83
         * @throws GPEParserCreationException  
84
         */
85
        public static IXmlStreamReader getParser(final String mimeType, final InputStream in) throws XmlStreamException {
86
                return createXmlParser(parserName,mimeType,in);
87
        }
88
        
89
        public static IXmlStreamReader createXmlParser(String name, String mimeType, InputStream in) throws XmlStreamException, IllegalArgumentException {
90
          factory = (IXmlStreamReaderFactory) new KxmlXmlParserFactory();
91
          if(factory.canParse(mimeType)){
92
              return factory.createParser(mimeType, in);
93
          }
94
          throw new XmlStreamException("ERROR: no xml parser factory found able to parse content type: " + mimeType);
95
        }
96

    
97
        public static IXmlStreamWriter getWriter(String format,        OutputStream outputStream) {
98
                // TODO Auto-generated method stub
99
                return (IXmlStreamWriter) new java.io.OutputStreamWriter(outputStream);
100
        }  
101
        
102
//        public static void setClassLoader(ClassLoader classLoader) {
103
//                GPEXmlParserFactory.classLoader = classLoader;
104
//        }
105
//    
106
//        private static Iterator availableParserFactories() {
107
//        if (classLoader != null){
108
//                return sun.misc.Service.providers(IXmlStreamReaderFactory.class, classLoader);
109
//        }else{
110
//                return sun.misc.Service.providers(IXmlStreamReaderFactory.class);
111
//        }       
112
//        
113
//    }
114
//    
115
//    /**
116
//     * @return the parser
117
//     * @throws XMLStreamException
118
//     */
119
//    public static IXmlStreamReader getParser(final String mimeType, final InputStream in) throws XmlStreamException {
120
//        Iterator parserFactories = availableParserFactories();
121
//        IXmlStreamReaderFactory factory;
122
//        while(parserFactories.hasNext()){
123
//            factory = (IXmlStreamReaderFactory) parserFactories.next();
124
//            if(factory.canParse(mimeType)){
125
//                return factory.createParser(mimeType, in);
126
//            }
127
//        }
128
//        //TODO update the GVSIG classpath to use SPI!!!
129
//        return new KxmlXmlParserFactory().createParser(mimeType, in);
130
//        //throw new XmlStreamException("ERROR: no xml parser factory found able to parse content type: " + mimeType);
131
//    }    
132
//    
133
//    private static Iterator availableWriterFactories() {
134
//        Iterator providers = sun.misc.Service.providers(IXmlStreamWriterFactory.class);
135
//        return providers;
136
//    }
137
//    
138
//    public static IXmlStreamWriter getWriter(final String mimeType, final OutputStream os) throws XmlStreamException, IllegalArgumentException
139
//    {
140
//            Iterator writerFactories = availableWriterFactories();
141
//            IXmlStreamWriterFactory factory;
142
//        while(writerFactories.hasNext()){
143
//            factory = (IXmlStreamWriterFactory) writerFactories.next();
144
//            if(factory.canWrite(mimeType)){
145
//                return factory.createWriter(mimeType, os);
146
//            }
147
//        }
148
//        //TODO update the GVSIG classpath to use SPI!!!
149
//        return new StaxXmlStreamWriter(os);
150
//        //throw new XmlStreamException("ERROR: no xml writer factory found able to write content type: " + mimeType);
151
//    }
152

    
153
}