public class InvCatalogFactory
extends java.lang.Object
InvCatalogFactory factory = new InvCatalogFactory("default", validate); InvCatalogImpl catalog = (InvCatalogImpl) factory.readXML( catalogURI); StringBuilder buff = new StringBuilder(); if (!catalog.check( buff)) { javax.swing.JOptionPane.showMessageDialog(this, "Invalid catalog <"+ catalogURI+">\n"+ buff.toString()); }
// write out catalog to String try { System.out.println("\Catalog in XML=\n" + factory.writeXML( catalog)); } catch (IOException e) { e.printStackTrace(); } // write out catalog to a file if (!factory.writeXML( catalog, filename)) System.out.println("Catalog failed to write to file=" + filename); // write out catalog to a stream, catch exceptions try { BufferedOutputStream os = new BufferedOutputStream (new FileOutputStream(filename)); factory.writeXML( catalog, os); os.close(); } catch (IOException e) { e.printStackTrace(); }Implementation details: Uses JDOM to read XML documents. Uses a pluggable InvCatalogConvertIF to transform the JDOM tree to the thredds.catalog objects. The converters are registered based on the namespace used. We are supporting:
Modifier and Type | Field and Description |
---|---|
static boolean |
debugDBurl |
static boolean |
debugOpen |
static boolean |
debugURL |
static boolean |
debugVersion |
static boolean |
debugXML |
static boolean |
debugXMLopen |
static boolean |
showCatalogXML |
static boolean |
showParsedXML |
static boolean |
showStackTrace |
Constructor and Description |
---|
InvCatalogFactory(java.lang.String name,
boolean validate)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
appendErr(java.lang.String err)
append an error message.
|
void |
appendFatalErr(java.lang.String err)
append a fatal error message
|
void |
appendWarning(java.lang.String err)
append a warning message
|
InvCatalogConvertIF |
getCatalogConverter(java.lang.String namespace)
Find the InvCatalogConvertIF registered for this namespace.
|
java.util.List<PathAliasReplacement> |
getDataRootLocationAliasExpanders() |
static InvCatalogConvertIF |
getDefaultConverter() |
static InvCatalogFactory |
getDefaultFactory(boolean validate)
Get new Factory for reading and writing catalogs.
|
MetadataConverterIF |
getMetadataConverter(java.lang.String key)
Find the MetadataConverterIF registered for this key
|
java.lang.String |
getName()
An InvCatalogFactory may have a name, in case you need to manage several of them.
|
static void |
main(java.lang.String[] args)
testing
|
InvCatalogImpl |
readXML(org.jdom2.Document jdomDoc,
java.net.URI uri)
Create an InvCatalog from a JDOM document.
|
InvCatalogImpl |
readXML(java.io.InputStream docIs,
java.net.URI uri)
Create an InvCatalog from an InputStream.
|
InvCatalogImpl |
readXML(java.lang.String uriString)
Create an InvCatalog from an XML document at a named URI.
|
InvCatalogImpl |
readXML(java.io.StringReader catAsStringReader,
java.net.URI baseUri)
Create an InvCatalog by reading catalog XML from a StringReader.
|
InvCatalogImpl |
readXML(java.lang.String catAsString,
java.net.URI baseUri)
Create an InvCatalog by reading catalog XML from a String.
|
InvCatalogImpl |
readXML(java.net.URI uri)
Read an InvCatalog from an a URI.
|
void |
readXMLasynch(java.lang.String uriString,
CatalogSetCallback callback)
This allows the possibility of reading a catalog in another thread.
|
void |
registerCatalogConverter(java.lang.String namespace,
InvCatalogConvertIF converter)
Register converters for creating InvCatalogs from specific catalog XML namespaces.
|
void |
registerMetadataConverter(java.lang.String key,
MetadataConverterIF converter)
Register metadata converters for reading metadata objects of a certain type or namespace.
|
void |
setDataRootLocationAliasExpanders(java.util.List<PathAliasReplacement> dataRootLocAliasExpanders) |
java.lang.String |
writeXML(InvCatalogImpl catalog)
Write the catalog as an XML document to a String.
|
void |
writeXML(InvCatalogImpl catalog,
java.io.OutputStream os)
Write the InvCatalogImpl to the OutputStream as a InvCatalog 1.0 document.
|
void |
writeXML(InvCatalogImpl catalog,
java.io.OutputStream os,
boolean raw)
Write the InvCatalogImpl to the OutputStream as a InvCatalog 1.0 document.
|
void |
writeXML(InvCatalogImpl catalog,
java.lang.String filename) |
public static boolean debugURL
public static boolean debugOpen
public static boolean debugVersion
public static boolean showParsedXML
public static boolean showStackTrace
public static boolean debugXML
public static boolean debugDBurl
public static boolean debugXMLopen
public static boolean showCatalogXML
public InvCatalogFactory(java.lang.String name, boolean validate)
name
- : optional name to keep track of factoriesvalidate
- : do XML validation or not.public static InvCatalogFactory getDefaultFactory(boolean validate)
validate
- : do XML validation or not.public static InvCatalogConvertIF getDefaultConverter()
public java.lang.String getName()
public void setDataRootLocationAliasExpanders(java.util.List<PathAliasReplacement> dataRootLocAliasExpanders)
public java.util.List<PathAliasReplacement> getDataRootLocationAliasExpanders()
public void registerCatalogConverter(java.lang.String namespace, InvCatalogConvertIF converter)
namespace
- : namespace of catalog; acts as the versionconverter
- : use this factory for this versionpublic InvCatalogConvertIF getCatalogConverter(java.lang.String namespace)
namespace
- : find InvCatalogConvertIF for this namespacepublic void registerMetadataConverter(java.lang.String key, MetadataConverterIF converter)
key
- : namespace or metadata type stringconverter
- : use this MetadataConverterIF for the given keyInvMetadata
public void readXMLasynch(java.lang.String uriString, CatalogSetCallback callback)
uriString
- : read this catalog.callback
- : call this if successfully read.CatalogSetCallback
public InvCatalogImpl readXML(java.lang.String uriString)
uriString
- : the URI name that the XML doc is at. May start with a "file:"public InvCatalogImpl readXML(java.net.URI uri)
uri
- : the URI of the document, used for resolving reletive references.public InvCatalogImpl readXML(java.lang.String catAsString, java.net.URI baseUri)
catAsString
- : the String from which to read the catalog.baseUri
- : the base URI of the document, used for resolving reletive references.public InvCatalogImpl readXML(java.io.StringReader catAsStringReader, java.net.URI baseUri)
catAsStringReader
- : the StreamReader from which to read the catalog.baseUri
- : the base URI of the document, used for resolving reletive references.public InvCatalogImpl readXML(java.io.InputStream docIs, java.net.URI uri)
docIs
- : the InputStream to read fromuri
- : the URI of the document, used for resolving reletive references.public InvCatalogImpl readXML(org.jdom2.Document jdomDoc, java.net.URI uri)
jdomDoc
- a parsed JDOM Documenturi
- : the URI of the document, used for resolving reletive references.public void writeXML(InvCatalogImpl catalog, java.io.OutputStream os, boolean raw) throws java.io.IOException
catalog
- - the catalog to be writtenos
- - the OutputStream to write toraw
- if true, write raw, vs convertedjava.io.IOException
- when the OutputStream can't be writtenjava.lang.IllegalStateException
- when the factory doesn't know how to write a 1.0 document.public void writeXML(InvCatalogImpl catalog, java.io.OutputStream os) throws java.io.IOException
catalog
- - the catalog to be writtenos
- - the OutputStream to write tojava.io.IOException
- when the OutputStream can't be writtenjava.lang.IllegalStateException
- when the factory doesn't know how to write a 1.0 document.public void writeXML(InvCatalogImpl catalog, java.lang.String filename) throws java.io.IOException
java.io.IOException
public java.lang.String writeXML(InvCatalogImpl catalog) throws java.io.IOException
catalog
- write this catalogjava.io.IOException
- on write errorpublic void appendErr(java.lang.String err)
err
- append this error messagepublic void appendFatalErr(java.lang.String err)
err
- append this error messagepublic void appendWarning(java.lang.String err)
err
- append this error messagepublic MetadataConverterIF getMetadataConverter(java.lang.String key)
key
- search on this keypublic static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception