package textbender.a.r.page; // Copyright 2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.awt.*; import java.io.*; import java.net.*; import java.util.concurrent.atomic.*; import javax.swing.*; import org.w3c.dom.*; import textbender.a.r.desk.*; import textbender.g.lang.*; import textbender.g.net.*; import textbender.g.util.logging.*; import textbender.o.*; import textbender.o.rhinohide.*; import textbender.o.rhinohide._.*; import static textbender.o.xhtml.XHTML.XHTML_NAMESPACE; /** The page daemon's default boot applet. Injected into each page * by the boot script, this applet in turn injects * the {@linkplain ToolbarApplet toolbar applet}. * Normally, the toolbar applet would be injected * by a user script (Greasemonkey); but demo users have no such script set up. * And the page daemon must run from a local codebase, * otherwise its Java code is inaccessible to JavaScript of the local document * Owing to JavaScript 'same-origin' restrictions, access attempts * would be met with an exception like this, from the plug-in: *
* sun.plugin.liveconnect.OriginNotAllowedException: JavaScript is not from the same origin as the Java code, caller=file:, callee=http://reluk.ca/var/cache/textbender-demo/textbender.jar *
* Therefore, we resort to a flying trapeze act. * This boot applet makes RMI contact with the local desk daemon; * then injects the toolbar applet from the local codebase. * So (at least for local documents) we have bi-directional Java/JavaScript. */ @ThreadRestricted( "AWT event dispatch" ) public final class BootApplet extends JApplet { /** Constructs a BootApplet. */ public BootApplet() { // Box contentPane = new Box( BoxLayout.X_AXIS ); // contentPane.setOpaque( true ); // required, if only per JRootPane ///// not painting, I'm forgetting how to Swing... JPanel contentPane = new JPanel( /*layout*/null ); assert contentPane.isOpaque(); // required, if only per JRootPane // contentPane.setBackground( Color.getHSBColor( /*H*/0.0f, /*S*/0.0f, /*B*/0.9f )); // grey contentPane.setBorder // for contrast, to ensure visibility ( BorderFactory.createMatteBorder ( /*top*/0, /*left*/0, /*bottom*/2, /*right*/2, contentPane.getBackground().darker() ) ); setContentPane( contentPane ); // setFocusable( false ); } // - A p p l e t ---------------------------------------------------------------------- private final AtomicBoolean isStartedA = new AtomicBoolean(); public @ThreadSafe void start() { if( isStartedA.getAndSet( true )) return; // start once only LoggerX.i(getClass()).fine( "booting" ); try { final RhiWindow window = RhiWindow.createWindow( BootApplet.this ); try { final File file = resolveFile( window ); if( file != null ) // then indicate to user that page source is a local file: { JComponent contentPane = (JComponent)getContentPane(); contentPane.setBackground // FIX to read from style sheets, somehow ( Color.getHSBColor( /*H*/0.60f, /*S*/0.25f, /*B*/1.00f )); // bluish // ( Color.getHSBColor( /*H*/0.33f, /*S*/0.40f, /*B*/0.99f )); // green // ( Color.getHSBColor( /*H*/0.12f, /*S*/0.40f, /*B*/0.99f )); // orange // ( Color.WHITE ); } final Document document = window.getDocument(); // <* id='textbender-a-r-page-applet-parent'> // ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` final Element appletParent = document.getElementById ( "textbender-a-r-page-applet-parent" ); try { final HostServiceRegistry hostServiceRegistry = HostServiceRegistry.X.findRegistry(); // toolbar applet's PageVisit will also do this lookup, through Connections.refresh, but they cannot share the reference in any way, because the two applets have separate classloaders (Firefox 2, Plug-In 1.6) if( hostServiceRegistry == null ) { // appletParent.insertBefore // ( // document.createTextNode( "No running desk daemon,\nomitting page daemon.\n" ), // appletParent.getFirstChild() // ); appletParent.appendChild ( document.createTextNode( "\nNo running desk daemon,\nomitting page daemon." ) ); return; } final String localJarURI = hostServiceRegistry.allInOneJar().toURI().toASCIIString(); LoggerX.i(getClass()).finest( "resolved local JAR: " + localJarURI ); //