svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / xmlViewer / TextXMLContent.java @ 40561
History | View | Annotate | Download (2.48 KB)
1 | 40561 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40561 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40561 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40561 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40561 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.utils.xmlViewer; |
||
25 | |||
26 | import java.io.ByteArrayInputStream; |
||
27 | import java.io.IOException; |
||
28 | |||
29 | import org.xml.sax.ContentHandler; |
||
30 | import org.xml.sax.InputSource; |
||
31 | import org.xml.sax.SAXException; |
||
32 | import org.xml.sax.XMLReader; |
||
33 | import org.xml.sax.helpers.XMLReaderFactory; |
||
34 | |||
35 | |||
36 | /**
|
||
37 | * Clase que sirve de XMLContent al control XMLViewer a partir de un string con
|
||
38 | * un fichero XML
|
||
39 | *
|
||
40 | * @author Fernando Gonz?lez Cort?s
|
||
41 | */
|
||
42 | public class TextXMLContent implements XMLContent { |
||
43 | private String text; |
||
44 | private ContentHandler handler; |
||
45 | |||
46 | /**
|
||
47 | * Crea un nuevo TextXMLContent.
|
||
48 | *
|
||
49 | * @param text Texto con el XML
|
||
50 | */
|
||
51 | public TextXMLContent(String text) { |
||
52 | this.text = text;
|
||
53 | } |
||
54 | |||
55 | /**
|
||
56 | * @see org.gvsig.utils.xmlViewer.XMLContent#setContentHandler(org.xml.sax.ContentHandler)
|
||
57 | */
|
||
58 | public void setContentHandler(ContentHandler handler) { |
||
59 | this.handler = handler;
|
||
60 | } |
||
61 | |||
62 | /**
|
||
63 | * @see org.gvsig.utils.xmlViewer.XMLContent#parse()
|
||
64 | */
|
||
65 | public void parse() throws SAXException { |
||
66 | XMLReader reader = XMLReaderFactory.createXMLReader(); |
||
67 | reader.setFeature("http://xml.org/sax/features/namespaces", false); |
||
68 | reader.setContentHandler(handler); |
||
69 | |||
70 | if (text == null) { |
||
71 | text = "<?xml version='1.0'?>";
|
||
72 | } |
||
73 | |||
74 | try {
|
||
75 | reader.parse(new InputSource(
|
||
76 | new ByteArrayInputStream(text.getBytes()))); |
||
77 | } catch (IOException e) { |
||
78 | //Una IO exception en un array de bytes???
|
||
79 | } |
||
80 | } |
||
81 | |||
82 | public String toString(){ |
||
83 | return text;
|
||
84 | } |
||
85 | } |