rendsite.engine.node
Class Node_File

java.lang.Object
  extended by rendsite.engine.node.Node
      extended by rendsite.engine.node.Node_File
All Implemented Interfaces:
FileInterface

public class Node_File
extends Node
implements FileInterface

Crawler node for a File.

Author:
erich Version History
 10NOV09 - EPG - First package release.
 

Field Summary
 Category category
          Unlike type, category must not be inferred.
 boolean copyOnly
           
 java.lang.String description
          Information about the file.
 boolean excluded
           
 boolean ignored
           
 RenderingType renderingType
          Rendering Type may be configured per file.
 java.lang.String type
          Type may be configured per file, but if not present the renderer may decide a type based on other information.
 
Constructor Summary
Node_File(java.io.File sourceFile, Node_Directory containingDir, FileContext fcontext)
          Create a node.
Node_File(java.io.File sourceFile, Node_Directory containingDir, FileContext fcontext, Node_File neighborOrigin)
          Create a node.
 
Method Summary
 void assertNeighbor(java.lang.String neighbor, boolean isCataloged)
          Assert that a neighbor exists.
 void copy()
          Copy file from source to destination.
 void failWrite()
          Not that the file write failed.
 Node_File getCatalogedFile()
          Get the cataloged file.
 java.lang.String getFileExtension()
          Get file extension.
 java.lang.String getName()
          Get the rendered name.
 java.util.Collection<Node_File> getNeighbors()
          Get all the neighbors.
 java.lang.String getURL(boolean encode)
          Get the URL for this file.
 java.lang.String getURLRendering(boolean encode)
          Get the rendering URL for this file.
 java.lang.String getURLtoRoot(boolean encode)
          Get the URL to the root from directory which contains this file.
 boolean isNeighbor()
          Is this is a neighbor file? If it is, the source doesn't actually exist.
 long lastModified()
          Get the last modified date for the file.
 long lastModifiedDestination()
          Get the last modified date for the destination file.
 java.io.InputStream openForRead()
          Open for the file for reading.
 java.io.OutputStream openForWrite()
          Open for the file for writing.
 java.io.OutputStream openNeighborForWrite(java.lang.String neighbor, boolean isCataloged)
          Open a neighbor file in the destination for writing.
 void setCatalogNeighbor(java.lang.String neighbor)
          Set a neighbor as the catalog file instead of this.
 void setRenderingType(RenderingType rType)
          Set the rendering type.
 
Methods inherited from class rendsite.engine.node.Node
getType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyOnly

public boolean copyOnly

ignored

public boolean ignored

excluded

public boolean excluded

description

public java.lang.String description
Information about the file. If the 'description' is null, there is no other info about the file.


type

public java.lang.String type
Type may be configured per file, but if not present the renderer may decide a type based on other information. In processing and rendering, configured type will always supersede type inferred from other sources. If it is null or blank, then its type is not known through any means.


renderingType

public RenderingType renderingType
Rendering Type may be configured per file. If it is not, the get method will see if a category can give a rendering type. If it can't the get will return OTHER. In processing and rendering, configured type will always supersede type inferred from other sources (including category). If it is null or blank, then its type is not known through any means.


category

public Category category
Unlike type, category must not be inferred. It must be explicitly configured per file. It will be used to derive a type, if type is not available. If it is null its category is not known.

Constructor Detail

Node_File

public Node_File(java.io.File sourceFile,
                 Node_Directory containingDir,
                 FileContext fcontext)
          throws java.lang.Throwable
Create a node.

Parameters:
sourceFile - the source FS file.
containingDir - the source Node Directory containing this file.
fcontext - the file context.
Throws:
java.lang.Throwable - mostly for bugs.

Node_File

public Node_File(java.io.File sourceFile,
                 Node_Directory containingDir,
                 FileContext fcontext,
                 Node_File neighborOrigin)
          throws java.lang.Throwable
Create a node.

Parameters:
sourceFile - the source FS file.
containingDir - the source Node Directory containing this file.
fcontext - the file context.
neighborOrigin - set this to the file for which this is a neighbor.
Throws:
java.lang.Throwable - mostly for bugs.
Method Detail

openForRead

public java.io.InputStream openForRead()
                                throws things.common.ThingsException
Open for the file for reading. The stream will not be buffered. You should close it when you are done.

Specified by:
openForRead in interface FileInterface
Returns:
an input stream for reading.
Throws:
things.common.ThingsException

openForWrite

public java.io.OutputStream openForWrite()
                                  throws things.common.ThingsException
Open for the file for writing. The stream will not be buffered. You should close it when you are done. It will mark the file as having been updated for other processing.

