package textbender.o.rhinohide.core; // Copyright 2006-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 netscape.javascript.*; import org.w3c.dom.*; import org.w3c.dom.ranges.*; import org.w3c.dom.traversal.*; import org.w3c.dom.views.*; import textbender.g.lang.*; import textbender.o.rhinohide.*; import textbender.o.rhinohide.html.*; import textbender.o.rhinohide.ranges.*; import textbender.o.rhinohide.traversal.*; /** A document implemented as an overlay of a JavaScript document. * The orthodox way to obtain the document displayed by the browser * is RhiWindow.{@linkplain RhiWindow#getDocument getDocument}(). */ public @ThreadSafe class RhiDocument extends RhiNode implements Document, DocumentRange, DocumentTraversal, DocumentView { /** Constructs a RhiDocument. * * @param window global object * @param jsObject bridge to underlying JavaScript document, * per {@linkplain Rhinohide#jsObject() jsObject}() * * @return document, or null if jsObject is null * * @throws IllegalArgumentException if jsObject is neither null * nor a document */ public static RhiDocument wrapDocument( RhiWindow window, JSObject jsObject ) { return wrapDocument( window, jsObject, /*doTypeCheck*/true ); } static RhiDocument wrapDocument( RhiWindow window, JSObject jsObject, boolean doTypeCheck ) { if( jsObject == null ) return null; if( doTypeCheck ) ensureNodeType( new Rhinohide(window,jsObject), DOCUMENT_NODE ); RhiDocument document = new RhiDocument( window, jsObject ); if( document.getImplementation().hasFeature( "HTML", ""/*any version*/ )) // OPT to do make a direct JavaScript call via jsObject bridge, instead of creating document and other nodes { document = new RhiHTMLDocument( window, jsObject ); // on second thought } return document; } protected RhiDocument( RhiWindow window, JSObject jsObject ) { super( window, jsObject ); } // - D o c u m e n t ------------------------------------------------------------------ /** Not yet coded. * * @throws UnsupportedOperationException */ public final Node adoptNode( Node source ) { throw new UnsupportedOperationException(); } public final Attr createAttribute( String name ) { return RhiAttr.wrapAttr ( window, (JSObject)callV( "createAttribute", name ), /*doTypeCheck*/false, /*allowEmptyValue*/true ); //JSObject o = (JSObject)callV( "createAttribute", name ); //System.out.println( "RD o=" + o ); //return RhiAttr.wrapAttr( window, o, /*doTypeCheck*/false ); } /** Untested */ public final Attr createAttributeNS( String namespaceURI, String qualifiedName ) { return RhiAttr.wrapAttr ( window, (JSObject)callV( "createAttributeNS", namespaceURI, qualifiedName ), /*doTypeCheck*/false, /*allowEmptyValue*/true ); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final CDATASection createCDATASection( String data ) { throw new UnsupportedOperationException(); } public final Comment createComment( String data ) { return RhiComment.wrapComment ( window, (JSObject)callV( "createComment", data ), /*doTypeCheck*/false ); } public final DocumentFragment createDocumentFragment() { return RhiDocumentFragment.wrapDocumentFragment ( window, (JSObject)callV( "createDocumentFragment" ), /*doTypeCheck*/false ); } public final Element createElement( String tagName ) { return RhiElement.wrapElement ( window, (JSObject)callV( "createElement", tagName ), /*doTypeCheck*/false ); } public final Element createElementNS( String namespaceURI, String qualifiedName ) { return RhiElement.wrapElement ( window, (JSObject)callV( "createElementNS", namespaceURI, qualifiedName ), /*doTypeCheck*/false ); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final EntityReference createEntityReference( String name ) { throw new UnsupportedOperationException(); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final ProcessingInstruction createProcessingInstruction( String target, String data ) { throw new UnsupportedOperationException(); } public final Text createTextNode( String data ) { return RhiText.wrapText ( window, (JSObject)callV( "createTextNode", data ), /*doTypeCheck*/false ); } public final DocumentType getDoctype() { return RhiDocumentType.wrapDocumentType ( window, (JSObject)getMember( "doctype"), /*doTypeCheck*/false ); } public final Element getDocumentElement() { return RhiElement.wrapElement ( window, (JSObject)getMemberV( "documentElement" ), /*doTypeCheck*/false ); } /** Untested. */ public final String getDocumentURI() { return (String)getMember( "documentURI" ); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final void setDocumentURI( String documentURI ) { throw new UnsupportedOperationException(); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final DOMConfiguration getDomConfig() { throw new UnsupportedOperationException(); } public final Element getElementById( String elementId ) { return RhiElement.wrapElement ( window, (JSObject)call( "getElementById", elementId ), /*doTypeCheck*/false ); } public final NodeList getElementsByTagName( String name ) { return RhiNodeList.wrapNodeList ( window, (JSObject)call( "getElementsByTagName", name )); } /** Untested. */ public final NodeList getElementsByTagNameNS( String namespaceURI, String localName ) { return RhiNodeList.wrapNodeList ( window, (JSObject)call( "getElementsByTagNameNS", namespaceURI, localName )); } public final DOMImplementation getImplementation() { return RhiDOMImplementation.wrapDOMImplementation ( window, (JSObject)getMemberV( "implementation" )); } /** Untested. */ public final String getInputEncoding() { return (String)getMember( "inputEncoding" ); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final boolean getStrictErrorChecking() { throw new UnsupportedOperationException(); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final void setStrictErrorChecking( boolean strictErrorChecking ) { throw new UnsupportedOperationException(); } public final String getXmlEncoding() { return (String)getMember( "xmlEncoding"); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final boolean getXmlStandalone() { throw new UnsupportedOperationException(); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final void setXmlStandalone( boolean xmlStandalone ) { throw new UnsupportedOperationException(); } public final String getXmlVersion() { return (String)getMember( "xmlVersion"); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final void setXmlVersion( String xmlVersion ) { throw new UnsupportedOperationException(); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final Node importNode( Node importedNode, boolean deep ) { throw new UnsupportedOperationException(); } /** Untested. */ public final void normalizeDocument() { call( "normalizeDocument" ); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final Node renameNode( Node n, String namespaceURI, String qualifiedName ) { throw new UnsupportedOperationException(); } // - D o c u m e n t - R a n g e ------------------------------------------------------ public final Range createRange() { return RhiRange.wrapRange( window, (JSObject)callV( "createRange" )); } // - D o c u m e n t - T r a v e r s a l ---------------------------------------------- /** @throws UnsupportedOperationException because it's not yet implemented in browsers (Mozilla), so we haven't coded it yet */ public final NodeIterator createNodeIterator( Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion ) { throw new UnsupportedOperationException( "not yet implemented in browsers (Mozilla), so we haven't coded it yet" ); } /** @throws IllegalArgumentException if filter is not null, because we haven't coded that part yet */ public final TreeWalker createTreeWalker( Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion ) { if( filter != null ) throw new IllegalArgumentException( "only null filters allowed, because we haven't coded that part yet" ); return RhiTreeWalker.wrapTreeWalker ( window, (JSObject)callV ( "createTreeWalker" , toJSObject( (RhiNode)root ), whatToShow, filter, entityReferenceExpansion ) ); } // - D o c u m e n t - V i e w -------------------------------------------------------- /** Not yet coded. * * @throws UnsupportedOperationException */ public final AbstractView getDefaultView() { throw new UnsupportedOperationException(); } }