wxtpages
Class unit

java.lang.Object
  extended byjavax.swing.tree.DefaultMutableTreeNode
      extended bywxtpages.unit
All Implemented Interfaces:
java.lang.Cloneable, javax.swing.tree.MutableTreeNode, java.io.Serializable, javax.swing.tree.TreeNode
Direct Known Subclasses:
unitContent, unitDBContent, unitGroup, unitPage, unitTemplate, unitTextContent, unitTransformation

public class unit
extends javax.swing.tree.DefaultMutableTreeNode

Base class for document-units. The class implements basic addressing dombuilding, load/save functionality. Inherits from DefaultMutableTreeNode.

See Also:
Serialized Form

Field Summary
static java.lang.String CONTENT_TYPE
           
static java.lang.String DBCONTENT_TYPE
           
static java.lang.String GROUP_TYPE
           
protected  java.net.URI m_absoluteUri
          The uri as calculated based on the original uri and the anchor available from the owning group
protected  java.lang.String m_description
          Description as from script.
protected  org.w3c.dom.Document m_Doc
          Content as DOM-tree.
protected  unitGroup m_GroupMaster
          The group object that "owns" this unit.
protected  long m_lastTimeUsed
          The last time this unit was used
protected  org.w3c.dom.Element m_myElement
          The element node in the script that defines this unit
protected  java.lang.String m_name
          name of this unit. m_type is used for anonymous units
protected  java.util.HashMap m_optionMap
          Options available for this unit: name - value pairs
protected  java.net.URI m_originalUri
          The uri as used in constructor, normally the address given in the script
protected  java.util.HashMap m_parameterMap
          Parameters and default values for actual transformation.
protected  java.util.HashMap m_propertyMap
          Properties available for this unit: name - value pairs
protected  java.lang.String m_txtContent
          Content as text
protected  java.lang.String m_type
          A string defining type of unit.
static java.lang.String PAGE_TYPE
           
static java.lang.String TEMPLATE_TYPE
           
static java.lang.String TEXTCONTENT_TYPE
           
static java.lang.String TRANSFORMATION_TYPE
           
static java.lang.String UNIT_TYPE
          string constants defining type of unit
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
unit(unitGroup master, org.w3c.dom.Element elt, reporter rep)
          Creates a new instance of unit
 
Method Summary
 void addTransformationParameters(java.util.HashMap transparams)
          Append new paramters to the transformation associated with this unit
 void browseUnit(java.awt.event.ActionEvent evt)
          What to do when we want to browse this unit in a browser.
 boolean build()
          Build this unit.
protected  boolean calculateAbsoluteAddress(java.lang.String location)
          Try to calculate the absolute URI based on the given location and the anchor address held by this units owning group The construction of an absolute URI is necessary for a unit to be reckognized and used.
 void controlLinks(java.util.Vector tagAttList, boolean includeAbsolutes)
          Checking all links according to list of tags and matching attribute
 void correctAllAddressingInDocument(org.w3c.dom.Document thisDoc, java.net.URI baseUri, java.util.Vector adrList)
          Correct all relevant links in the nodes of a Document.
 void correctAllAddressingInFragment(org.w3c.dom.Node theN, java.net.URI baseUri, java.util.Vector adrList)
          Correct all relevant links in the nodes of a fragment.
protected  java.lang.String correctOneCommonLink(java.net.URI baseUri, java.lang.String S, java.lang.String commonName, java.lang.String commonValue)
          Correct the link as found in a string
 void correctStyleAttributes(org.w3c.dom.Node theN)
          Correct common resources in style-attributes, not elements
 void correctStyleElements()
          Correct common resources in styles in style-elements, not attributes
 java.lang.String correctStyleString(java.lang.String styleString)
          Correct common resources in a style string
 void displayProperties(javax.swing.JFrame dialogOwner)
          Show the properties of this unit in a dialog box.
 void editUnit(java.awt.event.ActionEvent evt)
          What to do when we want to open this unit in an editor.
protected  boolean establishDom()
          Attempt to establish the DOM for this unit.
 java.net.URI getAbsoluteUri()
          Get the absolute URI for this unit as an URI
 java.lang.String getAbsoluteUriAsString()
          Get the absolute URI for this unit as a string
 java.lang.String getAsText()
          Get the units content as String.
 java.lang.String getDescription()
          Get the descrition as found in the script
 org.w3c.dom.Document getDoc()
          Returns the DOM Attempts to build the dom if necessary
 org.w3c.dom.Document getDocCopy()
          Returns a deep copy of the DOM Attempts to build the dom if necessary
 java.lang.String getEncoding()
          Get the encoding
 java.lang.String getFileName()
          Get the short filename
 java.lang.String getName()
          Get the name
 org.w3c.dom.NodeList getNodeList(command cmd)
          Get list of all selected nodes.
 java.lang.String getOption(java.lang.String key)
          Get a spesific option
 java.util.HashMap getOptions()
          Get the options that are active for this unit.
 java.lang.String getOriginalAsString()
          Get the original (given when constructed) URI for this unit as a string
 java.net.URI getOriginalUri()
          Get the original (given when constructed) URI for this unit as a string
 java.util.HashMap getProperties()
          Get the properties that are active for this unit.
 reporter getReporter()
          get the reporter for this unit
 unitTransformation getTransformation()
          Get the transformation for this unit Transformations are used on input on contentfiles and templates, and on output on pages
 java.lang.String getTransformationAsString()
          Get the URI of transformation for this unit as a String.
 java.lang.String getTransformationID()
          Get the id for this units transformation Transformations are used on input on contentfiles and templates, and on output on pages
 java.util.HashMap getTransformationParameterMap()
          Get the transformationparameters for this unit
 java.lang.String getType()
          Get the type of unit
 java.lang.String getURItoAsString(unit U)
          How to refer to the given unit from this unit
 boolean isSameAs(unit uc)
          Decides if two content files may be reused as DOM The condition is that they have same absolute URI, the same transformation (if any) and the same transformation parameters (if any)
 boolean isUpdatedAfterUse()
          Decides if this unit has been updated from an other program since it was last used by this program instance.
 void killDocument()
          Take it down, destroy text and DOM
 boolean loadAsText()
          Loading this unit as a text
 org.w3c.dom.Comment makeComment(java.lang.String s)
          Produce a legal XML-comment
 org.w3c.dom.Element makeImageRefToPage(unit P, java.lang.String imagepath, java.lang.String alt, java.lang.String targetFrame)
          Produce a refelement ( a ) to the given page The imagepath is searced for common resources and adjusted accordingly.
 org.w3c.dom.Element makeRefToPage(unit P, java.lang.String txt, java.lang.String targetFrame)
          Produce a refelement( a ) to the given page
 boolean prepare(unit p, java.lang.String theCommonName, java.lang.String theCommonValue)
          Prepare this unit with PI-imports with named URI's.
 void saveFromDOM()
          Saving from DOM-tree, take transformation into account
 void setEncoding(java.lang.String enc)
          Set the encoding in m_optionMap
 void setNowAsLastTimeUsed()
          Makes a note of current time as last time used
 void setReporter(reporter rep)
          set the reporter for this unit
 void setTransformationFromString(java.lang.String transString)
          Set a transformation for this unit
 void setTransformationId(java.lang.String transid)
          Set the transformation ID for this unit
 javax.swing.JPopupMenu setUpPopMenu(javax.swing.JPopupMenu theMenu, javax.swing.JFrame main)
          Produce a popupMenu for this unit.
 java.lang.String toString()
          Get the name of this unit
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIT_TYPE

public static final java.lang.String UNIT_TYPE
string constants defining type of unit

See Also:
Constant Field Values

GROUP_TYPE

public static final java.lang.String GROUP_TYPE
See Also:
Constant Field Values

PAGE_TYPE

public static final java.lang.String PAGE_TYPE
See Also:
Constant Field Values

TEMPLATE_TYPE

public static final java.lang.String TEMPLATE_TYPE
See Also:
Constant Field Values

TRANSFORMATION_TYPE

public static final java.lang.String TRANSFORMATION_TYPE
See Also:
Constant Field Values

CONTENT_TYPE

public static final java.lang.String CONTENT_TYPE
See Also:
Constant Field Values