Specified by:
openForWrite in interface FileInterface
Returns:
an output stream for writing.
Throws:
things.common.ThingsException

failWrite

public void failWrite()
               throws java.lang.Throwable
Not that the file write failed. The last modified date will be set to 1 (one millisecond after epoch) and the filecontext will be notified.

Throws:
things.common.ThingsException - will only happen for bugs, which will be a panic.
java.lang.Throwable

openNeighborForWrite

public java.io.OutputStream openNeighborForWrite(java.lang.String neighbor,
                                                 boolean isCataloged)
                                          throws things.common.ThingsException
Open a neighbor file in the destination for writing. The stream will not be buffered. You should close it when you are done. It will mark the file as having been updated for other processing. If the file already exists, it will be overwritten.

Specified by:
openNeighborForWrite in interface FileInterface
Parameters:
neighbor - the neighbor file name. This name must be unique for the neighborhood (containing directory) and can be used for other methods.
isCataloged - will this file be cataloged?
Returns:
an output stream for writing.
Throws:
things.common.ThingsException

assertNeighbor

public void assertNeighbor(java.lang.String neighbor,
                           boolean isCataloged)
                    throws things.common.ThingsException
Assert that a neighbor exists. If the file does not exist, it will cause an exception.

Parameters:
neighbor - the neighbor file name. This name must be unique for the neighborhood (containing directory) and can be used for other methods.
isCataloged - will this file be cataloged?
Throws:
things.common.ThingsException

setCatalogNeighbor

public void setCatalogNeighbor(java.lang.String neighbor)
                        throws things.common.ThingsException
Set a neighbor as the catalog file instead of this.

Specified by:
setCatalogNeighbor in interface FileInterface
Parameters:
neighbor - the neighbor file name. This name must be unique for the neighborhood (containing directory) and can be used for other methods. It is case sensitive.
Throws:
things.common.ThingsException - this will always happen if the neighbor has not been created through a openNeighborForWrite() call.

lastModified

public long lastModified()
                  throws things.common.ThingsException
Get the last modified date for the file. If it is a neighbor, it'll get it for its origin.

Specified by:
lastModified in interface FileInterface
Returns:
the last modified date as milliseconds from epoch.
Throws:
things.common.ThingsException

lastModifiedDestination

public long lastModifiedDestination()
                             throws things.common.ThingsException
Get the last modified date for the destination file. If it is a neighbor, it'll get it for its origin.

Specified by:
lastModifiedDestination in interface FileInterface
Returns:
the last modified date as milliseconds from epoch or 0 if the file does not exist.
Throws:
things.common.ThingsException

getNeighbors

public java.util.Collection<Node_File> getNeighbors()
Get all the neighbors.

Returns:
the neighbors.

getName

public java.lang.String getName()
Get the rendered name. It'll be nothing or overridden by a sub class.

Overrides:
getName in class Node
Returns:
the name. DO NOT USE THIS TO OPEN A FILE!

getFileExtension

public java.lang.String getFileExtension()
Get file extension.

Returns:
the file extension or a blank string.

setRenderingType

public void setRenderingType(RenderingType rType)
Set the rendering type. This should only be done by configuration.

Parameters:
rType - the rendering type. null is acceptable.

getCatalogedFile

public Node_File getCatalogedFile()
Get the cataloged file.

Returns:
the cataloged file.

isNeighbor

public boolean isNeighbor()
Is this is a neighbor file? If it is, the source doesn't actually exist. It should only be opened for writing.

Returns:
true if a neighbor, otherwise false.

getURL

public java.lang.String getURL(boolean encode)
                        throws java.lang.Throwable
Get the URL for this file.

Parameters:
encode - encode the URL properly. Set to false for it to be display worthy.
Returns:
the URL
Throws:
java.lang.Throwable - if there is a problem forming the URL or a bug.

getURLRendering

public java.lang.String getURLRendering(boolean encode)
Get the rendering URL for this file. basically, it traps any exception and just returns an error string. This is mostly just for exception rendering.

Parameters:
encode - encode the URL properly. Set to false for it to be display worthy.
Returns:
the URL or an error string.

getURLtoRoot

public java.lang.String getURLtoRoot(boolean encode)
                              throws java.lang.Throwable
Get the URL to the root from directory which contains this file.

Parameters:
encode - encode the URL properly. Set to false for it to be display worthy.
Returns:
the URL to the root.
Throws:
java.lang.Throwable

copy

public void copy()
          throws things.common.ThingsException
Copy file from source to destination.

Throws:
java.lang.Throwable - if the file could not be copied.
things.common.ThingsException


rendsite.