diff options
author | pdanner <pdanner@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2007-09-05 10:50:49 +0000 |
---|---|---|
committer | pdanner <pdanner@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2007-09-05 10:50:49 +0000 |
commit | 2006356de97eef6d8ce1f4e03ace9a42079be8d1 (patch) | |
tree | 0d418da384681d8e4e5f6c3054a3fb9f68bf8b5d /common/src/main/java/at/gv/egovernment/moa/util/StreamEntityResolver.java | |
parent | f5addfcb66da2761d2d862220766c047de7a1e32 (diff) | |
download | moa-id-spss-2006356de97eef6d8ce1f4e03ace9a42079be8d1.tar.gz moa-id-spss-2006356de97eef6d8ce1f4e03ace9a42079be8d1.tar.bz2 moa-id-spss-2006356de97eef6d8ce1f4e03ace9a42079be8d1.zip |
MOA-SP/SS Release 1.4.1tags/Build-SPSS-1.4.1
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/tags/Build-SPSS-1_4_1@995 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'common/src/main/java/at/gv/egovernment/moa/util/StreamEntityResolver.java')
-rw-r--r-- | common/src/main/java/at/gv/egovernment/moa/util/StreamEntityResolver.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/common/src/main/java/at/gv/egovernment/moa/util/StreamEntityResolver.java b/common/src/main/java/at/gv/egovernment/moa/util/StreamEntityResolver.java new file mode 100644 index 000000000..38c4e863c --- /dev/null +++ b/common/src/main/java/at/gv/egovernment/moa/util/StreamEntityResolver.java @@ -0,0 +1,64 @@ +package at.gv.egovernment.moa.util; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * An <code>EntityResolver</code> that maps system IDs to + * <code>InputStream</code>s. + * + * @author Patrick Peck + * @version $Id$ + */ +public class StreamEntityResolver implements EntityResolver { + + /** A mapping from Public ID or System ID to an <code>InputStream</code> + * containing the entity. */ + private Map mappedEntities; + + /** + * Create a <code>StreamEntityResolver</code>. + * + * @param mappedEntities A mapping from public or system IDs + * (<code>String</code> objects) to <code>InputStream</code>s. + */ + public StreamEntityResolver(Map mappedEntities) { + this.mappedEntities = mappedEntities; + } + + /** + * Resolve an entity by looking it up in the mapped entities. + * + * First, the public ID is looked up in the mapping, then the system ID. + * + * @param publicId The public ID of the entity. + * @param systemId The system ID of the entity. + * @return An <code>InputStream</code> containing the entity or + * <code>null</code> if no entity could be found. + * @throws SAXException Signalling a parsing exception. + * @throws IOException Error reading the entity. + */ + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + + InputSource src = null; + + if (publicId != null && mappedEntities.get(publicId) != null) { + src = new InputSource((InputStream) mappedEntities.get(publicId)); + } else if (systemId != null && mappedEntities.get(systemId) != null) { + src = new InputSource((InputStream) mappedEntities.get(systemId)); + } + + if (src != null) { + src.setPublicId(publicId); + src.setSystemId(systemId); + } + + return src; + } +} |