Revision 908

View differences:

org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.spi/src/main/java/org/gvsig/xmlpull/lib/spi/XmlPullProviderLocator.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.xmlpull.lib.spi;
29

  
30
import org.gvsig.tools.locator.AbstractLocator;
31
import org.gvsig.tools.locator.Locator;
32
import org.gvsig.tools.locator.LocatorException;
33

  
34
/**
35
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
36
 */
37
public class XmlPullProviderLocator extends AbstractLocator {
38
	private static final String LOCATOR_NAME = "XMLProviderLocator";
39
	/**
40
	 * XMLManager name used by the locator to access the instance
41
	 */
42
	public static final String XML_PROVIDER_MANAGER_NAME = "XMLProviderManager";
43
	private static final String XML_PROVIDER_MANAGER_DESCRIPTION = "XMLProviderManager of gvSIG";
44
	
45
	/**
46
	 * Unique instance.
47
	 */
48
	private static final XmlPullProviderLocator instance = new XmlPullProviderLocator();
49
	
50
	/* (non-Javadoc)
51
	 * @see org.gvsig.tools.locator.Locator#getLocatorName()
52
	 */
53
	public String getLocatorName() {
54
		return LOCATOR_NAME;
55
	}
56
	
57
	/**
58
	 * Return a reference to {@link XmlPullProviderManager}.
59
	 *
60
	 * @return a reference to XMLProviderManager
61
	 * @throws LocatorException
62
	 *             if there is no access to the class or the class cannot be
63
	 *             instantiated
64
	 * @see Locator#get(String)
65
	 */
66
	public static XmlPullProviderManager getXMLProviderManager() throws LocatorException {
67
		return (XmlPullProviderManager) getInstance().get(XML_PROVIDER_MANAGER_NAME);
68
	}
69
	
70
	/**
71
	 * Return the singleton instance.
72
	 *
73
	 * @return the singleton instance
74
	 */
75
	public static XmlPullProviderLocator getInstance() {
76
		return instance;
77
	}
78
	
79
	/**
80
	 * Registers the Class implementing the {@link XmlPullProviderManager} interface.
81
	 *
82
	 * @param clazz
83
	 *            implementing the XMLProviderManager interface
84
	 */
85
	public static void registerXMLProviderManager(Class clazz) {
86
		getInstance().register(XML_PROVIDER_MANAGER_NAME, 
87
				XML_PROVIDER_MANAGER_DESCRIPTION,
88
				clazz);
89
	}	
90
}
91

  
92

  
93

  
0 94

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.spi/src/main/java/org/gvsig/xmlpull/lib/spi/XmlPullProviderManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.xmlpull.lib.spi;
29

  
30
import java.io.InputStream;
31
import java.io.OutputStream;
32

  
33
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader;
34
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReaderFactory;
35
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter;
36
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriterFactory;
37
import org.gvsig.xmlpull.lib.api.stream.XmlStreamException;
38

  
39

  
40

  
41
/**
42
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
43
 */
44
public interface XmlPullProviderManager {
45
	
46
	public void registerXMLStreamReaderFactory(IXmlStreamReaderFactory xmlStreamReaderFactory);
47
		
48
	public void registerXMLStreamWriterFactory(IXmlStreamWriterFactory xmlStreamWriterFactory);
49
	
50
	public IXmlStreamReader createStreamReader(String mimeType, InputStream is) throws XmlStreamException, IllegalArgumentException;
51
	
52
	public IXmlStreamWriter createStreamWriter(String mimeType, OutputStream os) throws XmlStreamException, IllegalArgumentException;
53
}
54

  
0 55

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.spi/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.xmlpull.lib.spi</artifactId>
6
	<packaging>jar</packaging>
7
	<name>org.gvsig.xmlpull.lib.spi</name>
8
	<description>XML Pull library SPI</description>
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.xmlpull.lib</artifactId>
12
		<version>2.0.9</version>				
13
	</parent>
14
	<dependencies>
15
		<dependency>
16
			<groupId>org.gvsig</groupId>
