org.ceryle.util
Class ResourceOpener

java.lang.Object
  extended by java.lang.Thread
      extended by org.ceryle.util.ResourceOpener
All Implemented Interfaces:
Runnable, Constants

public class ResourceOpener
extends Thread
implements Constants

ResourceOpener extends java.lang.Thread to open files or documents via file or URL connections, provided a File, a URL object, or a command line with parameters. This is designed to resolve and open all URIs encountered within the application.

These are processed and fed into new or existing ViewFrames in the Ceryle Desktop, depending on the type of new content and the current front view type. In the case of content types that require external applications, these are opened when their content type is known (currently, only PDF is supported on unix/linux).

Note: Handling of MIME types not supported natively by Ceryle is done by external "Helper Applications" whose MIME types and application paths must be registered under Preferences.

Copyright 2001-2007 Murray Altheim. All Rights Reserved.
See LICENSE included with distribution.

Since:
JDK1.2
Version:
$Id: ResourceOpener.java,v 3.35 2007-06-20 01:28:32 altheim Exp $
Author:
Murray Altheim

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static int PROTOCOL_FILE
          A int indicating the HTTP protocol for files, "file".
static String PROTOCOL_FILE_STR
           
static int PROTOCOL_FRAGID
          A int indicating a relative URL reference (eg., "#id"; not strictly a protocol).
static int PROTOCOL_HTTP
          A int indicating the HTTP protocol for HTTP, "http".
static String PROTOCOL_HTTP_STR
           
static int PROTOCOL_UNKNOWN
          A int indicating an unknown protocol (-1).
static int PROTOCOL_URN
          A int indicating the HTTP protocol for URNs, "urn" (not strictly a protocol).
static String PROTOCOL_URN_STR
           
static int PROTOCOL_XNODE
          A int indicating the HTTP protocol for XNode, "xnode".
static String PROTOCOL_XNODE_STR
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface org.ceryle.util.Constants
Amp, AMP, Apos, APOS, APP_NAME, APP_VERSION_NAME, APP_VERSION_NUMBER, AT, BANG, BAR, BIT_dev, BIT_http, BIT_ignoreCom, BIT_merge, BIT_none, BIT_noPreload, BIT_simple, BIT_ui, BIT_unused1, BIT_unused2, BIT_unused3, BIT_validating, BIT_verbose, BIT_xcatalog, BIT_xlink, BIT_xmlnsAware, BIT_xsd, BROKB, BSlash, BSLASH, CERYLE_CREDITS_FILE, CERYLE_DATA_DIR, CERYLE_HIST_FILE, CERYLE_LICENSE_FILE, CERYLE_PREF_FILE, CERYLE_PROP, CERYLE_PROP_BASE, CERYLE_PROP_FILE, CERYLE_RSRC_DIR, CERYLE_THANKS_FILE, CFLEX, Colon, COLON, Comma, COMMA, CR, CRet, Dash, DASH, DEFAULT_DIRECTORY, DEVELOPER, DOLR, Dot, DOT, EIGHT, Ellip, EOF, EqQuot, EQUAL, Equals, False, FALSE, FileProt, Filesep, FileURL, Five, FIVE, FONTSIZES, Four, FOUR, FSchar, GCOL_PROP, GRAPH_PROP, GRAVE, GT, Hash, HASH, HOME_DIRECTORY, HOME_DIRECTORY_PATH, HOME_DIRECTORY_URL, HTML, HttpProt, HttpURL, INDENT, INDENT_0, INDENT_1, INDENT_10, INDENT_2, INDENT_3, INDENT_4, INDENT_5, INDENT_6, INDENT_7, INDENT_8, INDENT_9, INIT, LCURL, LCurly, LF, LFS, Localhost, LPAR, LParen, LS, LSBrkt, LSBrkt2, LSQB, LT, MT, NBSP, NEL, NINE, NL, NL20x, NLchar, No, Null, NULL, NULL_STATE, NumParams, One, ONE, Pathsep, Percent, PERO, PLUS, Prcnt, PS, QMark, QMARK, Quot, QUOT, RCURL, RCurly, RESOURCE_BUNDLE, RPAR, RParen, RSBrkt, RSBrkt2, RSQB, Semi, SEMI, SEVEN, SIX, Slash, SLASH, SP, SPACE, Stago, Star, STAR, Tab, TAB, Tee, Three, THREE, Tilde, TILDE, TM_PROP, True, TRUE, Two, TWO, Under, UNDER, URI, URL, VBar, WIKI_PROP, XNodePfx, XNodeURL, XtmExt, Yes, Zero, ZERO
 
