mn8 Language Reference | Index    

FileHandler

SUMMARY: NO ATTRIBUTES  NO ELEMENTS  CONSTRUCTORS SUMMARY  NO OPERATORS  METHODS SUMMARYDETAIL: NO ATTRIBUTES  NO ELEMENTS  CONSTRUCTOR DETAILS  NO OPERATORS  METHOD DETAILS

Description

FileHandler concept working with simple files. With this handler you can get or set the specified file content.

URL format is : file:/<path>

Possible options :

Usage

Get the specified file content.

            $file from  "file:/dirNane/fileName"
            print $file/content

Get the specified files name from specified directory recursively 5 times maximum 2 depth.

            $files from  "file:/dirName/" options "requests"=5 ,"depth"=2
            each $file in $files do [
                print $file@url]

Get the specified files name from specified directory recursively 5 times maximum 2 depth where files have 'txt' extension.

            $files from  "file:/dirName/" options "requests"=5 ,"depth"=2, "filter"=Simplex.create("*.txt")
            each $file in $files do [
                print $file@url]

Version: 0.1
Authors:Remus Pereni (http://neuro.nolimits.ro)
Location:
Inherits: Concept, URIHandler

Constructor List

create (String $url)
top

Method List

static LogicalacceptsURI (String $url)
LogicalcloseConnection
ConceptgetContent
Logicalinitialize (Map $options)
LogicalopenConnection
LogicalsetContent (Concept $value)
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI
Methods inherited from: URIHandler
acceptsURI, closeConnection, getContent, initialize, openConnection, setContent

Detailed Constructor Info

create (String $url)
Parameters:
$url :The url with which this FileHandler will be created.

Creates a new FileHandler concept with the given $url.

top

Detailed Method Info

static acceptsURI (String $url)
Parameters:
$url :The uri which will be tested if it is acceptable by this handler.
Returns: Logical

Returns true if the given $uri is acceptable by this handler, false otherwise.

                print FileHandler.acceptsURI("file:/home/crow")
                -- the result is --
                true
            

top
closeConnection
Returns: Logical

Returns true.

                $url = "file:/home/crow/text.txt"
                $file = FileHandler.create( $url )                                                                              
                if $file.acceptsURI( $url ) then [                                                                           
                    $m typeof Map 
                    if ( $file.initialize( $m ) ) then [
                        if ( $file.openConnection ) then [
                            print $file.getContent                                                                           
            
                            $file.closeConnection                                                                            
                    
                        ]                                                                                                   
                    ]                                                                                                       
                ] 
                -- the result is --
                File
                    contentType: text/plain url: file:/home/crow/text.txt   length: 19
                content
                    This is a test file
             

top
getContent
Returns: Concept

Returns the content of this FileHandler as String concept if the content type is text or ByteArray concept otherwise.

                $url = "file:/home/crow/text.txt"
                $file = FileHandler.create( $url )                                                                              
                if $file.acceptsURI( $url ) then [                                                                           
                    $m typeof Map 
                    if ( $file.initialize( $m ) ) then [
                        if ( $file.openConnection ) then [

                            print $file.getContent                                                                           
            
                            $file.closeConnection                                                                            
                        ]                                                                                                   
                    ]                                                                                                       
                ] 
                -- the result is --
                File
                    contentType: text/plain url: file:/home/crow/text.txt   length: 19
                content
                    This is a test file
             

top
initialize (Map $options)
Parameters:
$options :Contains a filter with which the returned content will be filtered.
Returns: Logical

Returns true if the FTPHandler was initilized successfully, false otherwise.

                $url = "file:/home/crow/text.txt"
                $file = FileHandler.create( $url )                                                                              
                if $file.acceptsURI( $url ) then [                                                                           
                    $m typeof Map 

                    if ( $file.initialize( $m ) ) then [
                
                        if ( $file.openConnection ) then [
                            print $file.getContent                                                                           
                            $file.closeConnection                                                                            
                        ]                                                                                                   
                    ]                                                                                                       
                ] 
                -- the result is --
                File
                    contentType: text/plain url: file:/home/crow/text.txt   length: 19
                content
                    This is a test file
             

top
openConnection
Returns: Logical

Returns true if the connection can be establised to the specified file, false otherwise.

                $url = "file:/home/crow/text.txt"
                $file = FileHandler.create( $url )                                                                              
                if $file.acceptsURI( $url ) then [                                                                           
                    $m typeof Map 
                    if ( $file.initialize( $m ) ) then [
                
                        if ( $file.openConnection ) then [

                            print $file.getContent                                                                           
                            $file.closeConnection                                                                            
                        ]                                                                                                   
                    ]                                                                                                       
                ] 
                -- the result is --
                File
                    contentType: text/plain url: file:/home/crow/text.txt   length: 19
                content
                    This is a test file
             

top
setContent (Concept $value)
Parameters:
$value : The value to be set. The $value must be a String or a ByteArray concept.
Returns: Logical

Sets this FileHandler content to the specified $value.

                $url = "file:/home/crow/text.txt"
                $file = FileHandler.create( $url )                                                                              
                if $file.acceptsURI( $url ) then [                                                                           
                    $m typeof Map 
                    $m.add("action","append") 
                    if ( $file.initialize( $m ) ) then [
                            if ( $file.openConnection ) then [
                             
                            $file.setContent(".")

                            print $file.getContent                                                                           
                            $file.closeConnection                                                                            
                        ]                                                                                                   
                    ]                                                                                                       
                ] 
                -- the result is --
                File
                    contentType: text/plain url: file:/home/crow/text.txt   length: 20
                content
                    This is a test file.
             

top