17
			<artifactId>org.gvsig.xmlpull.lib.api</artifactId>			
18
		</dependency>
19
		<dependency>
20
      		<groupId>org.gvsig</groupId>
21
      		<artifactId>org.gvsig.tools.lib</artifactId>
22
    	</dependency>
23
    	<dependency>
24
      		<groupId>org.gvsig</groupId>
25
      		<artifactId>org.gvsig.tools.lib</artifactId>
26
      		<type>test-jar</type>
27
    	</dependency>  
28
	</dependencies>
29
	<build>
30
		<plugins>
31
			<plugin>
32
				<groupId>org.apache.maven.plugins</groupId>
33
				<artifactId>maven-compiler-plugin</artifactId>
34
				<configuration>
35
					<source>1.4</source>
36
					<target>1.5</target>
37
				</configuration>
38
			</plugin>
39
		</plugins>
40
	</build>
41
	<profiles>
42
		<profile>
43
			<id>cdc</id>
44
			<build>
45
				<plugins>
46
					<plugin>
47
						<groupId>org.apache.maven.plugins</groupId>
48
						<artifactId>maven-compiler-plugin</artifactId>
49
						<configuration>
50
							<source>1.4</source>
51
							<target>1.4</target>
52
						</configuration>
53
					</plugin>
54
				</plugins>
55
			</build>
56
		</profile>
57
	</profiles>
58
</project>
0 59

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.impl/src/main/java/org/gvsig/xmlpull/lib/impl/CreateXmlStreamReaderException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
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
 * as published by the Free Software Foundation; either version 2
9
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {gvSIG}  {{Task}}
26
 */
27
package org.gvsig.xmlpull.lib.impl;
28

  
29
import org.gvsig.tools.exception.BaseRuntimeException;
30
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader;
31

  
32
/**
33
 * Exception thrown when there is an error creating a new {@link IXmlStreamReader}.
34
 * 
35
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
36
 */
37
public class CreateXmlStreamReaderException extends
38
	BaseRuntimeException {
39
	private static final long serialVersionUID = -8220667598288924597L;
40

  
41
	private final static String MESSAGE_FORMAT = "Exception creating the xml stream reader with " +
42
			"mimeType '%(mimeType)'.";
43
	private final static String MESSAGE_KEY = "_CreateXMLStreamReaderException";
44
	
45
	public CreateXmlStreamReaderException(String mimeType, Throwable cause){
46
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
47
		setValue("mimeType", mimeType);
48
	}
49
}
0 50

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.impl/src/main/java/org/gvsig/xmlpull/lib/impl/DefaultXmlPullLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.xmlpull.lib.impl;
29

  
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32
import org.gvsig.xmlpull.lib.api.XmlPullLibrary;
33
import org.gvsig.xmlpull.lib.api.XmlPullLocator;
34
import org.gvsig.xmlpull.lib.spi.XmlPullProviderLocator;
35

  
36
/**
37
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
38
 */
39
public class DefaultXmlPullLibrary extends AbstractLibrary {
40
	
41
	public void doRegistration() {
42
		registerAsImplementationOf(XmlPullLibrary.class);
43
	}
44

  
45
	protected void doInitialize() throws LibraryException {       
46
        XmlPullLocator.registerXMLManager(DefaultXmlPullManager.class);
47
        XmlPullProviderLocator.registerXMLProviderManager(DefaultXmlPullProviderManager.class);
48
	}
49

  
50
	protected void doPostInitialize() throws LibraryException {
51
		// Nothing to do
52
	}
53
}
0 54

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.impl/src/main/java/org/gvsig/xmlpull/lib/impl/DefaultXmlPullProviderManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.xmlpull.lib.impl;
29

  
30
import java.io.InputStream;
31
import java.io.OutputStream;
32
import java.util.ArrayList;
33
import java.util.Collections;
34
import java.util.Iterator;
35
import java.util.List;
36

  
37
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader;
38
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReaderFactory;
39
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter;
40
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriterFactory;
41
import org.gvsig.xmlpull.lib.api.stream.XmlStreamException;
42
import org.gvsig.xmlpull.lib.spi.XmlPullProviderManager;
43

  
44
/**
45
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
46
 */
47
public class DefaultXmlPullProviderManager implements XmlPullProviderManager{
48
	private List xmlStreamReaderFactories = Collections.synchronizedList(new ArrayList());
49
	private List xmlStreamWriterFactories = Collections.synchronizedList(new ArrayList());
50
	
51
	public IXmlStreamReader createStreamReader(String mimeType, InputStream is){
52
		Iterator it = xmlStreamReaderFactories.iterator();
53
		while (it.hasNext()){
54
			IXmlStreamReaderFactory xmlStreamReaderFactory = 
55
				(IXmlStreamReaderFactory)it.next();
56
			if (xmlStreamReaderFactory.canParse(mimeType)){
57
				try {
58
					return xmlStreamReaderFactory.createParser(mimeType, is);
59
				} catch (Exception e) {
60
					throw new CreateXmlStreamReaderException(mimeType, e);
61
				}
62
			}
63
		}		
64
		throw new IllegalArgumentException("There is not a " +
65
				"XMLStreamReader for the mimetype " + mimeType);
66
		
67
	}
68
	
69
	public void registerXMLStreamReaderFactory(IXmlStreamReaderFactory xmlStreamReaderFactory)  {
70
		xmlStreamReaderFactories.add(xmlStreamReaderFactory);		
71
	}
72

  
73
	public IXmlStreamWriter createStreamWriter(String mimeType, OutputStream os)
74
			throws XmlStreamException, IllegalArgumentException {
75
		Iterator it = xmlStreamWriterFactories.iterator();
76
		while (it.hasNext()){
77
			IXmlStreamWriterFactory xmlStreamWriterFactory = 
78
				(IXmlStreamWriterFactory)it.next();
79
			if (xmlStreamWriterFactory.canWrite(mimeType)){
80
				try {
81
					return xmlStreamWriterFactory.createWriter(mimeType, os);
82
				} catch (Exception e) {
83
					throw new CreateXmlStreamWriterException(mimeType, e);
84
				}
85
			}
86
		}		
87
		throw new IllegalArgumentException("There is not a " +
88
				"XMLStreamWriter for the mimetype " + mimeType);
89
	}
90

  
91
	public void registerXMLStreamWriterFactory(
92
			IXmlStreamWriterFactory xmlStreamWriterFactory) {
93
		xmlStreamWriterFactories.add(xmlStreamWriterFactory);			
94
	}
95

  
96

  
97
}
98

  
0 99

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.impl/src/main/java/org/gvsig/xmlpull/lib/impl/CreateXmlStreamWriterException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
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
 * as published by the Free Software Foundation; either version 2
9
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {gvSIG}  {{Task}}
26
 */
27
package org.gvsig.xmlpull.lib.impl;
28

  
29
import org.gvsig.tools.exception.BaseRuntimeException;
30
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader;
31

  
32
/**
33
 * Exception thrown when there is an error creating a new {@link IXmlStreamReader}.
34
 * 
35
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
36
 */
37
public class CreateXmlStreamWriterException extends
38
	BaseRuntimeException {
39
	private static final long serialVersionUID = 6894668637124114583L;
40
	
41
	private final static String MESSAGE_FORMAT = "Exception creating the xml stream writer with " +
42
			"mimeType '%(mimeType)'.";
43
	private final static String MESSAGE_KEY = "_CreateXMLStreamReaderException";
44
	
45
	public CreateXmlStreamWriterException(String mimeType, Throwable cause){
46
		super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID);
47
		setValue("mimeType", mimeType);
48
	}
49
}
0 50

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.impl/src/main/java/org/gvsig/xmlpull/lib/impl/DefaultXmlPullManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.xmlpull.lib.impl;
29

  
30
import java.io.InputStream;
31
import java.io.OutputStream;
32

  
33
import org.gvsig.xmlpull.lib.api.XmlPullManager;
34
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader;
35
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter;
36
import org.gvsig.xmlpull.lib.api.stream.XmlStreamException;
37
import org.gvsig.xmlpull.lib.spi.XmlPullProviderLocator;
38
import org.gvsig.xmlpull.lib.spi.XmlPullProviderManager;
39

  
40
/**
41
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
42
 */
