mn8 Language Reference | Index    

HTMLForm

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

Description

Just like the Cookie concept the HTMLForm concept is a helper concept. Forms can be seen as a special kind of links. It's completeness depends on the right parameters.

In this idea there are two simple ways to assist the navigation and extraction process using forms. First, the most simple approach is to use the HTMLForm concept to produce in the most simple way a complete URL by providing all the desired parameters and attributes (the action attribute and the name/value pairs). On the form initialized in this way by invoking the getEncodedUrl method will get a fully composed and encoded URL.

The second approach is most useful in automating the navigation process. In the same mode as with the Cookies we can create particular HTMLForm concepts (for different sites and with different parameters) and store them in as a Series of HTMLForms in the mem://hyper/html/forms/ context. The particular concepts stored in this way will be checked at navigation by the http protocol handler and if a match is found between the signatures of a form from a HTML page and one of our stored concepts the it will be used as a valid navigation path.

Usage

Searching for "pepsi music" keyword on google and show results.

        $myForm = HTMLForm.create()
        $myForm.setURL("http://www.google.com/search")
        $myForm.setMethod("GET")
        $myForm.add("q", "pepsi music")
        $myForm.add("btnG", "Google Search")

        $page = HTMLPage.create( $myForm )
        print $page/content

This example will show how you can looking for a Form and if you not have to store it.

        $url = "http://192.168.1.22/oursite/"
        $page from $url + "index.php"

        # creating a simplex expression
        $expr = Simplex.create( $url + "*" )

        # looking for the stored forms using the simplex
        $forms = HTMLForm.getStoredForms($expr)

        # if we not have stored any form     
        if $forms@length == 0 then [

           # pick up the form from the page
           $form = $page.getForms/1

           # change the value of "userid" 
           $idx = $form.indexOfKey("userid")
           $form.remove("userid")
           $form.insert ( $idx, "userid", "guest" )

           # change the value of "passwd" 
           $idx = $form.indexOfKey("passwd")
           $form.remove("passwd")
           $form.insert ( $idx, "passwd", "guest" )

           # storing the form
           $form.storeForm]

Version: 0.1
Authors:Szabo Csaba ()
Location:
Inherits: Concept, Map

Attribute List

 @encoding TYPEOF String LABEL "encoding"
 @hasNext TYPEOF Logical LABEL "Has next "
 @hasPrevious TYPEOF Logical LABEL "Has previous "
 @id TYPEOF String LABEL "id"
 @index TYPEOF Integer LABEL "Index"
 @length TYPEOF Integer LABEL "Length"
 @method TYPEOF String LABEL "method"
 @name TYPEOF name LABEL "name"
 @target TYPEOF String LABEL "target"
 @url TYPEOF String LABEL "url"
top
Attributes inherited from: Map
hasNext, hasPrevious, index, length

Method List

loadContent (Concept $from)
setEncoding (String $encoding)
setMethod (String $method)
setName (String $name)
setTarget (String $target)
setURL (String $url)
storeForm
static SeriesgetStoredForms (String $url)
static SeriesgetStoredForms (Expression $expr)
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: Map
add, clear, containsKey, containsValue, getConceptElement, getConceptElements, getConceptElementField, getConceptElementFields, getKeyAt, getKeys, getValue, getValueAt, getValues, setIndex, indexOfKey, indexOfValue, insert, insert, nextKey, nextValue, remove

Detailed Attribute Info

@encoding

Label:encoding
Type:String
Is Static:false
Is Hidden:false
Show Empty:true

A function whose domain is the set of sequences of octets, and whose range is the set of sequences of characters from a character repertoire; that is, a sequence of octets and a character encoding scheme determines a sequence of characters.

top

@hasNext

Label:Has next
Type:Logical
Is Static:false
Is Hidden:false
Show Empty:true

Specify whenever the index represents the last element of the series or not.

top

@hasPrevious

Label:Has previous
Type:Logical
Is Static:false
Is Hidden:false
Show Empty:true

Specify whenever the index represents the first element of the series or not.

top

@id

Label:id
Type:String
Is Static:false
Is Hidden:false
Show Empty:true

top

@index

Label:Index
Type:Integer
Is Static:false
Is Hidden:false
Show Empty:true

Specify the current position of the cursor in the HTMLForm, also used to move the cursor at the wanted position. Initially the index is positioned at the first element of the HTMLForm.

