thredds.catalog.dl.DCWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of netcdf Show documentation
Show all versions of netcdf Show documentation
The NetCDF-Java Library is a Java interface to NetCDF files,
as well as to many other types of scientific data formats.
// $Id: DCWriter.java 48 2006-07-12 16:15:40Z caron $
/*
* Copyright 1998-2009 University Corporation for Atmospheric Research/Unidata
*
* Portions of this software were developed by the Unidata Program at the
* University Corporation for Atmospheric Research.
*
* Access and use of this software shall impose the following obligations
* and understandings on the user. The user is granted the right, without
* any fee or cost, to use, copy, modify, alter, enhance and distribute
* this software, and any derivative works thereof, and its supporting
* documentation for any purpose whatsoever, provided that this entire
* notice appears in all copies of the software, derivative works and
* supporting documentation. Further, UCAR requests that the user credit
* UCAR/Unidata in any publications that result from the use of this
* software or in any product that includes this software. The names UCAR
* and/or Unidata, however, may not be used in any advertising or publicity
* to endorse or promote any products or commercial entity unless specific
* written permission is obtained from UCAR/Unidata. The user also
* understands that UCAR/Unidata is not obligated to provide the user with
* any support, consulting, training or assistance of any kind with regard
* to the use, operation and performance of this software nor to provide
* the user with any updates, revisions, new versions or "bug fixes."
*
* THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package thredds.catalog.dl;
import thredds.catalog.*;
import ucar.nc2.units.DateType;
import ucar.nc2.units.DateRange;
import org.jdom.*;
import org.jdom.output.*;
import java.io.*;
import java.util.*;
public class DCWriter {
private static final Namespace defNS = Namespace.getNamespace("http://purl.org/dc/elements/1.1/");
private static final String schemaLocation = defNS.getURI() + " http://www.unidata.ucar.edu/schemas/other/dc/dc.xsd";
private static final String schemaLocationLocal = defNS.getURI() + " file://P:/schemas/other/dc/dc.xsd";
private static String threddsServerURL = "http://localhost:8080/thredds/subset.html";
private InvCatalog cat;
public DCWriter( InvCatalog cat) {
this.cat = cat;
}
public void writeItems( String fileDir) {
File dir = new File(fileDir);
if (!dir.exists())
dir.mkdirs();
List datasets = cat.getDatasets();
for (int i=0; i
*/
public void writeDataset(InvDataset ds, Element rootElem) {
rootElem.addContent( new Element("title", defNS).addContent(ds.getName()));
rootElem.addContent( new Element("Entry_ID", defNS).addContent(ds.getUniqueID()));
// keywords
List list = ds.getKeywords();
if (list.size() > 0) {
for (int i=0; i 0) {
for (int i=0; i 0)
dataCenter.addContent( new Element("Data_Center_URL", defNS).addContent(p.getUrl()));
Element person = new Element("Personnel", defNS);
dataCenter.addContent( person);
person.addContent( new Element("Role", defNS).addContent("DATA CENTER CONTACT"));
person.addContent( new Element("Email", defNS).addContent(p.getEmail()));
}
private void writeVariable( Element param, ThreddsMetadata.Variable v) {
String vname = v.getVocabularyName();
StringTokenizer stoker = new StringTokenizer(vname,">");
if (stoker.hasMoreTokens())
param.addContent( new Element("Category", defNS).addContent(stoker.nextToken().trim()));
if (stoker.hasMoreTokens())
param.addContent( new Element("Topic", defNS).addContent(stoker.nextToken().trim()));
if (stoker.hasMoreTokens())
param.addContent( new Element("Term", defNS).addContent(stoker.nextToken().trim()));
if (stoker.hasMoreTokens())
param.addContent( new Element("Variable", defNS).addContent(stoker.nextToken().trim()));
if (stoker.hasMoreTokens())
param.addContent( new Element("Detailed_Variable", defNS).addContent(stoker.nextToken().trim()));
}
// test
private static void doOne( InvCatalogFactory fac, String url) {
System.out.println("***read "+url);
try {
InvCatalogImpl cat = (InvCatalogImpl) 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));
DCWriter w = new DCWriter( cat);
w.writeItems( "C:/temp/dif");
} catch (Exception e) {
e.printStackTrace();
}
}
/** testing */
public static void main (String[] args) throws Exception {
InvCatalogFactory catFactory = InvCatalogFactory.getDefaultFactory(true);
doOne(catFactory, "file:///C:/dev/thredds/catalog/test/data/TestHarvest.xml");
}
}
/* Change History:
$Log: DCWriter.java,v $
Revision 1.7 2006/04/20 22:13:14 caron
improve DL record extraction
CatalogCrawler improvements
Revision 1.6 2006/01/04 00:16:33 caron
jdom 1.0
use nj22.12, visadNoDods
Revision 1.5 2005/05/04 17:56:26 caron
use nj22.09
Revision 1.4 2005/05/04 17:16:23 caron
replace ThreddsMetadata.TimeCoverage object with DateRange
Revision 1.3 2004/09/24 03:26:28 caron
merge nj22
Revision 1.2 2004/06/09 00:27:26 caron
version 2.0a release; cleanup javadoc
*/