Constructor Summary
ResourceOpener(File file, ViewFrame vf)
          Constructor provided a File.
ResourceOpener(String[] ids, ViewFrame vf)
          Constructor provided an array of Strings containing the Collection ID, Node ID, and fragment ID (resp.).
ResourceOpener(URL url, ViewFrame vf)
          Constructor provided a URL.
ResourceOpener(XNodeID xid, ViewFrame vf)
          Constructor provided an XNodeID indicating the Collection ID and Node ID.
 
Method Summary
 PlainDocument getDocument()
          Returns the PlainDocument opened, null if unavailable.
 MIME getMIMEtype()
          Returns the MIME type of the last document opened (or if this has been set), null if unavailable.
static String getProlog(XNode xnode, int method)
          Provided an XNode xnode with a content type of XML or XHTML, checks for DOCTYPE or other prolog stored properties, and returns a reconstruction to the document prolog.
static int getProtocol(String uriRef)
          A static method that returns the URL protocol as an int.
 String getResponse()
          Returns the http response of the last document opened, null if unavailable.
static int getScheme(URI uri)
          A static method that returns the URI scheme as an int.
 String getSystemId()
          Returns the system identifier of the last document opened, null if unavailable.
 XNode getXNode()
          Returns the XNode opened, null if unavailable.
protected  void initialize()
          Initialization upon construction of common member variables.
 PlainDocument openXNode(XNodeID xid, PlainDocument pdoc)
          Open the XNode indicated by the XNodeID xid.
 boolean processRequest(MIME mime, String systemId, File file)
          Processes the file request if a Helper Application for the system identifier and/or MIME type is available, returning true if it was handled.
 boolean processRequest(MIME mime, String systemId, URL url)
          Processes the URL request if a Helper Application for the system identifier and/or MIME type, returning true if it was handled.
 void run()
          Starts the thread by calling start().
 void setActionListener(ActionListener listener)
          Sets an ActionListener to listen for successful loading of the PlainDocument.
 void setActiveBrowser(boolean active)
          When set true, requests to load documents with recognized MIME types that have been registered for support by helper applications are sent off to load via those applications.
 void setDocument(PlainDocument doc)
          Returns the PlainDocument opened, null if unavailable.
 void setMIMEType(MIME type)
          Presets the MIME type in preparation for the document to be opened.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROTOCOL_UNKNOWN

public static final int PROTOCOL_UNKNOWN
A int indicating an unknown protocol (-1).

See Also:
Constant Field Values

PROTOCOL_HTTP

public static final int PROTOCOL_HTTP
A int indicating the HTTP protocol for HTTP, "http".

See Also:
Constant Field Values

PROTOCOL_FILE

public static final int PROTOCOL_FILE
A int indicating the HTTP protocol for files, "file".

See Also:
Constant Field Values

PROTOCOL_XNODE

public static final int PROTOCOL_XNODE
A int indicating the HTTP protocol for XNode, "xnode".

See Also:
Constant Field Values

PROTOCOL_URN

public static final int PROTOCOL_URN
A int indicating the HTTP protocol for URNs, "urn" (not strictly a protocol).

See Also:
Constant Field Values

PROTOCOL_FRAGID

public static final int PROTOCOL_FRAGID
A int indicating a relative URL reference (eg., "#id"; not strictly a protocol).

See Also:
Constant Field Values

PROTOCOL_HTTP_STR

public static final String PROTOCOL_HTTP_STR
See Also:
Constant Field Values

PROTOCOL_FILE_STR

public static final String PROTOCOL_FILE_STR
See Also:
Constant Field Values

PROTOCOL_XNODE_STR

public static final String PROTOCOL_XNODE_STR
See Also:
Constant Field Values

PROTOCOL_URN_STR

public static final String PROTOCOL_URN_STR
See Also:
Constant Field Values
Constructor Detail

ResourceOpener

public ResourceOpener(URL url,
                      ViewFrame vf)
Constructor provided a URL. If docview is non-null, opens the content into its editor, otherwise creates a new view.


ResourceOpener

public ResourceOpener(File file,
                      ViewFrame vf)
               throws MalformedURLException
Constructor provided a File. If docview is non-null, opens the content into its editor, otherwise creates a new view.

Throws:
MalformedURLException

ResourceOpener

public ResourceOpener(XNodeID xid,
                      ViewFrame vf)
               throws ProcessException