43
public class DefaultXmlPullManager implements XmlPullManager{
44
	private XmlPullProviderManager xmlPullProviderManager = null;
45

  
46
	private XmlPullProviderManager getXmlPullProviderManager() {
47
		if (xmlPullProviderManager == null){
48
			xmlPullProviderManager = XmlPullProviderLocator.getXMLProviderManager();
49
		}
50
		return xmlPullProviderManager;
51
	}
52

  
53
	public IXmlStreamReader createStreamReader(String mimeType, InputStream is)
54
			throws XmlStreamException, IllegalArgumentException {
55
		return getXmlPullProviderManager().createStreamReader(mimeType, is);
56
	}
57

  
58
	public IXmlStreamWriter createStreamWriter(String mimeType, OutputStream os)
59
			throws XmlStreamException, IllegalArgumentException {
60
		return getXmlPullProviderManager().createStreamWriter(mimeType, os);
61
	}
62
	
63
}
64

  
0 65

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.xmlpull.lib.impl.DefaultXmlPullLibrary
2

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.impl/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.xmlpull.lib.impl</artifactId>
6
	<packaging>jar</packaging>
7
	<name>org.gvsig.xmlpull.lib.impl</name>
8
	<description>Default XML Pull library Implementation</description>
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.xmlpull.lib</artifactId>	
12
		<version>2.0.9</version>			
13
	</parent>
14
	<dependencies>
15
	
16
		<dependency>
17
      		<groupId>org.gvsig</groupId>
18
      		<artifactId>org.gvsig.tools.lib</artifactId>
19
    	</dependency>
20
    	<dependency>
21
      		<groupId>org.gvsig</groupId>
22
      		<artifactId>org.gvsig.tools.lib</artifactId>
23
      		<type>test-jar</type>
24
    	</dependency>  
25

  
26
		<dependency>
27
			<groupId>org.gvsig</groupId>
28
			<artifactId>org.gvsig.xmlpull.lib.api</artifactId>	
29
		</dependency>
30
		<dependency>
31
			<groupId>org.gvsig</groupId>
32
			<artifactId>org.gvsig.xmlpull.lib.spi</artifactId>			
33
		</dependency>
34
	</dependencies>
35
	<build>
36
		<plugins>
37
			<plugin>
38
				<groupId>org.apache.maven.plugins</groupId>
39
				<artifactId>maven-compiler-plugin</artifactId>
40
				<configuration>
41
					<source>1.4</source>
42
					<target>1.5</target>
43
				</configuration>
44
			</plugin>
45
		</plugins>
46
	</build>
47
	<profiles>
48
		<profile>
49
			<id>cdc</id>
50
			<build>
51
				<plugins>
52
					<plugin>
53
						<groupId>org.apache.maven.plugins</groupId>
54
						<artifactId>maven-compiler-plugin</artifactId>
55
						<configuration>
56
							<source>1.4</source>
57
							<target>1.4</target>
58
						</configuration>
59
					</plugin>
60
				</plugins>
61
			</build>
62
		</profile>
63
	</profiles>
64
</project>
0 65

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.xmlpull.lib</artifactId>
6
	<packaging>pom</packaging>	
7
	<name>org.gvsig.xmlpull.lib</name>
8
	<description>XML Pull library</description>
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.xmlpull</artifactId>	
12
		<version>2.0.9</version>	
13
	</parent>
14
	<modules>
15
		<module>org.gvsig.xmlpull.lib.api</module>
16
		<module>org.gvsig.xmlpull.lib.spi</module>
17
		<module>org.gvsig.xmlpull.lib.impl</module>
18
	</modules>
