fi.hut.tml.xsmiles
Class XSmilesXMLDocument

java.lang.Object
  extended byfi.hut.tml.xsmiles.XSmilesXMLDocument
All Implemented Interfaces:
MediaQueryEvaluator, XMLDocument
Direct Known Subclasses:
HTMLDocument

public class XSmilesXMLDocument
extends java.lang.Object
implements XMLDocument, MediaQueryEvaluator

The XMLdocument is an object that can retrieve and parse a XML document when given the URL of the document as an argument in the constructor. The document can then be accessed through the DOM-interface that it provides. The document also saves the original source of the document, so that the source can be given to any component that is interested of it (for example the SourceViewMLFC)

Version:
$Revision: 6535 $
Author:
Kreivi, Mikko Honkala, Juha

Field Summary
protected  ECMAScripter currentScripter
           
protected  java.lang.String currentStylesheetTitle
           
protected  org.w3c.dom.Document destXMLDoc
           
protected  BrowserWindow m_browser
           
protected  XSLTEngine m_engine
           
protected  XLink m_link
           
protected  XMLParser m_parser
           
protected  java.io.InputStream m_stream
           
protected  MLFC mlfc
           
protected  java.lang.String parserClass
           
protected  java.lang.String preferredTitle
           
protected  org.w3c.dom.Document sourceXMLDoc
           
protected  java.net.URL sourceXMLURL
           
protected  java.util.Vector stylesheetTitles
           
protected  boolean trueDocument
           
protected  org.w3c.dom.Document XSLDoc
           
protected  java.lang.String xslProcessor
           
protected  java.net.URL XSLURL
           
 
Fields inherited from interface fi.hut.tml.xsmiles.mlfc.general.MediaQueryEvaluator
MEDIA_TYPES
 
Constructor Summary
XSmilesXMLDocument(BrowserWindow browser, org.w3c.dom.Document doc)
          Another alternative constructor
XSmilesXMLDocument(BrowserWindow browser, java.io.InputStream stream)
          This constructor is used for the docs gotten via sockets etc.
XSmilesXMLDocument(BrowserWindow browser, java.io.InputStream stream, XLink link)
          This constructor is used by the Browser when it requests a new XMLdocument.
XSmilesXMLDocument(BrowserWindow browser, java.lang.String s)
          An alternative constructor, where the source can be given as a string.
XSmilesXMLDocument(BrowserWindow browser, XLink link)
          This constructor is used by the Browser when it requests a new XMLdocument.
 
Method Summary
 void acquireToken()
          Used for locking/unlocking the document for mutex-reasons.
protected  org.w3c.dom.Document createDomFromString(java.lang.String source)
           
 void deactivate()
           
 boolean evalMediaQuery(java.lang.String media)
          Public method accessible from MLFCs and used above in findXSL().
protected  org.w3c.dom.Document fetchAndSetDOM(java.net.URL sourceURL)
          This method is alternative for fetchXMLDOM().
protected  org.w3c.dom.Document fetchXMLDOM(java.io.InputStream stream)
           
protected  org.w3c.dom.Document fetchXMLDOM(java.io.InputStream stream, java.net.URL sourceURL)
           
protected  org.w3c.dom.Document fetchXMLDOM(java.net.URL sourceURL)
           
protected  XSmilesPI findXSL(org.w3c.dom.Document doc)
          This method gets the first processing instruction from doc, which contains the target 'xml-stylesheet'.
static java.lang.String getAttribute(java.lang.String data, java.lang.String att)
          return an xml attribute from a data String
 BrowserWindow getBrowser()
           
 java.lang.String getCurrentStylesheetTitle()
          If the current stylesheet does not exist, then "" is returned.
 org.w3c.dom.Document getDocument()
          Accessor method.
 ECMAScripter getECMAScripter()
           
 XLink getLink()
          Accessor method.
 java.lang.String getMLName()
          Accessor method.
 java.util.Enumeration getSourceEnumeration()
          Accessor method.
 java.lang.String getSourceText(org.w3c.dom.Document doc)
          Accessor method.
 java.lang.String getSourceText(org.w3c.dom.Document doc, boolean prettyPrinting)
           
 java.util.Vector getSourceVector()
          Accessor method.
 java.util.Vector getStylesheetTitles()
           
 org.w3c.dom.Document getXMLDocument()
          Accessor method.
 java.net.URL getXMLURL()
          Accessor method
 java.util.Vector getXMLVector()
          Accessor method.
 org.w3c.dom.Document getXSLDocument()
          Accessor method.
 java.net.URL getXSLURL()
          Accessor method
 java.util.Vector getXSLVector()
          Accessor method.
 void init(BrowserWindow browser)
           
 void init(BrowserWindow browser, java.lang.String s)
           
 org.w3c.dom.Document insertSourceIntoEditor(org.w3c.dom.Document d, XSmilesPI pi)
           
 boolean isTrueDocument()
           