TEXTCONTENT_TYPE

public static final java.lang.String TEXTCONTENT_TYPE
See Also:
Constant Field Values

DBCONTENT_TYPE

public static final java.lang.String DBCONTENT_TYPE
See Also:
Constant Field Values

m_type

protected java.lang.String m_type
A string defining type of unit. One of these: UNIT,GROUP,PAGE,TEMPLATE,CONTENT,TRANSFORMATION,TEXTCONTENT,RSSCONTENT


m_GroupMaster

protected unitGroup m_GroupMaster
The group object that "owns" this unit.


m_txtContent

protected java.lang.String m_txtContent
Content as text


m_Doc

protected org.w3c.dom.Document m_Doc
Content as DOM-tree.


m_name

protected java.lang.String m_name
name of this unit. m_type is used for anonymous units


m_description

protected java.lang.String m_description
Description as from script.


m_myElement

protected org.w3c.dom.Element m_myElement
The element node in the script that defines this unit


m_lastTimeUsed

protected long m_lastTimeUsed
The last time this unit was used


m_originalUri

protected java.net.URI m_originalUri
The uri as used in constructor, normally the address given in the script


m_absoluteUri

protected java.net.URI m_absoluteUri
The uri as calculated based on the original uri and the anchor available from the owning group


m_optionMap

protected java.util.HashMap m_optionMap
Options available for this unit: name - value pairs


m_propertyMap

protected java.util.HashMap m_propertyMap
Properties available for this unit: name - value pairs


m_parameterMap

protected java.util.HashMap m_parameterMap
Parameters and default values for actual transformation. If this is a transformation it is basic parametrs from script. Otherwise it is the parameters given in parenthesis in the transform attribute in the script

Constructor Detail

unit

public unit(unitGroup master,
            org.w3c.dom.Element elt,
            reporter rep)
Creates a new instance of unit

Parameters:
master - The owning unitGroup-object, null if this is a unitGroup
elt - The element in the script that describes this unit
Method Detail

getName

public java.lang.String getName()
Get the name

Returns:
The name, m_name

getReporter

public reporter getReporter()
get the reporter for this unit

Returns:
the reporter

setReporter

public void setReporter(reporter rep)
set the reporter for this unit

Parameters:
rep - The reporter

getEncoding

public java.lang.String getEncoding()
Get the encoding

Returns:
Value for encoding key in m_optionMap

setEncoding

public void setEncoding(java.lang.String enc)
Set the encoding in m_optionMap

Parameters:
enc - The encoding to be set

getType

public java.lang.String getType()
Get the type of unit

Returns:
The type, m_type

getDescription

public java.lang.String getDescription()
Get the descrition as found in the script

Returns:
The descrition, m_description

getAbsoluteUri

public java.net.URI getAbsoluteUri()
Get the absolute URI for this unit as an URI

Returns:
The absolute URI, m_absoluteUri

getFileName

public java.lang.String getFileName()
Get the short filename

Returns:
The file name, as the rightmost part of the path

getAbsoluteUriAsString

public java.lang.String getAbsoluteUriAsString()
Get the absolute URI for this unit as a string

Returns:
The absolute URI (m_absoluteUri) as string,

getOriginalUri

public java.net.URI getOriginalUri()
Get the original (given when constructed) URI for this unit as a string

Returns:
The original URI, m_originalUri

getOriginalAsString

public java.lang.String getOriginalAsString()
Get the original (given when constructed) URI for this unit as a string

Returns:
The original URI (m_originalUri) as a string

toString

public java.lang.String toString()
Get the name of this unit

Returns:
The name m_name
See Also:
DefaultMutableTreeNode.getUserObject()

getOptions

public java.util.HashMap getOptions()
Get the options that are active for this unit. Including those heritated from owning pages and group

Returns:
The value of m_optionMap

getOption

public java.lang.String getOption(java.lang.String key)
Get a spesific option

Parameters:
key - The key
Returns:
The found value or null

getProperties

public java.util.HashMap getProperties()
Get the properties that are active for this unit. Including those inherited from owning pages and group

Returns:
The value of m_propertyMap

getTransformationID