19
</project>
0 20

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.api/src/main/java/org/gvsig/xmlpull/lib/api/XmlPullLocator.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.xmlpull.lib.api;
29

  
30
import org.gvsig.tools.locator.AbstractLocator;
31
import org.gvsig.tools.locator.Locator;
32
import org.gvsig.tools.locator.LocatorException;
33

  
34
/**
35
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
36
 */
37
public class XmlPullLocator extends AbstractLocator {
38
	private static final String LOCATOR_NAME = "XMLLocator";
39
	/**
40
	 * XMLManager name used by the locator to access the instance
41
	 */
42
	public static final String XML_MANAGER_NAME = "XMLManager";
43
	private static final String XML_MANAGER_DESCRIPTION = "XMLManager of gvSIG";
44
	
45
	/**
46
	 * Unique instance.
47
	 */
48
	private static final XmlPullLocator instance = new XmlPullLocator();
49
	
50
	/* (non-Javadoc)
51
	 * @see org.gvsig.tools.locator.Locator#getLocatorName()
52
	 */
53
	public String getLocatorName() {
54
		return LOCATOR_NAME;
55
	}
56
	
57
	/**
58
	 * Return a reference to {@link XmlPullManager}.
59
	 *
60
	 * @return a reference to XMLManager
61
	 * @throws LocatorException
62
	 *             if there is no access to the class or the class cannot be
63
	 *             instantiated
64
	 * @see Locator#get(String)
65
	 */
66
	public static XmlPullManager getXMLManager() throws LocatorException {
67
		return (XmlPullManager) getInstance().get(XML_MANAGER_NAME);
68
	}
69
	
70
	/**
71
	 * Return the singleton instance.
72
	 *
73
	 * @return the singleton instance
74
	 */
75
	public static XmlPullLocator getInstance() {
76
		return instance;
77
	}
78
	
79
	/**
80
	 * Registers the Class implementing the {@link XmlPullManager} interface.
81
	 *
82
	 * @param clazz
83
	 *            implementing the XMLManager interface
84
	 */
85
	public static void registerXMLManager(Class clazz) {
86
		getInstance().register(XML_MANAGER_NAME, 
87
				XML_MANAGER_DESCRIPTION,
88
				clazz);
89
	}	
90
}
91

  
92

  
93

  
0 94

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.api/src/main/java/org/gvsig/xmlpull/lib/api/XmlPullLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.xmlpull.lib.api;
29

  
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32

  
33
/**
34
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
35
 */
36
public class XmlPullLibrary extends AbstractLibrary  {
37
	
38
	public void doRegistration() {
39
		registerAsAPI(XmlPullLibrary.class);
40
	}
41

  
42
	protected void doInitialize() throws LibraryException {
43
		// Nothing to do 
44
	}
45

  
46
	protected void doPostInitialize() throws LibraryException {
47
		// Nothing to do		
48
	}
49
}
50

  
0 51

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.api/src/main/java/org/gvsig/xmlpull/lib/api/XmlPullManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.xmlpull.lib.api;
29

  
30
import java.io.InputStream;
31
import java.io.OutputStream;
32

  
33
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader;
34
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamWriter;
35
import org.gvsig.xmlpull.lib.api.stream.XmlStreamException;
36

  
37
/**
38
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
39
 */
40
public interface XmlPullManager {
41

  
42
	public IXmlStreamReader createStreamReader(String mimeType, InputStream is) throws XmlStreamException, IllegalArgumentException;
43
	
44
	public IXmlStreamWriter createStreamWriter(String mimeType, OutputStream os) throws XmlStreamException, IllegalArgumentException;
45

  
46
}
47

  
0 48

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.api/src/main/java/org/gvsig/xmlpull/lib/api/stream/IXmlStreamReader.java
1
package org.gvsig.xmlpull.lib.api.stream;
2

  
3
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
4
 *
5
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
20
 *
21
 * For more information, contact:
22
 *
23
 *  Generalitat Valenciana
24
 *   Conselleria d'Infraestructures i Transport
25
 *   Av. Blasco Ib??ez, 50
26
 *   46010 VALENCIA
