org.opensourcephysics.tools
Class LibraryComPADRE

java.lang.Object
  extended by org.opensourcephysics.tools.LibraryComPADRE

public class LibraryComPADRE
extends java.lang.Object

This provides static methods for getting a LibraryCollection from ComPADRE. Adapted from code written for EJS by Francisco Esquembre.

Version:
1.0
Author:
Francisco Esquembre, Douglas Brown

Field Summary
static java.lang.String ABOUT_OSP
           
static java.lang.String EJS_COLLECTION_NAME
           
static java.lang.String EJS_INFO_URL
           
static java.lang.String EJS_SERVER_RECORDS
           
static java.lang.String EJS_SERVER_TREE
           
static java.lang.String GENERIC_COLLECTION_NAME
           
static java.lang.String HOST
           
static java.lang.String OSP_INFO_URL
           
static java.lang.String PRIMARY_ONLY
           
static java.lang.String TRACKER_COLLECTION_NAME
           
static java.lang.String TRACKER_INFO_URL
           
static java.lang.String TRACKER_SERVER_RECORDS
           
static java.lang.String TRACKER_SERVER_TREE
           
 
Constructor Summary
LibraryComPADRE()
           
 
Method Summary
protected static java.util.List<org.w3c.dom.Node> getAllChildren(org.w3c.dom.Node parent, java.lang.String name)
          Returns all child nodes with the given name.
protected static java.lang.String[] getAttachment(org.w3c.dom.Node node, java.lang.String attachmentType)
          Returns data for a downloadable DOM Node attachment.
protected static java.lang.String getChildValue(org.w3c.dom.Node parent, java.lang.String name)
          Gets the value of the first child node with a given name.
protected static LibraryCollection getCollection(java.lang.String path)
          Returns the LibraryCollection for a given ComPADRE path (query).
static java.lang.String getCollectionName(java.lang.String path)
          Returns a descriptive name for a given ComPADRE path (query).
protected static java.lang.String getCollectionPath(java.lang.String path, boolean primarySubjectOnly)
          Returns the collection path for an EJS or tracker tree.
protected static org.w3c.dom.Node getFirstChild(org.w3c.dom.Node parent, java.lang.String name)
          Returns the first child node with the given name.
protected static java.lang.String getNodeValue(org.w3c.dom.Node node)
          Gets the value of a Node.
protected static boolean isComPADREPath(java.lang.String path)
          Determines if a path is a valid ComPADRE query.
protected static boolean isPrimarySubjectOnly(java.lang.String path)
          Determines if a query path limits results to the primary subject only.
protected static boolean load(LibraryCollection collection, java.lang.String query)
          Loads a collection using a specified comPADRE search query.
protected static boolean loadResource(LibraryResource record, org.w3c.dom.Node node, java.lang.String[] attachment, LibraryTreeNode treeNode)
          Reloads a ComPADRE record into a LibraryTreeNode.
protected static boolean loadResources(LibraryTreeNode treeNode)
          Loads ComPADRE records into a LibraryTreeNode collection.
protected static boolean loadSubtrees(LibraryCollection collection, org.w3c.dom.NodeList nodeList, java.lang.String attributeType, java.lang.String serviceParameter)
          Loads a collection with subtree collections that meet the specified requirements.
protected static java.lang.String processURL(java.lang.String url)
          Replaces "&" with "&" in HTML code.
protected static boolean reloadResource(LibraryTreeNode treeNode, java.lang.String urlPath)
          Reloads a ComPADRE record into a LibraryTreeNode.
protected static java.lang.String writeXmlFile(org.w3c.dom.Document doc, java.lang.String filename)
          Writes a DOM document to a file for testing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OSP_INFO_URL

public static final java.lang.String OSP_INFO_URL
See Also:
Constant Field Values

EJS_SERVER_TREE

public static final java.lang.String EJS_SERVER_TREE
See Also:
Constant Field Values

EJS_SERVER_RECORDS

public static final java.lang.String EJS_SERVER_RECORDS
See Also:
Constant Field Values

EJS_COLLECTION_NAME

public static final java.lang.String EJS_COLLECTION_NAME
See Also:
Constant Field Values

EJS_INFO_URL

public static final java.lang.String EJS_INFO_URL
See Also:
Constant Field Values

TRACKER_SERVER_TREE

public static final java.lang.String TRACKER_SERVER_TREE
See Also:
Constant Field Values

TRACKER_SERVER_RECORDS

public static final java.lang.String TRACKER_SERVER_RECORDS
See Also:
Constant Field Values

TRACKER_COLLECTION_NAME

public static final java.lang.String TRACKER_COLLECTION_NAME
See Also:
Constant Field Values

TRACKER_INFO_URL

public static final java.lang.String TRACKER_INFO_URL
See Also:
Constant Field Values

PRIMARY_ONLY

public static final java.lang.String PRIMARY_ONLY
See Also:
Constant Field Values

GENERIC_COLLECTION_NAME

public static final java.lang.String GENERIC_COLLECTION_NAME
See Also:
Constant Field Values

ABOUT_OSP

public static final java.lang.String ABOUT_OSP
See Also:
Constant Field Values

HOST

public static final java.lang.String HOST
See Also:
Constant Field Values
Constructor Detail

LibraryComPADRE

public LibraryComPADRE()
Method Detail

load

protected static boolean load(LibraryCollection collection,
                              java.lang.String query)
Loads a collection using a specified comPADRE search query.

Parameters:
collection - the LibraryCollection to load
query - the search query
Returns:
true if successfully loaded

loadSubtrees

protected static boolean loadSubtrees(LibraryCollection collection,
                                      org.w3c.dom.NodeList nodeList,
                                      java.lang.String attributeType,
                                      java.lang.String serviceParameter)
Loads a collection with subtree collections that meet the specified requirements.

Parameters:
collection - the LibraryCollection to load
nodeList - a list of Nodes
attributeType - the desired attribute
serviceParameter - the desired service parameter
Returns:
true if at least one subtree collection was loaded

loadResources

protected static boolean loadResources(LibraryTreeNode treeNode)
Loads ComPADRE records into a LibraryTreeNode collection.

Parameters:
treeNode - the LibraryTreeNode to load--note record MUST be a collection
Returns:
true if one or more ComPADRE records were successfully loaded

reloadResource

protected static boolean reloadResource(LibraryTreeNode treeNode,
                                        java.lang.String urlPath)
Reloads a ComPADRE record into a LibraryTreeNode.

Parameters:
treeNode - the LibraryTreeNode to reload
Returns:
true if successfully reloaded

loadResource

protected static boolean loadResource(LibraryResource record,
                                      org.w3c.dom.Node node,
                                      java.lang.String[] attachment,
                                      LibraryTreeNode treeNode)
Reloads a ComPADRE record into a LibraryTreeNode.

Parameters:
treeNode - the LibraryTreeNode to reload
Returns:
true if successfully reloaded

getAttachment

protected static java.lang.String[] getAttachment(org.w3c.dom.Node node,
                                                  java.lang.String attachmentType)
Returns data for a downloadable DOM Node attachment.

Parameters:
node - the DOM Node
attachmentType - the attachment type
Returns:
String[] {URL, filename, size in Bytes}, or null if no attachment found

getFirstChild

protected static org.w3c.dom.Node getFirstChild(org.w3c.dom.Node parent,
                                                java.lang.String name)
Returns the first child node with the given name.

Parameters:
parent - the parent Node
name - the child name
Returns:
the first child Node found, or null if none

getAllChildren

protected static java.util.List<org.w3c.dom.Node> getAllChildren(org.w3c.dom.Node parent,
                                                                 java.lang.String name)
Returns all child nodes with the given name.

Parameters:
parent - the parent Node
name - the name
Returns:
a list of Nodes (may be empty)

getNodeValue

protected static java.lang.String getNodeValue(org.w3c.dom.Node node)
Gets the value of a Node.

Parameters:
node - the Node
Returns:
the value

getChildValue

protected static java.lang.String getChildValue(org.w3c.dom.Node parent,
                                                java.lang.String name)
Gets the value of the first child node with a given name.

Parameters:
parent - the parent Node
name - the name of the child
Returns:
the value of the first child found, or null if none

processURL

protected static java.lang.String processURL(java.lang.String url)
Replaces "&" with "&" in HTML code.

Parameters:
url - the HTML code
Returns:
the clean URL string

writeXmlFile

protected static java.lang.String writeXmlFile(org.w3c.dom.Document doc,
                                               java.lang.String filename)
Writes a DOM document to a file for testing.

Parameters:
doc - the Document
filename - the filename to write to
Returns:
the String contents of the document

getCollectionName

public static java.lang.String getCollectionName(java.lang.String path)
Returns a descriptive name for a given ComPADRE path (query).

Parameters:
path - the query string
Returns:
the name of the collection

getCollection

protected static LibraryCollection getCollection(java.lang.String path)
Returns the LibraryCollection for a given ComPADRE path (query).

Parameters:
path - the query string
Returns:
the collection

getCollectionPath

protected static java.lang.String getCollectionPath(java.lang.String path,
                                                    boolean primarySubjectOnly)
Returns the collection path for an EJS or tracker tree.

Parameters:
path - the ComPADRE query string
primarySubjectOnly - true to limit results to their primary subject
Returns:
the corrected ComPADRE query string

isComPADREPath

protected static boolean isComPADREPath(java.lang.String path)
Determines if a path is a valid ComPADRE query.

Parameters:
path - the path
Returns:
true if path is a valid ComPADRE query string

isPrimarySubjectOnly

protected static boolean isPrimarySubjectOnly(java.lang.String path)
Determines if a query path limits results to the primary subject only.

Parameters:
path - the path
Returns:
true if path contains a primary-subject-only flag