top

@length

Label:Length
Type:Integer
Is Static:false
Is Hidden:false
Show Empty:true

Specify the number of items this HTMLForm contains.

top

@method

Label:method
Type:String
Is Static:false
Is Hidden:false
Show Empty:true

Selects a method of accessing the action URI. The set of applicable methods is a function of the scheme of the action URI of the form.

top

@name

Label:name
Type:name
Is Static:false
Is Hidden:false
Show Empty:true

The name of this HTMLForm.

top

@target

Label:target
Type:String
Is Static:false
Is Hidden:false
Show Empty:true

Identifies the default window or frame to be used to display the result that is opened by submit this form.

top

@url

Label:url
Type:String
Is Static:false
Is Hidden:false
Show Empty:true

Is the URL of the query server to which the form contents will be submitted; if this attribute is absent, then the current document URL will be used.

top

@hasNext

Label:Has next
Type:Logical
Is Static:false
Is Hidden:false
Show Empty:true

Specify whenever the index represents the last element of the series or not.

top

@hasPrevious

Label:Has previous
Type:Logical
Is Static:false
Is Hidden:false
Show Empty:true

Specify whenever the index represents the first element of the series or not.

top

@index

Label:Index
Type:Integer
Is Static:false
Is Hidden:false
Show Empty:true

Specify the current position of the cursor in the Map, also used to move the cursor at the wanted position. Initially the index is positioned at the first element of the map.

top

@length

Label:Length
Type:Integer
Is Static:false
Is Hidden:false
Show Empty:true

Specify the number of items this Map contains.

top

Detailed Method Info

loadContent (Concept $from)
Parameters:
$from :An element concept to be loaded.
Returns:

