mn8 Language Reference | Index    

HttpHandler

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

Description

HTTPHandler concept working with HTML pages. This concept is able to get HTML page content.

URL format is : http://<hostName>:<port>/<path>

Possible options :

Usage

Connect to google page and get content of this page

            $x from "http://www.google.com"
            print $x/content

Connect to google page and get page links recursively 5 times in 3 depth.

            $pages from "http://www.google.com" options "requests"=5 ,"depth"=3
            each $page in $pages do [
                print $page@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 $uri)
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 HttpHandler will be created.

Creates a new HttpHandler concept with the given $url.

top

Detailed Method Info

static acceptsURI (String $uri)
Parameters:
$uri : 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 HttpHandler.acceptsURI("http://www.google.com")
                -- the result is --
                true
            

top
closeConnection
Returns: Logical

Returns true and close this connection.

                $url = "http://www.google.com"
                $page = HttpHandler.create( $url )                                                                              
                if $page.acceptsURI( $url ) then [                                                                           
                    $m typeof Map 
                    if ( $page.initialize( $m ) ) then [
                        if ( $page.openConnection ) then [
                            print $page.getContent                                                                           
            
                            $page.closeConnection                                                                            
                    
                        ]                                                                                                   
                    ]                                                                                                       
                ] 
                -- the result is --
                return the google Page.
             

top
getContent
Returns: Concept
Exceptions:
badURLException :
(Error)
If the URL is not valid.
IOException :
(Error)
If an I/O exception occurs.
httpOperationFailed :
(Error)
If can't get HTML page header or page content.

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

                $url = "http://www.google.com"
                $page = HttpHandler.create( $url )                                                                              
                if $page.acceptsURI( $url ) then [                                                                           
                    $m typeof Map 
                    if ( $page.initialize( $m ) ) then [
                        if ( $page.openConnection ) then [

                            print $page.getContent                                                                           
            
                            $page.closeConnection                                                                            
                        ]                                                                                                   
                    ]                                                                                                       
                ] 
                -- the result is --
                return the google Page.
             

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

Returns true.

                $url = "http://www.google.com"
                $page = HttpHandler.create( $url )                                                                              
                if $page.acceptsURI( $url ) then [                                                                           
                    $m typeof Map 

                    if ( $page.initialize( $m ) ) then [

                        if ( $page.openConnection ) then [
                            print $page.getContent                                                                           
                            $page.closeConnection                                                                            
                        ]                                                                                                   
                    ]                                                                                                       
                ] 
                -- the result is --
                return the google Page.
             

top
openConnection
Returns: Logical
Exceptions:
badURLException :
(Error)
If the URL is not valid.
IOException :
(Error)
If an I/O exception occurs.
httpOperationException :
(Error)
If can't get HTML page header or page content.

Returns true and open a new connection.

                $url = "http://www.google.com"
                $page = HttpHandler.create( $url )                                                                              
                if $page.acceptsURI( $url ) then [                                                                           
                    $m typeof Map 
                    if ( $page.initialize( $m ) ) then [

                        if ( $page.openConnection ) then [

                            print $page.getContent                                                                           
                            $page.closeConnection                                                                            
                        ]                                                                                                   
                    ]                                                                                                       
                ] 
                -- the result is --
                return the google Page.
             

top
setContent (Concept $value)
Parameters:
$value :The value to be set.
Returns: Logical

Return false.

top