public java.lang.String getTransformationID()
Get the id for this units transformation

Transformations are used on input on contentfiles and templates, and on output on pages

Returns:
The id of the transformation that will be used on this unit, m_transformationID

getTransformation

public unitTransformation getTransformation()
Get the transformation for this unit

Transformations are used on input on contentfiles and templates, and on output on pages

Returns:
The transformation object found

getTransformationAsString

public java.lang.String getTransformationAsString()
Get the URI of transformation for this unit as a String.

Transformations are used on input on contentfiles and templates, and on output on pages

Returns:
The URI of the found transformation

setTransformationId

public void setTransformationId(java.lang.String transid)
Set the transformation ID for this unit

Parameters:
transid - The new value for the transformation ID

addTransformationParameters

public void addTransformationParameters(java.util.HashMap transparams)
Append new paramters to the transformation associated with this unit

Parameters:
transparams - The new parameter as name-value pairs

getNodeList

public org.w3c.dom.NodeList getNodeList(command cmd)
Get list of all selected nodes. Does nothing at this level

Parameters:
cmd - The command that describes the parameetrs
Returns:
null, allways

makeComment

public org.w3c.dom.Comment makeComment(java.lang.String s)
Produce a legal XML-comment

Parameters:
s - The string in the comment
Returns:
a Comment-node

setUpPopMenu

public javax.swing.JPopupMenu setUpPopMenu(javax.swing.JPopupMenu theMenu,
                                           javax.swing.JFrame main)
Produce a popupMenu for this unit. Will offer user to inspect properties of this unit.

Parameters:
theMenu - The menu we will prepare
main - The frame that owns the menu
Returns:
A popupMenu customized for this page

displayProperties

public void displayProperties(javax.swing.JFrame dialogOwner)
Show the properties of this unit in a dialog box. Do nothing. Subclasses overrides this function if they have anything to show.

Parameters:
dialogOwner - The frame that will own this dialog.

editUnit

public void editUnit(java.awt.event.ActionEvent evt)
What to do when we want to open this unit in an editor.

Parameters:
evt - The event that triggered this action

browseUnit

public void browseUnit(java.awt.event.ActionEvent evt)
What to do when we want to browse this unit in a browser.

Parameters:
evt - The evente that triggrede this action

isUpdatedAfterUse

public boolean isUpdatedAfterUse()
Decides if this unit has been updated from an other program since it was last used by this program instance.

Returns:
true if it has been updated, false otherwise

setNowAsLastTimeUsed

public void setNowAsLastTimeUsed()
Makes a note of current time as last time used


getDoc

public org.w3c.dom.Document getDoc()
Returns the DOM Attempts to build the dom if necessary

Returns:
The DOM for this unit

getDocCopy

public org.w3c.dom.Document getDocCopy()
Returns a deep copy of the DOM Attempts to build the dom if necessary

Returns:
A deep copy of the DOM for this unit

getURItoAsString

public java.lang.String getURItoAsString(unit U)
How to refer to the given unit from this unit

Parameters:
U - The unit we will refer to from this unit
Returns:
The calculated URI as a String

getTransformationParameterMap

public java.util.HashMap getTransformationParameterMap()
Get the transformationparameters for this unit

Returns:
The value of m_parameterMap

killDocument

public void killDocument()
Take it down, destroy text and DOM


isSameAs

public boolean isSameAs(unit uc)
Decides if two content files may be reused as DOM The condition is that they have same absolute URI, the same transformation (if any) and the same transformation parameters (if any)

Parameters:
uc - The unitContent object to compare with
Returns:
true if they are identical at DOM-level

calculateAbsoluteAddress

protected boolean calculateAbsoluteAddress(java.lang.String location)
Try to calculate the absolute URI based on the given location and the anchor address held by this units owning group

The construction of an absolute URI is necessary for a unit to be reckognized and used. Failing to calculate an absolute URI is considered a fatal error.

Parameters:
location - The given unit as given in script or found otherwise
Returns:
true if we can make a successfull absolute address, false if we can not or if the URI is opaque or if the owner does not exist

setTransformationFromString

public void setTransformationFromString(java.lang.String transString)
                                 throws java.lang.Exception
