/** * Constructs the CatalogGen for the given config document. * * @param configDocURL - the URL of the configuration document */ public CatalogGen( URL configDocURL) { // Create a InvCatalogFactory with CATALOG_GEN_CONFIG MetadataType registered. log.debug( "CatalogGen(URL): create catalog and CatalogGenConfig converter." ); this.catFactory = InvCatalogFactory.getDefaultFactory( true ); this.catFactory.registerMetadataConverter( MetadataType.CATALOG_GEN_CONFIG.toString(), new CatGenConfigMetadataFactory()); // Read the given XML config file. log.debug( "CatalogGen(URL): reading the config doc <" + configDocURL.toString() + ">."); this.catalog = this.catFactory.readXML( configDocURL.toString()); log.debug( "CatalogGen(URL): done."); }
/** * Constructs the CatalogGen for the given config document InputStream. * * @param configDocInputStream - the InputStream from which to read the config document. * @param configDocURL - the URL for the config document. */ public CatalogGen( InputStream configDocInputStream, URL configDocURL ) { // Create a InvCatalogFactory with CATALOG_GEN_CONFIG MetadataType registered. log.debug( "CatalogGen(InputStream): create catalog and CatalogGenConfig converter." ); this.catFactory = new InvCatalogFactory( "default", true ); this.catFactory.registerMetadataConverter( MetadataType.CATALOG_GEN_CONFIG.toString(), new CatGenConfigMetadataFactory() ); // Read the given XML config file. log.debug( "CatalogGen(InputStream): reading the config doc <" + configDocURL.toString() + ">." ); this.catalog = this.catFactory.readXML( configDocInputStream, URI.create( configDocURL.toExternalForm()) ); log.debug( "CatalogGen(InputStream): CatalogGenConfig doc <" + this.catalog.getName() + "> read."); }
protected DateType makeDateType(String text, String format, String type) { if (text == null) return null; try { return new DateType(text, format, type); } catch (java.text.ParseException e) { factory.appendErr(" ** Parse error: Bad date format = " + text + "\n"); return null; } }
/** * testing */ public static void main(String[] args) throws Exception { InvCatalogFactory catFactory = InvCatalogFactory.getDefaultFactory(false); //doOne(catFactory, "http://www.unidata.ucar.edu/georesources/idvcatalog.xml", true); doOne(catFactory, "file:C:/data/work/maurer/atm_mod.xml", true); }
static String convertCatalogToString( InvCatalog catalog ) { InvCatalogFactory fac = InvCatalogFactory.getDefaultFactory( false ); try { return fac.writeXML( (InvCatalogImpl) catalog ); } catch ( IOException e ) { return null; } } }
static Document convertCatalogToDocument( InvCatalog catalog ) { InvCatalogFactory fac = InvCatalogFactory.getDefaultFactory( false ); InvCatalogConvertIF converter = fac.getCatalogConverter( XMLEntityResolver.CATALOG_NAMESPACE_10 ); InvCatalogFactory10 fac10 = (InvCatalogFactory10) converter; return fac10.writeCatalog( (InvCatalogImpl) catalog ); }
private InvDatasetImpl openResolver(String urlString, ucar.nc2.util.CancelTask task, Result result) { InvCatalogFactory catFactory = new InvCatalogFactory("", false); InvCatalogImpl catalog = catFactory.readXML(urlString); if (catalog == null) { result.errLog.format("Couldnt open Resolver %s %n ", urlString); return null; } StringBuilder buff = new StringBuilder(); if (!catalog.check(buff)) { result.errLog.format("Invalid catalog from Resolver <%s>%n%s%n", urlString, buff.toString()); result.fatalError = true; return null; } InvDataset top = catalog.getDataset(); if (top.hasAccess()) return (InvDatasetImpl) top; else { java.util.List datasets = top.getDatasets(); return (InvDatasetImpl) datasets.get(0); } }
/** * Create an InvCatalog by reading catalog XML from a String. * * Failures and exceptions are handled by causing validate() to * fail. Therefore, be sure to call validate() before trying to use * the InvCatalog object. * * @param catAsString : the String from which to read the catalog. * @param baseUri : the base URI of the document, used for resolving reletive references. * @return an InvCatalogImpl object */ public InvCatalogImpl readXML( String catAsString, URI baseUri ) { return readXML( new StringReader( catAsString ), baseUri ); }
/** testing */ public static void main (String[] args) throws Exception { InvCatalogFactory catFactory = InvCatalogFactory.getDefaultFactory(true); doCatalog(catFactory, "http://thredds.ucar.edu:9080/thredds/idd/models.xml"); }
public static List<InvDataset> getCatalogDatasets(InputStream catalogIS, URI catalogBaseUri) { final InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(true); final InvCatalogImpl catalog = factory.readXML(catalogIS, catalogBaseUri); return catalog.getDatasets(); }
private static void doCatalog( InvCatalogFactory fac, String url) { System.out.println("***read "+url); try { InvCatalogImpl cat = fac.readXML(url); StringBuilder buff = new StringBuilder(); boolean isValid = cat.check( buff, false); System.out.println("catalog <" + cat.getName()+ "> "+ (isValid ? "is" : "is not") + " valid"); System.out.println(" validation output=\n" + buff); System.out.println(" catalog=\n" + fac.writeXML(cat)); DIFWriter w = new DIFWriter(); StringBuilder sbuff = new StringBuilder(); w.writeDatasetEntries( cat, "C:/temp/dif2", sbuff); System.out.println(" messages=\n"+sbuff); } catch (Exception e) { e.printStackTrace(); } }
factory.appendWarning("**Warning: Dataset " + name + " using old form of DatasetScan (dirLocation instead of location)\n");
this.catFactory.writeXML( (InvCatalogImpl) catalog, System.out); this.catFactory.writeXML( (InvCatalogImpl) catalog, outFileName ); InvCatalogFactory10 fac10 = (InvCatalogFactory10) this.catFactory.getCatalogConverter( XMLEntityResolver.CATALOG_NAMESPACE_10 ); fac10.setVersion( this.catalog.getVersion() ); BufferedOutputStream osCat = new BufferedOutputStream( new FileOutputStream( outFileName ) );
/** * Write the catalog as an XML document to the specified stream. * * @param os write to this OutputStream * @throws java.io.IOException on an error. */ public void writeXML(java.io.OutputStream os) throws java.io.IOException { InvCatalogConvertIF converter = InvCatalogFactory.getDefaultConverter(); converter.writeXML(this, os); }
/** * Get new Factory for reading and writing catalogs. * For multithreading, get seperate InvCatalogFactory for each thread. * * @param validate : do XML validation or not. * @return default factory */ public static InvCatalogFactory getDefaultFactory(boolean validate) { return new InvCatalogFactory("default", validate); }
/** * Write the InvCatalogImpl to the OutputStream as a InvCatalog 1.0 document. * * @param catalog - the catalog to be written * @param os - the OutputStream to write to * @param raw if true, write raw, vs converted * @throws IOException when the OutputStream can't be written * @throws IllegalStateException when the factory doesn't know how to write a 1.0 document. */ public void writeXML(InvCatalogImpl catalog, OutputStream os, boolean raw) throws IOException { InvCatalogConvertIF converter = this.getCatalogConverter(XMLEntityResolver.CATALOG_NAMESPACE_10); converter.writeXML(catalog, os, raw); }
if (debug) System.out.println(" InvCatalogRef readXMLasynch " + getFullName() + " hrefResolved = " + hrefResolved); factory.readXMLasynch(hrefResolved, new Callback(caller)); } catch (Exception e) {
MetadataConverterIF metaConverter = factory.getMetadataConverter(namespace.getURI()); if (metaConverter == null) metaConverter = factory.getMetadataConverter(mtype); if (metaConverter != null) { if (debugMetadataRead) System.out.println("found factory for metadata type = " + mtype + " namespace = " +
private InvDatasetImpl openResolver(String urlString, ucar.nc2.util.CancelTask task, Result result) { InvCatalogFactory catFactory = new InvCatalogFactory("", false); InvCatalogImpl catalog = catFactory.readXML(urlString); if (catalog == null) { result.errLog.format("Couldnt open Resolver %s %n ", urlString); return null; } StringBuilder buff = new StringBuilder(); if (!catalog.check(buff)) { result.errLog.format("Invalid catalog from Resolver <%s>%n%s%n", urlString, buff.toString()); result.fatalError = true; return null; } InvDataset top = catalog.getDataset(); if (top.hasAccess()) return (InvDatasetImpl) top; else { java.util.List datasets = top.getDatasets(); return (InvDatasetImpl) datasets.get(0); } }
/** * Create an InvCatalog by reading catalog XML from a String. * * Failures and exceptions are handled by causing validate() to * fail. Therefore, be sure to call validate() before trying to use * the InvCatalog object. * * @param catAsString : the String from which to read the catalog. * @param baseUri : the base URI of the document, used for resolving reletive references. * @return an InvCatalogImpl object */ public InvCatalogImpl readXML( String catAsString, URI baseUri ) { return readXML( new StringReader( catAsString ), baseUri ); }