27
 *   SPAIN
28
 *
29
 *      +34 963862235
30
 *   gvsig@gva.es
31
 *      www.gvsig.gva.es
32
 *
33
 *    or
34
 *
35
 *   IVER T.I. S.A
36
 *   Salamanca 50
37
 *   46005 Valencia
38
 *   Spain
39
 *
40
 *   +34 963163400
41
 *   dac@iver.es
42
 */
43
/* CVS MESSAGES:
44
 *
45
 * $Id: IXmlStreamReader.java 19593 2008-03-12 17:23:30Z groldan $
46
 * $Log$
47
 */
48

  
49

  
50

  
51
/**
52
 * Represents an abstraction layer over a concrete XML parsing technology.
53
 * <p>
54
 * This interface provides a pull like approach to parsing xml formatted documents for the libGPE
55
 * library, yet allowing to interchange implementations which can be based, for example, in XML SAX,
56
 * XML Pull, Binary XML, etc.
57
 * </p>
58
 * <p>
59
 * Note at this time this interface contract is made just of the methods from XmlPullParser that
60
 * where already used so far in the libGPE-GML and libGPE-KML modules. The intention is to first
61
 * introduce this abstraction layer and then evolve it as needed to support an intermediate level of
62
 * abstraction between actual xml parsing and {@link IGPEContentHandler}, while keeping the unit
63
 * tests passing all the time. So this is work in progress and expected to change dramatically,
64
 * though ensuring no functional breackages in any time.
65
 * </p>
66
 * 
67
 * @author Gabriel Roldan (TOPP)
68
 * @version $Id: IXmlStreamReader.java 19593 2008-03-12 17:23:30Z groldan $
69
 */
70
public interface IXmlStreamReader {
71

  
72
    /**
73
     * Indicates an event is a start element
74
     */
75
    public static final int START_ELEMENT = 1;
76
    /**
77
     * Indicates an event is an end element
78
     */
79
    public static final int END_ELEMENT = 2;
80
    /**
81
     * Indicates an event is a processing instruction
82
     */
83
    public static final int PROCESSING_INSTRUCTION = 3;
84

  
85
    /**
86
     * Indicates an event is characters
87
     */
88
    public static final int CHARACTERS = 4;
89

  
90
    /**
91
     * Indicates an event is a comment
92
     */
93
    public static final int COMMENT = 5;
94

  
95
    /**
96
     * The characters are white space (see [XML], 2.10 "White Space Handling"). Events are only
97
     * reported as SPACE if they are ignorable white space. Otherwise they are reported as
98
     * CHARACTERS.
99
     */
100
    public static final int SPACE = 6;
101

  
102
    /**
103
     * Indicates an event is a start document
104
     */
105
    public static final int START_DOCUMENT = 7;
106

  
107
    /**
108
     * Indicates an event is an end document
109
     */
110
    public static final int END_DOCUMENT = 8;
111

  
112
    /**
113
     * Indicates an event is an entity reference
114
     */
115
    public static final int ENTITY_REFERENCE = 9;
116

  
117
    /**
118
     * Indicates an event is an attribute
119
     * 
120
     * @see javax.xml.stream.events.Attribute
121
     */
122
    //public static final int ATTRIBUTE = 10;
123

  
124
    /**
125
     * Indicates an event is a DTD
126
     */
127
    public static final int DTD = 11;
128

  
129
    /**
130
     * Indicates an event is a CDATA section
131
     */
132
    public static final int CDATA = 12;
133

  
134
    /**
135
     * Indicates the event is a namespace declaration
136
     */
137
    public static final int NAMESPACE = 13;
138

  
139
    /**
140
     * Indicates a Notation
141
     */
142
    public static final int NOTATION_DECLARATION = 14;
143

  
144
    /**
145
     * Indicates a Entity Declaration
146
     */
147
    public static final int ENTITY_DECLARATION = 15;
148

  
149
    /**
150
     * @return
151
     * @throws IllegalStateException
152
     */
153
    int getAttributeCount() throws XmlStreamException;
154

  
155
    IQName getAttributeName(int i) throws XmlStreamException;
156

  
157
    /**
158
     * Returns the complete (coalesced) value for the attribute at index {@code i}
159
     * @param i
160
     * @return
161
     * @throws XmlStreamException
162
     */
163
    String getAttributeValue(int i) throws XmlStreamException;
164

  
165
    /**
166
     * Returns the qualified name (with prefix if applicable) for the current element.
167
     * 
168
     * @return the qualified name for the current START_ELEMENT or END_ELEMENT event, or
169
     *         <code>null</code> if the current event is not a START_ELEMENT or END_ELEMENT.
170
     * @throws XmlStreamException
171
     */
172
    IQName getName() throws XmlStreamException;
173

  
174
    int getEventType() throws XmlStreamException;
175

  
176
    String getText() throws XmlStreamException;
177

  
178
    int next() throws XmlStreamException;
179

  
180
    int nextTag() throws XmlStreamException;
181

  
182
    boolean isWhitespace() throws XmlStreamException;
183
}
0 184

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.api/src/main/java/org/gvsig/xmlpull/lib/api/stream/IQName.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
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
* as published by the Free Software Foundation; either version 2
9
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.xmlpull.lib.api.stream;
29
/**
30
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
31
 */
32
public interface IQName {
33

  
34
	public String getLocalPart();
35

  
36
	public String getNamespaceURI();
37

  
38
}
39

  
0 40

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.api/src/main/java/org/gvsig/xmlpull/lib/api/stream/IXmlStreamWriterFactory.java
1
package org.gvsig.xmlpull.lib.api.stream;
2

  
3
import java.io.OutputStream;
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45

  
46
/**
47
 * 
48
 */
49
public interface IXmlStreamWriterFactory {
50

  
51
    boolean canWrite(final String mimeType);
52

  
53
    IXmlStreamWriter createWriter(final String mimeType, final OutputStream out)
54
            throws XmlStreamException, IllegalArgumentException;
55
}
0 56

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.api/src/main/java/org/gvsig/xmlpull/lib/api/stream/XmlStreamException.java
1
package org.gvsig.xmlpull.lib.api.stream;
2

  
3
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
4
 *
5
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
20
 *
21
 * For more information, contact:
22
 *
23
 *  Generalitat Valenciana
24
 *   Conselleria d'Infraestructures i Transport
25
 *   Av. Blasco Ib??ez, 50
26
 *   46010 VALENCIA
27
 *   SPAIN
28
 *
29
 *      +34 963862235
30
 *   gvsig@gva.es
31
 *      www.gvsig.gva.es
32
 *
33
 *    or
34
 *
35
 *   IVER T.I. S.A
36
 *   Salamanca 50
37
 *   46005 Valencia
38
 *   Spain
39
 *
40
 *   +34 963163400
41
 *   dac@iver.es
42
 */
43
/* CVS MESSAGES:
44
 *
45
 * $Id: XmlStreamException.java 19593 2008-03-12 17:23:30Z groldan $
46
 * $Log$
47
 */
48

  
49
import java.io.IOException;
50

  
51
/**
52
 * Signals either a parsing or io error ocurred while scanning or writing an xml formatted document.
53
 * 
54
 * @author Gabriel Roldan (TOPP)
55
 * @version $Id: XmlStreamException.java 19593 2008-03-12 17:23:30Z groldan $
56
 */
