net.xoetrope.builder.w3c.html
Class XHtmlBuilder

java.lang.Object
  extended by net.xoetrope.builder.XuiBuilder
      extended by net.xoetrope.builder.w3c.html.XHtmlBuilder
All Implemented Interfaces:
XPageLoader

public class XHtmlBuilder
extends XuiBuilder

A build for W3C HTML forms/pages. The builder can create XUI pages on-the-fly or it can be used to convert and save an html page to a xui format.

Copyright (c) Xoetrope Ltd., 2002-2006

$Revision: 1.7 $

License: see License.txt


Field Summary
protected static boolean debugLayout
           
protected static java.net.URL documentUrl
           
protected  XHtmlComponentFactory htmlFactory
           
protected  XHtmlTagHandler lastHandler
           
protected  java.lang.String packageName
           
protected  java.lang.String selectStyle
           
 
Fields inherited from class net.xoetrope.builder.XuiBuilder
adapter, attributeSets, checkBoxGroup, componentFactory, currentAttributes, currentProject, customizer, DEFAULT_PAGE_CLASS, evaluator, eventHandler, includeFileName, layoutHelper, menuBar, page, rootPage, secondaryClassloader, validationFactories
 
Constructor Summary
XHtmlBuilder(XProject project)
          Create a new builder
 
Method Summary
 void addScript(java.lang.String componentName, java.lang.String eventName, java.lang.String methodName, java.lang.String script)
          Add a new script function to the current class
static java.net.URL findResource(java.lang.String fileName)
          Find a resource URl from a resource string, resolving relative resource names in the process.
static java.awt.Color getColor(java.lang.String colorSpec)
          Get a color from a color specification
 java.lang.Object getComponentAttribute(java.lang.String compName, java.lang.String attribName)
          Get a named attributes.
static int getSwingConstant(java.lang.String name)
          Get a SwingConstant for an attribute
 XHtmlTagHandler getTagHandler(javax.swing.text.html.HTML.Tag t)
           
protected  java.io.InputStream getUrlInputStream(java.lang.String urlStr)
          Attempt to get an input stream from the specified path
static boolean isDebugLayout()
          Is a debug layout to be used?
 PageSupport loadPage(java.lang.String defPackageName, java.lang.String pageName, boolean include)
          Loads an XPage via a reader obtained from the XProject (searches the classpath).
 void processEvent(XHtmlTagHandler handler, java.lang.String attribName, java.lang.String attribValue)
          Process the event specification, specified as an attribute of an HTML element
 PageSupport readPage(java.io.Reader reader, java.lang.String pageName, java.lang.String ext, boolean include)
          Read an XML description of the page and construct a new XPage.
 void setClass(java.awt.Component c, java.lang.String className)
          Set the class of an element
 void setComponentAttribute(java.lang.String compName, java.lang.String attribName, java.lang.Object attribValue)
          Set a named attributes.
static void setDebugLayout(boolean state)
          Set the debug layout flag
protected  void setupHtmlTags()
          Create a hashtable of tags and ids to speed processing of HTML
protected  void setupPage(java.lang.String pageName, java.lang.String ext, boolean include)
          Loads the page based on the contents of the page tag or by using default values.
 void setupStyle(java.lang.String styleInfo)
          Setup a new style or styles by parsing the stylesheet
 
Methods inherited from class net.xoetrope.builder.XuiBuilder
addBinding, addBindings, addComponent, addComponents, addEvent, addEvents, addHandler, addMenu, addScripts, addValidations, evaluateAttribute, evaluateAttributeAsString, getCurrentAttributes, getFactoryBinding, getInt, getMenuItem, getValidationFactory, init, insertAttributes, loadAttributeSet, loadClass, loadFrames, loadOtherElement, loadSingleTarget, popIncludeReference, popRepeatReference, pushIncludeReference, pushRepeatReference, setAttributeEvaluator, setClassLoader, setComponentAttributes, setPackageName, setPage, setPageAttribute, setPageExtension, setPageName, setResourceBundle, setupPage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugLayout

protected static boolean debugLayout

packageName

protected java.lang.String packageName

selectStyle

protected java.lang.String selectStyle

htmlFactory

protected XHtmlComponentFactory htmlFactory

lastHandler

protected XHtmlTagHandler lastHandler

documentUrl

protected static java.net.URL documentUrl
Constructor Detail

XHtmlBuilder

public XHtmlBuilder(XProject project)
Create a new builder

Parameters:
project - the current xui project
factory - the component factory
Method Detail

isDebugLayout

public static boolean isDebugLayout()
Is a debug layout to be used?

Returns:
true if the debug layout is to be used

setDebugLayout

public static void setDebugLayout(boolean state)
Set the debug layout flag

Parameters:
state - true if the debug layout is to be used

getUrlInputStream

protected java.io.InputStream getUrlInputStream(java.lang.String urlStr)
Attempt to get an input stream from the specified path

Parameters:
urlStr - the url string
Returns:
the inputstream or null if the strean cannot be opened.

loadPage

public PageSupport loadPage(java.lang.String defPackageName,
                            java.lang.String pageName,
                            boolean include)
Loads an XPage via a reader obtained from the XProject (searches the classpath). The pageName is assumed to be the name of an XML file. For example if the pageName is 'welcome' then the 'welcome.xml' file is read as a UTF8 encoded XML file (by default).

Specified by:
loadPage in interface XPageLoader
Overrides:
loadPage in class XuiBuilder
Parameters:
defPackageName - the package or path to the page
pageName - the page name or the name of the class implementing the page
include - true if the page to be loaded is being included in another page in which case any class attribute of the included page is ignored
Returns:
the page

readPage

public PageSupport readPage(java.io.Reader reader,
                            java.lang.String pageName,
                            java.lang.String ext,
                            boolean include)
Read an XML description of the page and construct a new XPage. An instance of the class specified by the class attribute is constructed or else an instance of XPage if no class attribute is specified. The new page is populated but is not yet added to its parent.
The startup file parameter 'DefaultClass' is used to obtain a default for each page's class if a class parameter is not specified in the page's XML
The startup file parameter 'Validations' is used to obtain a default for each page's set of validation rules

Specified by:
readPage in interface XPageLoader
Overrides:
readPage in class XuiBuilder
Parameters:
reader - a input stream from which to read the page
pageName - the name of the page
ext - the file extension
include - the page to be loaded is being included in another page
Returns:
the page

setupPage

protected void setupPage(java.lang.String pageName,
                         java.lang.String ext,
                         boolean include)
Loads the page based on the contents of the page tag or by using default values.

Parameters:
pageName - the name of the page
ext - the file extension
include - the page to be loaded is being included in another page

findResource

public static java.net.URL findResource(java.lang.String fileName)
Find a resource URl from a resource string, resolving relative resource names in the process.

Parameters:
fileName - the resource string
Returns:
the resource url

setComponentAttribute

public void setComponentAttribute(java.lang.String compName,
                                  java.lang.String attribName,
                                  java.lang.Object attribValue)

Set a named attributes. The attributes are stored in a hashtable owned by the page. Derived classes may access the hashtable directly but the preferred method of access is the getAttribute method. Attributes are used by the XuiBuilder class for component attributes other than those it handles directly. The attributes can be thought of as component properties or extra data and need not be used directly by the component.

Attributes are stored using a key in the form attribName_compName or just the attribName if compName is null.

Parameters:
attribName - the attribute name
compName - the component name or null if it is a page attribute
attribValue - the attribute value

getComponentAttribute

public java.lang.Object getComponentAttribute(java.lang.String compName,
                                              java.lang.String attribName)

Get a named attributes. The attributes are stored in a hashtable owned by the page. Derived classes may access the hashtable directly but the preferred method of access is the getAttribute method. Attributes are used by the XuiBuilder class for component attributes other than those it handles directly. The attributes can be thought of as component properties or extra data and need not be used directly by the component.

Attributes are stored using a key in the form attribName_compName or just the attribName if compName is null.

Parameters:
attribName - the attribute name
compName - the component name or null if it is a page attribute

addScript

public void addScript(java.lang.String componentName,
                      java.lang.String eventName,
                      java.lang.String methodName,
                      java.lang.String script)
Add a new script function to the current class

Parameters:
componentName - the name of the element being processed
eventName - the name of the html event or null if a page event is being processed
methodName - the name of the new method
script - the contents of the method - the original javascript (assuming it is javascript)

processEvent

public void processEvent(XHtmlTagHandler handler,
                         java.lang.String attribName,
                         java.lang.String attribValue)
Process the event specification, specified as an attribute of an HTML element

Parameters:
handler - the tag handler
attribName - the attribute name
attribValue - the attribute value, containing the script

setupHtmlTags

protected void setupHtmlTags()
Create a hashtable of tags and ids to speed processing of HTML


getTagHandler

public XHtmlTagHandler getTagHandler(javax.swing.text.html.HTML.Tag t)

setClass

public void setClass(java.awt.Component c,
                     java.lang.String className)
Set the class of an element

Parameters:
c - the component affected by the style
className - the name of the class

setupStyle

public void setupStyle(java.lang.String styleInfo)
Setup a new style or styles by parsing the stylesheet

Parameters:
styleInfo - the full style information

getColor

public static java.awt.Color getColor(java.lang.String colorSpec)
Get a color from a color specification

Parameters:
the - html color spec
Returns:
the Color object

getSwingConstant

public static int getSwingConstant(java.lang.String name)
Get a SwingConstant for an attribute

Parameters:
the - attribute name as a string
Returns:
the constant