Constructor provided an XNodeID indicating the Collection ID and Node ID. If the ViewFrame vf is non-null, opens the content into it, otherwise creates a new view.

Throws:
ProcessException

ResourceOpener

public ResourceOpener(String[] ids,
                      ViewFrame vf)
               throws ProcessException
Constructor provided an array of Strings containing the Collection ID, Node ID, and fragment ID (resp.). If the ViewFrame vf is non-null, opens the content into it, otherwise creates a new view. This requires that the opened content can be opened into the specific view type. If this is not the case, opens a view that can handle it, ignoring the provided one.

Throws:
ProcessException
Method Detail

initialize

protected void initialize()
Initialization upon construction of common member variables.


setActiveBrowser

public void setActiveBrowser(boolean active)
When set true, requests to load documents with recognized MIME types that have been registered for support by helper applications are sent off to load via those applications.


run

public void run()
Starts the thread by calling start().

Specified by:
run in interface Runnable
Overrides:
run in class Thread

setMIMEType

public void setMIMEType(MIME type)
Presets the MIME type in preparation for the document to be opened. In the case where the MIME type has a bearing on what the ResourceOpener will do (such as PDF files), this needs to be set before the thread is started.


getMIMEtype

public MIME getMIMEtype()
Returns the MIME type of the last document opened (or if this has been set), null if unavailable. In the case of Files (vs. http URLs, where the content type is available), a guess can be made based on file name extension.


getSystemId

public String getSystemId()
Returns the system identifier of the last document opened, null if unavailable.


getResponse

public String getResponse()
Returns the http response of the last document opened, null if unavailable.


setActionListener

public void setActionListener(ActionListener listener)
Sets an ActionListener to listen for successful loading of the PlainDocument. When this listener is non-null, it will receive an actionPerformed() message upon loading the PlainDocument, and further processing will cease (such as opening up a frame). Only one listener may be set. To remove it, set it back to null.


getXNode

public XNode getXNode()
Returns the XNode opened, null if unavailable.


getDocument

public PlainDocument getDocument()
Returns the PlainDocument opened, null if unavailable.


setDocument

public void setDocument(PlainDocument doc)
Returns the PlainDocument opened, null if unavailable.


openXNode

public PlainDocument openXNode(XNodeID xid,
                               PlainDocument pdoc)
                        throws XNodeException,
                               ProcessException
Open the XNode indicated by the XNodeID xid. If for some reason this fails, writes error messages and returns null. Returns the resulting PlainDocument.

Throws:
XNodeException
ProcessException

processRequest

public boolean processRequest(MIME mime,
                              String systemId,
                              File file)
Processes the file request if a Helper Application for the system identifier and/or MIME type is available, returning true if it was handled.


processRequest

public boolean processRequest(MIME mime,
                              String systemId,
                              URL url)
Processes the URL request if a Helper Application for the system identifier and/or MIME type, returning true if it was handled. The system identifier is used solely to assist in determining the MIME type. Priority is given a lookup is done on the Helper Application list of file extensions, and if this doesn't provide a helper application path, the provided MIME is then tried in a secondary attempt to obtain a Helper Application. If neither of these work, the process fails and returns false.

If the provided helper application String includes "$FILE", assume that there are command line parameters and substitute the URL for "%1", otherwise append it to the end of the path.

E.g., a helper path of /usr/bin/acroread will create a command line of (where "file:/boo.pdf" is the provided URL):

    /usr/bin/acroread file:/boo.pdf
 
 whereas a helper path of /usr/bin/mozilla -remote "openURL(%1)"
 will create a command line of:
 
    /usr/bin/mozilla -remote "openURL(file:/boo.pdf)"
 


getProlog

public static String getProlog(XNode xnode,
                               int method)
Provided an XNode xnode with a content type of XML or XHTML, checks for DOCTYPE or other prolog stored properties, and returns a reconstruction to the document prolog. Note that this should not be called in conjunction with a serialized document that already has a prolog.


getProtocol

public static int getProtocol(String uriRef)
A static method that returns the URL protocol as an int. The protocols understood include the list defined in this class as PROTOCOL_*. If the protocol is unknown, returns PROTOCOL_UNKNOWN (-1).


getScheme

public static int getScheme(URI uri)
A static method that returns the URI scheme as an int. The scheme understood include the list defined in this class as PROTOCOL_*. If the protocol is unknown, returns PROTOCOL_UNKNOWN (-1). If the URI is a fragment ID reference (e.g., "#durrell"), returns PROTOCOL_FRAGID



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.