ptolemy.actor.lib
Class URLDirectoryReader

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.Source
                              extended by ptolemy.actor.lib.URLReader
                                  extended by ptolemy.actor.lib.URLDirectoryReader
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

Deprecated. Use DirectoryListing instead.

public class URLDirectoryReader
extends URLReader

This actor reads a URL and if the URL names a directory, it outputs the name of each file or subdirectory contained in the directory. If the URL names a file, then it outputs the name of that file.

If the repeat flag is true, then the sequence of file names is repeated indefinitely. If the refresh flag is true, and the repeat flag is true, then the directory is re-read before repeating the sequence of files and subdirectories.

If the endsWith String parameter is non-null and non-empty, then only file names or subdirectories that end with the value of the endsWith parameter are output.

One alternative implementation would be that if the URL named a file, then the actor would output the names of the files and subdirectories in the directory that contains the file.
Another alternative implementation would output the names of the files and subdirectories in an array.
An extension would be to include a filter parameter that could be a regular expression that would allow us to filter the file names.
Should this actor extend URLReader or SequenceActor?

Since:
Ptolemy II 2.0
Version:
$Id: URLDirectoryReader.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Christopher Hylands
See Also:
Serialized Form
Accepted Rating:
Red (liuj)
Proposed Rating:
Red (liuj)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  java.lang.String[] _data
          Deprecated.  
private  java.lang.String _endsWithValue
          Deprecated.  
private  int _iterationCount
          Deprecated.  
private  boolean _repeatFlag
          Deprecated.  
 Parameter endsWith
          Deprecated. If non-null and non-empty, then only output file names and sub directories that end with this String value.
 Parameter repeat
          Deprecated. Repeat after outputting all elements of the directory.
 
Fields inherited from class ptolemy.actor.lib.URLReader
_reader, _refreshFlag, _source, _stdIn, refresh, sourceURL
 
Fields inherited from class ptolemy.actor.lib.Source
output, trigger
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
URLDirectoryReader(CompositeEntity container, java.lang.String name)
          Deprecated. Construct an actor with the given container and name.
 
Method Summary
private  java.lang.String[] _list(java.lang.String source, java.lang.String endsWith)
          Deprecated. If the URL names a directory return an array containing the names of the files and subdirectories contained in the directory.
private  java.lang.String[] _listFile(java.lang.String source, java.lang.String endsWith)
          Deprecated. Return files and directories contained in the source url.
private static java.lang.String[] _listFileOrURL(java.lang.String source, java.lang.String endsWith)
          Deprecated. Return files and directories contained in the source url.
 void attributeChanged(Attribute attribute)
          Deprecated. If the specified attribute is URL, then close the current file (if there is one) and open the new one.
 void fire()
          Deprecated. Output the data read in the prefire.
 void initialize()
          Deprecated. Open the file at the URL, and set the width of the output.
 boolean postfire()
          Deprecated. Update the iteration counter until it exceeds the number of elements in the directory.
 boolean prefire()
          Deprecated. Read one row from the input and prepare for output them.
 
Methods inherited from class ptolemy.actor.lib.URLReader
_setURLReader, wrapup
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

endsWith

public Parameter endsWith
Deprecated. 
If non-null and non-empty, then only output file names and sub directories that end with this String value. The default value of this parameter is the empty String "".


repeat

public Parameter repeat
Deprecated. 
Repeat after outputting all elements of the directory. The default value of this parameter is a false BooleanToken.


_endsWithValue

private java.lang.String _endsWithValue
Deprecated. 

_iterationCount

private int _iterationCount
Deprecated. 

_data

private java.lang.String[] _data
Deprecated. 

_repeatFlag

private boolean _repeatFlag
Deprecated. 
Constructor Detail

URLDirectoryReader

public URLDirectoryReader(CompositeEntity container,
                          java.lang.String name)
                   throws IllegalActionException,
                          NameDuplicationException
Deprecated. 
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
Deprecated. 
If the specified attribute is URL, then close the current file (if there is one) and open the new one.

Overrides:
attributeChanged in class URLReader
Parameters:
attribute - The attribute that has changed.
Throws:
IllegalActionException - If the specified attribute is URL and the file cannot be opened.

fire

public void fire()
          throws IllegalActionException
Deprecated. 
Output the data read in the prefire.

Specified by:
fire in interface Executable
Overrides:
fire in class Source
Throws:
IllegalActionException - If there's no director.

initialize

public void initialize()
                throws IllegalActionException
Deprecated. 
Open the file at the URL, and set the width of the output.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class URLReader
Throws:
IllegalActionException - Not thrown in this base class

postfire

public boolean postfire()
                 throws IllegalActionException
Deprecated. 
Update the iteration counter until it exceeds the number of elements in the directory. If the repeat parameter is true, then repeat the same sequence of directory elements again. If the repeat and refresh parameters are both true, then reread the directory before repeating the sequence of directory elements

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True if execution can continue into the next iteration.
Throws:
IllegalActionException - If the sourceURL is not valid.

prefire

public boolean prefire()
                throws IllegalActionException
Deprecated. 
Read one row from the input and prepare for output them.

Specified by:
prefire in interface Executable
Overrides:
prefire in class Source
Returns:
True, unless the trigger input is connected and has no input.
Throws:
IllegalActionException - If the sourceURL is invalid.

_list

private java.lang.String[] _list(java.lang.String source,
                                 java.lang.String endsWith)
                          throws IllegalActionException
Deprecated. 
If the URL names a directory return an array containing the names of the files and subdirectories contained in the directory. If the URL names a file, then return an array of size 1 containing the name of the file. If the URL names neither a file or directory, return null.

Parameters:
source - The filename or URL to open
endsWith - If non-null, then only files or subdirectories that end with this string are reported.
Returns:
An array of Strings where each element of the array names a file or subdirectory.
Throws:
IllegalActionException - If the source is a malformed URL

_listFile

private java.lang.String[] _listFile(java.lang.String source,
                                     java.lang.String endsWith)
                              throws IllegalActionException
Deprecated. 
Return files and directories contained in the source url.

Parameters:
source - The source URL to query for files and subdirectories. The source url must be a String using the "file:" protocol.
endsWith - If non-null and of length greater than 0, then only files or subdirectories that end with this string are reported.
Returns:
An array containing the files and subdirectories in the source URL.
Throws:
IllegalActionException - If the source does not have the file: protocol, or if the source is neither a file nor a directory, or if there is some other problem.

_listFileOrURL

private static java.lang.String[] _listFileOrURL(java.lang.String source,
                                                 java.lang.String endsWith)
                                          throws java.net.MalformedURLException,
                                                 java.io.IOException
Deprecated. 
Return files and directories contained in the source url. This method attempts to parse the html results returned by reading a URL connection, so the parsing may fail. If the URL uses the http: protocol, then the remote webserver configuration determines whether it is possible to read the contents of a directory. Usually, the server has to have directory listing enabled, and the default html file (index.htm, index.html, default.htm etc. ) must not be present.

Parameters:
source - The source URL to query for files and subdirectories. The source url must be a String using the "file:" protocol.
endsWith - If non-null and of length greater than 0, then only files or subdirectories that end with this string are reported.
Returns:
An array containing the files and subdirectories in the source URL.
Throws:
IllegalActionException - If the source does not have the file: protocol, or if the source is neither a file nor a directory, or if there is some other problem.
java.net.MalformedURLException
java.io.IOException