Set a transformation for this unit

Parameters:
transString - A string that stems either from an element or a command
Throws:
java.lang.Exception

prepare

public boolean prepare(unit p,
                       java.lang.String theCommonName,
                       java.lang.String theCommonValue)
Prepare this unit with PI-imports with named URI's. Does necessary address calculations on the imported pieces

Parameters:
p - The unit that will use this unit as content, may not be null
theCommonName - The name used for common resources in the material
theCommonValue - The value that we will use
Returns:
false if a fatal error occurs during preparation, true otherwise

build

public boolean build()
Build this unit. Does not have meaning at this general level

Returns:
true allways

establishDom

protected boolean establishDom()
Attempt to establish the DOM for this unit. Take input transformation into account.

Returns:
true if we can establish dom from actual absolute address, false otherwise

loadAsText

public boolean loadAsText()
Loading this unit as a text

Returns:
true if we can load the text from normal absolute address, false eotherwise

getAsText

public java.lang.String getAsText()
Get the units content as String. Attempts to load if necessary.

Returns:
The units content as a String

saveFromDOM

public void saveFromDOM()
Saving from DOM-tree, take transformation into account


makeRefToPage

public org.w3c.dom.Element makeRefToPage(unit P,
                                         java.lang.String txt,
                                         java.lang.String targetFrame)
                                  throws org.w3c.dom.DOMException
Produce a refelement( a ) to the given page

Parameters:
targetFrame - The target frame
P - The page we are refering to
txt - The text that will show
Returns:
A ready prepared a-element which contains the ref
Throws:
org.w3c.dom.DOMException - when we cannot make the Element

makeImageRefToPage

public org.w3c.dom.Element makeImageRefToPage(unit P,
                                              java.lang.String imagepath,
                                              java.lang.String alt,
                                              java.lang.String targetFrame)
Produce a refelement ( a ) to the given page

The imagepath is searced for common resources and adjusted accordingly. A title attribute is added based on the page's description

Parameters:
targetFrame - The target frame
P - The page we are referring to
imagepath - Path to the image that will represent the link
alt - String to the alt attribute in the img element. If null the image name is used.
Returns:
A ready prepared Element of type a

correctAllAddressingInFragment

public void correctAllAddressingInFragment(org.w3c.dom.Node theN,
                                           java.net.URI baseUri,
                                           java.util.Vector adrList)
Correct all relevant links in the nodes of a fragment.

Parameters:
theN - The fragment we will investigate
baseUri - The uri we will use as an anchor
adrList - The uri's we assume may be current base

correctAllAddressingInDocument

public void correctAllAddressingInDocument(org.w3c.dom.Document thisDoc,
                                           java.net.URI baseUri,
                                           java.util.Vector adrList)
Correct all relevant links in the nodes of a Document. Different from correctAllAddressingInDocument for effiecency reasons, avoid xpath

Parameters:
baseUri - The uri we will use as an anchor
adrList - The uri's we assume may be current base

correctOneCommonLink

protected java.lang.String correctOneCommonLink(java.net.URI baseUri,
                                                java.lang.String S,
                                                java.lang.String commonName,
                                                java.lang.String commonValue)
Correct the link as found in a string

Parameters:
baseUri - The URI which is used as an anchor
S - the string we attempt to correct
commonName - The name of the catalog we are looking for in S. We will detect and remove ../'s preceding the name
commonValue - The value we will replace commonName with
Returns:
The corrected string

correctStyleElements

public void correctStyleElements()
Correct common resources in styles in style-elements, not attributes


correctStyleAttributes

public void correctStyleAttributes(org.w3c.dom.Node theN)
Correct common resources in style-attributes, not elements

Parameters:
theN - The Node we investigate

correctStyleString

public java.lang.String correctStyleString(java.lang.String styleString)
Correct common resources in a style string

Parameters:
styleString - The string we investigate
Returns:
The corrected string

controlLinks

public void controlLinks(java.util.Vector tagAttList,
                         boolean includeAbsolutes)
Checking all links according to list of tags and matching attribute

Parameters:
includeAbsolutes - true if absolute links are to be checked
tagAttList - List of tags and attributes to check