Package edu.ucsb.nceas.metacat
Class DocumentImpl
java.lang.Object
edu.ucsb.nceas.metacat.DocumentImpl
A class that represents an XML document. It can be created with a simple document identifier from
a database connection. It also will write an XML text document to a database connection using
SAX.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
protected String
protected String
static final String
protected String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
protected long
static final String
static final String
static final String
static final String
-
Constructor Summary
ConstructorDescriptionDefault constructorDocumentImpl
(String docid) Constructor, creates document from database connection, used for reading the documentDocumentImpl
(String accNum, boolean readNodes) Constructor used to create a document and read the document information from the database. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
archive
(String accnum, org.dataone.service.types.v1.Identifier guid, String user, boolean changeDateModified, SystemMetadataManager.SysMetaVersion sysMetaCheck) Archive an object.static void
Delete an object totally from the db and file system.static void
deleteFromFileSystem
(String accNumber, boolean isXml) Deletes a doc or data file from the filesystem using the accession number.get the creation dategetDocID()
Get the document identifier (docid)get the document nameget the document type (which is the PublicID)int
getRev()
long
get the root node identifierget the system identifierget the update datestatic boolean
hasAllPermission
(String user, String[] groups, String docid) Check for "ALL" or "CHMOD" permission on @docid for @user and/or @groups from DB connectionstatic boolean
hasWritePermission
(String user, String[] groups, String docid) Check for "WRITE" permission on @docid for @user and/or @groups from DB connectionstatic XMLReader
initializeParser
(Vector<XMLSchema> schemaList, Reader dtd, String ruleBase, boolean needValidation, String schemaLocation) Set up the parser handlers for writing the document to the databasereadFromFileSystem
(OutputStream out, String user, String[] groups, String documentPath) Read the XML document from the file system and write to a Writer.static void
registerDocument
(String docname, String doctype, DBConnection conn, String accnum, String user) Register a document that resides on the filesystem with the database.toString()
Print a string representation of the XML document NOTE: this detects the character encoding, or uses the XML defaulttoXml
(OutputStream out, String user, String[] groups, boolean withInLineData) Print a text representation of the XML document to a Writer
-
Field Details
-
SCHEMA
- See Also:
-
NONAMESPACESCHEMA
- See Also:
-
DTD
- See Also:
-
EML200
- See Also:
-
EML210
- See Also:
-
EXTERNALSCHEMALOCATIONPROPERTY
- See Also:
-
EXTERNALNONAMESPACESCHEMALOCATIONPROPERTY
- See Also:
-
REVISIONTABLE
- See Also:
-
DOCUMENTTABLE
- See Also:
-
BIN
- See Also:
-
DECLARATIONHANDLERPROPERTY
- See Also:
-
LEXICALPROPERTY
- See Also:
-
VALIDATIONFEATURE
- See Also:
-
SCHEMAVALIDATIONFEATURE
- See Also:
-
FULLSCHEMAVALIDATIONFEATURE
- See Also:
-
NAMESPACEFEATURE
- See Also:
-
NAMESPACEPREFIXESFEATURE
- See Also:
-
EML2_0_0NAMESPACE
-
EML2_0_1NAMESPACE
-
EML2_1_0NAMESPACE
-
EML2_1_1NAMESPACE
-
EML2_2_0NAMESPACE
-
RDF_SYNTAX_NAMESPACE
-
DOCNAME
- See Also:
-
PUBLICID
- See Also:
-
SYSTEMID
- See Also:
-
docname
-
doctype
-
docid
-
rootnodeid
protected long rootnodeid
-
-
Constructor Details
-
DocumentImpl
public DocumentImpl()Default constructor -
DocumentImpl
Constructor used to create a document and read the document information from the database. If readNodes is false, then the node data is not read at this time, but is deferred until it is needed (such as when a call to toXml() is made).- Parameters:
conn
- the database connection from which to read the documentreadNodes
- flag indicating whether the xmlnodes should be read- Throws:
McdbException
-
DocumentImpl
Constructor, creates document from database connection, used for reading the document- Parameters:
conn
- the database connection from which to read the documentdocid
- the identifier of the document to be created- Throws:
McdbException
-
-
Method Details
-
registerDocument
public static void registerDocument(String docname, String doctype, DBConnection conn, String accnum, String user) throws SQLException, AccessionNumberException, edu.ucsb.nceas.utilities.PropertyNotFoundException, MetacatException Register a document that resides on the filesystem with the database. (ie, just an entry in xml_documents). Creates a reference to a filesystem document (used for non-xml data files).- Parameters:
docname
- - the name of DTD, i.e. the name immediately following the DOCTYPE keyword ( should be the root element name ) or the root element name if no DOCTYPE declaration provided (Oracle's and IBM parsers are not aware if it is not the root element name)doctype
- - Public ID of the DTD, i.e. the name immediately following the PUBLIC keyword in DOCTYPE declaration or the docname if no Public ID provided or null if no DOCTYPE declaration providedconn
- the connection to databaseaccnum
- the accession number to use for the INSERT OR UPDATE, which includes a revision number for this revision of the document (e.g., knb.1.1)user
- the user that owns the document- Throws:
SQLException
AccessionNumberException
MetacatException
edu.ucsb.nceas.utilities.PropertyNotFoundException
-
getDocname
get the document name -
getDoctype
get the document type (which is the PublicID) -
getSystemID
get the system identifier -
getRootNodeID
public long getRootNodeID()get the root node identifier -
getCreateDate
get the creation date -
getUpdateDate
get the update date -
getDocID
Get the document identifier (docid) -
getUserowner
-
getUserupdated
-
getRev
public int getRev() -
getValidateType
-
toString
Print a string representation of the XML document NOTE: this detects the character encoding, or uses the XML default -
toXml
public InputStream toXml(OutputStream out, String user, String[] groups, boolean withInLineData) throws McdbException Print a text representation of the XML document to a Writer- Parameters:
pw
- the Writer to which we print the document Now we decide no matter withinInlineData's value, the document will- Throws:
McdbException
-
readFromFileSystem
public InputStream readFromFileSystem(OutputStream out, String user, String[] groups, String documentPath) throws McdbException Read the XML document from the file system and write to a Writer. Strip out any inline data that the user does not have permission to read.- Parameters:
pw
- the Writer to which we print the documentuser
- the user we will use to verify inline data accessgroups
- the groups we will use to verify inline data accessdocumentPath
- the location of the document on disk- Throws:
McdbException
-
deleteFromFileSystem
Deletes a doc or data file from the filesystem using the accession number.- Parameters:
accNumber
-isXml
-- Throws:
McdbException
-
delete
public static void delete(String accnum, org.dataone.service.types.v1.Identifier guid) throws SQLException, org.dataone.service.exceptions.InvalidRequest, McdbDocNotFoundException, org.dataone.service.exceptions.ServiceFailure Delete an object totally from the db and file system. It doesn't check permission- Parameters:
accnum
- the local id (including the rev) will be deletedguid
- the dataone identifier associated with accnum- Throws:
SQLException
org.dataone.service.exceptions.InvalidRequest
McdbDocNotFoundException
org.dataone.service.exceptions.ServiceFailure
-
archive
public static void archive(String accnum, org.dataone.service.types.v1.Identifier guid, String user, boolean changeDateModified, SystemMetadataManager.SysMetaVersion sysMetaCheck) throws SQLException, org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure Archive an object. Set the archived flag true, also move the object from the xml_documents table to the xml_revisions table if it exists in the xml_documents table. This method will submit the reindex task as well.- Parameters:
accnum
- the local id (including the revision) will be applied.guid
- the dataone identifier associated with the given accnumuser
- the identity of operatorchangeDateModified
- if it needs to change the dateModified field in the system metadatasysMetaCheck
- check whether the version of the provided '@param sysMeta' matches the version of the existing system metadata- Throws:
SQLException
org.dataone.service.exceptions.InvalidRequest
org.dataone.service.exceptions.ServiceFailure
-
hasWritePermission
public static boolean hasWritePermission(String user, String[] groups, String docid) throws SQLException, Exception Check for "WRITE" permission on @docid for @user and/or @groups from DB connection- Throws:
SQLException
Exception
-
hasAllPermission
public static boolean hasAllPermission(String user, String[] groups, String docid) throws SQLException, Exception Check for "ALL" or "CHMOD" permission on @docid for @user and/or @groups from DB connection- Throws:
SQLException
Exception
-
initializeParser
public static XMLReader initializeParser(Vector<XMLSchema> schemaList, Reader dtd, String ruleBase, boolean needValidation, String schemaLocation) throws org.dataone.service.exceptions.ServiceFailure, edu.ucsb.nceas.utilities.PropertyNotFoundException, SAXException Set up the parser handlers for writing the document to the database- Parameters:
schemaList
- the list of schema will be useddtd
- the dtd contentruleBase
- the validation base - schema or dtdneedValidation
- if the document needs to be validatedschemaLocation
- the string contains the schema location- Returns:
- the XMLReader object
- Throws:
edu.ucsb.nceas.utilities.PropertyNotFoundException
SAXException
org.dataone.service.exceptions.ServiceFailure
-