Method Summary

Werbung
Tobias Specht
Matr.-Nr.: 640 412
[email protected]
BWS
Using Web-Browsers as Application Platform
Appendix
March 29, 2004
University of Augsburg
Chair for Business Administration, Business Information Systems III
Prof. Rony G. Flatscher
Contents
A
B
BWS 1.0 API Documentation
3
A.1
Package Overview
3
A.2
Class Hierarchy
4
A.3
BWS2XHTML
5
A.4
BWSApplet
7
A.5
BWSDevelopmentApplet
13
A.6
BWSDocument
18
A.7
BWSRewriter
22
A.8
JSNode
24
A.9
RewriterApplet
41
A.10
ScriptString
47
A.11
Method Index
49
BWS 1.0 Source Code
57
B.1
BWS2XHTML.java
57
B.2
BWSApplet.java
59
B.3
BWSDevelopmentApplet.java
70
B.4
BWSDocument.java
73
B.5
BWSRewriter.java
78
B.6
JSNode.java
80
B.7
RewriterApplet.java
96
B.8
ScriptString.java
100
B.9
BWSExampleDocument.bws
104
B.10
BWSExampleDocument.html
105
B.11
BWSRewriterDocument.html
106
B.12
readFileScript.rex
107
org.tsp.bws
Package Class Tree Deprecated Index Help
PREV PACKAGE NEXT PACKAGE
FRAMES
NO FRAMES
All Classes
Package org.tsp.bws
Class Summary
BWS2XHTML
This applications rewrites a BWS document to an BWS/HTML
document.
BWSApplet
This applet handles DOM->BSF communication, passes scripts from
the document to their respective scripting engines and provides
methods scripting languages can use to access and manipulate DOM
objects
BWSDevelopmentApplet Deprecated. Only for testing purposes, should not be used anymore.
BWSDocument
This class represents a BWS-XHTML document for parsing and
rewriting purpose.
BWSRewriter
A small application that reades a BWS-XHTML document from an
URL and rewrites it to a browser-interpretable XHTML document.
JSNode
This class capsules the DOM-node object provided by the JavaScript/
ECMAScript engine.
RewriterApplet
This applet rewrites a BWS document to a BWS/HTML document and
writes it to a newly opened window.
ScriptString
A class for handling bws script strings (strings passed from html that
are used to invoke bws scripts)
Package Class Tree Deprecated Index Help
PREV PACKAGE NEXT PACKAGE
FRAMES
file:///D|/programme/bws/doc/org/tsp/bws/package-summary.html26.03.2004 17:32:01
NO FRAMES
All Classes
org.tsp.bws Class Hierarchy
Package Class Tree Deprecated Index Help
PREV NEXT
FRAMES
NO FRAMES
All Classes
Hierarchy For Package org.tsp.bws
Class Hierarchy
❍
class java.lang.Object
❍ class org.tsp.bws.BWS2XHTML
❍ class org.tsp.bws.BWSDocument
❍ class org.tsp.bws.BWSRewriter
❍ class java.awt.Component (implements java.awt.image.ImageObserver, java.awt.
MenuContainer, java.io.Serializable)
❍ class java.awt.Container
❍ class java.awt.Panel (implements javax.accessibility.Accessible)
❍ class java.applet.Applet
❍ class org.tsp.bws.BWSApplet
❍ class org.tsp.bws.BWSDevelopmentApplet
❍ class org.tsp.bws.RewriterApplet
❍ class org.tsp.bws.JSNode
❍ class org.tsp.bws.ScriptString
Package Class Tree Deprecated Index Help
PREV NEXT
FRAMES
NO FRAMES
All Classes
file:///D|/programme/bws/doc/org/tsp/bws/package-tree.html26.03.2004 17:32:01
BWS2XHTML
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
org.tsp.bws
Class BWS2XHTML
java.lang.Object
|
+--org.tsp.bws.BWS2XHTML
public class BWS2XHTML
extends java.lang.Object
This applications rewrites a BWS document to an BWS/HTML document.
Constructor Summary
BWS2XHTML()
Method Summary
static void main(java.lang.String[] args)
Main method, calls the methods necessary for document rewriting and writes
the document to the standard output from where it can be redirected to a file.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
toString, wait, wait, wait
Constructor Detail
BWS2XHTML
file:///D|/programme/bws/doc/org/tsp/bws/BWS2XHTML.html (1 von 2)26.03.2004 17:32:00
BWS2XHTML
public BWS2XHTML()
Method Detail
main
public static void main(java.lang.String[] args)
Main method, calls the methods necessary for document rewriting and writes the document to
the standard output from where it can be redirected to a file.
Parameters:
args - String array of command line arguments, first parameter is the URL from
which the document shall be read, second parameter (optional) specifies to which file
the output shall be written. (This is not implemented yet)
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
file:///D|/programme/bws/doc/org/tsp/bws/BWS2XHTML.html (2 von 2)26.03.2004 17:32:00
NO FRAMES
All Classes
BWSApplet
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
org.tsp.bws
Class BWSApplet
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--java.awt.Panel
|
+--java.applet.Applet
|
+--org.tsp.bws.BWSApplet
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.
io.Serializable
public class BWSApplet
extends java.applet.Applet
This applet handles DOM->BSF communication, passes scripts from the document to their respective
scripting engines and provides methods scripting languages can use to access and manipulate DOM
objects
See Also:
Serialized Form
Field Summary
Fields inherited from class java.awt.Component
file:///D|/programme/bws/doc/org/tsp/bws/BWSApplet.html (1 von 6)26.03.2004 17:32:03
BWSApplet
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT,
RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS,
WIDTH
Constructor Summary
BWSApplet()
Applet standard constructor, prints a message to the standard output.
Method Summary
void destroy()
Relase bsf manager by setting it null and prints a message to the standard out.
java. executeScript(java.lang.String scriptString)
lang.
Reads a script from the docuemnt and passes it to the bsf engine specified in the
Object scripts type attribute.
java. executeScript(java.lang.String scriptString, java.lang.
lang. Object domObject)
Object
Reads a script from the document and passes it to the bsf engine specified in the
scripts type attribute.
org.
tsp. getNode(java.lang.String nodeId)
bws.
Get the html/xml node with the specified id.
JSNode
java. getScriptingEngine(java.lang.String scriptId)
lang.
Reades the type attribute of the script and parses it for the scripting engine.
String
void init()
Creates a BSFManager, obtains the applet window and registers the applet and java.
System.out to the bsf registry
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo,
getAudioClip, getAudioClip, getCodeBase, getDocumentBase,
getImage, getImage, getLocale, getParameter, getParameterInfo,
isActive, newAudioClip, play, play, resize, resize, setStub,
showStatus, start, stop
file:///D|/programme/bws/doc/org/tsp/bws/BWSApplet.html (2 von 6)26.03.2004 17:32:03
BWSApplet
Methods inherited from class java.awt.Panel
addNotify
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl,
addPropertyChangeListener, addPropertyChangeListener,
applyComponentOrientation, areFocusTraversalKeysSet,
countComponents, deliverEvent, doLayout, findComponentAt,
findComponentAt, getAlignmentX, getAlignmentY, getComponent,
getComponentAt, getComponentAt, getComponentCount, getComponents,
getContainerListeners, getFocusTraversalKeys,
getFocusTraversalPolicy, getInsets, getLayout, getListeners,
getMaximumSize, getMinimumSize, getPreferredSize, insets,
invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot,
isFocusTraversalPolicySet, layout, list, list, locate,
minimumSize, paint, paintComponents, paramString, preferredSize,
print, printComponents, processContainerEvent, processEvent,
remove, remove, removeAll, removeContainerListener, removeNotify,
setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy,
setFont, setLayout, transferFocusBackward, transferFocusDownCycle,
update, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener,
addHierarchyBoundsListener, addHierarchyListener,
addInputMethodListener, addKeyListener, addMouseListener,
addMouseMotionListener, addMouseWheelListener, bounds, checkImage,
checkImage, coalesceEvents, contains, contains, createImage,
createImage, createVolatileImage, createVolatileImage, disable,
disableEvents, dispatchEvent, enable, enable, enableEvents,
enableInputMethods, firePropertyChange, firePropertyChange,
firePropertyChange, getBackground, getBounds, getBounds,
getColorModel, getComponentListeners, getComponentOrientation,
getCursor, getDropTarget, getFocusCycleRootAncestor,
getFocusListeners, getFocusTraversalKeysEnabled, getFont,
getFontMetrics, getForeground, getGraphics,
getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners,
getHierarchyListeners, getIgnoreRepaint, getInputContext,
getInputMethodListeners, getInputMethodRequests, getKeyListeners,
getLocation, getLocation, getLocationOnScreen, getMouseListeners,
getMouseMotionListeners, getMouseWheelListeners, getName,
getParent, getPeer, getPropertyChangeListeners,
file:///D|/programme/bws/doc/org/tsp/bws/BWSApplet.html (3 von 6)26.03.2004 17:32:03
BWSApplet
getPropertyChangeListeners, getSize, getSize, getToolkit,
getTreeLock, getWidth, getX, getY, gotFocus, handleEvent,
hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet,
isDisplayable, isDoubleBuffered, isEnabled, isFocusable,
isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet,
isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown,
keyUp, list, list, list, location, lostFocus, mouseDown,
mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move,
nextFocus, paintAll, postEvent, prepareImage, prepareImage,
printAll, processComponentEvent, processFocusEvent,
processHierarchyBoundsEvent, processHierarchyEvent,
processInputMethodEvent, processKeyEvent, processMouseEvent,
processMouseMotionEvent, processMouseWheelEvent, remove,
removeComponentListener, removeFocusListener,
removeHierarchyBoundsListener, removeHierarchyListener,
removeInputMethodListener, removeKeyListener, removeMouseListener,
removeMouseMotionListener, removeMouseWheelListener,
removePropertyChangeListener, removePropertyChangeListener,
repaint, repaint, repaint, repaint, requestFocus, requestFocus,
requestFocusInWindow, requestFocusInWindow, reshape,
setBackground, setBounds, setBounds, setComponentOrientation,
setCursor, setDropTarget, setEnabled, setFocusable,
setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint,
setLocale, setLocation, setLocation, setName, setSize, setSize,
setVisible, show, show, size, toString, transferFocus,
transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
wait, wait, wait
Constructor Detail
BWSApplet
public BWSApplet()
Applet standard constructor, prints a message to the standard output.
Method Detail
file:///D|/programme/bws/doc/org/tsp/bws/BWSApplet.html (4 von 6)26.03.2004 17:32:03
BWSApplet
init
public void init()
Creates a BSFManager, obtains the applet window and registers the applet and java.System.
out to the bsf registry
Overrides:
init in class java.applet.Applet
destroy
public void destroy()
Relase bsf manager by setting it null and prints a message to the standard out.
Overrides:
destroy in class java.applet.Applet
executeScript
public java.lang.Object executeScript(java.lang.String scriptString,
java.lang.Object domObject)
Reads a script from the document and passes it to the bsf engine specified in the scripts type
attribute. Returns the object it gets from apply().
Parameters:
scriptString - String containing scriptId, returnValue key and parameters keys.
domObject - object that is used in script evaluation (usually this).
Returns:
the object returned from the executed script.
executeScript
public java.lang.Object executeScript(java.lang.String scriptString)
file:///D|/programme/bws/doc/org/tsp/bws/BWSApplet.html (5 von 6)26.03.2004 17:32:03
BWSApplet
Reads a script from the docuemnt and passes it to the bsf engine specified in the scripts type
attribute.
Parameters:
scriptString - String containing scriptId, returnValue key and parameters keys
Returns:
the object returned from script execution.
getNode
public org.tsp.bws.JSNode getNode(java.lang.String nodeId)
Get the html/xml node with the specified id.
Parameters:
nodeId - html/xml id attribute of the desired node.
Returns:
reference to the specified node.
getScriptingEngine
public java.lang.String getScriptingEngine(java.lang.
String scriptId)
Reades the type attribute of the script and parses it for the scripting engine.
Parameters:
scriptId - id of the script tag.
Returns:
the bsf key of the scripting engine.
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
file:///D|/programme/bws/doc/org/tsp/bws/BWSApplet.html (6 von 6)26.03.2004 17:32:03
NO FRAMES
All Classes
BWSDevelopmentApplet
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
org.tsp.bws
Class BWSDevelopmentApplet
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--java.awt.Panel
|
+--java.applet.Applet
|
+--org.tsp.bws.BWSDevelopmentApplet
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.
io.Serializable
Deprecated. Only for testing purposes, should not be used anymore.
public class BWSDevelopmentApplet
extends java.applet.Applet
Test applet for Java DOM communication and the JSNode class. Demonstrates manipulating a inbrowser document using JSNode and LiveConnect.
See Also:
Serialized Form
Field Summary
file:///D|/programme/bws/doc/org/tsp/bws/BWSDevelopmentApplet.html (1 von 5)26.03.2004 17:32:04
BWSDevelopmentApplet
protected
netscape. jsWindow
javascript.
Deprecated.
JSObject
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT,
RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS,
WIDTH
Constructor Summary
BWSDevelopmentApplet()
Deprecated. Applet standard constructor + debug message.
Method Summary
void getWindow()
Deprecated. Obtains the document window and references it in jsWindow.
void start()
Deprecated. Overwriten start method, calls getWindow() and tests several of
JSNode's methods.
Methods inherited from class java.applet.Applet
destroy, getAccessibleContext, getAppletContext, getAppletInfo,
getAudioClip, getAudioClip, getCodeBase, getDocumentBase,
getImage, getImage, getLocale, getParameter, getParameterInfo,
init, isActive, newAudioClip, play, play, resize, resize, setStub,
showStatus, stop
Methods inherited from class java.awt.Panel
addNotify
Methods inherited from class java.awt.Container
file:///D|/programme/bws/doc/org/tsp/bws/BWSDevelopmentApplet.html (2 von 5)26.03.2004 17:32:04
BWSDevelopmentApplet
add, add, add, add, add, addContainerListener, addImpl,
addPropertyChangeListener, addPropertyChangeListener,
applyComponentOrientation, areFocusTraversalKeysSet,
countComponents, deliverEvent, doLayout, findComponentAt,
findComponentAt, getAlignmentX, getAlignmentY, getComponent,
getComponentAt, getComponentAt, getComponentCount, getComponents,
getContainerListeners, getFocusTraversalKeys,
getFocusTraversalPolicy, getInsets, getLayout, getListeners,
getMaximumSize, getMinimumSize, getPreferredSize, insets,
invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot,
isFocusTraversalPolicySet, layout, list, list, locate,
minimumSize, paint, paintComponents, paramString, preferredSize,
print, printComponents, processContainerEvent, processEvent,
remove, remove, removeAll, removeContainerListener, removeNotify,
setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy,
setFont, setLayout, transferFocusBackward, transferFocusDownCycle,
update, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener,
addHierarchyBoundsListener, addHierarchyListener,
addInputMethodListener, addKeyListener, addMouseListener,
addMouseMotionListener, addMouseWheelListener, bounds, checkImage,
checkImage, coalesceEvents, contains, contains, createImage,
createImage, createVolatileImage, createVolatileImage, disable,
disableEvents, dispatchEvent, enable, enable, enableEvents,
enableInputMethods, firePropertyChange, firePropertyChange,
firePropertyChange, getBackground, getBounds, getBounds,
getColorModel, getComponentListeners, getComponentOrientation,
getCursor, getDropTarget, getFocusCycleRootAncestor,
getFocusListeners, getFocusTraversalKeysEnabled, getFont,
getFontMetrics, getForeground, getGraphics,
getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners,
getHierarchyListeners, getIgnoreRepaint, getInputContext,
getInputMethodListeners, getInputMethodRequests, getKeyListeners,
getLocation, getLocation, getLocationOnScreen, getMouseListeners,
getMouseMotionListeners, getMouseWheelListeners, getName,
getParent, getPeer, getPropertyChangeListeners,
getPropertyChangeListeners, getSize, getSize, getToolkit,
getTreeLock, getWidth, getX, getY, gotFocus, handleEvent,
hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet,
isDisplayable, isDoubleBuffered, isEnabled, isFocusable,
isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet,
isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown,
keyUp, list, list, list, location, lostFocus, mouseDown,
file:///D|/programme/bws/doc/org/tsp/bws/BWSDevelopmentApplet.html (3 von 5)26.03.2004 17:32:04
BWSDevelopmentApplet
mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move,
nextFocus, paintAll, postEvent, prepareImage, prepareImage,
printAll, processComponentEvent, processFocusEvent,
processHierarchyBoundsEvent, processHierarchyEvent,
processInputMethodEvent, processKeyEvent, processMouseEvent,
processMouseMotionEvent, processMouseWheelEvent, remove,
removeComponentListener, removeFocusListener,
removeHierarchyBoundsListener, removeHierarchyListener,
removeInputMethodListener, removeKeyListener, removeMouseListener,
removeMouseMotionListener, removeMouseWheelListener,
removePropertyChangeListener, removePropertyChangeListener,
repaint, repaint, repaint, repaint, requestFocus, requestFocus,
requestFocusInWindow, requestFocusInWindow, reshape,
setBackground, setBounds, setBounds, setComponentOrientation,
setCursor, setDropTarget, setEnabled, setFocusable,
setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint,
setLocale, setLocation, setLocation, setName, setSize, setSize,
setVisible, show, show, size, toString, transferFocus,
transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
wait, wait, wait
Field Detail
jsWindow
protected netscape.javascript.JSObject jsWindow
Deprecated.
Constructor Detail
BWSDevelopmentApplet
public BWSDevelopmentApplet()
Deprecated.
Applet standard constructor + debug message.
file:///D|/programme/bws/doc/org/tsp/bws/BWSDevelopmentApplet.html (4 von 5)26.03.2004 17:32:04
BWSDevelopmentApplet
Method Detail
start
public void start()
Deprecated.
Overwriten start method, calls getWindow() and tests several of JSNode's methods.
Overrides:
start in class java.applet.Applet
getWindow
public void getWindow()
Deprecated.
Obtains the document window and references it in jsWindow.
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
file:///D|/programme/bws/doc/org/tsp/bws/BWSDevelopmentApplet.html (5 von 5)26.03.2004 17:32:04
All Classes
BWSDocument
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
org.tsp.bws
Class BWSDocument
java.lang.Object
|
+--org.tsp.bws.BWSDocument
public class BWSDocument
extends java.lang.Object
This class represents a BWS-XHTML document for parsing and rewriting purpose. It provides
methods to read an BWS conform XHTML document from an URL and rewrite it as an standard
JavaScript XHTML document that can be interpreted by a standard compliant web browser. It uses
dom4j for DOM manipulation, so if you want to compile it, make sure you've got the dom4j classes
in your CLASSPATH.
Constructor Summary
BWSDocument()
Method Summary
void appendApplet()
Inserts the applet tag
void getAttributeElement(java.lang.String attributeValue)
Get and rewrite all calls to a specific BWS occuring in the document.
java. getDocument()
lang.
Get the complete document as a string .
String
void getScriptNames()
Prints the names and ids of all scripts found in the document.
file:///D|/programme/bws/doc/org/tsp/bws/BWSDocument.html (1 von 4)26.03.2004 17:32:04
BWSDocument
void printDocumentSource()
Prints the current document to the console via the dom4j XMLWriter
void printVector()
Prints every element from the scriptNames vector.
void readDocumentFromURL(java.lang.String documentURLString)
Loads a document from an URL and parses it to a dom4j XML document.
void rewriteDocument()
Rewrite the complete document and append the applet.
void rewriteScriptCalls()
Rewrites the BWS script calls of all elements.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
toString, wait, wait, wait
Constructor Detail
BWSDocument
public BWSDocument()
Method Detail
readDocumentFromURL
public void readDocumentFromURL(java.lang.String documentURLString)
throws org.dom4j.DocumentException
Loads a document from an URL and parses it to a dom4j XML document.
Parameters:
documentURLString - URL of the document to be rewriten.
Throws:
org.dom4j.DocumentException - occurs when building the document fails.
file:///D|/programme/bws/doc/org/tsp/bws/BWSDocument.html (2 von 4)26.03.2004 17:32:04
BWSDocument
printDocumentSource
public void printDocumentSource()
Prints the current document to the console via the dom4j XMLWriter
getDocument
public java.lang.String getDocument()
Get the complete document as a string .
Returns:
A String containing the XML document.
getScriptNames
public void getScriptNames()
Prints the names and ids of all scripts found in the document.
printVector
public void printVector()
Prints every element from the scriptNames vector.
getAttributeElement
public void getAttributeElement(java.lang.String attributeValue)
Get and rewrite all calls to a specific BWS occuring in the document.
Parameters:
attributeValue - the id of the script that is searched for.
file:///D|/programme/bws/doc/org/tsp/bws/BWSDocument.html (3 von 4)26.03.2004 17:32:04
BWSDocument
rewriteScriptCalls
public void rewriteScriptCalls()
Rewrites the BWS script calls of all elements. Script calls are of the form #:script_id and bws:
script_id and are rewritten to the corresponding javascript/liveconnect calls using the
getAttributeElement(java.lang.String) method.
See Also:
getAttributeElement(java.lang.String)
appendApplet
public void appendApplet()
Inserts the applet tag
rewriteDocument
public void rewriteDocument()
Rewrite the complete document and append the applet. Equivalent to getScriptNames(),
rewriteScriptCalls() and appendApplet().
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
file:///D|/programme/bws/doc/org/tsp/bws/BWSDocument.html (4 von 4)26.03.2004 17:32:04
NO FRAMES
All Classes
BWSRewriter
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
org.tsp.bws
Class BWSRewriter
java.lang.Object
|
+--org.tsp.bws.BWSRewriter
public class BWSRewriter
extends java.lang.Object
A small application that reades a BWS-XHTML document from an URL and rewrites it to a browserinterpretable XHTML document. Uses BWSDocument. Prints final document an several status
messages to standard out. Useful only for debugging! Use BWS2XHTML for actual rewriting.
Constructor Summary
BWSRewriter()
Method Summary
static void main(java.lang.String[] args)
Main method, calls all other methods.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
toString, wait, wait, wait
Constructor Detail
file:///D|/programme/bws/doc/org/tsp/bws/BWSRewriter.html (1 von 2)26.03.2004 17:32:05
BWSRewriter
BWSRewriter
public BWSRewriter()
Method Detail
main
public static void main(java.lang.String[] args)
Main method, calls all other methods.
Parameters:
args - String array of command line arguments.
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
file:///D|/programme/bws/doc/org/tsp/bws/BWSRewriter.html (2 von 2)26.03.2004 17:32:05
NO FRAMES
All Classes
JSNode
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
org.tsp.bws
Class JSNode
java.lang.Object
|
+--org.tsp.bws.JSNode
public class JSNode
extends java.lang.Object
This class capsules the DOM-node object provided by the JavaScript/ECMAScript engine. All core
methods defined in the DOM (Core) Level 1 Standard as methods of DOM node are available.
Additionally, the methods of the CharacterData and the Element interfaces are implemented
except the Element's getElementsByTagName() and normalize() methods.
Constructor Summary
JSNode(netscape.javascript.JSObject window, netscape.javascript.
JSObject existingNode)
Creates a new JSNode in the specified window and from an existing JSObject node.
JSNode(netscape.javascript.JSObject window, netscape.javascript.
JSObject existingNode, java.lang.String id)
Creates a new JSNode in the specified window and from an existing node, also sets the id
attribute so the element can be accessed easily later.
JSNode(netscape.javascript.JSObject window, java.lang.
String nodeRef)
Creates a new JSNode reference to the indicated DOM node.
Method Summary
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (1 von 17)26.03.2004 17:32:06
JSNode
void addEventListener(java.lang.String event, java.lang.
String handler)
Sets the specified event of the node to the specified handlerint appendChild(org.tsp.bws.JSNode childNode)
Appends a child to the current node as the last child.
int appendData(int childId, java.lang.String data)
Appends data to the specified child.
void appendData(java.lang.String appendString)
Append the string to the end of the character data of the node.
org.tsp. cloneNode(boolean sub)
bws.JSNode
Creates a clone of the current node.
org.tsp. createAttribute(java.lang.String attributeType, java.
bws.JSNode lang.String attributeValue)
Creates a attribute node of the specified type and with the specified value.
org.tsp. createElement(java.lang.String elementType)
bws.JSNode
Creates a HTML element (for example <h1>).
org.tsp. createTextNode(java.lang.String elementText)
bws.JSNode
Creates a text node (text between html nodes).
void deleteData(int offset, int count)
Remove a range of characters from the node.
int deleteData(int childId, int startPosition, int number)
Deletes part of the data in the specified child of the current node.
protected finalize()
void
Overwritten destructor, prints a 'notice of destruction' to the standard out.
java.lang. getAttribute(java.lang.String attributeName)
String
Returns the value of the specified attribute.
org.tsp. getAttributeNode(java.lang.String attributeName)
bws.JSNode
Returns the specified attribute of the node as a node.
java.lang. getData()
String
Retrieves the textual content of the node (must be a content/text node.
org.tsp. getFirstChild()
bws.JSNode
Returns the first child node of the current JSNode.
java.lang. getIdentifier()
String
Returns the id attribute of the Object.
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (2 von 17)26.03.2004 17:32:06
JSNode
java.lang. getInnerHTML()
String
Returns the html content of a tag (the part between the opening tag and the
closing tag (including html entities), e.g.
org.tsp. getJSNode(netscape.javascript.JSObject newNode)
bws.JSNode
Creates a JSNode from an existing JavaScript/JSObject node.
netscape. getNode()
javascript.
Returns the JSObject underlying this JSNode.
JSObject
java.lang. getNodeValue()
String
Returns the value of an node/input field
boolean hasChildNodes()
Check if the node has got any child nodes.
int insertBefore(org.tsp.bws.JSNode newNode, org.tsp.bws.
JSNode positionNode)
Inserts a child node in front of another node.
int insertData(int childId, int position, java.lang.
String data)
Inserts string data in a nodes child starting from a given position.
void insertData(int offset, java.lang.String insertString)
Inserts data at the specified character offset.
int removeAttribute(java.lang.String attributeName)
Removes an attribute (sets it to null) from a DOM node.
int removeAttributeNode(int attributeIdentifier)
Removes an attribute node.
org.tsp. removeAttributeNode(org.tsp.bws.JSNode oldAttr)
bws.JSNode
Removes and returns the specified attribute; DOM (Core) Level 1
conforming implementation.
int removeChild(int childIdentifier)
Removes a dom node from the tree, nodes are counted differently on ie and
mozilla.
org.tsp. removeChild(org.tsp.bws.JSNode refNode)
bws.JSNode
Removes a child from the current node and returns it, DOM (Core) Level 1
implementation.
org.tsp. replaceChild(org.tsp.bws.JSNode newChild, org.tsp.bws.
bws.JSNode JSNode oldChild)
Replaces the child node oldChild with the node newChild and returns
the oldChild.
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (3 von 17)26.03.2004 17:32:06
JSNode
int replaceChild(java.lang.String newNodeText,
int oldNodeIdentifier)
Replaces a child elements text.
void replaceData(int start, int length, java.lang.
String newData)
Replaces the first child elements data, example: in <h1
id="h1id">text</h1>, the specified part of text is replaced.
int setAttribute(java.lang.String attribute, java.lang.
String value)
Sets the given attribute to the given value using the JavaScript node's
setAttribute method.
org.tsp. setAttributeNode(org.tsp.bws.JSNode newAttr)
bws.JSNode
Adds a new attribute.
int setAttributeNode(java.lang.String attribute, java.lang.
String value)
Sets the given attribute to the given value using the JavaScript node's
setAttributeNode method.
int setStyleAttribute(java.lang.String styleAttribute, java.
lang.String value)
Sets the value of a style attribute.
java.lang. substringData(int offset, int count)
String
Extracs a range of data from the Node, return this String.
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString,
wait, wait, wait
Constructor Detail
JSNode
public JSNode(netscape.javascript.JSObject window,
java.lang.String nodeRef)
Creates a new JSNode reference to the indicated DOM node.
Parameters:
window - the window the DOM node resides in.
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (4 von 17)26.03.2004 17:32:06
JSNode
nodeRef - the id of the node.
JSNode
public JSNode(netscape.javascript.JSObject window,
netscape.javascript.JSObject existingNode)
Creates a new JSNode in the specified window and from an existing JSObject node.
Parameters:
window - the base window of the new JSNode.
existingNode - the node that shall be constructed in this window.
JSNode
public JSNode(netscape.javascript.JSObject window,
netscape.javascript.JSObject existingNode,
java.lang.String id)
Creates a new JSNode in the specified window and from an existing node, also sets the id
attribute so the element can be accessed easily later.
Parameters:
window - the base window of the new JSNode.
existingNode - the node that shall be constructed in this window.
id - the id under which the node shall be available in the dom.
Method Detail
finalize
protected void finalize()
Overwritten destructor, prints a 'notice of destruction' to the standard out.
Overrides:
finalize in class java.lang.Object
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (5 von 17)26.03.2004 17:32:06
JSNode
getJSNode
public org.tsp.bws.JSNode getJSNode(netscape.javascript.
JSObject newNode)
Creates a JSNode from an existing JavaScript/JSObject node.
Parameters:
newNode - the pre-existing node.
Returns:
the newly created JSNode.
getNode
public netscape.javascript.JSObject getNode()
Returns the JSObject underlying this JSNode.
Returns:
the underlying node as JSObject.
createAttribute
public org.tsp.bws.JSNode createAttribute(java.lang.
String attributeType,
java.lang.
String attributeValue)
Creates a attribute node of the specified type and with the specified value.
Parameters:
attributeType - type of the attribute.
attributeValue - value the attribute will be set to.
Returns:
a JSNode referencing the attribute.
createElement
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (6 von 17)26.03.2004 17:32:06
JSNode
public org.tsp.bws.JSNode createElement(java.lang.
String elementType)
Creates a HTML element (for example <h1>).
Parameters:
elementType - type of the element.
Returns:
a JSNode referencing this element.
createTextNode
public org.tsp.bws.JSNode createTextNode(java.lang.
String elementText)
Creates a text node (text between html nodes).
Parameters:
elementText - the text
Returns:
a JSNode referencing the TextNode.
getIdentifier
public java.lang.String getIdentifier()
Returns the id attribute of the Object.
Returns:
The id attribute of the underlying DOM node.
appendChild
public int appendChild(org.tsp.bws.JSNode childNode)
Appends a child to the current node as the last child.
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (7 von 17)26.03.2004 17:32:06
JSNode
Parameters:
childNode - the node to be appended.
Returns:
Integer 0.
appendData
public void appendData(java.lang.String appendString)
Append the string to the end of the character data of the node. DOM (Core) Level 1
conforming implementation.
Parameters:
appendString - the String to be appended.
appendData
public int appendData(int childId,
java.lang.String data)
Appends data to the specified child.
Parameters:
childId - append to the n'th child.
data - the data to be appended.
Returns:
Integer 0.
cloneNode
public org.tsp.bws.JSNode cloneNode(boolean sub)
Creates a clone of the current node.
Parameters:
sub - specifies if the nodes children shall be cloned or if only the node itself is cloned.
Returns:
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (8 von 17)26.03.2004 17:32:06
JSNode
a reference too the clone.
deleteData
public void deleteData(int offset,
int count)
Remove a range of characters from the node. DOM (Core) Level 1 conforming
implementation.
Parameters:
offset - The offset from which to remove characters.
count - The number of characters to delete.
deleteData
public int deleteData(int childId,
int startPosition,
int number)
Deletes part of the data in the specified child of the current node.
Parameters:
childId - delete data from the childNumber'th child.
startPosition - delete data from this position.
number - delete as many characters.
Returns:
Integer 0.
getAttribute
public java.lang.String getAttribute(java.lang.String attributeName)
Returns the value of the specified attribute.
Parameters:
attributeName - the name of the attribute whose value shall be returned.
Returns:
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (9 von 17)26.03.2004 17:32:06
JSNode
the value of the specified attribute as String.
getAttributeNode
public org.tsp.bws.JSNode getAttributeNode(java.lang.
String attributeName)
Returns the specified attribute of the node as a node.
Parameters:
attributeName - the attribute that shall be returned.
Returns:
the specified attribute as a JSNode.
hasChildNodes
public boolean hasChildNodes()
Check if the node has got any child nodes.
Returns:
true if the node has child nodes, else false.
insertBefore
public int insertBefore(org.tsp.bws.JSNode newNode,
org.tsp.bws.JSNode positionNode)
Inserts a child node in front of another node.
Parameters:
newNode - the node that will be inserted
positionNode - the node before which the new node will be inserted
Returns:
Integer 0.
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (10 von 17)26.03.2004 17:32:06
JSNode
insertData
public void insertData(int offset,
java.lang.String insertString)
Inserts data at the specified character offset. DOM (Core) Level 1 conforming
implementation.
Parameters:
offset - the offset of the String to be inserted.
insertString - the String to be inserted.
insertData
public int insertData(int childId,
int position,
java.lang.String data)
Inserts string data in a nodes child starting from a given position.
Parameters:
childId - number of the child where the data will be inserted.
position - position at which the string will be inserted.
data - String to be inserted.
Returns:
Integer 0.
removeAttribute
public int removeAttribute(java.lang.String attributeName)
Removes an attribute (sets it to null) from a DOM node.
Parameters:
attributeName - name of the attribute to be removed.
Returns:
Integer 0.
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (11 von 17)26.03.2004 17:32:06
JSNode
removeAttributeNode
public org.tsp.bws.JSNode removeAttributeNode(org.tsp.bws.
JSNode oldAttr)
Removes and returns the specified attribute; DOM (Core) Level 1 conforming
implementation.
Parameters:
oldAttr - The node to remove from the attribute list.
Returns:
the removed attribute as a JSNode.
removeAttributeNode
public int removeAttributeNode(int attributeIdentifier)
Removes an attribute node. This is of limited use as on microsoft internet explorer as
attributes are not numbered in order of appearance.
Parameters:
attributeIdentifier - number of the attribute to be removed. This is either the
position of the attribute specified in the HTML tag (on Mozilla, Opera, etc.) or the
position of the attribute in all attributes theoretically available for the attribute's
element (on Internet Explorer)
Returns:
Integer 0.
removeChild
public org.tsp.bws.JSNode removeChild(org.tsp.bws.JSNode refNode)
Removes a child from the current node and returns it, DOM (Core) Level 1 implementation.
Parameters:
refNode - the node to be removed.
Returns:
The removed child as a JSNode.
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (12 von 17)26.03.2004 17:32:06
JSNode
removeChild
public int removeChild(int childIdentifier)
Removes a dom node from the tree, nodes are counted differently on ie and mozilla.
replaceChild
public int replaceChild(java.lang.String newNodeText,
int oldNodeIdentifier)
Replaces a child elements text.
Parameters:
newNodeText - The new text.
oldNodeIdentifier - number of the node that shall be accessed.
Returns:
Integer 0.
replaceChild
public org.tsp.bws.JSNode replaceChild(org.tsp.bws.JSNode newChild,
org.tsp.bws.JSNode oldChild)
Replaces the child node oldChild with the node newChild and returns the oldChild.
Conforms to the DOM (Core) Level 1 specification
Parameters:
newChild - the child that replaces oldChild
oldChild - the child that will be replaced and returned, must be a child of this node
Returns:
The node that was replaced.
replaceData
public void replaceData(int start,
int length,
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (13 von 17)26.03.2004 17:32:06
JSNode
java.lang.String newData)
Replaces the first child elements data, example: in <h1 id="h1id">text</h1>, the
specified part of text is replaced. DOM (Core) Level 1 conforming implementation.
Parameters:
start - the first character that will be replaced.
newData - the string that replaces the specified part of the original string.
setAttribute
public int setAttribute(java.lang.String attribute,
java.lang.String value)
Sets the given attribute to the given value using the JavaScript node's setAttribute method. If
the attribute does not exist, it is created. This method does not work with all attributes on
MSIE (for example changing an elements style does not work).
Parameters:
attribute - name of the attribute to be set.
value - the attribute shall be set to.
Returns:
Integer 0.
setStyleAttribute
public int setStyleAttribute(java.lang.String styleAttribute,
java.lang.String value)
Sets the value of a style attribute.
Parameters:
styleAttribute - the name of the attribute.
value - the value to be set.
Returns:
Integer 0.
setAttributeNode
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (14 von 17)26.03.2004 17:32:06
JSNode
public org.tsp.bws.JSNode setAttributeNode(org.tsp.bws.
JSNode newAttr)
Adds a new attribute. If an attribute with that name is already present in the element, it is
replaced by the new one.
Parameters:
newAttr - the node to be added to the attribute list.
Returns:
the node that was set.
setAttributeNode
public int setAttributeNode(java.lang.String attribute,
java.lang.String value)
Sets the given attribute to the given value using the JavaScript node's setAttributeNode
method. If the attribute does not exist, it is created. This method does not work with all
attributes on MSIE (for example changing an elements style does not work).
Parameters:
attribute - name of the attribute to be set.
value - the attribute shall be set to.
Returns:
Integer 0.
substringData
public java.lang.String substringData(int offset,
int count)
Extracs a range of data from the Node, return this String.
Parameters:
offset - Start offset of substring to extract.
count - The number of characters to extract.
Returns:
the extracted String.
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (15 von 17)26.03.2004 17:32:06
JSNode
getInnerHTML
public java.lang.String getInnerHTML()
Returns the html content of a tag (the part between the opening tag and the closing tag
(including html entities), e.g.
this is the text
). This is a method not defined in any DOM standard by is available on Internet Explorer and Mozilla
and often comes in handy.
Returns:
The HTML content of the node.
getNodeValue
public java.lang.String getNodeValue()
Returns the value of an node/input field
Returns:
The value of the node.
getFirstChild
public org.tsp.bws.JSNode getFirstChild()
Returns the first child node of the current JSNode.
Returns:
the first child node.
getData
public java.lang.String getData()
Retrieves the textual content of the node (must be a content/text node.
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (16 von 17)26.03.2004 17:32:06
JSNode
Returns:
the textual content of the node.
addEventListener
public void addEventListener(java.lang.String event,
java.lang.String handler)
Sets the specified event of the node to the specified handlerParameters:
event - the event for which the event handler shall be set, e.g. onclick
handler - the code that shall be run upon code execution
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
file:///D|/programme/bws/doc/org/tsp/bws/JSNode.html (17 von 17)26.03.2004 17:32:06
NO FRAMES
All Classes
RewriterApplet
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
org.tsp.bws
Class RewriterApplet
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--java.awt.Panel
|
+--java.applet.Applet
|
+--org.tsp.bws.RewriterApplet
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.
io.Serializable
public class RewriterApplet
extends java.applet.Applet
This applet rewrites a BWS document to a BWS/HTML document and writes it to a newly opened
window. The applet version of BWS2XHTML. Requires dom4j installed.
See Also:
Serialized Form
Field Summary
Fields inherited from class java.awt.Component
file:///D|/programme/bws/doc/org/tsp/bws/RewriterApplet.html (1 von 6)26.03.2004 17:32:07
RewriterApplet
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT,
RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS,
WIDTH
Constructor Summary
RewriterApplet()
Method Summary
void destroy()
No changes to the method of Applet.
void init()
No changes to the method of Applet.
void rewrite()
Read and transform the document directly.
void rewriteFile()
Read and transform the document using a file.
void start()
No changes to the method of Applet.
void stop()
No changes to the method of Applet.
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo,
getAudioClip, getAudioClip, getCodeBase, getDocumentBase,
getImage, getImage, getLocale, getParameter, getParameterInfo,
isActive, newAudioClip, play, play, resize, resize, setStub,
showStatus
Methods inherited from class java.awt.Panel
addNotify
Methods inherited from class java.awt.Container
file:///D|/programme/bws/doc/org/tsp/bws/RewriterApplet.html (2 von 6)26.03.2004 17:32:07
RewriterApplet
add, add, add, add, add, addContainerListener, addImpl,
addPropertyChangeListener, addPropertyChangeListener,
applyComponentOrientation, areFocusTraversalKeysSet,
countComponents, deliverEvent, doLayout, findComponentAt,
findComponentAt, getAlignmentX, getAlignmentY, getComponent,
getComponentAt, getComponentAt, getComponentCount, getComponents,
getContainerListeners, getFocusTraversalKeys,
getFocusTraversalPolicy, getInsets, getLayout, getListeners,
getMaximumSize, getMinimumSize, getPreferredSize, insets,
invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot,
isFocusTraversalPolicySet, layout, list, list, locate,
minimumSize, paint, paintComponents, paramString, preferredSize,
print, printComponents, processContainerEvent, processEvent,
remove, remove, removeAll, removeContainerListener, removeNotify,
setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy,
setFont, setLayout, transferFocusBackward, transferFocusDownCycle,
update, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener,
addHierarchyBoundsListener, addHierarchyListener,
addInputMethodListener, addKeyListener, addMouseListener,
addMouseMotionListener, addMouseWheelListener, bounds, checkImage,
checkImage, coalesceEvents, contains, contains, createImage,
createImage, createVolatileImage, createVolatileImage, disable,
disableEvents, dispatchEvent, enable, enable, enableEvents,
enableInputMethods, firePropertyChange, firePropertyChange,
firePropertyChange, getBackground, getBounds, getBounds,
getColorModel, getComponentListeners, getComponentOrientation,
getCursor, getDropTarget, getFocusCycleRootAncestor,
getFocusListeners, getFocusTraversalKeysEnabled, getFont,
getFontMetrics, getForeground, getGraphics,
getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners,
getHierarchyListeners, getIgnoreRepaint, getInputContext,
getInputMethodListeners, getInputMethodRequests, getKeyListeners,
getLocation, getLocation, getLocationOnScreen, getMouseListeners,
getMouseMotionListeners, getMouseWheelListeners, getName,
getParent, getPeer, getPropertyChangeListeners,
getPropertyChangeListeners, getSize, getSize, getToolkit,
getTreeLock, getWidth, getX, getY, gotFocus, handleEvent,
hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet,
isDisplayable, isDoubleBuffered, isEnabled, isFocusable,
isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet,
isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown,
keyUp, list, list, list, location, lostFocus, mouseDown,
file:///D|/programme/bws/doc/org/tsp/bws/RewriterApplet.html (3 von 6)26.03.2004 17:32:07
RewriterApplet
mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move,
nextFocus, paintAll, postEvent, prepareImage, prepareImage,
printAll, processComponentEvent, processFocusEvent,
processHierarchyBoundsEvent, processHierarchyEvent,
processInputMethodEvent, processKeyEvent, processMouseEvent,
processMouseMotionEvent, processMouseWheelEvent, remove,
removeComponentListener, removeFocusListener,
removeHierarchyBoundsListener, removeHierarchyListener,
removeInputMethodListener, removeKeyListener, removeMouseListener,
removeMouseMotionListener, removeMouseWheelListener,
removePropertyChangeListener, removePropertyChangeListener,
repaint, repaint, repaint, repaint, requestFocus, requestFocus,
requestFocusInWindow, requestFocusInWindow, reshape,
setBackground, setBounds, setBounds, setComponentOrientation,
setCursor, setDropTarget, setEnabled, setFocusable,
setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint,
setLocale, setLocation, setLocation, setName, setSize, setSize,
setVisible, show, show, size, toString, transferFocus,
transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
wait, wait, wait
Constructor Detail
RewriterApplet
public RewriterApplet()
Method Detail
init
public void init()
No changes to the method of Applet.
Overrides:
init in class java.applet.Applet
file:///D|/programme/bws/doc/org/tsp/bws/RewriterApplet.html (4 von 6)26.03.2004 17:32:07
RewriterApplet
start
public void start()
No changes to the method of Applet.
Overrides:
start in class java.applet.Applet
stop
public void stop()
No changes to the method of Applet.
Overrides:
stop in class java.applet.Applet
destroy
public void destroy()
No changes to the method of Applet.
Overrides:
destroy in class java.applet.Applet
rewrite
public void rewrite()
Read and transform the document directly. Reads the document from the specified URL
(available from the HTML input field with the id filename), transform it to a BWS/HTML
document and open it in a new browser window.
file:///D|/programme/bws/doc/org/tsp/bws/RewriterApplet.html (5 von 6)26.03.2004 17:32:07
RewriterApplet
rewriteFile
public void rewriteFile()
Read and transform the document using a file. Use a file for temporary saving it. Requires
permission to read deployment.user.tmpdir system property as well as permission to
create a file in this directory.
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
file:///D|/programme/bws/doc/org/tsp/bws/RewriterApplet.html (6 von 6)26.03.2004 17:32:07
NO FRAMES
All Classes
ScriptString
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
org.tsp.bws
Class ScriptString
java.lang.Object
|
+--org.tsp.bws.ScriptString
public class ScriptString
extends java.lang.Object
A class for handling bws script strings (strings passed from html that are used to invoke bws scripts)
Constructor Summary
ScriptString(java.lang.String passedString)
interprets the passed string
Method Summary
java. getParameters()
lang.
Returns a String array of all parameters specified in the script string.
String[]
java. getRetKey()
lang.
Returns the return value key specified in the script string (the part in front of
String =)
java. getScriptId()
lang.
Returns the script id of the referenced script.
String
void interpretScriptString(java.lang.String passedString)
Checks validity of the string and parses it.
file:///D|/programme/bws/doc/org/tsp/bws/ScriptString.html (1 von 3)26.03.2004 17:32:07
ScriptString
protected
java. parseParameters(java.lang.String passedString)
lang.
Parse the parameters part of the script string to the individual parameter keys.
String[]
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
toString, wait, wait, wait
Constructor Detail
ScriptString
public ScriptString(java.lang.String passedString)
interprets the passed string
Method Detail
interpretScriptString
public void interpretScriptString(java.lang.String passedString)
Checks validity of the string and parses it.
Parameters:
passedString - the script string to be interpreted.
parseParameters
protected java.lang.String[] parseParameters(java.lang.
String passedString)
Parse the parameters part of the script string to the individual parameter keys.
Parameters:
passedString - the script string which parameters shall be parsed.
Returns:
file:///D|/programme/bws/doc/org/tsp/bws/ScriptString.html (2 von 3)26.03.2004 17:32:07
ScriptString
the individual keys that were parsed from the script string.
getScriptId
public java.lang.String getScriptId()
Returns the script id of the referenced script.
getParameters
public java.lang.String[] getParameters()
Returns a String array of all parameters specified in the script string.
getRetKey
public java.lang.String getRetKey()
Returns the return value key specified in the script string (the part in front of =)
Package Class Tree Deprecated Index Help
PREV CLASS NEXT CLASS
FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
file:///D|/programme/bws/doc/org/tsp/bws/ScriptString.html (3 von 3)26.03.2004 17:32:07
NO FRAMES
All Classes
Index
Package Class Tree Deprecated Index Help
PREV NEXT
FRAMES
NO FRAMES
All Classes
ABCDEFGHIJMOPRS
A
addEventListener(String, String) - Method in class org.tsp.bws.JSNode
Sets the specified event of the node to the specified handlerappendApplet() - Method in class org.tsp.bws.BWSDocument
Inserts the applet tag
appendChild(JSNode) - Method in class org.tsp.bws.JSNode
Appends a child to the current node as the last child.
appendData(int, String) - Method in class org.tsp.bws.JSNode
Appends data to the specified child.
appendData(String) - Method in class org.tsp.bws.JSNode
Append the string to the end of the character data of the node.
B
BWS2XHTML - class org.tsp.bws.BWS2XHTML.
This applications rewrites a BWS document to an BWS/HTML document.
BWS2XHTML() - Constructor for class org.tsp.bws.BWS2XHTML
BWSApplet - class org.tsp.bws.BWSApplet.
This applet handles DOM->BSF communication, passes scripts from the document to their
respective scripting engines and provides methods scripting languages can use to access and
manipulate DOM objects
BWSApplet() - Constructor for class org.tsp.bws.BWSApplet
Applet standard constructor, prints a message to the standard output.
BWSDevelopmentApplet - class org.tsp.bws.BWSDevelopmentApplet.
Deprecated. Only for testing purposes, should not be used anymore.
BWSDevelopmentApplet() - Constructor for class org.tsp.bws.BWSDevelopmentApplet
Deprecated. Applet standard constructor + debug message.
BWSDocument - class org.tsp.bws.BWSDocument.
This class represents a BWS-XHTML document for parsing and rewriting purpose.
BWSDocument() - Constructor for class org.tsp.bws.BWSDocument
BWSRewriter - class org.tsp.bws.BWSRewriter.
A small application that reades a BWS-XHTML document from an URL and rewrites it to a
file:///D|/programme/bws/doc/index-all.html (1 von 7)26.03.2004 17:32:02
Index
browser-interpretable XHTML document.
BWSRewriter() - Constructor for class org.tsp.bws.BWSRewriter
C
cloneNode(boolean) - Method in class org.tsp.bws.JSNode
Creates a clone of the current node.
createAttribute(String, String) - Method in class org.tsp.bws.JSNode
Creates a attribute node of the specified type and with the specified value.
createElement(String) - Method in class org.tsp.bws.JSNode
Creates a HTML element (for example <h1>).
createTextNode(String) - Method in class org.tsp.bws.JSNode
Creates a text node (text between html nodes).
D
deleteData(int, int) - Method in class org.tsp.bws.JSNode
Remove a range of characters from the node.
deleteData(int, int, int) - Method in class org.tsp.bws.JSNode
Deletes part of the data in the specified child of the current node.
destroy() - Method in class org.tsp.bws.BWSApplet
Relase bsf manager by setting it null and prints a message to the standard out.
destroy() - Method in class org.tsp.bws.RewriterApplet
No changes to the method of Applet.
E
executeScript(String) - Method in class org.tsp.bws.BWSApplet
Reads a script from the docuemnt and passes it to the bsf engine specified in the scripts type
attribute.
executeScript(String, Object) - Method in class org.tsp.bws.BWSApplet
Reads a script from the document and passes it to the bsf engine specified in the scripts type
attribute.
file:///D|/programme/bws/doc/index-all.html (2 von 7)26.03.2004 17:32:02
Index
F
finalize() - Method in class org.tsp.bws.JSNode
Overwritten destructor, prints a 'notice of destruction' to the standard out.
G
getAttribute(String) - Method in class org.tsp.bws.JSNode
Returns the value of the specified attribute.
getAttributeElement(String) - Method in class org.tsp.bws.BWSDocument
Get and rewrite all calls to a specific BWS occuring in the document.
getAttributeNode(String) - Method in class org.tsp.bws.JSNode
Returns the specified attribute of the node as a node.
getData() - Method in class org.tsp.bws.JSNode
Retrieves the textual content of the node (must be a content/text node.
getDocument() - Method in class org.tsp.bws.BWSDocument
Get the complete document as a string .
getFirstChild() - Method in class org.tsp.bws.JSNode
Returns the first child node of the current JSNode.
getIdentifier() - Method in class org.tsp.bws.JSNode
Returns the id attribute of the Object.
getInnerHTML() - Method in class org.tsp.bws.JSNode
Returns the html content of a tag (the part between the opening tag and the closing tag
(including html entities), e.g.
getJSNode(JSObject) - Method in class org.tsp.bws.JSNode
Creates a JSNode from an existing JavaScript/JSObject node.
getNode() - Method in class org.tsp.bws.JSNode
Returns the JSObject underlying this JSNode.
getNode(String) - Method in class org.tsp.bws.BWSApplet
Get the html/xml node with the specified id.
getNodeValue() - Method in class org.tsp.bws.JSNode
Returns the value of an node/input field
getParameters() - Method in class org.tsp.bws.ScriptString
Returns a String array of all parameters specified in the script string.
getRetKey() - Method in class org.tsp.bws.ScriptString
Returns the return value key specified in the script string (the part in front of =)
getScriptId() - Method in class org.tsp.bws.ScriptString
Returns the script id of the referenced script.
getScriptingEngine(String) - Method in class org.tsp.bws.BWSApplet
Reades the type attribute of the script and parses it for the scripting engine.
file:///D|/programme/bws/doc/index-all.html (3 von 7)26.03.2004 17:32:02
Index
getScriptNames() - Method in class org.tsp.bws.BWSDocument
Prints the names and ids of all scripts found in the document.
getWindow() - Method in class org.tsp.bws.BWSDevelopmentApplet
Deprecated. Obtains the document window and references it in jsWindow.
H
hasChildNodes() - Method in class org.tsp.bws.JSNode
Check if the node has got any child nodes.
I
init() - Method in class org.tsp.bws.BWSApplet
Creates a BSFManager, obtains the applet window and registers the applet and java.System.
out to the bsf registry
init() - Method in class org.tsp.bws.RewriterApplet
No changes to the method of Applet.
insertBefore(JSNode, JSNode) - Method in class org.tsp.bws.JSNode
Inserts a child node in front of another node.
insertData(int, int, String) - Method in class org.tsp.bws.JSNode
Inserts string data in a nodes child starting from a given position.
insertData(int, String) - Method in class org.tsp.bws.JSNode
Inserts data at the specified character offset.
interpretScriptString(String) - Method in class org.tsp.bws.ScriptString
Checks validity of the string and parses it.
J
JSNode - class org.tsp.bws.JSNode.
This class capsules the DOM-node object provided by the JavaScript/ECMAScript engine.
JSNode(JSObject, JSObject) - Constructor for class org.tsp.bws.JSNode
Creates a new JSNode in the specified window and from an existing JSObject node.
JSNode(JSObject, JSObject, String) - Constructor for class org.tsp.bws.JSNode
Creates a new JSNode in the specified window and from an existing node, also sets the id
attribute so the element can be accessed easily later.
JSNode(JSObject, String) - Constructor for class org.tsp.bws.JSNode
file:///D|/programme/bws/doc/index-all.html (4 von 7)26.03.2004 17:32:02
Index
Creates a new JSNode reference to the indicated DOM node.
jsWindow - Variable in class org.tsp.bws.BWSDevelopmentApplet
Deprecated.
M
main(String[]) - Static method in class org.tsp.bws.BWS2XHTML
Main method, calls the methods necessary for document rewriting and writes the document to
the standard output from where it can be redirected to a file.
main(String[]) - Static method in class org.tsp.bws.BWSRewriter
Main method, calls all other methods.
O
org.tsp.bws - package org.tsp.bws
P
parseParameters(String) - Method in class org.tsp.bws.ScriptString
Parse the parameters part of the script string to the individual parameter keys.
printDocumentSource() - Method in class org.tsp.bws.BWSDocument
Prints the current document to the console via the dom4j XMLWriter
printVector() - Method in class org.tsp.bws.BWSDocument
Prints every element from the scriptNames vector.
R
readDocumentFromURL(String) - Method in class org.tsp.bws.BWSDocument
Loads a document from an URL and parses it to a dom4j XML document.
removeAttribute(String) - Method in class org.tsp.bws.JSNode
Removes an attribute (sets it to null) from a DOM node.
removeAttributeNode(int) - Method in class org.tsp.bws.JSNode
Removes an attribute node.
file:///D|/programme/bws/doc/index-all.html (5 von 7)26.03.2004 17:32:02
Index
removeAttributeNode(JSNode) - Method in class org.tsp.bws.JSNode
Removes and returns the specified attribute; DOM (Core) Level 1 conforming
implementation.
removeChild(int) - Method in class org.tsp.bws.JSNode
Removes a dom node from the tree, nodes are counted differently on ie and mozilla.
removeChild(JSNode) - Method in class org.tsp.bws.JSNode
Removes a child from the current node and returns it, DOM (Core) Level 1 implementation.
replaceChild(JSNode, JSNode) - Method in class org.tsp.bws.JSNode
Replaces the child node oldChild with the node newChild and returns the oldChild.
replaceChild(String, int) - Method in class org.tsp.bws.JSNode
Replaces a child elements text.
replaceData(int, int, String) - Method in class org.tsp.bws.JSNode
Replaces the first child elements data, example: in <h1 id="h1id">text</h1>, the
specified part of text is replaced.
rewrite() - Method in class org.tsp.bws.RewriterApplet
Read and transform the document directly.
rewriteDocument() - Method in class org.tsp.bws.BWSDocument
Rewrite the complete document and append the applet.
rewriteFile() - Method in class org.tsp.bws.RewriterApplet
Read and transform the document using a file.
RewriterApplet - class org.tsp.bws.RewriterApplet.
This applet rewrites a BWS document to a BWS/HTML document and writes it to a newly
opened window.
RewriterApplet() - Constructor for class org.tsp.bws.RewriterApplet
rewriteScriptCalls() - Method in class org.tsp.bws.BWSDocument
Rewrites the BWS script calls of all elements.
S
ScriptString - class org.tsp.bws.ScriptString.
A class for handling bws script strings (strings passed from html that are used to invoke bws
scripts)
ScriptString(String) - Constructor for class org.tsp.bws.ScriptString
interprets the passed string
setAttribute(String, String) - Method in class org.tsp.bws.JSNode
Sets the given attribute to the given value using the JavaScript node's setAttribute method.
setAttributeNode(JSNode) - Method in class org.tsp.bws.JSNode
Adds a new attribute.
setAttributeNode(String, String) - Method in class org.tsp.bws.JSNode
Sets the given attribute to the given value using the JavaScript node's setAttributeNode
file:///D|/programme/bws/doc/index-all.html (6 von 7)26.03.2004 17:32:02
Index
method.
setStyleAttribute(String, String) - Method in class org.tsp.bws.JSNode
Sets the value of a style attribute.
start() - Method in class org.tsp.bws.BWSDevelopmentApplet
Deprecated. Overwriten start method, calls getWindow() and tests several of JSNode's
methods.
start() - Method in class org.tsp.bws.RewriterApplet
No changes to the method of Applet.
stop() - Method in class org.tsp.bws.RewriterApplet
No changes to the method of Applet.
substringData(int, int) - Method in class org.tsp.bws.JSNode
Extracs a range of data from the Node, return this String.
ABCDEFGHIJMOPRS
Package Class Tree Deprecated Index Help
PREV NEXT
FRAMES
NO FRAMES
All Classes
file:///D|/programme/bws/doc/index-all.html (7 von 7)26.03.2004 17:32:02
Datei: H:\cvs_bws\org\tsp\bws\BWS2XHTML.java 24.03.2004, 16:33:19
1 /******************************************************************************
2 * Class BWS2XTHML.java
3 * 2003-12-27 by Tobias Specht
4 ******************************************************************************
5 * A small application that reades a BWS-XHTML document from an URL and
6 * rewrites it to a browser-interpretable XHTML document. Uses BWSDocument.
7 * Prints final document to the standard output
8 *
9 * Invokation: java BWSRewriter URLToRewrite
10 *
e.g.: java BWSRewriter http://some.server.com/document.xhtml
11 ******************************************************************************
12 *
13 * Changelog
14 * --------15 *
16 * V0.1
@ 2003-12-27
17 *
18 *******************************************************************************
19 *
20 * - Add option to write output directly to a file
21 *
22 ******************************************************************************
23 *
24 * Licencing Information
25 * --------------------26 *
27 * Copyright (C) 2002-2003 Tobias Specht
28 *
29 * This program is free software; you can redistribute it and/or
30 * modify it under the terms of the GNU General Public License
31 * as published by the Free Software Foundation; either version 2
32 * of the License, or (at your option) any later version.
33 *
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
38 *
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
42 *
43 * The GNU General Public License is also available on the Web:
44 * http://www.gnu.org/copyleft/gpl.html
45 *
46 ******************************************************************************
47 *
48 * Contact information
49 * ------------------50 *
51 * For further information on this class mail me at:
52 *
53 *
[email protected]
54 *
55 * The most recent version of this file is available from
56 *
57 *
http://bsfws.berlios.de/
58 *
59 *****************************************************************************/
60
61 package org.tsp.bws;
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\BWS2XHTML.java 24.03.2004, 16:33:19
62
63 /**
64 * This applications rewrites a BWS document to an BWS/HTML document.
65 *
66 * @author Tobias Specht
67 * @version 1.0
68 */
69 public class BWS2XHTML {
70
/** reads a document from an URL and rewrites it as an bws document */
71
72
/**
73
* Main method, calls the methods necessary for document rewriting and
74
* writes the document to the standard output from where it can be
75
* redirected to a file.
76
*
77
* @param args String array of command line arguments, first parameter
78
* is the URL from which the document shall be read, second parameter
79
* (optional) specifies to which file the output shall be written.
80
* <i>(This is not implemented yet)</i>
81
*/
82
public static void main(String args[]) {
83
char debug=0;
84
BWSDocument docToRewrite=new BWSDocument();
85
86
87
try {
88
docToRewrite.readDocumentFromURL(args[0]);
89
// write to standard error
90
if (debug>0) {
91
System.err.println(docToRewrite.toString());
92
}
93
} catch (Exception e) {
94
// write to standard error
95
System.out.println("[Error] Exception while building document");
96
}
97
docToRewrite.getScriptNames();
98
docToRewrite.rewriteScriptCalls();
99
100
// if a second parameter is given, write the output to a file
101
// with the given name
102
if (args.length>1) {
103
String fileName=args[1];
104
// open file and write (not implementet)
105
} else {
106
// print file to stdOut
107
docToRewrite.printDocumentSource();
108
}
109
}
110 }
111
Seite: 2
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/******************************************************************************
* Class BWSApplet.java
* 2003-11-15 by Tobias Specht
*******************************************************************************
* This applet handles DOM->BSF communication, passes scripts from the document
* to their respective scripting engines and provides methods scripting
* languages can use to access and manipulate DOM objects
*******************************************************************************
*
* Changelog
* --------*
* V0.1
@ 2003-12-15
*
*******************************************************************************
*
* Planned improvements
* -------------------*
* none
*
* see also bws wiki:
*
http://openfacts.berlios.de/index-en.phtml?title=BSFWebScripting
*
*******************************************************************************
*
* Licencing Information
* --------------------*
* Copyright (C) 2002-2003 Tobias Specht
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The GNU General Public License is also available on the Web:
* http://www.gnu.org/copyleft/gpl.html
*
*******************************************************************************
*
* Contact information
* ------------------*
* For further information on this script mail me at:
*
*
[email protected]
*
* The most recent version of this file is available from
*
*
http://bsfws.berlios.de/
*
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
******************************************************************************/
package org.tsp.bws;
// import some standard java classes
import java.lang.*;
import java.applet.*;
import java.util.*;
import java.security.*;
import java.net.URL;
// the bsf
import com.ibm.bsf.*;
// and liveconnect
import netscape.javascript.*;
/**
* This applet handles DOM->BSF communication, passes scripts from the document
* to their respective scripting engines and provides methods scripting
* languages can use to access and manipulate DOM objects
*
* @author Tobias Specht
* @version 1.0
*/
public class BWSApplet extends Applet {
// the bsf manager
private BSFManager mgr;
// object for the browser window
private JSObject jsWindow;
// an int for setting the debug leve
// 0 = no debug output
// 1 = normal debug
// 2 = additional messages
private static int debugLevel=5;
/**
* Applet standard constructor, prints a message to the standard output.
*/
public BWSApplet() {
if (debugLevel>0) {
System.out.println("[BWSApplet.constructor] applet object created ...");
}
}
/**
* Creates a BSFManager, obtains the applet window and registers
* the applet and java.System.out to the bsf registry
*/
public void init() {
// first the manager is created
mgr=new BSFManager();
if (debugLevel>0) {
System.out.println("[BWSApplet.init] BSFManager instantiated:
"+mgr);
118
}
119
120
// register applet and java.System
121
mgr.registerBean("BWSApplet",this);
Seite: 2
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
mgr.registerBean("SystemOut",System.out);
// get the window and register it
jsWindow=JSObject.getWindow(this);
if (debugLevel>0) {
System.out.println("[BWSApplet.init] got a window: " + jsWindow);
}
mgr.registerBean("DocumentWindow",jsWindow);
}
/**
* Relase bsf manager by setting it <tt>null</tt> and prints a
* message to the standard out.
*/
public void destroy() {
mgr=null;
System.out.println("[BWSApplet.destroy] unloading ...");
}
/**
* Reads a script from the document and passes it to the bsf engine
* specified in the scripts type attribute. Returns the object it gets
* from apply().
*
* @param scriptString String containing scriptId, returnValue key and
parameters keys.
* @param domObject object that is used in script evaluation (usually
<em>this</em>).
* @return the object returned from the executed script.
*/
public Object executeScript(String scriptString, Object domObject) {
if (debugLevel>0) {
System.out.println("[BWSApplet.executeScript] got this domObject:
" + domObject);
}
// create a ScriptString
ScriptString currentScriptString=new ScriptString(scriptString);
// obtain script id from the script string
String scriptId=currentScriptString.getScriptId();
// load the scripting engine
BSFEngine evalEngine=this.loadScriptingEngine(scriptId);
// lookup script tag from the given id
JSNode scriptContainer=getNode(scriptId);
// read the script code from the container
String script=this.getScript(scriptContainer);
if (debugLevel>0) {
System.out.println("[BWSApplet.executeScript] script code");
System.out.println(script);
System.out.println("[BWSApplet.executeScript] script code end");
}
// get parameters
String[] paramArray=currentScriptString.getParameters();
Vector argumentVector;
Seite: 3
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
180
181
182
183
184
185
186
187
188
189
190
// check if arguments are given, do evaluate only if yes
if (paramArray==null) {
argumentVector=new Vector();
} else {
argumentVector=evaluateParameters(paramArray,domObject);
}
// parameters must be accessible in scripts under know references
// to keep scriptcalls easy (parameter nameing unnecessary)
// these names are predefined as argument+number, eg. argument1,
argument2, ...
191
// starting with argument0
192
Vector namesVector=new Vector();
193
194
int nrOfArguments=argumentVector.size();
195
for (int argumentCounter=0;argumentCounter<nrOfArguments;argumentCounter++) {
196
String nextArgumentName="argument" + String.valueOf(argumentCounter);
197
if (debugLevel>1) {
198
System.out.println("[BWSApplet.executeScript] names vector gets this
string: " + nextArgumentName);
199
}
200
namesVector.add(nextArgumentName);
201
}
202
203
// the return value of the apply function will be stored to the bsf registry
204
// under the key specified in the ScriptString
205
// get this return value key from ScriptString:
206
String returnKey=currentScriptString.getRetKey();
207
208
Object applyReturnedObject=null;
209
210
// execute script
211
try {
212
// for parameter use and returning values, use apply()
213
// retVal=evalEngine.apply()
214
/* method prototype for apply()
215
* public Object apply(String source,
216
*
int lineNo,
217
*
int columnNo,
218
*
Object funcBody,
219
*
Vector namesVec,
220
*
Vector argsVec)
221
*
throws org.apache.bsf.BSFException
222
*
223
* script code must be in 'funcBody'
224
* namesVec contains the names of the arguments passed
225
* argsVec contains the values
226
*/
227
228
// the script is executed, return value referenced by
applyReturnedObject
229
230
final String finalScript=script;
231
final Vector finalNamesVector=namesVector;
232
final Vector finalArgumentVector=argumentVector;
233
final BSFEngine finalEvalEngine=evalEngine;
234
235
try {
236
applyReturnedObject = AccessController.doPrivileged(new
PrivilegedAction() {
Seite: 4
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
public Object run() {
Object applyReturnedObjectInner = new Object();
try {
applyReturnedObjectInner=finalEvalEngine.apply("",0,0,finalScript,finalNamesVecto
r,finalArgumentVector);
} catch (Exception e) {
System.out.println("[BWSApplet.executeScript] Uups! Something went
wrong during apply!");
//
System.out.println("[BWSApplet.executeScript] Stack trace: " +
e.printStackTrace());
}
return applyReturnedObjectInner;
}
});
} catch (Exception e) {
System.out.println("[BWSApplet.executeScript] exception at ?");
}
if (debugLevel>0) {
System.out.println("[BWSApplet.executeScript] apply returned the
following object: " + applyReturnedObject);
254
}
255
256
if (debugLevel>1) {
257
System.out.println("[BWSApplet.executeScript] namesVector was: " +
namesVector);
258
System.out.println("[BWSApplet.executeScript] argumentVector was: "
+ argumentVector);
259
System.out.println("[BWSApplet.executeScript] script was: " +
script);
260
}
261
262
// the returned object now gets referenced in the bsf registry be the
specified
263
// key (returnKey) (from where it is accessible by any bsf script)
264
if ((applyReturnedObject!=null) && (returnKey!=null)) {
265
if (debugLevel>1) {
266
System.out.println("[BWSApplet.executeScript] trying to register
-" + applyReturnedObject + "- as " + returnKey);
267
}
268
mgr.registerBean(returnKey,applyReturnedObject);
269
}
270
} catch (Exception e) {
271
applyReturnedObject=null;
272
System.out.println("[BWSApplet.executeScript] exception while trying
to execute");
273
e.printStackTrace();
274
}
275
276
return applyReturnedObject;
277
}
278
279
/**
280
* Reads a script from the docuemnt and passes it to the bsf engine
281
* specified in the scripts type attribute.
282
*
283
* @param scriptString String containing scriptId, returnValue key and
parameters keys
284
* @return the object returned from script execution.
285
*/
Seite: 5
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
public Object executeScript(String scriptString) {
// code execution could probably also be done by the BSFManager, i.e.
// without explicitly loading a scripting engine
// create a ScriptString
ScriptString currentScriptString=new ScriptString(scriptString);
// obtain script id from the script string
String scriptId=currentScriptString.getScriptId();
// if no 'this' object is given, use the script as 'this'
Object
returnedObject=executeScript(scriptString,this.getNode(scriptId).getNode());
return returnedObject;
}
/**
* Get the html/xml node with the specified id.
*
* @param nodeId html/xml id attribute of the desired node.
* @return reference to the specified node.
*/
public JSNode getNode(String nodeId) {
JSNode tmpJSNode=new JSNode(jsWindow,nodeId);
return tmpJSNode;
}
/**
* Reades the type attribute of the script and parses it for the scripting
engine.
*
* @param scriptId id of the script tag.
* @return the bsf key of the scripting engine.
*/
public String getScriptingEngine(String scriptId) {
JSNode tmpJSNode=new JSNode(jsWindow,scriptId);
String typeString=tmpJSNode.getAttribute("type");
// get the relevant substring from the typestring
// typstring is bsf/engine
String
engineString=typeString.substring(typeString.indexOf("/")+1,typeString.length());
return engineString;
}
private BSFEngine loadScriptingEngine(String scriptId) {
// going to an inner class, all variables that shall be accessible
// must be declared final
//final BSFManager newBSFManager=new BSFManager();
//newBSFManager.setObjectRegistry(mgr.getObjectRegistry());
// store script language (=scripting engine) to a final var to
// be able to use it in doPrivileged
final String scriptingEngine=this.getScriptingEngine(scriptId);
try {
BSFEngine evalEngine = (BSFEngine) AccessController.doPrivileged(new
PrivilegedAction() {
342
Seite: 6
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
343
public Object run() {
344
BSFEngine currentEngine;
345
346
try {
347
currentEngine=mgr.loadScriptingEngine(scriptingEngine);
348 //
currentEngine=newBSFManager.loadScriptingEngine(scriptingEngine);
349
if (debugLevel>0) {
350
System.out.println("[BWSApplet.loadScriptingEngine] scripting
engine loaded successfully");
351
System.out.println("[BWSApplet.loadScriptingEngine] +- engine: " +
currentEngine);
352
}
353
return currentEngine;
354
} catch (Exception e) {
355
System.out.println("[BWSApplet.loadScriptingEngine] loading engine
failed!");
356
e.printStackTrace();
357
}
358
return null;
359
}
360
});
361
return evalEngine;
362
} catch (Exception e) {
363
System.out.println("[BWSApplet.loadScriptingEngine] exception at ?");
364
}
365
return null;
366
}
367
368
private Vector evaluateParameters(String[] paramArray, Object thisObject) {
369
if (debugLevel>1) {
370
System.out.println("[BWSApplet.evaluateParameters] just entered
evaluateParameters");
371
}
372
373
if (debugLevel>0) {
374
System.out.println("[BWSApplet.evaluateParameters] got this DOM object:
" + thisObject.toString());
375
}
376
377
Vector paramVector=evaluateParameters(paramArray);
378
379
// check every element in the Vector if it equals 'this'
380
for (int paramCounter=0;paramCounter<paramVector.size();paramCounter++) {
381
try {
382
String tempString=(String) paramVector.elementAt(paramCounter);
383
384
if (debugLevel>0) {
385
System.out.println("[BWSApplet.evaluateParameters] got this from the
Vector: " + tempString);
386
}
387
388
if (tempString.equals("this")) {
389
// replace 'this' with the JSObject handed over
390
System.out.println("[BWSApplet.evaluateParameters] found 'this',
replacing with: " + thisObject);
391
paramVector.setElementAt(thisObject,paramCounter);
392
}
393
} catch (Exception e) {
394
System.out.println("[BWSApplet.evaluateParameters] caught an exception,
object probably wasn't a String, ignoring object");
395
}
Seite: 7
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
396
397
398
399
400
401
402
403
}
return paramVector;
}
private Vector evaluateParameters(String[] paramArray) {
if (debugLevel>1) {
System.out.println("[BWSApplet.evaluateParameters] just entered
evaluateParameters");
404
}
405
406
if (debugLevel>0) {
407
System.out.println("[BWSApplet.evaluateParameters] paramArray has #" +
paramArray.length + "# Elements");
408
}
409
410
// create a new vector the size of the current array
411
Vector paramVector=new Vector(paramArray.length);
412
413
// fill the vector with n nulls
414
for (int paramCounter=0;paramCounter<paramArray.length;paramCounter++) {
415
paramVector.add(null);
416
}
417
418
for (int paramCounter=0;paramCounter<paramArray.length;paramCounter++) {
419
String currentString=paramArray[paramCounter];
420
421
if (debugLevel>1) {
422
System.out.println("[BWSApplet.evaluateParameters] current string: "
+ currentString);
423
}
424
425
// if the current string is enclosed in quotation marks, strip the
quotation marks and use it as String
426
if ((currentString.indexOf("\"")==0) &&
(currentString.lastIndexOf("\"")==currentString.length())) {
427
String
paramString=currentString.substring(1,currentString.length()-1);
428
System.out.println("[BWSApplet.evaluateParameters] parameter string:
" + paramString);
429
paramVector.setElementAt(paramString,paramCounter);
430
} else {
431
// try to lookup bean in the bsf registry
432
Object tmpObject=(Object)this.mgr.lookupBean(currentString);
433
434
if (debugLevel>0) {
435
System.out.println("[BWSApplet.evaluateParameters] registry object: " +
tmpObject);
436
}
437
438
// if the object is != null, put it on the array
439
if (tmpObject!=null) {
440
if (debugLevel>1) {
441
System.out.println("[BWSApplet.evaluateParameters] +- object
was != null -> Vector");
442
}
443
paramVector.setElementAt(tmpObject,paramCounter);
444
} else {
445
JSNode tempNode=this.getNode(currentString);
446
447
// if the string references an existing node, use it
Seite: 8
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
if (tempNode.getNode()!=null) {
System.out.println("[BWSApplet.evaluateParameters] +- found a
JSNode -> Vector");
System.out.println("[BWSApplet.evaluateParameters] +- JSNode
was: " + tempNode.getNode().toString());
System.out.println("[BWSApplet.evaluateParameters] +- JSNode
id: " + tempNode.getAttribute("id"));
paramVector.setElementAt(tempNode,paramCounter);
} else {
// else use the string
paramVector.setElementAt(currentString,paramCounter);
}
}
}
}
return paramVector;
}
private String getScript(JSNode scriptContainer) {
String script;
// check if the script has got an source (src="") attribute
// if a src attribute is given, the content of the script tag
// is ignored
if (!((scriptContainer.getAttribute("src")==null) ||
("".equals(scriptContainer.getAttribute("src"))))) {
String scriptSrc=scriptContainer.getAttribute("src");
if (debugLevel>1) {
System.out.println("[BWSApplet.getScript] code source is: " +
scriptSrc);
}
// scriptSrc may contain either:
//
- a URL -> contains ://
//
- an absolute path -> starts with /
//
- a relative path -> neither of the two above
// if the scriptSrc contains a ':', it is treated as an absolute path
to the document
// Note: permissions must be set to allow the applet access to any
directory not lying
//
under the appletCodeBase directory!
// else the url is treated as relative
String urlString;
// if it does not contain :// it is not an URL
if (scriptSrc.indexOf("://")==-1) {
// if it starts with / it is an absolute path, else it is an
relative path
if (scriptSrc.startsWith("/")) {
// absolute, obtain server name and protocol, concat protocol,
serverName and path
java.net.URL documentURL=this.getDocumentBase();
urlString=documentURL.getProtocol() + "://" +
documentURL.getHost() + ":" + documentURL.getPort() + scriptSrc;
if (debugLevel>0) {
System.out.println("[BWSApplet.getScript] generated URL is: "
+urlString);
}
Seite: 9
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
} else {
// relative, obtain document code base, append path
String documentCodeBase=this.getDocumentBase().toString();
System.out.println("[BWSApplet.getScript] code base is: " +
documentCodeBase);
urlString=documentCodeBase + scriptSrc;
}
} else {
urlString=scriptSrc;
}
URL scriptCodeURL=null;
try {
scriptCodeURL=new URL(urlString);
} catch (java.net.MalformedURLException e) {
System.out.println("[BWSApplet.getScript] MalformedURLException,
stack trace:");
514
e.printStackTrace();
515
script="";
516
}
517
518
if (debugLevel>0) {
519
System.out.println("[BWSApplet.getScript] code url is: " +
urlString);
520
System.out.println("[BWSApplet.getScript] created URL: " +
scriptCodeURL);
521
}
522
523
Object tempScriptObject=null;
524
525
try {
526
tempScriptObject=scriptCodeURL.getContent();
527
528
if (tempScriptObject instanceof java.io.InputStream) {
529
// convert to InputStream
530
java.io.InputStream
tempScriptInputStream=(java.io.InputStream)tempScriptObject;
531
// see how many bytes are available
532
int availableBytes=tempScriptInputStream.available();
533
534
// create an according byte[]
535
byte[] urlContent=new byte[availableBytes];
536
537
// read content
538
tempScriptInputStream.read(urlContent);
539
540
// convert to a String
541
script=new String(urlContent);
542
543
// close the stream
544
tempScriptInputStream.close();
545
546
} else {
547
System.out.println("[BWSApplet.getScript] referenced object
was not a string! It was: " + tempScriptObject);
548
script="";
549
}
550
} catch (java.io.IOException e) {
551
System.out.println("[BWSApplet.getScript] IOException, stack trace:");
552
e.printStackTrace();
Seite: 10
Datei: H:\cvs_bws\org\tsp\bws\BWSApplet.java 24.03.2004, 16:33:19
553
554
555
556
script="";
}
} else {
// using innerHTML, does not work with all browsers (not konqueror,
opera)
557
//script=scriptContainer.getInnerHTML();
558
// using getData, should work browser independent
559
try {
560
JSNode scriptTextNode=scriptContainer.getFirstChild();
561
script=scriptTextNode.getData();
562
} catch (Exception e) {
563
System.err.println("An exception occurred: " + e);
564
e.printStackTrace();
565
System.err.println("trying another way");
566
script=scriptContainer.getInnerHTML();
567
}
568
}
569
570
return script;
571
}
572 }
573 =
Seite: 11
Datei: H:\cvs_bws\org\tsp\bws\BWSDevelopmentApplet.java 24.03.2004, 16:33:19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/******************************************************************************
* Class BWSDevelopmentApplet.java
* 2003-12-02 by Tobias Specht
*******************************************************************************
* Test applet for Java DOM communication and the JSNode class. Demonstrates
* manipulating a in-browser document using JSNode and LiveConnect.
*******************************************************************************
*
* Changelog
* --------*
* V0.1
@ 2003-12-02
*
*******************************************************************************
*
* Licencing Information
* --------------------*
* Copyright (C) 2002-2003 Tobias Specht
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The GNU General Public License is also available on the Web:
* http://www.gnu.org/copyleft/gpl.html
*
*******************************************************************************
*
* Contact information
* ------------------*
* For further information on this script mail me at:
*
*
[email protected]
*
* The most recent version of this file is available from
*
*
http://bsfws.berlios.de/
*
******************************************************************************/
package org.tsp.bws;
// import standard java classes
import java.lang.*;
import java.applet.*;
import java.security.*;
// import liveconnect
import netscape.javascript.*;
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\BWSDevelopmentApplet.java 24.03.2004, 16:33:19
62
63 /**
64 * Test applet for Java DOM communication and the JSNode class. Demonstrates
65 * manipulating a in-browser document using JSNode and LiveConnect.
66 *
67 * @author Tobias Specht
68 * @version 1.0
69 * @deprecated Only for testing purposes, should not be used anymore.
70 */
71 public class BWSDevelopmentApplet extends Applet {
72
// browser window the applet is embedded in
73
protected JSObject jsWindow;
74
75
// current document
76
private JSObject jsDocument;
77
78
// node used for temporary storage
79
private JSNode currentNode;
80
81
/* debug level,
82
* 0 = don't debug, almost no output
83
* 1 = standard debug
84
*/
85
private int debugLevel=1;
86
87
/**
88
* Applet standard constructor + debug message.
89
*/
90
public BWSDevelopmentApplet() {
91
if (debugLevel>0) {
92
System.out.println("[bwsDevelopmentApplet constructor] applet object
created...");
93
}
94
}
95
96
/**
97
* Overwriten start method, calls getWindow() and tests several of JSNode's
methods.
98
*/
99
public void start() {
100
// obtain the applets window
101
jsWindow=JSObject.getWindow(this);
102
if (debugLevel > 0) {
103
System.out.println("[getWindow] window: " + jsWindow.toString());
104
}
105
106
JSObject jsDocument=(JSObject)jsWindow.getMember("document");
107
if (debugLevel > 0) {
108
System.out.println("[getWindow] document: " + jsDocument.toString());
109
}
110
111
JSNode headNode=new JSNode(jsWindow,"testhead");
112
JSNode bodyNode=new JSNode(jsWindow,"theBody");
113
JSNode dieListe=new JSNode(jsWindow,"dieListe");
114
JSNode span=new JSNode(jsWindow,"sp2");
115
116
JSNode newHeading=bodyNode.createElement("h2");
117
JSNode headingText=bodyNode.createTextNode("die zweite überschrift");
118
119
// this is not a debug message! it tests if JSNode.hasChildNodes() works
120
// headingText does not hava any child nodes, answer should be 'false'
Seite: 2
Datei: H:\cvs_bws\org\tsp\bws\BWSDevelopmentApplet.java 24.03.2004, 16:33:19
121
122
123
124
125
126
127
128
129
130
131
132
133
134
System.out.println("[main] headingText has child nodes: " +
headingText.hasChildNodes());
newHeading.appendChild(headingText);
bodyNode.insertBefore(newHeading,span);
//bodyNode.appendChild(newHeading);
span.appendData(0,"--append");
span.deleteData(0,2,5);
dieListe.removeChild(0);
dieListe.removeChild(1);
// again not a debug message! dieListe should have childNodes -> answer
should be 'true'
135
System.out.println("[main] dieListe has child nodes: " +
dieListe.hasChildNodes());
136
137
bodyNode.setAttribute("bgColor","#00ff00");
138
bodyNode.setStyleAttribute("color","red");
139
headNode.setStyleAttribute("backgroundColor","#88ff88");
140
headNode.setStyleAttribute("border","1px solid #555555");
141
bodyNode.setStyleAttribute("fontFamily","verdana");
142
143
// two more test (=not debug) messages
144
System.out.println("[main] body - color attribute: " +
bodyNode.getAttribute("bgColor"));
145
System.out.println("[main] body - color attribute node: " +
bodyNode.getAttributeNode("bgColor").getNode().getMember("value"));
146
147
headNode.replaceChild("Replaced",0);
148
headNode.replaceData(2,7,"---");
149
150
headNode.insertData(0,2,"(TEST)");
151
}
152
153
/**
154
* Obtains the document window and references it in jsWindow.
155
*/
156
public void getWindow() {
157
jsWindow=JSObject.getWindow(this);
158
if (debugLevel>0) {
159
System.out.println("[getWindow] window: " + jsWindow.toString());
160
}
161
}
162 }i
Seite: 3
Datei: H:\cvs_bws\org\tsp\bws\BWSDocument.java 24.03.2004, 16:33:19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/******************************************************************************
** Class BWSDocument.java
** 2003-11-24 by Tobias Specht
*******************************************************************************
** This class represents a BWS-XHTML document for parsing and rewriting
** purpose. It provides methods to read an BWS conform XHTML document from
** an URL and rewrite it as an standard JavaScript XHTML document that can
** be interpreted by a standard compliant web browser. It uses dom4j for
** DOM manipulation, so if you want to compile it, make sure you've got the
** dom4j classes in your CLASSPATH.
*******************************************************************************
**
** Changelog
** --------**
** V0.1
@ 2003-11-24
**
*******************************************************************************
*
* - rewriting code must be changed to enable argument passing, cf. bws wiki
*
http://openfacts.berlios.de/index-en.phtml?title=BSFWebScripting
* - allow printing only the final xml document (for redirection)
*
*******************************************************************************
**
** Licencing Information
** --------------------**
** Copyright (C) 2002-2003 Tobias Specht
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** The GNU General Public License is also available on the Web:
** http://www.gnu.org/copyleft/gpl.html
**
*******************************************************************************
**
** Contact information
** ------------------**
** For further information on this script mail me at:
**
**
[email protected]
**
** The most recent version of this file is available from
**
**
http://bsfws.berlios.de/
**
******************************************************************************/
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\BWSDocument.java 24.03.2004, 16:33:19
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package org.tsp.bws;
import
import
import
import
import
java.io.File;
java.util.Iterator;
java.util.List;
java.util.Vector;
java.net.URL;
import
import
import
import
import
import
org.dom4j.Attribute;
org.dom4j.Document;
org.dom4j.DocumentException;
org.dom4j.DocumentHelper;
org.dom4j.Element;
org.dom4j.XPath;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.dom4j.io.OutputFormat;
/**
* This class represents a BWS-XHTML document for parsing and rewriting
* purpose. It provides methods to read an BWS conform XHTML document from
* an URL and rewrite it as an standard JavaScript XHTML document that can
* be interpreted by a standard compliant web browser. It uses dom4j for
* DOM manipulation, so if you want to compile it, make sure you've got the
* dom4j classes in your CLASSPATH.
*
* @author Tobias Specht
* @version 1.0
*/
public class BWSDocument {
/** internal representation of the non-bws'd xml document */
private Document xmlDocument;
/** list of all bws scripts */
private Vector scriptNames=new Vector();
/** debug variable, 0=no debug except rewriten code, 1=some messages,
2=more messages */
99
private char debug=0;
100
101
/**
102
* Loads a document from an URL and parses it to a dom4j XML document.
103
*
104
* @param documentURLString URL of the document to be rewriten.
105
* @throws DocumentException occurs when building the document fails.
106
*/
107
public void readDocumentFromURL(String documentURLString) throws
DocumentException {
108
URL documentURL;
109
try {
110
documentURL=new URL(documentURLString);
111
SAXReader xmlReader = new SAXReader();
112
this.xmlDocument = xmlReader.read(documentURL);
113
if (debug>1) {
114
System.out.println(xmlDocument.toString());
115
}
116
} catch (Exception e) {
117
System.err.println("[Error] Exception creating URL, probably
malformed URL");
118
e.printStackTrace();
119
}
Seite: 2
Datei: H:\cvs_bws\org\tsp\bws\BWSDocument.java 24.03.2004, 16:33:19
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
}
/**
* Prints the current document to the console via the dom4j XMLWriter
*/
public void printDocumentSource() {
// use pretty printing
OutputFormat outformat=new OutputFormat();// =
OutputFormat.createPrettyPrint();
//
outformat.setEnconding();
// use standard encoding, else: outformat.setEncoding(String
encodingScheme)
try {
XMLWriter writer = new XMLWriter(System.out);
writer.write(this.xmlDocument);
writer.flush();
// go to the next line
System.out.println("\n");
} catch (Exception e) {
System.out.println("[Error] Exception printing the
document, wrong encoding scheme?");
e.printStackTrace();
}
}
/**
* Get the complete document as a string .
*
* @return A String containing the XML document.
*/
public String getDocument() {
return xmlDocument.asXML();
}
/**
* Prints the names and ids of all scripts found in the document.
*/
public void getScriptNames() {
XPath xpathSelector = DocumentHelper.createXPath("//script");
List results = xpathSelector.selectNodes(xmlDocument);
Element curElement;
Attribute tempAttribute;
String tempString=new String();
for (Iterator
elementIterator=results.iterator();elementIterator.hasNext();) {
curElement = (Element)elementIterator.next();
if (debug>0) {
System.out.println("Element found");
System.out.println(" Name: " + curElement.getName());
}
try {
tempAttribute=curElement.attribute("id");
tempString=tempAttribute.getValue();
} catch (Exception e) {
try {
tempAttribute=curElement.attribute("name");
tempString=tempAttribute.getValue();
Seite: 3
Datei: H:\cvs_bws\org\tsp\bws\BWSDocument.java 24.03.2004, 16:33:19
176
177
} catch (Exception e2) {
System.out.println("[Error] Script
without id or name");
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
}
}
if (debug>1) {
System.out.println(" " + tempString);
}
scriptNames.addElement((Object)tempString);
}
}
/**
* Prints every element from the scriptNames vector.
*/
public void printVector() {
for (int counter=0;counter<scriptNames.size();counter++) {
System.out.println((String)scriptNames.elementAt(counter));
}
}
/**
* Get and rewrite all calls to a specific BWS occuring in the document.
*
* @param attributeValue the id of the script that is searched for.
*/
public void getAttributeElement(String attributeValue) {
XPath xpathSelector = DocumentHelper.createXPath("//@*");
List results = xpathSelector.selectNodes(xmlDocument);
List elementAttributes;
Attribute curAttribute;
for (Iterator
attributeIterator=results.iterator();attributeIterator.hasNext();) {
curAttribute = (Attribute)attributeIterator.next();
if (debug>0) {
System.out.println(attributeValue + "-" +
curAttribute.getValue() + "-" + curAttribute.getValue().equals("#:" +
attributeValue));
}
if ((curAttribute.getValue().startsWith("bws:") ||
curAttribute.getValue().startsWith("#:")) &&
curAttribute.getValue().indexOf(attributeValue)>0) {
215
//curAttribute.setValue("document.getElementById('BWSApplet').executeScript('" +
attributeValue + "',this)");
216
//System.out.println("#:" +
curAttribute.getValue().indexOf(":"));
217
curAttribute.setValue("document.getElementById('BWSApplet').executeScript('" +
curAttribute.getValue().substring(curAttribute.getValue().indexOf(":")+1) +
"',this)");
218
//curAttribute.setValue("javascript:bwsexec(" +
attributeValue + ")");
219
}
220
}
221
222
}
Seite: 4
Datei: H:\cvs_bws\org\tsp\bws\BWSDocument.java 24.03.2004, 16:33:19
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**
* Rewrites the BWS script calls of all elements. Script calls are of the
form #:script_id and bws:script_id
* and are rewritten to the corresponding javascript/liveconnect calls
using the {@link org.tsp.bws.BWSDocument#getAttributeElement} method.
*
* @see org.tsp.bws.BWSDocument#getAttributeElement
*/
public void rewriteScriptCalls() {
String curName;
for (int
scriptCounter=0;scriptCounter<scriptNames.size();scriptCounter++) {
curName=(String)scriptNames.elementAt(scriptCounter);
getAttributeElement(curName);
}
}
/**
* Inserts the <tt>applet</tt> tag
*/
public void appendApplet() {
XPath xpathSelector = DocumentHelper.createXPath("/html/body");
List results = xpathSelector.selectNodes(xmlDocument);
// body should only occur once per document!
if (results.size()>1) {
System.err.println("[BWSDocument.appendApplet] Warning! More than
one <body> found, using the first!");
249
}
250
// use the first element returned
251
Element bodyElement=(Element)results.get(0);
252
bodyElement.addElement("applet")
253
.addAttribute("code","org.tsp.bws.BWSApplet")
254
.addAttribute("id","BWSApplet")
255
.addAttribute("width","0")
256
.addAttribute("height","0")
257
.addAttribute("mayscript","true");
258
259
260
}
261
262
/**
263
* Rewrite the complete document and append the applet. Equivalent to
264
* <tt>getScriptNames()</tt>, <tt>rewriteScriptCalls()</tt> and
265
* <tt>appendApplet()</tt>.
266
*/
267
public void rewriteDocument() {
268
this.getScriptNames();
269
this.rewriteScriptCalls();
270
this.appendApplet();
271
}
272 }p
Seite: 5
Datei: H:\cvs_bws\org\tsp\bws\BWSRewriter.java 24.03.2004, 16:33:20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/******************************************************************************
* Class BWSRewriter.java
* 2002-10-17 by Tobias Specht
*******************************************************************************
* A small application that reades a BWS-XHTML document from an URL and
* rewrites it to a browser-interpretable XHTML document. Uses BWSDocument.
* Prints final document an several status messages to standard out.
*
* Invokation: java BWSRewriter URLToRewrite
*
e.g.: java BWSRewriter http://some.server.com/document.xhtml
*******************************************************************************
*
* Changelog
* --------*
* V0.1
@ 2003-10-17
*
*******************************************************************************
*
* - Add option to output only the final document or write document to file
*
*******************************************************************************
*
* Licencing Information
* --------------------*
* Copyright (C) 2002-2003 Tobias Specht
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The GNU General Public License is also available on the Web:
* http://www.gnu.org/copyleft/gpl.html
*
*******************************************************************************
*
* Contact information
* ------------------*
* For further information on this class mail me at:
*
*
[email protected]
*
* The most recent version of this file is available from
*
*
http://bsfws.berlios.de/
*
******************************************************************************/
package org.tsp.bws;
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\BWSRewriter.java 24.03.2004, 16:33:20
62
63 /**
64 * A small application that reades a BWS-XHTML document from an URL and
65 * rewrites it to a browser-interpretable XHTML document. Uses BWSDocument.
66 * Prints final document an several status messages to standard out.
67 * Useful only for debugging! Use {@link org.tsp.bws.BWS2XHTML} for actual
68 * rewriting.
69 *
70 * @author Tobias Specht
71 * @version 1.0
72 */
73 public class BWSRewriter {
74
/** reads a document from an URL and rewrites it as an bws document */
75
76
/**
77
* Main method, calls all other methods.
78
*
79
* @param args String array of command line arguments.
80
*/
81
public static void main(String args[]) {
82
BWSDocument docToRewrite=new BWSDocument();
83
try {
84
docToRewrite.readDocumentFromURL(args[0]);
85
System.out.println(docToRewrite.toString());
86
} catch (Exception e) {
87
System.out.println("[Error] Exception while building
document");
88
}
89
docToRewrite.printDocumentSource();
90
docToRewrite.getScriptNames();
91
docToRewrite.printVector();
92
docToRewrite.rewriteScriptCalls();
93
docToRewrite.printDocumentSource();
94
}
95 }
96
Seite: 2
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/******************************************************************************
** Class JSNode.java
** 2002-11-23 by Tobias Specht
*******************************************************************************
** This class capsules the DOM-node object provided by the Mozilla JavaScript
** engine
*******************************************************************************
*
* Changelog
* --------*
* V0.1
@ 2003-01-21
* V0.2
@ 2003-12-12
*
Nearly complete rewrite, JSNode should no work without problems with
*
any DOM/LiveConnect compliant browser
*
*******************************************************************************
**
** Planned improvements - Release criteria:
** ---------------------------------------** - none atm
**
*******************************************************************************
**
** Licencing Information
** --------------------**
** Copyright (C) 2002-2003 Tobias Specht
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** The GNU General Public License is also available on the Web:
** http://www.gnu.org/copyleft/gpl.html
**
*******************************************************************************
**
** Contact information
** ------------------**
** For further information on this script mail me at:
**
**
[email protected]
**
** The most recent version of this file is available from
**
**
http://bsfws.berlios.de/
**
******************************************************************************/
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package org.tsp.bws;
import java.lang.*;
import netscape.javascript.*;
/**
* This class capsules the DOM-node object provided by the JavaScript/ECMAScript
* engine.
* All core methods defined in the DOM (Core) Level 1 Standard as methods of DOM
node
* are available. Additionally, the methods of the <tt>CharacterData</tt> and the
* <tt>Element</tt> interfaces are implemented except the <tt>Element</tt>'s
* <tt>getElementsByTagName()</tt> and <tt>normalize()</tt> methods.
*
* @author Tobias Specht
* @version 1.0
*/
public class JSNode {// extends JSObject {
private JSObject node;
private JSObject jsWindow;
private JSObject jsDocument;
// set debug mode
private int debug=1;
// callArgs Array are used for storing the arguments of JSObject.call() calls
// callArgs1 is used when one parameter is necessary, callArgs2 is used for
// two parameters and so on
private Object[] callArgs1=new Object[1];
private Object[] callArgs2=new Object[2];
private String htmlId;
/**
* Creates a new JSNode reference to the indicated DOM node.
*
* @param window the window the DOM node resides in.
* @param nodeRef the <tt>id</tt> of the node.
*/
public JSNode(JSObject window, String nodeRef) {
htmlId=nodeRef;
Object[] callArgs=new Object[1];
callArgs[0]=nodeRef;
jsWindow=window;
// 'document' is needed here!
//JSObject
jsDocument=(JSObject)jsWindow.getMember("document");
if (debug==1) {
System.out.println("[JSNode.constructor] document: " +
jsDocument);
109
}
110
node=(JSObject) jsDocument.call("getElementById",callArgs);
111
112
if (debug==1) {
113
System.out.println("[JSNode.constructor] New JSNode
created: "+ this.toString());
114
}
115
}
116
117
/**
118
* Creates a new JSNode in the specified window and from an existing
{@link JSObject} node.
Seite: 2
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
*
* @param window the base window of the new JSNode.
* @param existingNode the node that shall be constructed in this window.
*/
public JSNode(JSObject window, JSObject existingNode) {
jsWindow=window;
jsDocument=(JSObject)jsWindow.getMember("document");
node=existingNode;
}
/**
* Creates a new JSNode in the specified window and from an existing
node, also
* sets the <tt>id</tt> attribute so the element can be accessed easily
later.
*
* @param window the base window of the new JSNode.
* @param existingNode the node that shall be constructed in this window.
* @param id the id under which the node shall be available in the dom.
*/
public JSNode(JSObject window, JSObject existingNode, String id) {
jsWindow=window;
jsDocument=(JSObject)jsWindow.getMember("document");
existingNode.setMember("id",id);
node=existingNode;
}
/**
* Overwritten destructor, prints a 'notice of destruction' to the
standard out.
*/
protected void finalize() {
System.out.println("[JSNode.finalize] deleting reference to this
node: " + node.toString());
}
/**
* Creates a JSNode from an existing JavaScript/JSObject node.
*
* @param newNode the pre-existing node.
* @return the newly created JSNode.
*/
public JSNode getJSNode(JSObject newNode) {
JSNode tempNode;
try {
tempNode=new
JSNode(jsWindow,newNode,(String)newNode.getMember("id"));
} catch (Exception e) {
System.out.println("[getJSNode] no id attribute found,
creating without id!");
tempNode=new JSNode(jsWindow,newNode);
}
return tempNode;
}
/**
* Returns the JSObject underlying this JSNode.
*
* @return the underlying node as JSObject.
*/
public JSObject getNode() {
Seite: 3
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
return node;
}
/**
* Returns this node's parent window.
*
* @return the parent window as JSObject.
*/
private JSObject getWindow() {
// get the window the node exists in
return jsWindow;
}
/**
* Returns this node's parent document.
*
* @return the parent document as JSObject.
*/
private JSObject getDocument() {
// get the document the node exists in
System.out.println(jsWindow.toString());
JSObject theDocument=(JSObject)jsWindow.getMember("document");
System.out.println(theDocument.toString());
return theDocument;
}
/**
* Creates a attribute node of the specified type and with the specified
value.
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
*
* @param attributeType type of the attribute.
* @param attributeValue value the attribute will be set to.
* @return a JSNode referencing the attribute.
*/
public JSNode createAttribute(String attributeType, String
attributeValue) {
callArgs1[0]=attributeType;
JSObject
tempNode=(JSObject)jsDocument.call("createAttribute",callArgs1);
callArgs1[0]=attributeValue;
tempNode.setMember("nodeValue",callArgs1);
JSNode theNode=new JSNode(jsWindow,tempNode);
return theNode;
}
/**
* Creates a HTML element (for example <tt><h1></tt>).
*
* @param elementType type of the element.
* @return a JSNode referencing this element.
*/
public JSNode createElement(String elementType) {
callArgs1[0]=elementType;
JSObject
tempNode=(JSObject)jsDocument.call("createElement",callArgs1);
225
JSNode theNode=new JSNode(jsWindow,tempNode);
226
return theNode;
227
}
228
229
/**
230
* Creates a text node (text between html nodes).
Seite: 4
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
231
232
233
234
235
236
237
*
* @param elementText the text
* @return a JSNode referencing the TextNode.
*/
public JSNode createTextNode(String elementText) {
callArgs1[0]=elementText;
JSObject
tempNode=(JSObject)jsDocument.call("createTextNode",callArgs1);
238
JSNode theNode=new JSNode(jsWindow,tempNode);
239
return theNode;
240
}
241
242
/**
243
* Returns the <tt>id</tt> attribute of the Object.
244
*
245
* @return The <tt>id</tt> attribute of the underlying DOM node.
246
*/
247
public String getIdentifier() {
248
return this.getAttribute("id");
249
}
250
251
/**
252
* Appends a child to the current node as the last child.
253
*
254
* @param childNode the node to be appended.
255
* @return Integer 0.
256
*/
257
public int appendChild(JSNode childNode) {
258
Object[] callArgs=new Object[1];
259
callArgs[0]=childNode.getNode();
260 //
JSObject textNode=(JSObject)
getDocument().call("createTextNode",callArgs);
261 //
callArgs[0]=textNode;
262
node.call("appendChild",callArgs);
263
return 0;
264
}
265
266
/**
267
* Append the string to the end of the character data of the node. DOM
(Core) Level 1 conforming implementation.
268
*
269
* @param appendString the <tt>String</tt> to be appended.
270
*/
271
public void appendData(String appendString) {
272
callArgs1[0]=appendString;
273
node.call("appendData",callArgs1);
274
}
275
276
/**
277
* Appends data to the specified child.
278
*
279
* @param childId append to the n'th child.
280
* @param data the data to be appended.
281
* @return Integer 0.
282
*/
283
public int appendData(int childId, String data) {
284
if (debug==1) {
285
System.out.println("[appendData] entered, node is " +
node);
286
}
287
Seite: 5
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
288
289
callArgs1[0]=htmlId;
JSObject tempNode=(JSObject)
getDocument().call("getElementById",callArgs1);
290
291
292
293
294
295
296
297
298
299
if (!(tempNode.equals(node))) {
System.out.println("[appendData] corrected node!");
node=tempNode;
}
JSObject childNodes=(JSObject)node.getMember("childNodes");
if (debug==1) {
System.out.println("[appendData] childNodes: " +
childNodes);
300
301
302
303
304
305
}
JSObject desiredNode=(JSObject)childNodes.getSlot(childId);
if (debug==1) {
System.out.println("[appendData] node cast to: " +
desiredNode);
306
307
308
309
310
311
312
313
314
315
316
}
callArgs1[0]=data;
desiredNode.call("appendData",callArgs1);
return 0;
}
/**
* Creates a clone of the current node.
*
* @param sub specifies if the nodes children shall be cloned or if only
the node itself is cloned.
317
* @return a reference too the clone.
318
*/
319
public JSNode cloneNode(boolean sub) {
320 //
Object[] callArgs=new Object[1];
321
callArgs1[0]=new Boolean(sub);
322 //
callArgs[0]=new Boolean(sub);
323
JSObject newNode=(JSObject)node.call("cloneNode",callArgs1);
324
JSNode newJSNode=this.getJSNode(newNode);
325
return newJSNode;
326
}
327
328
/**
329
* Remove a range of characters from the node. DOM (Core) Level 1
conforming implementation.
330
*
331
* @param offset The offset from which to remove characters.
332
* @param count The number of characters to delete.
333
*/
334
public void deleteData(int offset, int count) {
335
callArgs2[0]=new Integer(offset);
336
callArgs2[1]=new Integer(count);
337
node.call("deleteData",callArgs2);
338
}
339
340
/**
341
* Deletes part of the data in the specified child of the current node.
342
*
343
* @param childId delete data from the childNumber'th child.
Seite: 6
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
344
345
346
347
348
349
350
351
352
353
354
355
356
* @param startPosition delete data from this position.
* @param number delete as many characters.
* @return Integer 0.
*/
public int deleteData(int childId, int startPosition, int number) {
if (debug==1) {
System.out.println("[deleteData] entered");
}
JSObject childNodes=(JSObject)node.getMember("childNodes");
if (debug==1) {
System.out.println("[deleteData] childNodes: " +
childNodes);
357
358
359
360
361
362
}
JSObject desiredNode=(JSObject)childNodes.getSlot(childId);
if (debug==1) {
System.out.println("[deleteData] node cast to: " +
desiredNode);
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
}
callArgs2[0]=new Integer(startPosition);
callArgs2[1]=new Integer(number);
desiredNode.call("deleteData",callArgs2);
return 0;
}
/**
* Returns the value of the specified attribute.
*
* @param attributeName the name of the attribute whose value shall be
returned.
* @return the value of the specified attribute as <tt>String</tt>.
*/
public String getAttribute(String attributeName) {
Object[] callArgs=new Object[1];
callArgs[0]=attributeName;
//
String attribute=(String)node.call("getAttribute",callArgs);
// alternative try with getMemeber
String attribute=(String)node.getMember(attributeName);
if (debug>0) {
System.out.println("[JSNode.getAttribute] got this
attribute: " + attribute);
};
return attribute;
}
/**
* Returns the specified attribute of the node as a node.
*
* @param attributeName the attribute that shall be returned.
* @return the specified attribute as a JSNode.
*/
public JSNode getAttributeNode(String attributeName) {
Object[] callArgs=new Object[1];
callArgs[0]=attributeName;
JSObject
attributeNode=(JSObject)node.call("getAttributeNode",callArgs);
399
JSNode attributeJSNode=this.getJSNode(attributeNode);
Seite: 7
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
return attributeJSNode;
}
/**
* Check if the node has got any child nodes.
*
* @return <tt>true</tt> if the node has child nodes, else <tt>false</tt>.
*/
public boolean hasChildNodes() {
Object[] callArgs=new Object[0];
Boolean ergebnis=(Boolean) node.call("hasChildNodes",callArgs);
return ergebnis.booleanValue();
}
/**
* Inserts a child node in front of another node.
*
* @param newNode the node that will be inserted
* @param positionNode the node before which the new node will be
inserted
419
420
421
422
423
424
425
426
* @return Integer 0.
*/
public int insertBefore(JSNode newNode, JSNode positionNode) {
JSObject jsNewNode=newNode.getNode();
JSObject jsPositionNode=positionNode.getNode();
if (debug==1) {
System.out.println("[insertBefore] got the JSObjects: " +
jsNewNode + "/" + jsPositionNode);
427
}
428
429
callArgs2[0]=jsNewNode;
430
callArgs2[1]=jsPositionNode;
431
432
if (debug==1) {
433
System.out.println("[insertBefore] callArgs2 ready: " +
callArgs2);
434
}
435
436
node.call("insertBefore",callArgs2);
437
return 0;
438
}
439
/*
440
public int insertBefore(String newNodeText, String childIdentifier) {
441
callArgs1[0]=newNodeText;
442
JSObject newNode=(JSObject)
getDocument().call("createTextNode",callArgs1);
443
Object[] callArgs=new Object[2];
444
callArgs[0]=newNode;
445
Object[] subCallArgs=new Object[1];
446
subCallArgs[0]=childIdentifier;
447
callArgs[1]=(JSObject)
getDocument().call("getElementById",subCallArgs);
448
node.call("insertBefore",callArgs);
449
return 0;
450
}
451
*/
452
453
/**
454
* Inserts data at the specified character offset. DOM (Core) Level 1
conforming implementation.
Seite: 8
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
*
* @param offset the offset of the <tt>String</tt> to be inserted.
* @param insertString the <tt>String</tt> to be inserted.
*/
public void insertData(int offset, String insertString) {
callArgs2[0]=new Integer(offset);
callArgs2[1]=insertString;
node.call("insertData",callArgs2);
}
/**
* Inserts string data in a nodes child starting from a given position.
*
* @param childId number of the child where the data will be inserted.
* @param position position at which the string will be inserted.
* @param data String to be inserted.
* @return Integer 0.
*/
public int insertData(int childId, int position, String data) {
if (debug==1) {
System.out.println("[insertData] entered");
}
JSObject childNodes=(JSObject)node.getMember("childNodes");
if (debug==1) {
System.out.println("[insertData] childNodes: " +
childNodes);
482
483
484
485
486
487
}
JSObject desiredNode=(JSObject)childNodes.getSlot(childId);
if (debug==1) {
System.out.println("[insertData] node cast to: " +
desiredNode);
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
}
callArgs2[0]=new Integer(position);
callArgs2[1]=data;
desiredNode.call("insertData",callArgs2);
return 0;
}
/**
* Removes an attribute (sets it to null) from a DOM node.
*
* @param attributeName name of the attribute to be removed.
* @return Integer 0.
*/
public int removeAttribute(String attributeName) {
if (debug==1) {
System.out.println("[removeAttribute] entered");
}
callArgs1[0]=attributeName;
node.call("removeAttribute",callArgs1);
return 0;
}
/**
* Removes and returns the specified attribute; DOM (Core) Level 1 conforming
implementation.
Seite: 9
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
513
514
515
516
517
518
519
*
* @param oldAttr The node to remove from the attribute list.
* @return the removed attribute as a JSNode.
*/
public JSNode removeAttributeNode(JSNode oldAttr) {
callArgs1[0]=oldAttr.getNode();
JSObject
returnedAttr=(JSObject)node.call("removeAttributeNode",callArgs1);
520
JSNode toBeReturned=new JSNode(jsWindow,returnedAttr);
521
return toBeReturned;
522
}
523
524
/**
525
* Removes an attribute node. This is of limited use as on microsoft
internet explorer
526
* as attributes are not numbered in order of appearance.
527
*
528
* @param attributeIdentifier number of the attribute to be removed. This
is either
529
*
the position of the attribute specified in the
HTML tag (on Mozilla, Opera, etc.)
530
*
or the position of the attribute in all
attributes theoretically available for
531
*
the attribute's element (on Internet Explorer)
532
* @return Integer 0.
533
*/
534
public int removeAttributeNode(int attributeIdentifier) {
535
JSObject attributesNode=(JSObject)node.getMember("attributes");
536
537
if (debug==1) {
538
System.out.println("[removeAttributeNode] attributes: " +
attributesNode);
539
}
540
541
JSObject
desiredNode=(JSObject)attributesNode.getSlot(attributeIdentifier);
542
543
if (debug==1) {
544
System.out.println("[removeAttributeNode] attribute: " +
desiredNode);
545
}
546
547
callArgs1[0]=desiredNode;
548
549
node.call("removeAttributeNode",callArgs1);
550 /*
callArgs1[0]=nodeIdentifier;
551
callArgs1[0]=(JSObject)
getDocument().call("document.getElementById",callArgs1);
552
node.call("removeAttributeNode",callArgs1);*/
553
return 0;
554
}
555
556
/**
557
* Removes a child from the current node and returns it,
558
* DOM (Core) Level 1 implementation.
559
*
560
* @param refNode the node to be removed.
561
* @return The removed child as a JSNode.
562
*/
563
public JSNode removeChild(JSNode refNode) {
564
callArgs1[0]=refNode.getNode();
Seite: 10
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
JSObject deletedNode=(JSObject)node.call("removeChild",callArgs1);
JSNode toBeReturned=new JSNode(jsWindow,deletedNode);
return toBeReturned;
}
/** Removes a dom node from the tree, nodes are counted differently on ie
and mozilla.
*
* @param Number of the child to be removed.
* @param Integer 0.
*/
public int removeChild(int childIdentifier) {
if (debug==1) {
System.out.println("[removeChild] entered
removeChild()");
}
JSObject childNodes=(JSObject)node.getMember("childNodes");
if (debug==1) {
System.out.println("[removeChild] got node array: " +
childNodes);
585
586
587
}
JSObject
toBeRemoved=(JSObject)childNodes.getSlot(childIdentifier);
588
589
590
if (debug==1) {
System.out.println("[removeChild] childNode: " +
toBeRemoved);
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
}
callArgs1[0]=toBeRemoved;
node.call("removeChild",callArgs1);
return 0;
}
/**
* Replaces a child elements text.
*
* @param newNodeText The new text.
* @param oldNodeIdentifier number of the node that shall be accessed.
* @return Integer 0.
*/
public int replaceChild(String newNodeText, int oldNodeIdentifier) {
callArgs1[0]=newNodeText;
JSObject
newNode=(JSObject)jsDocument.call("createTextNode",callArgs1);
JSObject childNodes=(JSObject)node.getMember("childNodes");
JSObject
childNode=(JSObject)childNodes.getSlot(oldNodeIdentifier);
callArgs2[0]=newNode;
callArgs2[1]=childNode;
node.call("replaceChild",callArgs2);
return 0;
}
/**
* Replaces the child node <tt>oldChild</tt> with the node <tt>newChild</tt>
Seite: 11
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
* and returns the <tt>oldChild</tt>. Conforms to the DOM (Core) Level 1
specification
*
* @param newChild the child that replaces oldChild
* @param oldChild the child that will be replaced and returned, must be a
child
*
of this node
* @return The node that was replaced.
*/
public JSNode replaceChild(JSNode newChild, JSNode oldChild) {
callArgs2[0]=newChild.getNode();
callArgs2[1]=oldChild.getNode();
JSObject oldNode=(JSObject)node.call("replaceChild",callArgs2);
JSNode toBeReturned=new JSNode(jsWindow,oldNode);
return toBeReturned;
}
/**
* Replaces the first child elements data, example: in <tt><h1
id="h1id">text</h1></tt>,
* the specified part of <tt>text</tt> is replaced. DOM (Core) Level 1
conforming implementation.
*
* @param start the first character that will be replaced.
* @param value the last character that will be replaced.
* @param newData the string that replaces the specified part of the
original string.
*/
public void replaceData(int start, int length, String newData) {
Object[] callArgs=new Object[3];
callArgs[0]=new Integer(start);
callArgs[1]=new Integer(length);
callArgs[2]=newData;
642
643
644
645
646
647
648
649 //
JSObject childElement=(JSObject)node.getMember("firstChild");
650
node.call("replaceData",callArgs);
651
652
if (debug==1) {
653
System.out.println("[replaceData] current node: " +
this.toString());
654
//System.out.println("[replaceData] evalString: " +
evalString);
655
}
656 //
return 0;
657
}
658
659
/**
660
* Sets the given attribute to the given value using the JavaScript
node's setAttribute method.
661
* If the attribute does not exist, it is created. This method does not
work with all attributes
662
* on MSIE (for example changing an elements style does not work).
663
*
664
* @param attribute name of the attribute to be set.
665
* @param value the attribute shall be set to.
666
* @return Integer 0.
667
*/
668
public int setAttribute(String attribute, String value) {
669
callArgs2[0]=attribute;
670
callArgs2[1]=value;
Seite: 12
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
671
672
673
674
675
node.call("setAttribute",callArgs2);
if (debug==1) {
System.out.println("[setAttribute] Attribute: " +
attribute + ", Value: " + value);
676
}
677
return 0;
678
}
679
680
/**
681
* Sets the value of a style attribute.
682
*
683
* @param styleAttribute the name of the attribute.
684
* @param value the value to be set.
685
* @return Integer 0.
686
*/
687
public int setStyleAttribute(String styleAttribute, String value) {
688
if (debug==1) {
689
System.out.println("[setStyleAttribute] entered ...");
690
}
691
692
JSObject styleNode=(JSObject)node.getMember("style");
693
694
if (debug==1) {
695
System.out.println("[setStyleAttribute] Style node: " +
styleNode);
696
}
697
698
styleNode.setMember(styleAttribute,value);
699
700
if (debug==1) {
701
System.out.println("[setStyleAttribute] Style node (member set):
" + styleNode);
702
}
703
704
callArgs1[0]=styleNode;
705
706
if (debug==1) {
707
System.out.println("[setStyleAttribute] params: " +
styleAttribute + "/" + value);
708
System.out.println("[setStyleAttribute] Call args: " + callArgs1);
709
System.out.println("[setStyleAttribute] returning ... node: " +
node);
710
}
711
712
return 0;
713
}
714
715
/**
716
* Adds a new attribute. If an attribute with that name is already present in
the element, it is replaced by the new one.
717
*
718
* @param newAttr the node to be added to the attribute list.
719
* @return the node that was set.
720
*/
721
public JSNode setAttributeNode(JSNode newAttr) {
722
callArgs1[0]=newAttr;
723
JSObject oldAttribute=(JSObject)node.call("setAttributeNode",callArgs1);
724
JSNode toBeReturned=new JSNode(jsWindow, oldAttribute);
725
return toBeReturned;
Seite: 13
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
}
/**
* Sets the given attribute to the given value using the JavaScript
node's setAttributeNode method.
* If the attribute does not exist, it is created.
* This method does not work with all attributes on MSIE (for example
changing an elements style does not work).
*
* @param attribute name of the attribute to be set.
* @param value the attribute shall be set to.
* @return Integer 0.
*/
public int setAttributeNode(String attribute,String value) {
callArgs1[0]=attribute;
if (debug==1) {
System.out.println("[setAttributeNode] :" + jsDocument);
}
JSObject
attributeNode=(JSObject)jsDocument.call("createAttribute",callArgs1);
attributeNode.setMember("nodeValue",value);
callArgs1[0]=attributeNode;
node.call("setAttributeNode",callArgs1);
if (debug==1) {
System.out.println("[setAttributeNode] Attribute: " +
attribute + ", value: " + value);
750
}
751
return 0;
752
}
753
754
/* DOCUMENT IT
755
This method does not seem to be necessary, it is not different
from setStyleAttribute!
756
/
757
public int setStyleAttributeNode(String styleAttribute, String value) {
758
callArgs1[0]=styleAttribute;
759
760
JSObject attributeNode=(JSObject)node.getMember("style");
761
762
if (debug>0) {
763
System.out.println("[setStyleAttributeNode] attributeNode: " +
attributeNode);
764
}
765
766
attributeNode.setMember(styleAttribute,value);
767
768
if (debug>0) {
769
System.out.println("[setStyleAttributeNode]
attributeNode: " + attributeNode + attributeNode.getMember(styleAttribute));
770
System.out.println("[setStyleAttributeNode] attributeNode
value: " + attributeNode.getMember(styleAttribute));
771
}
772
773
return 0;
774
}*/
775
776
/**
777
* Extracs a range of data from the Node, return this String.
778
*
Seite: 14
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
* @param offset Start offset of substring to extract.
* @param count The number of characters to extract.
* @return the extracted String.
*/
public String substringData(int offset, int count) {
String fullData=this.getData();
if ((offset>fullData.length()) || (count<=0)) {
return null;
}
if (count+offset>fullData.length()) {
count=fullData.length()-offset;
}
int endOffset=offset+count;
String returnString=fullData.substring(offset,endOffset);
return returnString;
}
/**
* Returns the html content of a tag
* (the part between the opening tag and the closing tag (including html
entities),
* e.g. <div>this <em>is</em> the text</div>). This is a method not defined
in
* any DOM standard by is available on Internet Explorer and Mozilla and
often
* comes in handy.
*
* @return The HTML content of the node.
*/
public String getInnerHTML() {
String theInnerHTML=(String)node.getMember("innerHTML");
if (debug>0) {
System.out.println("[JSNode.getInnerHTML] innerHTML: " +
theInnerHTML);
}
return theInnerHTML;
}
/*********************************************************
***
methods for accessing DOM node attributes
***
*********************************************************
* these are named get + CamelCase attribute name for
*
obtaining the attribute and set + CamelCase attribute
*
name for setting it: e.g. getNodeValue and
*
setNodeValue for modifying nodeValue
*********************************************************/
/**
* Returns the value of an node/input field
*
* @return The value of the node.
*/
public String getNodeValue() {
return (String) node.getMember("nodeValue");
}
//
//
//
//
/* returns an array of the nodes children as <tt>JSNode</tt>s */
public JSNode[] getChildNodes() {
node.getMember("childNodes");
}
Seite: 15
Datei: H:\cvs_bws\org\tsp\bws\JSNode.java 24.03.2004, 16:33:20
836
837
838
839
840
841
842
843
844
845
/**
* Returns the first child node of the current JSNode.
*
* @return the first child node.
*/
public JSNode getFirstChild() {
JSObject jsObjNode=(JSObject)node.getMember("firstChild");
if (debug>0) {
System.out.println("[JSNode.getFirstChild] first child is: " +
jsObjNode);
}
JSNode theFirstChild=new JSNode(this.jsWindow,jsObjNode);
if (debug>0) {
System.out.println("[JSNode.getFirstChild] JSNode is: " + theFirstChild);
}
return theFirstChild;
}
846
847
848
849
850
851
852
853
854
/**
855
* Retrieves the textual content of the node (must be a content/text node.
856
*
857
* @return the textual content of the node.
858
*/
859
public String getData() {
860
//
callArgs2[0]=new String("getAttribute");
861 //
callArgs1[0]=new String("data");
862
System.out.println("[JSNode.getData] about to invoke
getAttribute!");
863 // getAttribute seems not to work here!
864 //
String nodeData=(String)node.call("getAttribute",callArgs1);
865
String nodeData=(String)node.getMember("data");
866
System.out.println("[JSNode.getData] string: " + nodeData);
867
return nodeData;
868
}
869
870
871
872 /*********************************************************
873 ***
event handler methods
***
874 *********************************************************
875 * dom event handler attaching works with the
876 * .attachEventListener method, the same is done here.
877 * however, the implementation of this is _NOT_ DOM
878 * conform, it uses node.setMember, which should
879 * work with any up-to-date browser. The DOM conform
880 * event handling does not work with any IE, cf.
881 * http://www.quirksmode.org/dom/w3c_events.html#registration
882 *********************************************************/
883
884
/** Sets the specified event of the node to the specified
885
* handler886
*
887
* @param event the event for which the event handler shall be
888
*
set, e.g. <tt>onclick</tt>
889
* @param handler the code that shall be run upon code execution
890
*/
891
public void addEventListener(String event, String handler) {
892
node.setMember(event,handler);
893
}
894 }
Seite: 16
Datei: H:\cvs_bws\org\tsp\bws\RewriterApplet.java 24.03.2004, 16:33:20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/******************************************************************************
** Class RewriterApplet
** 2002-11-23 by Tobias Specht
*******************************************************************************
* This applet rewrites a BWS document to a BWS/HTML document and writes it
* to a newly opened window.
*******************************************************************************
**
** Planned improvements - Release criteria:
** ---------------------------------------** - none atm
**
*******************************************************************************
**
** Licencing Information
** --------------------**
** Copyright (C) 2002-2003 Tobias Specht
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** The GNU General Public License is also available on the Web:
** http://www.gnu.org/copyleft/gpl.html
**
*******************************************************************************
**
** Contact information
** ------------------**
** For further information on this script mail me at:
**
**
[email protected]
**
** The most recent version of this file is available from
**
**
http://bsfws.berlios.de/
**
******************************************************************************/
package org.tsp.bws;
// java standard classes
import java.applet.*;
import java.io.*;
// dom4j
import org.dom4j.io.XMLWriter;
// and liveconnect
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\RewriterApplet.java 24.03.2004, 16:33:20
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import netscape.javascript.*;
/**
* This applet rewrites a BWS document to a BWS/HTML document and writes it
* to a newly opened window. The applet version of {@link org.tsp.bws.BWS2XHTML}.
* Requires dom4j installed.
*
* @author Tobias Specht
* @version 1.0
*/
public class RewriterApplet extends Applet {
/**
* No changes to the method of {@link java.applet.Applet}.
*/
public void init() {}
/**
* No changes to the method of {@link java.applet.Applet}.
*/
public void start() {}
/**
* No changes to the method of {@link java.applet.Applet}.
*/
public void stop() {}
/**
* No changes to the method of {@link java.applet.Applet}.
*/
public void destroy() {}
/**
* Read and transform the document directly.
* Reads the document from the specified URL (available from
* the HTML input field with the id <tt>filename</tt>), transform it
* to a BWS/HTML document and open it in a new browser window.
*/
public void rewrite() {
JSObject myWindow=JSObject.getWindow(this);
JSNode filenameNode=new JSNode(myWindow,"filename");
System.out.println(filenameNode);
String filename=filenameNode.getAttribute("value");
BWSDocument docToRewrite=new BWSDocument();
try {
docToRewrite.readDocumentFromURL(filename);
} catch (Exception e) {
e.printStackTrace();
}
docToRewrite.getScriptNames();
docToRewrite.rewriteScriptCalls();
docToRewrite.appendApplet();
String rewrittenString=docToRewrite.getDocument();
//
// for a first test, just open a window
Object[] paramObjects=new Object[2];
paramObjects[0]="about:blank";
paramObjects[1]="bwsWindow";
JSObject newWindow=(JSObject)myWindow.call("open",paramObjects);
JSObject newDocu=(JSObject)newWindow.getMember("document");
System.out.println(newDocu);
Seite: 2
Datei: H:\cvs_bws\org\tsp\bws\RewriterApplet.java 24.03.2004, 16:33:20
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
paramObjects[0]="text/html";
paramObjects[1]=null;
newDocu.call("open",paramObjects);
paramObjects=new Object[1];
//delete the xml declaration
rewrittenString=rewrittenString.substring(rewrittenString.indexOf("\n")+1);
//replace / in tags with \/
rewrittenString=rewrittenString.replaceAll("</","<\\/");
rewrittenString=rewrittenString.replaceAll("/>"," \\/>");
//replace ' with '
paramObjects[0]=rewrittenString.replaceAll("'","'");
System.out.println((String)paramObjects[0]);
newDocu.call("write",paramObjects);
newDocu.call("close",paramObjects);
}
/**
* Read and transform the document using a file.
* Use a file for temporary saving it. Requires permission to read
* <tt>deployment.user.tmpdir</tt> system property as well as
* permission to create a file in this directory.
*/
public void rewriteFile() {
JSObject myWindow=JSObject.getWindow(this);
JSNode filenameNode=new JSNode(myWindow,"filename");
System.out.println(filenameNode);
String filename=filenameNode.getAttribute("value");
BWSDocument docToRewrite=new BWSDocument();
try {
docToRewrite.readDocumentFromURL(filename);
} catch (Exception e) {
e.printStackTrace();
}
docToRewrite.getScriptNames();
docToRewrite.rewriteScriptCalls();
docToRewrite.appendApplet();
String rewrittenString=docToRewrite.getDocument();
//insert space before ending /
rewrittenString=rewrittenString.replaceAll("/>"," />");
//replace ' with '
rewrittenString=rewrittenString.replaceAll("'","'");
String documentURL="about:blank";
//obtain tmp path
try {
String tmpPath=System.getProperty("deployment.user.tmpdir");
File dir = new File(tmpPath);
File tmpFile = new File(dir, "theBWSDocument.html");
try {
FileOutputStream outStream = new FileOutputStream(tmpFile);
outStream.write(rewrittenString.getBytes());
} catch (Exception e) {
e.printStackTrace();
Seite: 3
Datei: H:\cvs_bws\org\tsp\bws\RewriterApplet.java 24.03.2004, 16:33:20
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
}
documentURL = tmpFile.toURL().toString();
} catch (Exception e) {
e.printStackTrace();
}
//
//
//
//
//
//
//
/*
Object[] paramObjects=new Object[2];
paramObjects[0]=documentURL;
paramObjects[1]="bwsWindow";
JSObject newWindow=(JSObject)myWindow.call("open",paramObjects);
JSObject newDocu=(JSObject)newWindow.getMember("document");
for a first test, just open a window
Object[] paramObjects=new Object[2];
paramObjects[0]="about:blank";
paramObjects[1]="bwsWindow";
JSObject newWindow=(JSObject)myWindow.call("open",paramObjects);
JSObject newDocu=(JSObject)newWindow.getMember("document");
System.out.println(newDocu);
paramObjects[0]="text/html";
paramObjects[1]=null;
newDocu.call("open",paramObjects);
paramObjects=new Object[1];
//delete the xml declaration
rewrittenString=rewrittenString.substring(rewrittenString.indexOf("\n")+1);
//replace / in tags with \/
rewrittenString=rewrittenString.replaceAll("</","<\\/");
System.out.println((String)paramObjects[0]);
newDocu.call("write",paramObjects);
newDocu.call("close",paramObjects);*/
//
}
}
Seite: 4
Datei: H:\cvs_bws\org\tsp\bws\ScriptString.java 24.03.2004, 16:33:20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*********************************************************************
* A class for handling bws script strings (strings passed from html
* that are used to invoke bws scripts)
*********************************************************************
* the following schemas are allowed for script invokation:
*
scriptId
*
returnValue=scriptId
*
scriptId(parameter,parameter,...)
*
returnValue=scriptId(parameter,parameter,...)
********************************************************************/
package org.tsp.bws;
import java.lang.String;
/**
* A class for handling bws script strings (strings passed from html
* that are used to invoke bws scripts).
*
* @author Tobias Specht
* @version 1.0
*/
public class ScriptString {
// class internal representation of the string
//private String scriptString;
// the id of the script referenced by this script string
private String scriptId;
// the key that references the value returned by the script
private String returnValue;
// string array of parameters used in the function call
private String[] parameters;
// set a debug level for this class
private static int debugLevel=1;
/** interprets the passed string */
public ScriptString(String passedString) {
this.interpretScriptString(passedString);
}
/**
* Checks validity of the string and parses it.
*
* @param passedString the script string to be interpreted.
*/
public void interpretScriptString(String passedString) {
// it would be nice if the constructor checked for duplicate
// =,( and ) and throw an exception if these occur
// start indices probably should be +1
//scriptString=passedString;
if (debugLevel>0) {
System.out.println("[ScriptString.constructor] entered
constructur, passedString: " + passedString);
57
}
58
59
// if no return value is specified (no = in passed String)
60
if (passedString.indexOf("=")<0) {
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\ScriptString.java 24.03.2004, 16:33:20
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// if no parameters are given (no ( in passed String))
if (passedString.indexOf("(")<0) {
scriptId=passedString.trim();
// if debug
System.out.println("[ScriptString.constructor] no
retval, no args, scriptId: " + scriptId);
} else {
// parameters are given
scriptId=passedString.substring(0,passedString.indexOf("("));
scriptId=scriptId.trim();
// if debug
System.out.println("[ScriptString.constructor] no
retval, args, scriptId: " + scriptId);
parameters=this.parseParameters(passedString);
}
} else {
// any parameters?
if (passedString.indexOf("(")<0) {
// no parameters
scriptId=passedString.substring(passedString.indexOf("=")+1,passedString.length()
);
83
scriptId=scriptId.trim();
84
85
// if debug
86
System.out.println("[ScriptString.constructor]
retval, no args, scriptId: " + scriptId);
87
} else {
88
// parameters
89
scriptId=passedString.substring(passedString.indexOf("=")+1,passedString.indexOf(
"("));
90
scriptId=scriptId.trim();
91
92
// if debug
93
System.out.println("[ScriptString.constructor]
retval, args, scriptId: " + scriptId);
94
95
parameters=this.parseParameters(passedString);
96
}
97
98
returnValue=passedString.substring(0,passedString.indexOf("="));
99
System.out.println("[ScriptString.constructor] retval: " +
returnValue);
100
}
101
//scriptString=passedString;
102
103
104
}
105
106
/**
107
* Parse the parameters part of the script string to the individual
parameter keys.
108
*
109
* @param passedString the script string which parameters shall be
Seite: 2
Datei: H:\cvs_bws\org\tsp\bws\ScriptString.java 24.03.2004, 16:33:20
parsed.
110
111
112
113
114
* @return the individual keys that were parsed from the script string.
*/
protected String[] parseParameters(String passedString) {
if (debugLevel>0) {
System.out.println("[ScriptString.parseParameters]
scriptString: " + passedString);
115
}
116
117
String
parametersString=passedString.substring(passedString.indexOf("(")+1,passedString.
indexOf(")"));
118
119
if (debugLevel>0) {
120
System.out.println("[ScriptString.parseParameters]
parametersString: " + parametersString);
121
}
122
123
// now split with parametersString.split(",");
124
String[] parametersArray=parametersString.split(",");
125
126
for (int
parametersCounter=0;parametersCounter<parametersArray.length;parametersCounter++)
{
127
128
parametersArray[parametersCounter]=parametersArray[parametersCounter].trim();
129
130
if (debugLevel>0) {
131
System.out.println("[ScriptString.parseParameters] +- parameter " +
parametersCounter + ": " + parametersArray[parametersCounter]);
132
}
133
}
134
135
// return a String array
136
return parametersArray;
137
}
138
139
/**
140
* Returns the script id of the referenced script.
141
*/
142
public String getScriptId() {
143
return scriptId;
144
}
145
146
/**
147
* Returns a String array of all parameters specified in the script
string.
148
*/
149
public String[] getParameters() {
150
return parameters;
151
}
152
153
/**
154
* Returns the return value key specified in the script string (the part in
front of =)
155
*/
156
public String getRetKey() {
157
return returnValue;
158
}
Seite: 3
Datei: H:\cvs_bws\org\tsp\bws\ScriptString.java 24.03.2004, 16:33:20
159 }
160
Seite: 4
Datei: D:\programme\bws\BWSExampleDocument.bws 22.03.2004, 18:27:35
1 <html>
2 <head>
3
<title>
4
BWSExamplaryDocument
5
</title>
6
<script id="readFile" type="bws/rexx" src="org/tsp/bws/readFileScript.rex">
7
</script>
8 </head>
9
10 <body>
11
File to open: <input type="text" id="filename" />
12
<input type="button" onclick="bws:readFile(filename,output)" value="Open!" />
13
<div id="output">
14
</div>
15 </body>
16 </html>
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\BWSExampleDocument.html 24.03.2004, 16:33:24
1 <html>
2 <head>
3
<title>
4
BWSExamplaryDocument
5
</title>
6
<script id="readFile" type="bws/rexx" src="org/tsp/bws/readFileScript.rex">
7
</script>
8 </head>
9
10 <body>
11
File to open: <input type="text" id="filename" />
12
<input type="button"
onclick="document.getElementById('BWSApplet').executeScript('readFile(filename,ou
tput)'),this)" value="Open!" />
13
<div id="output">
14
</div>
15
16
17
<applet code="org.tsp.bws.BWSApplet" name="BWSApplet" id="BWSApplet"
mayscript="true" width="0" height="0"></applet>
18 </body>
19
20 </html>
Seite: 1
Datei: H:\cvs_bws\org\tsp\bws\RewriterDocument.html 24.03.2004, 16:33:25
1 <html>
2
3 <body>
4 <form
action="javascript:document.getElementById('rewriterApplet').rewriteFile()">
5 BWS Document URL: <input type="text" name="filename" id="filename" />
6 <input type="submit" value="Open" />
7 </form>
8
9 <applet code="org.tsp.bws.RewriterApplet" name="rewriterApplet"
id="rewriterApplet" mayscript="true" width="0" height="0"></applet>
10 </body>
11 </html>
Seite: 1
Datei: D:\programme\bws\org\tsp\bws\readFileScript.rex 01.03.2004, 22:47:11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
parse arg filename, outputArea
filename=.bsf~lookupbean(filename)
outputArea=.bsf~lookupbean(outputArea)
file=.stream~new(filename~getAttribute('value'))
do while file~lines<>0
text=file~linein
anElementNode=outputArea~createElement('div')
anElementNode~addEventListener('onClick','alertMe')
contentText=outputArea~createTextNode(text)
anElementNode~appendChild(contentText)
anElementNode~setStyleAttribute('padding','2px')
anElementNode~setStyleAttribute('backgroundColor','#aaffaa')
anElementNode~setStyleAttribute('margin','5px')
anElementNode~setStyleAttribute('border','#00cc00 2px ridge')
outputArea~appendChild(anElementNode)
end
outputArea~setStyleAttribute('backgroundColor','#99ff99')
outputArea~setStyleAttribute('border','#009900 2px dashed')
::REQUIRES BSF.CLS
Seite: 1
Herunterladen