57
public class XmlStreamException extends IOException {
58

  
59
	private static final long serialVersionUID = 2565360995097194850L;
60

  
61
	public XmlStreamException(String message) {
62
        this(message, null);
63
    }
64

  
65
    public XmlStreamException(String message, Throwable cause) {
66
        super(message);
67
        super.initCause(cause);
68
    }
69

  
70
    public XmlStreamException(Throwable cause) {
71
        this(null, cause);
72
    }
73

  
74
}
0 75

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.api/src/main/java/org/gvsig/xmlpull/lib/api/stream/StreamUtils.java
1
package org.gvsig.xmlpull.lib.api.stream;
2

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

  
6
class StreamUtils {
7

  
8
    private StreamUtils() {
9
        // do nothing
10
    }
11

  
12
    /**
13
     * @param _is
14
     * @return Returns the encoding or UTF-8 encoding by default.
15
     * @throws IOException
16
     */
17
    public static String getEncoding(final InputStream _is) throws IOException {
18
        String encoding = "UTF-8";
19
        int srcCount = 0;
20
        char[] srcBuf = new char[128];
21

  
22
        // read four bytes
23
        int chk = 0;
24
        try {
25
            while (srcCount < 4) {
26
                int i = _is.read();
27
                if (i == -1)
28
                    break;
29
                chk = (chk << 8) | i;
30
                srcBuf[srcCount++] = (char) i;
31
            }
32

  
33
            if (srcCount == 4) {
34
                switch (chk) {
35
                case 0x00000FEFF:
36
                    encoding = "UTF-32BE";
37
                    srcCount = 0;
38
                    break;
39

  
40
                case 0x0FFFE0000:
41
                    encoding = "UTF-32LE";
42
                    srcCount = 0;
43
                    break;
44

  
45
                case 0x03c:
46
                    encoding = "UTF-32BE";
47
                    srcBuf[0] = '<';
48
                    srcCount = 1;
49
                    break;
50

  
51
                case 0x03c000000:
52
                    encoding = "UTF-32LE";
53
                    srcBuf[0] = '<';
54
                    srcCount = 1;
55
                    break;
56

  
57
                case 0x0003c003f:
58
                    encoding = "UTF-16BE";
59
                    srcBuf[0] = '<';
60
                    srcBuf[1] = '?';
61
                    srcCount = 2;
62
                    break;
63

  
64
                case 0x03c003f00:
65
                    encoding = "UTF-16LE";
66
                    srcBuf[0] = '<';
67
                    srcBuf[1] = '?';
68
                    srcCount = 2;
69
                    break;
70

  
71
                case 0x03c3f786d:
72
                    while (true) {
73
                        int i = _is.read();
74
                        if (i == -1)
75
                            break;
76
                        srcBuf[srcCount++] = (char) i;
77
                        if (i == '>') {
78
                            String s = new String(srcBuf, 0, srcCount);
79
                            int i0 = s.indexOf("encoding");
80
                            if (i0 != -1) {
81
                                while (s.charAt(i0) != '"' && s.charAt(i0) != '\'')
82
                                    i0++;
83
                                char deli = s.charAt(i0++);
84
                                int i1 = s.indexOf(deli, i0);
85
                                encoding = s.substring(i0, i1);
86
                            }
87
                            break;
88
                        }
89
                    }
90

  
91
                default:
92
                    if ((chk & 0x0ffff0000) == 0x0FEFF0000) {
93
                        encoding = "UTF-16BE";
94
                        srcBuf[0] = (char) ((srcBuf[2] << 8) | srcBuf[3]);
95
                        srcCount = 1;
96
                    } else if ((chk & 0x0ffff0000) == 0x0fffe0000) {
97
                        encoding = "UTF-16LE";
98
                        srcBuf[0] = (char) ((srcBuf[3] << 8) | srcBuf[2]);
99
                        srcCount = 1;
100
                    } else if ((chk & 0x0ffffff00) == 0x0EFBBBF00) {
101
                        encoding = "UTF-8";
102
                        srcBuf[0] = srcBuf[3];
103
                        srcCount = 1;
104
                    }
105
                }
106
            }
107
        } catch (IOException ex) {
108
            return null;
109
        }
110
        return encoding;
111
    }
112

  
113
}
0 114

  
org.gvsig.xmlpull/library/tags/org.gvsig.xmlpull-2.0.9/org.gvsig.xmlpull.lib/org.gvsig.xmlpull.lib.api/src/main/java/org/gvsig/xmlpull/lib/api/stream/IXmlStreamReaderFactory.java
1
package org.gvsig.xmlpull.lib.api.stream;
2

  
3
import java.io.InputStream;
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff