Difference between revisions of "API:EPrints/DataObj/Document"

From EPrints Documentation
Jump to: navigation, search
Line 265: Line 265:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_get_url -->
+
<!-- Pod2Wiki=item_path -->
===get_url===
+
===path===
 +
 
 +
$path = $doc-&gt;path
 +
Returns the relative path to the document WITHOUT any file.
 +
 
 +
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<span style='display:none'>User Comments</span>
 +
<!-- Edit below this comment -->
 +
 
 +
 
 +
<!-- Pod2Wiki= -->
 +
</div>
 +
<!-- Pod2Wiki=item_file_path -->
 +
===file_path===
  
  $url = $doc-&gt;get_url( [$file] )
+
  $path = $doc-&gt;file_path( [ $filename ] )
Return the full URL of the document. Overrides the stub in DataObj.
+
Returns the relative path to $filename stored in this document. If $filename is undefined returns the path to the main file.
  
If file is not specified then the "main" file is used.
+
This is an efficient shortcut to this:
  
 +
  my $file = $doc-&gt;stored_file( $filename );
 +
  my $path = $file-&gt;path;
 +
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<span style='display:none'>User Comments</span>
Line 280: Line 296:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_local_path -->
+
<!-- Pod2Wiki=item_get_url -->
===local_path===
+
===get_url===
  
  $path = $doc-&gt;local_path
+
  $url = $doc-&gt;get_url( [$file] )
Return the full path of the directory where this document is stored in the filesystem.
+
Return the full URL of the document. Overrides the stub in DataObj.
 +
 
 +
If file is not specified then the "main" file is used.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 323: Line 341:
  
 
  $doc-&gt;set_main( $main_file )
 
  $doc-&gt;set_main( $main_file )
Sets the main file. Won't affect the database until a $doc-&gt;commit().
+
Sets the main file and adjusts format and mime type as necessary. Won't affect the database until a $doc-&gt;commit().
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 363: Line 381:
 
  $doc-&gt;set_format_desc( $format_desc )
 
  $doc-&gt;set_format_desc( $format_desc )
 
Set the format description.  Won't affect the database until a commit(). Just an alias for $doc-&gt;set_value( "format_desc" , $format_desc );
 
Set the format description.  Won't affect the database until a commit(). Just an alias for $doc-&gt;set_value( "format_desc" , $format_desc );
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki= -->
 
</div>
 
<!-- Pod2Wiki=item_upload -->
 
===upload===
 
 
$success = $doc-&gt;upload( $filehandle, $filename [, $preserve_path [, $filesize ] ] )
 
Upload the contents of the given file handle into this document as the given filename.
 
 
If $preserve_path then make any subdirectories needed, otherwise place this in the top level.
 
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 389: Line 392:
 
===add_file===
 
===add_file===
  
  $success = $doc-&gt;add_file( $file, $filename, [$preserve_path] )
+
  $fileobj = $doc-&gt;add_file( $file, $filename [, $preserve_path] )
$file is the full path to a file to be added to the document, with name $filename.
+
$file is the full path to a file to be added to the document, with name $filename. $filename is passed through [[API:EPrints/System#sanitise|EPrints::System/sanitise]] before being written.
 
 
If $preserve_path then keep the filename as is (including subdirs and spaces)
 
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<!-- Edit below this comment -->
 
 
 
 
 
<!-- Pod2Wiki= -->
 
</div>
 
<!-- Pod2Wiki=item_sanitise -->
 
===sanitise===
 
 
 
$cleanfilename = sanitise( $filename )
 
Return just the filename (no leading path) and convert any naughty characters to underscore.
 
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<!-- Edit below this comment -->
 
 
 
  
<!-- Pod2Wiki= -->
+
If $preserve_path is true then include path components in $filename.
</div>
 
<!-- Pod2Wiki=item_upload_archive -->
 
===upload_archive===
 
  
$success = $doc-&gt;upload_archive( $filehandle, $filename, $archive_format )
+
Returns the $fileobj created or undef on failure.
Upload the contents of the given archive file. How to deal with the  archive format is configured in SystemSettings.
 
 
 
(In case the over-loading of the word "archive" is getting confusing,  in this context we mean ".zip" or ".tar.gz" archive.)
 
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 561: Line 538:
 
  $doc = $doc-&gt;remove_indexcodes()
 
  $doc = $doc-&gt;remove_indexcodes()
 
Remove any documents containing index codes for this document. Returns the number of documents removed.
 
Remove any documents containing index codes for this document. Returns the number of documents removed.
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki= -->
 
</div>
 
<!-- Pod2Wiki=item_cache_file -->
 
===cache_file===
 
 
$filename = $doc-&gt;cache_file( $suffix );
 
Return a cache filename for this document with the givven suffix.
 
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>

Revision as of 12:27, 1 December 2011

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki


NAME

EPrints::DataObj::Document - A single format of a record.

User Comments


DESCRIPTION

Document represents a single format of an EPrint (eg. PDF) - the actual file(s) rather than the metadata.

This class is a subclass of DataObj, with the following metadata fields:

User Comments


docid (text)

The unique ID of the document. This is a string of the format 123-02 where the first number is the eprint id and the second is the document number within that eprint.

This should probably have been and "int" but isn't. I later version of EPrints may change this.

User Comments


eprintid (itemref)

The id number of the eprint to which this document belongs.

User Comments


placement (int)

Placement of the document - the order documents should be shown in.

User Comments


format (namedset)

The format of this document. One of the types of the dataset "document".

User Comments


formatdesc (text)

An additional description of this document. For example the specific version of a format.

User Comments


language (namedset)

The ISO ID of the language of this document. The default configuration of EPrints does not set this.

User Comments


security (namedset)

The security type of this document - who can view it. One of the types of the dataset "security".

User Comments


main (text)

The file which we should link to. For something like a PDF file this is the only file. For an HTML document with images it would be the name of the actual HTML file.

User Comments


files (subobject, multiple)

A virtual field which represents the list of Files which are part of this record.

User Comments


media

A compound field containing a description of the document media - dimensions, codec etc.

User Comments


METHODS

User Comments


get_system_field_info

$metadata = EPrints::DataObj::Document->get_system_field_info

Return an array describing the system metadata of the Document dataset.

User Comments


get_dataset_id

$dataset = EPrints::DataObj::Document->get_dataset_id

Returns the id of the EPrints::DataSet object to which this record belongs.

User Comments


get_defaults

$defaults = EPrints::DataObj::Document->get_defaults( $session, $data )

Return default values for this object based on the starting data.

User Comments


clone

$newdoc = $doc->clone( $eprint )

Attempt to clone this document. Both the document metadata and the actual files. The clone will be associated with the given EPrint.

User Comments


remove

$success = $doc->remove

Attempt to completely delete this document

User Comments


get_eprint

$eprint = $doc->get_eprint

Return the EPrint this document is associated with.

This is a synonym for get_parent().

User Comments


get_baseurl

$url = $doc->get_baseurl( [$staff] )

Return the base URL of the document. Overrides the stub in DataObj. $staff is currently ignored.

User Comments


is_public

$boolean = $doc->is_public()

True if this document has no security set and is in the live archive.

User Comments


path

$path = $doc->path

Returns the relative path to the document WITHOUT any file.

User Comments


file_path

$path = $doc->file_path( [ $filename ] )

Returns the relative path to $filename stored in this document. If $filename is undefined returns the path to the main file.

This is an efficient shortcut to this:

 my $file = $doc->stored_file( $filename );
 my $path = $file->path;
 

User Comments


get_url

$url = $doc->get_url( [$file] )

Return the full URL of the document. Overrides the stub in DataObj.

If file is not specified then the "main" file is used.

User Comments


files

%files = $doc->files

Return a hash, the keys of which are all the files belonging to this document (relative to $doc->local_path). The values are the sizes of the files, in bytes.

User Comments


remove_file

$success = $doc->remove_file( $filename )

Attempt to remove the given file. Give the filename as it is returned by get_files().

User Comments


set_main

$doc->set_main( $main_file )

Sets the main file and adjusts format and mime type as necessary. Won't affect the database until a $doc->commit().

User Comments


get_main

$filename = $doc->get_main

Return the name of the main file in this document.

User Comments


set_format

$doc->set_format( $format )

Set format. Won't affect the database until a commit(). Just an alias for $doc->set_value( "format" , $format );

User Comments


set_format_desc

$doc->set_format_desc( $format_desc )

Set the format description. Won't affect the database until a commit(). Just an alias for $doc->set_value( "format_desc" , $format_desc );

User Comments


add_file

$fileobj = $doc->add_file( $file, $filename [, $preserve_path] )

$file is the full path to a file to be added to the document, with name $filename. $filename is passed through EPrints::System/sanitise before being written.

If $preserve_path is true then include path components in $filename.

Returns the $fileobj created or undef on failure.

User Comments


add_archive

$success = $doc->add_archive( $file, $archive_format )

$file is the full path to an archive file, eg. zip or .tar.gz

This function will add the contents of that archive to the document.

User Comments


add_directory

$success = $doc->add_directory( $directory )

Upload the contents of $directory to this document. This will not set the main file.

This method expects $directory to have a trailing slash (/).

User Comments


upload_url

$success = $doc->upload_url( $url )

Attempt to grab stuff from the given URL. Grabbing HTML stuff this way is always problematic, so (by default): only relative links will be followed and only links to files in the same directory or subdirectory will be followed.

This (by default) uses wget. The details can be configured in SystemSettings.

User Comments


commit

$success = $doc->commit

Commit any changes that have been made to this object to the database.

Calls "set_document_automatic_fields" in the ArchiveConfig first to set any automatic fields that may be needed.

User Comments


validate

$problems = $doc->validate( [$for_archive] )

Return an array of XHTML DOM objects describing validation problems with the entire document, including the metadata and repository config specific requirements.

A reference to an empty array indicates no problems.

User Comments


get_type

$type = $doc->get_type

Return the type of this document.

User Comments


files_modified

$doc->files_modified

This method does all the things that need doing when a file has been modified.

User Comments


rehash

$doc->rehash

Recalculate the hash value of the document. Uses MD5 of the files (in alphabetic order), but can use user specified hashing function instead.

User Comments


make_indexcodes

$doc = $doc->make_indexcodes()

Make the indexcodes document for this document. Returns the generated document or undef on failure.

User Comments


remove_indexcodes

$doc = $doc->remove_indexcodes()

Remove any documents containing index codes for this document. Returns the number of documents removed.

User Comments


render_icon_link

$frag = $doc->render_icon_link( %opts )

Render a link to the icon for this document.

Options:

User Comments


new_window_1

new_window => 1

Make link go to _blank not current window.

User Comments


preview_1

preview => 1

If possible, provide a preview pop-up.

User Comments


public_0

public => 0

Show thumbnail/preview only on public docs.

User Comments


public_1

public => 1

Show thumbnail/preview on all docs if poss.

User Comments


render_preview_link

$frag = $doc->render_preview_link( %opts )

Render a link to the preview for this document (if available) using a lightbox.

Options:

User Comments


caption_frag

caption => $frag

XHTML fragment to use as the caption, defaults to empty.

User Comments


set_foo

set => "foo"

The name of the set this document belongs to, defaults to none (preview won't be shown as part of a set).

User Comments


add_relation

$doc->add_relation( $tgt, @types )

Add one or more relations to $doc pointing to $tgt (does not modify $tgt).

User Comments


remove_relation

$doc->remove_relation( $tgt [, @types ] )

Removes the relations in $doc to $tgt. If @types isn't given removes all relations to $tgt. If $tgt is undefined removes all relations given in @types.

If you want to remove all relations do $doc->set_value( "relation", [] );

User Comments


has_relation

$bool = $doc->has_relation( $tgt [, @types ] )

Returns true if $doc has relations to $tgt. If @types is given checks that $doc satisfies all of the given types. $tgt may be undefined.

User Comments


search_related

$list = $doc->search_related( [ $type ] )

Return a EPrints::List that contains all documents related to this document. If $type is defined returns only those documents related by $type.

User Comments


COPYRIGHT

User Comments