Class DirectoryListing
- java.lang.Object
-
- All Implemented Interfaces:
java.io.FilenameFilter
,java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,SequenceActor
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class DirectoryListing extends SequenceSource implements java.io.FilenameFilter
Given a URL or directory name, produce an array of file names in that directory that match an (optional) pattern.The file names include the complete path, unless relative is set to true, in which case, the names are relative to the directory. The pattern is a regular expression. For a reference on regular expression syntax see: http://download.oracle.com/javase/tutorial/essential/regex/
If directoryOrURL is a local directory (not a URL), then you can optionally list only contained files or directories. If listOnlyDirectories is true, then only directories will be listed on the output. If listOnlyFiles is true, then only files will be listed on the output. If both are true, then an exception is thrown.
If directoryOrURL is a URL, then this actor assumes that the server will list the contents of the referenced directory in an HTML file where each file listed will have the following form:
<a href="filename">filename</a>
If the filename is longer than 20 characters, then only the first 20 characters of the two appearances of the filename are compared, since some servers truncate the file names.
If allowEmptyDirectory controls whether reading an empty directory will throw an exception.
Note that DirectoryListing returns the contents of the directory in a different order depending on whether one is using the Sun JVM or the IBM JVM. Thus, you may want to connect the output to an ArraySort actor.
- Since:
- Ptolemy II 4.0
- Version:
- $Id$
- Author:
- Christopher Hylands, Edward A. Lee, Contributor: Jianwu Wang
- Pt.AcceptedRating:
- Red (liuj)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description Parameter
allowEmptyDirectory
If true, and directoryOrURL refers to a local directory (not a URL), that is empty, then the output will be empty string array and no exception is reported.FilePortParameter
directoryOrURL
The directory name or URL from which to read.Parameter
listOnlyDirectories
If true, and directoryOrURL refers to a local directory (not a URL), then only directories will be listed on the output.Parameter
listOnlyFiles
If true, and directoryOrURL refers to a local directory (not a URL), then only files will be listed on the output.StringParameter
pattern
If non-empty, then only output file and directory names that match the specified (regular expression) pattern.Parameter
recursive
Whether files in the subdirectories should be searched as well.Parameter
relative
If true, then produce an array with file names relative to the specified directory.-
Fields inherited from class ptolemy.actor.lib.LimitedFiringSource
_firingCountLimit, _iterationCount, firingCountLimit
-
Fields inherited from class ptolemy.actor.lib.Source
_triggered, output, trigger
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description DirectoryListing(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(java.io.File directory, java.lang.String name)
Return true if the specified name matches the specified pattern, or if no pattern has been specified.void
attributeChanged(Attribute attribute)
Override the base class to locally cache parameter values.void
fire()
Output an array containing file and/or directory names.-
Methods inherited from class ptolemy.actor.lib.LimitedFiringSource
initialize, postfire
-
Methods inherited from class ptolemy.actor.lib.Source
_customTypeConstraints, prefire
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
-
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
_addPort, _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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, 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, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
directoryOrURL
public FilePortParameter directoryOrURL
The directory name or URL from which to read. This is a string with any form accepted byFilePortParameter
. By default, this is empty. An empty string is equivalent to specifying "$CWD", the current working directory.
-
listOnlyDirectories
public Parameter listOnlyDirectories
If true, and directoryOrURL refers to a local directory (not a URL), then only directories will be listed on the output. If directoryOrURL is a URL, then this parameter is ignored (there appears to be no reliable way to tell whether the URL refers to a directory or file). This is a boolean that defaults to false.
-
listOnlyFiles
public Parameter listOnlyFiles
If true, and directoryOrURL refers to a local directory (not a URL), then only files will be listed on the output. If directoryOrURL is a URL, then this parameter is ignored (there appears to be no reliable way to tell whether the URL refers to a directory or file). This is a boolean that defaults to false.
-
allowEmptyDirectory
public Parameter allowEmptyDirectory
If true, and directoryOrURL refers to a local directory (not a URL), that is empty, then the output will be empty string array and no exception is reported. If directoryOrURL is a URL, then this parameter is ignored (there appears to be no reliable way to tell whether the URL refers to a directory or file). This is a boolean that defaults to false.
-
pattern
public StringParameter pattern
If non-empty, then only output file and directory names that match the specified (regular expression) pattern. The default value of this parameter is the empty String "", which indicates that everything matches.
-
recursive
public Parameter recursive
Whether files in the subdirectories should be searched as well. The recursive parameter only works if directoryOrURL refers to a local directory (not a URL). This is a boolean that defaults to false.
-
relative
public Parameter relative
If true, then produce an array with file names relative to the specified directory. This is a boolean that defaults to false, which causes the absolute (complete) path to be produced.
-
-
Constructor Detail
-
DirectoryListing
public DirectoryListing(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
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
-
accept
public boolean accept(java.io.File directory, java.lang.String name)
Return true if the specified name matches the specified pattern, or if no pattern has been specified.- Specified by:
accept
in interfacejava.io.FilenameFilter
- Parameters:
directory
- The directory in which the file was found (ignored, but required by the FilenameFilter interface).name
- The name of the file or directory.- Returns:
- True if the specified name matches.
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
Override the base class to locally cache parameter values.- Overrides:
attributeChanged
in classLimitedFiringSource
- 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
Output an array containing file and/or directory names.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classSource
- Throws:
IllegalActionException
- If there's no director or if the directory or URL is invalid.
-
-