protected  org.w3c.dom.Document processStyleSheet(org.w3c.dom.Document xml_dom, java.net.URL xsl_url, java.net.URL xml_url)
           
 void releaseToken()
          Used for locking/unlocking the document for mutex-reasons.
 void retrieveDocument()
          This is the method that performs all the actual work of the XMLDocument.
 void setPreferredStylesheetTitle(java.lang.String title)
           
protected  java.util.Vector sourceStringToVector(java.lang.String sourcestring)
           
 void transformDocument()
          Just transform existing document again
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mlfc

protected MLFC mlfc

m_link

protected XLink m_link

m_stream

protected java.io.InputStream m_stream

m_parser

protected XMLParser m_parser

m_engine

protected XSLTEngine m_engine

m_browser

protected BrowserWindow m_browser

XSLURL

protected java.net.URL XSLURL

sourceXMLURL

protected java.net.URL sourceXMLURL

currentStylesheetTitle

protected java.lang.String currentStylesheetTitle

preferredTitle

protected java.lang.String preferredTitle

sourceXMLDoc

protected org.w3c.dom.Document sourceXMLDoc

XSLDoc

protected org.w3c.dom.Document XSLDoc

destXMLDoc

protected org.w3c.dom.Document destXMLDoc

xslProcessor

protected java.lang.String xslProcessor

parserClass

protected java.lang.String parserClass

stylesheetTitles

protected java.util.Vector stylesheetTitles

trueDocument

protected boolean trueDocument

currentScripter

protected ECMAScripter currentScripter
Constructor Detail

XSmilesXMLDocument

public XSmilesXMLDocument(BrowserWindow browser,
                          XLink link)
This constructor is used by the Browser when it requests a new XMLdocument.
The DOM-implementation is set here.


XSmilesXMLDocument

public XSmilesXMLDocument(BrowserWindow browser,
                          java.io.InputStream stream)
This constructor is used for the docs gotten via sockets etc. (not http, i.e., no URI available).
The DOM-implementation is set here.


XSmilesXMLDocument

public XSmilesXMLDocument(BrowserWindow browser,
                          java.io.InputStream stream,
                          XLink link)
This constructor is used by the Browser when it requests a new XMLdocument.
The DOM-implementation is set here.


XSmilesXMLDocument

public XSmilesXMLDocument(BrowserWindow browser,
                          java.lang.String s)
An alternative constructor, where the source can be given as a string.


XSmilesXMLDocument

public XSmilesXMLDocument(BrowserWindow browser,
                          org.w3c.dom.Document doc)
Another alternative constructor

Parameters:
browser - The BrowserWindow
doc - The Document
Method Detail

init

public void init(BrowserWindow browser)

init

public void init(BrowserWindow browser,
                 java.lang.String s)

retrieveDocument

public void retrieveDocument()
                      throws java.lang.Exception
This is the method that performs all the actual work of the XMLDocument. It fetches and parses the document (determined in the constructor) and makes the document available for use by the other browser components. The handle to the DOM-interface is kept in a variable called doc. Run by a separate thread, so that fetching can be interrupted, for example in error situations.

Specified by:
retrieveDocument in interface XMLDocument
Throws:
java.lang.Exception

transformDocument

public void transformDocument()
                       throws java.lang.Exception
Just transform existing document again

Throws:
TransformerException, - if something went wrong.
java.lang.Exception

insertSourceIntoEditor

public org.w3c.dom.Document insertSourceIntoEditor(org.w3c.dom.Document d,
                                                   XSmilesPI pi)
Parameters:
pi - The processing instruction, which has been chosen to be used.

isTrueDocument

public boolean isTrueDocument()

fetchAndSetDOM

protected org.w3c.dom.Document fetchAndSetDOM(java.net.URL sourceURL)
                                       throws java.lang.Exception
This method is alternative for fetchXMLDOM(). Creates the DOM tree for the document defined by

Throws:
java.lang.Exception

fetchXMLDOM

protected org.w3c.dom.Document fetchXMLDOM(java.net.URL sourceURL)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

fetchXMLDOM

protected org.w3c.dom.Document fetchXMLDOM(java.io.InputStream stream,
                                           java.net.URL sourceURL)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

fetchXMLDOM

protected org.w3c.dom.Document fetchXMLDOM(java.io.InputStream stream)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

processStyleSheet

protected org.w3c.dom.Document processStyleSheet(org.w3c.dom.Document xml_dom,
                                                 java.net.URL xsl_url,
                                                 java.net.URL xml_url)
                                          throws java.lang.Exception
Throws:
java.lang.Exception

findXSL

protected XSmilesPI findXSL(org.w3c.dom.Document doc)
                     throws java.lang.Exception