Loads from an Element concept all elements and attributes to this HTMLForm.

            <code language="mn8">
            <![CDATA[
            $form = HTMLForm.create
            $form.setURL("http://www.google.com/search")
            $form.setEncoding("application/x-www-form-urlencoded")
            $form.setMethod("GET")
            $form.setName("form1")
            $form.setTarget("mFrame")
            $form.add("q", "html form")
            $form.add("btnG", "Google Search")
            $form.storeForm
            $f typeof HTMLForm
            $f.loadContent(HTMLForm.getStoredForms("http://www.google.com/search")/1/)
            print $f
            -- the result is --
            HTMLForm
            method: GET     url: http://www.google.com/search       name: form1    
            encoding: application/x-www-form-urlencoded      target: mFrame
            q html form
            btnG Google Search
            

top
setEncoding (String $encoding)
Parameters:
$encoding :The encoding to be set.
Returns:

Sets this HTMLForm encoding to the specified value.

            $form = HTMLForm.create
            $form.setURL("http://www.google.com/search")

            $form.setEncoding("application/x-www-form-urlencoded")

            $form.setMethod("GET")
            $form.setName("form1")
            $form.setTarget("mFrame")
            $form.add("q", "html form")
            $form.add("btnG", "Google Search")
            $form.storeForm
            print HTMLForm.getStoredForms("http://www.google.com/search")
            -- the result is --
            HTMLForm
            method: GET     url: http://www.google.com/search       name: form1    
            encoding: application/x-www-form-urlencoded      target: mFrame
            q html form
            btnG Google Search
            

top
setMethod (String $method)
Parameters:
$method :The method to be set.
Returns:

Sets this HTMLForm method to the specified value.

            $form = HTMLForm.create
            $form.setURL("http://www.google.com/search")
            $form.setEncoding("application/x-www-form-urlencoded")

            $form.setMethod("GET")

            $form.setName("form1")
            $form.setTarget("mFrame")
            $form.add("q", "html form")
            $form.add("btnG", "Google Search")
            $form.storeForm
            print HTMLForm.getStoredForms("http://www.google.com/search")
            -- the result is --
            HTMLForm
            method: GET     url: http://www.google.com/search       name: form1    
            encoding: application/x-www-form-urlencoded      target: mFrame
            q html form
            btnG Google Search
            

top
setName (String $name)
Parameters:
$name :The name to be set.
Returns:

Sets this HTMLForm name to the specified value.

            $form = HTMLForm.create
            $form.setURL("http://www.google.com/search")
            $form.setEncoding("application/x-www-form-urlencoded")
            $form.setMethod("GET")

            $form.setName("form1")

            $form.setTarget("mFrame")
            $form.add("q", "html form")
            $form.add("btnG", "Google Search")
            $form.storeForm
            print HTMLForm.getStoredForms("http://www.google.com/search")
            -- the result is --
            HTMLForm
            method: GET     url: http://www.google.com/search       name: form1    
            encoding: application/x-www-form-urlencoded      target: mFrame
            q html form
            btnG Google Search
            

top
setTarget (String $target)
Parameters:
$target :The target to be set.
Returns:

Sets this HTMLForm target to the specified value.

            $form = HTMLForm.create
            $form.setURL("http://www.google.com/search")
            $form.setEncoding("application/x-www-form-urlencoded")
            $form.setMethod("GET")
            $form.setName("form1")

            $form.setTarget("mFrame")

            $form.add("q", "html form")
            $form.add("btnG", "Google Search")
            $form.storeForm
            print HTMLForm.getStoredForms("http://www.google.com/search")
            -- the result is --
            HTMLForm
            method: GET     url: http://www.google.com/search       name: form1    
            encoding: application/x-www-form-urlencoded      target: mFrame
            q html form
            btnG Google Search
            

top
setURL (String $url)
Parameters:
$url :The URL to be set.
Returns:

Sets this HTMLForm URL to the specified value.

            $form = HTMLForm.create

            $form.setURL("http://www.google.com/search")

            $form.setEncoding("application/x-www-form-urlencoded")
            $form.setMethod("GET")
            $form.setName("form1")
            $form.setTarget("mFrame")
            $form.add("q", "html form")
            $form.add("btnG", "Google Search")
            $form.storeForm
            print HTMLForm.getStoredForms("http://www.google.com/search")
            -- the result is --
            HTMLForm
            method: GET     url: http://www.google.com/search       name: form1    
            encoding: application/x-www-form-urlencoded      target: mFrame
            q html form
            btnG Google Search
            

top
storeForm
Returns:
Exceptions:
badURLException :
(Error)
If can't save this form to specified location.

Saves your form to your forms directory.

            $form = HTMLForm.create
            $form.setURL("http://www.google.com/search")
            $form.setEncoding("application/x-www-form-urlencoded")
            $form.setMethod("GET")
            $form.setName("form1")
            $form.setTarget("mFrame")
            $form.add("q", "html form")
            $form.add("btnG", "Google Search")
            $form.storeForm
            print HTMLForm.getStoredForms("http://www.google.com/search")
            -- the result is --
            HTMLForm
            method: GET     url: http://www.google.com/search       name: form1    
            encoding: application/x-www-form-urlencoded      target: mFrame
            q html form
            btnG Google Search
            

top
static getStoredForms (String $url)
Parameters:
$url :URL for searching forms.
Returns: Series
Exceptions:
badURLException :
(Error)
If can't get the host name or the path from the URL.

Seaching for the forms with the specified URL attribute.

            $form = HTMLForm.create
            $form.setURL("http://www.google.com/search")
            $form.setEncoding("application/x-www-form-urlencoded")
            $form.setMethod("GET")
            $form.setName("form1")
            $form.setTarget("mFrame")
            $form.add("q", "html form")
            $form.add("btnG", "Google Search")
            $form.storeForm

            print HTMLForm.getStoredForms("http://www.google.com/search")

            -- the result is --
            HTMLForm
            method: GET     url: http://www.google.com/search       name: form1    
            encoding: application/x-www-form-urlencoded      target: mFrame
            q html form
            btnG Google Search
            

top
static getStoredForms (Expression $expr)
Parameters:
$expr :Expression (Simplex or Regexp) with pattern for searching forms.
Returns: Series

Seaching for the forms where the Expression matches is true.

            $form = HTMLForm.create
            $form.setURL("http://www.google.com/search")
            $form.setEncoding("application/x-www-form-urlencoded")
            $form.setMethod("GET")
            $form.setName("form1")
            $form.setTarget("mFrame")
            $form.add("q", "html form")
            $form.add("btnG", "Google Search")
            $form.storeForm

            print HTMLForm.getStoredForms(Simplex.create("*google*"))

            -- the result is --
            HTMLForm
            method: GET     url: http://www.google.com/search       name: form1    
            encoding: application/x-www-form-urlencoded      target: mFrame
            q html form
            btnG Google Search
            

top