edu.ucsb.nceas.morpho.datapackage
Class PackageUtil

java.lang.Object
  |
  +--edu.ucsb.nceas.morpho.datapackage.PackageUtil

public class PackageUtil
extends java.lang.Object

This class contains static utility methods that are used throughtout the other *.morpho.datapackage.* classes.


Constructor Summary
PackageUtil()
           
 
Method Summary
static java.lang.String addTriplesToTriplesFile(TripleCollection triples, DataPackage dataPackage, Morpho morpho)
          method to add a collection of triples to a triples file.
static java.lang.String addTriplesToTriplesString(TripleCollection triples, java.lang.String dataPackageString, Morpho morpho)
          method to add a collection of triples to a triples string.
static java.lang.String deleteTriplesInTriplesFile(java.lang.String searchstring, DataPackage dataPackage, Morpho morpho)
          method to delete triples with a specified string from the triples file
static java.util.Hashtable getConfigFileTypeAttributes(Morpho morpho, java.lang.String hashby)
          gets the file types from the config file and hashes them by a specified attribute
static org.w3c.dom.Document getDoc(java.io.File file, Morpho morpho)
          parses file with the dom parser and returns a dom Document
static org.w3c.dom.Document getDoc(java.io.File file, java.lang.String catalogPath)
          parses file with the dom parser and returns a dom Document
static EditorInterface getEditor(Morpho morpho)
          gets the editor context and returns it
static org.w3c.dom.NodeList getPathContent(java.io.File f, java.lang.String path, Morpho morpho)
          gets the content of a tag in a given xml file with the given path
static org.w3c.dom.NodeList getPathContent(java.io.File f, java.util.Vector paths, Morpho morpho)
          Takes in a vector of paths and searches for each of the paths until a node is found that matches the paths.
static java.lang.String getStringFromFile(java.io.File xmlFile)
          returns the string representation of a file
static java.io.File openFile(java.lang.String name, Morpho morpho)
          opens a file on metacat or local.
static java.io.File openFile(java.lang.String name, java.lang.String location, Morpho morpho)
          figures out a files location if it is not known and opens it.
static java.lang.String print(org.w3c.dom.Node node)
          This method can 'print' any DOM subtree.
static java.lang.String printDoctype(org.w3c.dom.Document doc)
          prints out the doctype part of and xml document.
static void save(java.lang.String filename, org.w3c.dom.Document doc, java.lang.String doctype, Morpho morpho)
          Save the DOM doc as a file
static void saveDOM(java.lang.String fileName, org.w3c.dom.Document doc, java.lang.String doctype, Morpho morpho)
          This method wraps the 'print' method to send DOM back to the XML document (file) that was used to create the DOM.
protected static org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs)
          Returns a sorted list of attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackageUtil

public PackageUtil()
Method Detail

getPathContent

public static org.w3c.dom.NodeList getPathContent(java.io.File f,
                                                  java.util.Vector paths,
                                                  Morpho morpho)
Takes in a vector of paths and searches for each of the paths until a node is found that matches the paths. It returns the node of the first path in the vector that it matches. if none of the paths in the vector match it returns null

getPathContent

public static org.w3c.dom.NodeList getPathContent(java.io.File f,
                                                  java.lang.String path,
                                                  Morpho morpho)
gets the content of a tag in a given xml file with the given path
Parameters:
f - the file to parse
path - the path to get the content from
morpho - a morpho object that has a valid config file

getDoc

public static org.w3c.dom.Document getDoc(java.io.File file,
                                          java.lang.String catalogPath)
                                   throws org.xml.sax.SAXException,
                                          java.lang.Exception
parses file with the dom parser and returns a dom Document
Parameters:
file - the file to create the document from
catalogPath - the path to the catalog where the files doctype info can be found.

getDoc

public static org.w3c.dom.Document getDoc(java.io.File file,
                                          Morpho morpho)
                                   throws org.xml.sax.SAXException,
                                          java.lang.Exception
parses file with the dom parser and returns a dom Document
Parameters:
file - the file to create the document from
morpho - the top level Morpho class

print

public static java.lang.String print(org.w3c.dom.Node node)
This method can 'print' any DOM subtree. Specifically it is set (by means of 'out') to write the in-memory DOM to the same XML file that was originally read. Action thus saves a new version of the XML doc. Adapted from configXML.java.
Parameters:
node - node usually set to the 'doc' node for complete XML file re-write

sortAttributes

protected static org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs)
Returns a sorted list of attributes. Taken from configXML.java

printDoctype

public static java.lang.String printDoctype(org.w3c.dom.Document doc)
prints out the doctype part of and xml document. this can be appended to the output from print().
Parameters:
doc - the dom of the document to print the doctype for

openFile

public static java.io.File openFile(java.lang.String name,
                                    Morpho morpho)
                             throws java.io.FileNotFoundException,
                                    CacheAccessException
opens a file on metacat or local. It defaults to local if it is on both.
Parameters:
name - the name of the file
morpho - the morpho object that is currently running.

openFile

public static java.io.File openFile(java.lang.String name,
                                    java.lang.String location,
                                    Morpho morpho)
                             throws java.io.FileNotFoundException,
                                    CacheAccessException
figures out a files location if it is not known and opens it. the default is to open it from the local system, if it is in both places.
Parameters:
name - the file to open
location - the location of the file. set to null if the location is unknown
morpho - the morpho object that is currently running.

getEditor

public static EditorInterface getEditor(Morpho morpho)
gets the editor context and returns it

getStringFromFile

public static java.lang.String getStringFromFile(java.io.File xmlFile)
returns the string representation of a file

addTriplesToTriplesFile

public static java.lang.String addTriplesToTriplesFile(TripleCollection triples,
                                                       DataPackage dataPackage,
                                                       Morpho morpho)
method to add a collection of triples to a triples file. this method searches for any triples already in the file and appends the new ones after the existing ones.
Parameters:
triples - the collection of triples to add
dataPackage - the package that you want to add the triples to
morpho - the morpho object that is currently running.

addTriplesToTriplesString

public static java.lang.String addTriplesToTriplesString(TripleCollection triples,
                                                         java.lang.String dataPackageString,
                                                         Morpho morpho)
method to add a collection of triples to a triples string. this method searches for any triples already in the string and appends the new ones after the existing ones.
Parameters:
triples - the collection of triples to add
dataPackageString - the package that you want to add the triples to
morpho - the morpho object that is currently running.

deleteTriplesInTriplesFile

public static java.lang.String deleteTriplesInTriplesFile(java.lang.String searchstring,
                                                          DataPackage dataPackage,
                                                          Morpho morpho)
method to delete triples with a specified string from the triples file
Parameters:
searchstring - the string to search for in the triples. when this string is found the entire triple to which it belongs is deleted.
dataPackage - the package that you want to delete the triples from
morpho - the morpho object that is currently running.

getConfigFileTypeAttributes

public static java.util.Hashtable getConfigFileTypeAttributes(Morpho morpho,
                                                              java.lang.String hashby)
gets the file types from the config file and hashes them by a specified attribute
Parameters:
morpho - the client morpho that is currently active
hashby - a key from the attributes to hash the table by. note that this must be one of the required fields or else the hashtable will try to hash values to null

save

public static void save(java.lang.String filename,
                        org.w3c.dom.Document doc,
                        java.lang.String doctype,
                        Morpho morpho)
Save the DOM doc as a file

saveDOM

public static void saveDOM(java.lang.String fileName,
                           org.w3c.dom.Document doc,
                           java.lang.String doctype,
                           Morpho morpho)
This method wraps the 'print' method to send DOM back to the XML document (file) that was used to create the DOM. i.e. this method saves changes to disk
Parameters:
nd - node (usually the document root)


Copyright © 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.