This method gets the first processing instruction from doc, which contains the target 'xml-stylesheet'. It returs the href - attribute of that processing instruction as an URL. Additions: Read all stylsheets, and choose the correct one. (juha)

Throws:
java.lang.Exception

evalMediaQuery

public boolean evalMediaQuery(java.lang.String media)
Public method accessible from MLFCs and used above in findXSL().

Specified by:
evalMediaQuery in interface XMLDocument
Parameters:
media - Media attribute string
Returns:
true if media query evaluates to true

getAttribute

public static java.lang.String getAttribute(java.lang.String data,
                                            java.lang.String att)
return an xml attribute from a data String

Parameters:
data - The datastring
att - The attribute to look for
Returns:
the value of attribute, (null if not found)

getStylesheetTitles

public java.util.Vector getStylesheetTitles()
Specified by:
getStylesheetTitles in interface XMLDocument
Returns:
A Vector containing titles of all stylesheets assosiated with browser

getCurrentStylesheetTitle

public java.lang.String getCurrentStylesheetTitle()
Description copied from interface: XMLDocument
If the current stylesheet does not exist, then "" is returned. If no title has been specified, then the title = the URI of the stylesheet currently used

Specified by:
getCurrentStylesheetTitle in interface XMLDocument
Returns:
the title of the current stylesheet

sourceStringToVector

protected java.util.Vector sourceStringToVector(java.lang.String sourcestring)

createDomFromString

protected org.w3c.dom.Document createDomFromString(java.lang.String source)

getDocument

public org.w3c.dom.Document getDocument()
Accessor method.

Specified by:
getDocument in interface XMLDocument
Returns:
an object providing the DOM-interface to the document.

getXMLDocument

public org.w3c.dom.Document getXMLDocument()
Accessor method.

Specified by:
getXMLDocument in interface XMLDocument
Returns:
an object providing the DOM-interface to the XML part of the document.

getXSLDocument

public org.w3c.dom.Document getXSLDocument()
Accessor method.

Specified by:
getXSLDocument in interface XMLDocument
Returns:
an object providing the DOM-interface to the XSL part of the document.

getMLName

public java.lang.String getMLName()
Accessor method.

Returns:
String the name of the markup-language of the current document. !NOTE! Do not trust this blindly. The implementation is non-standard.

acquireToken

public void acquireToken()
Used for locking/unlocking the document for mutex-reasons. !Note! Not implemented yet!


releaseToken

public void releaseToken()
Used for locking/unlocking the document for mutex-reasons. !Note! Not implemented yet!


getSourceText

public java.lang.String getSourceText(org.w3c.dom.Document doc)
Accessor method.

Returns:
the source of the destination XML document as one String.

getSourceText

public java.lang.String getSourceText(org.w3c.dom.Document doc,
                                      boolean prettyPrinting)
Specified by:
getSourceText in interface XMLDocument
Parameters:
doc - the dom to convert
prettyPrinting - prettyprinting
Returns:
Transformed xml document in a string

getSourceEnumeration

public java.util.Enumeration getSourceEnumeration()
Accessor method.

Returns:
the source of the destination XML document as a Enumeration.

getSourceVector

public java.util.Vector getSourceVector()
Accessor method.

Specified by:
getSourceVector in interface XMLDocument
Returns:
the source of the destination XML document as a Vector.

getXMLVector

public java.util.Vector getXMLVector()
Accessor method.

Specified by:
getXMLVector in interface XMLDocument
Returns:
returns the source of the source XML document as a Vector.

getXSLVector

public java.util.Vector getXSLVector()
Accessor method.

Specified by:
getXSLVector in interface XMLDocument
Returns:
returns the source of XSL-stylesheet as a Vector.

getLink

public XLink getLink()
Accessor method.

Specified by:
getLink in interface XMLDocument
Returns:
the XLink object associated with the document.

getXMLURL

public java.net.URL getXMLURL()
Accessor method

Specified by:
getXMLURL in interface XMLDocument
Returns:
the URL of the source xml document

getXSLURL

public java.net.URL getXSLURL()
Accessor method

Specified by:
getXSLURL in interface XMLDocument
Returns:
the URL of the xsl document

getECMAScripter

public ECMAScripter getECMAScripter()
Specified by:
getECMAScripter in interface XMLDocument
Returns:
Instance of the ECMAScripter associated with this document

setPreferredStylesheetTitle

public void setPreferredStylesheetTitle(java.lang.String title)
Specified by:
setPreferredStylesheetTitle in interface XMLDocument
Parameters:
title - Sets the preferred stylesheet title.

deactivate

public void deactivate()
Specified by:
deactivate in interface XMLDocument

getBrowser

public BrowserWindow getBrowser()
Specified by:
getBrowser in interface XMLDocument


X-Smiles 1.2