bug 79278

This checkin migrates javaDOM to use the new nsIWebProgressListener
interface, removing its dependency on the now non-existant
nsIDocumentLoaderObserver.

It has only been tested inside webclient.  QA needs to do the standalone
javaDOM tests.

The following files are in this bugfix:

dom/jni/org_mozilla_dom_DOMAccessor.cpp
dom/src/nsIJavaDOM.h
dom/src/nsJavaDOMImpl.cpp
dom/src/nsJavaDOMImpl.h
webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java
webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java


git-svn-id: svn://10.0.0.236/trunk@94264 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
edburns%acm.org 2001-05-08 20:34:31 +00:00
parent 687609c9ea
commit df9807ce08
6 changed files with 2259 additions and 2158 deletions

View File

@ -1,118 +1,138 @@
#include "prlog.h"
#include "javaDOMGlobals.h"
#include "nsIDocumentLoader.h"
#include "nsIDocumentLoaderObserver.h"
#include "nsIServiceManager.h"
#include "nsCURILoader.h"
#include "nsIJavaDOM.h"
#include "org_mozilla_dom_DOMAccessor.h"
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
static NS_DEFINE_IID(kJavaDOMCID, NS_JAVADOM_CID);
/*
* Class: org_mozilla_dom_DOMAccessor
* Method: register
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_register
(JNIEnv *env, jclass jthis)
{
if (!JavaDOMGlobals::log) {
JavaDOMGlobals::Initialize(env);
}
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsIDocumentLoader, docLoaderService, kDocLoaderServiceCID, &rv);
if (NS_FAILED(rv) || !docLoaderService) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::register: GetService(JavaDOM) failed: %x\n",
rv));
} else {
NS_WITH_SERVICE(nsIDocumentLoaderObserver, javaDOM, kJavaDOMCID, &rv);
if (NS_FAILED(rv) || !javaDOM) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::register: GetService(JavaDOM) failed: %x\n",
rv));
} else {
rv = docLoaderService->AddObserver((nsIDocumentLoaderObserver*)javaDOM);
if (NS_FAILED(rv)) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::register: AddObserver(JavaDOM) failed x\n",
rv));
}
}
}
}
/*
* Class: org_mozilla_dom_DOMAccessor
* Method: unregister
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_unregister
(JNIEnv *, jclass jthis)
{
PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG,
("DOMAccessor::unregister: unregistering %x\n", jthis));
nsresult rv = NS_OK;
NS_WITH_SERVICE(nsIDocumentLoader, docLoaderService, kDocLoaderServiceCID, &rv);
if (NS_FAILED(rv) || !docLoaderService) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::unregister: GetService(DocLoaderService) failed %x\n",
rv));
} else {
NS_WITH_SERVICE(nsIDocumentLoaderObserver, javaDOM, kJavaDOMCID, &rv);
if (NS_FAILED(rv) || !javaDOM) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::unregister: GetService(JavaDOM) failed %x\n",
rv));
} else {
rv = docLoaderService->RemoveObserver((nsIDocumentLoaderObserver*)javaDOM);
if (NS_FAILED(rv)) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::unregister: RemoveObserver(JavaDOM) failed x\n",
rv));
}
}
}
}
/*
* Class: org_mozilla_dom_DOMAccessor
* Method: createElement
* Signature: (J)Lorg/w3c/dom/Element;
*/
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DOMAccessor_getNodeByHandle
(JNIEnv *env, jclass jthis, jlong p)
{
if (!JavaDOMGlobals::log) {
JavaDOMGlobals::Initialize(env);
}
nsIDOMNode *node = (nsIDOMNode*)p;
return JavaDOMGlobals::CreateNodeSubtype(env, node);
}
/*
* Class: org_mozilla_dom_DOMAccessor
* Method: doGC
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_doGC
(JNIEnv *, jclass)
{
JavaDOMGlobals::TakeOutGarbage();
}
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_initialize
(JNIEnv *env, jclass)
{
if (!JavaDOMGlobals::log) {
JavaDOMGlobals::Initialize(env);
}
}
#include "prlog.h"
#include "javaDOMGlobals.h"
#include "nsIDocumentLoader.h"
#include "nsIWebProgress.h"
#include "nsIWebProgressListener.h"
#include "nsIServiceManager.h"
#include "nsCURILoader.h"
#include "nsIJavaDOM.h"
#include "org_mozilla_dom_DOMAccessor.h"
static NS_DEFINE_IID(kJavaDOMCID, NS_JAVADOM_CID);
/*
* Class: org_mozilla_dom_DOMAccessor
* Method: register
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_register
(JNIEnv *env, jclass jthis)
{
if (!JavaDOMGlobals::log) {
JavaDOMGlobals::Initialize(env);
}
nsresult rv = NS_OK;
nsCOMPtr<nsIDocumentLoader> docLoaderService =
do_GetService(NS_URI_LOADER_CONTRACTID, &rv);
nsCOMPtr<nsIWebProgress> webProgressService;
if (NS_FAILED(rv) || !docLoaderService) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::register: GetService(JavaDOM) failed: %x\n",
rv));
} else {
NS_WITH_SERVICE(nsIWebProgressListener, javaDOM, kJavaDOMCID, &rv);
if (NS_FAILED(rv) || !javaDOM) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::register: GetService(JavaDOM) failed: %x\n",
rv));
} else {
webProgressService = do_QueryInterface(docLoaderService, &rv);
if (NS_FAILED(rv) || !webProgressService) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::register: QueryInterface(nsIWebProgressService) failed: %x\n",
rv));
} else {
rv = webProgressService->AddProgressListener((nsIWebProgressListener*)javaDOM);
if (NS_FAILED(rv)) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::register: AddObserver(JavaDOM) failed x\n",
rv));
}
}
}
}
}
/*
* Class: org_mozilla_dom_DOMAccessor
* Method: unregister
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_unregister
(JNIEnv *, jclass jthis)
{
PR_LOG(JavaDOMGlobals::log, PR_LOG_DEBUG,
("DOMAccessor::unregister: unregistering %x\n", jthis));
nsresult rv = NS_OK;
nsCOMPtr<nsIDocumentLoader> docLoaderService =
do_GetService(NS_URI_LOADER_CONTRACTID, &rv);
nsCOMPtr<nsIWebProgress> webProgressService;
if (NS_FAILED(rv) || !docLoaderService) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::unregister: GetService(DocLoaderService) failed %x\n",
rv));
} else {
NS_WITH_SERVICE(nsIWebProgressListener, javaDOM, kJavaDOMCID, &rv);
if (NS_FAILED(rv) || !javaDOM) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::unregister: GetService(JavaDOM) failed %x\n",
rv));
} else {
webProgressService = do_QueryInterface(docLoaderService, &rv);
if (NS_FAILED(rv) || !webProgressService) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::unregister: QueryInterface(nsIWebProgressService) failed: %x\n",
rv));
} else {
rv = webProgressService->RemoveProgressListener((nsIWebProgressListener*)javaDOM);
if (NS_FAILED(rv)) {
PR_LOG(JavaDOMGlobals::log, PR_LOG_ERROR,
("DOMAccessor::unregister: RemoveObserver(JavaDOM) failed x\n",
rv));
}
}
}
}
}
/*
* Class: org_mozilla_dom_DOMAccessor
* Method: createElement
* Signature: (J)Lorg/w3c/dom/Element;
*/
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_DOMAccessor_getNodeByHandle
(JNIEnv *env, jclass jthis, jlong p)
{
if (!JavaDOMGlobals::log) {
JavaDOMGlobals::Initialize(env);
}
nsIDOMNode *node = (nsIDOMNode*)p;
return JavaDOMGlobals::CreateNodeSubtype(env, node);
}
/*
* Class: org_mozilla_dom_DOMAccessor
* Method: doGC
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_doGC
(JNIEnv *, jclass)
{
JavaDOMGlobals::TakeOutGarbage();
}
JNIEXPORT void JNICALL Java_org_mozilla_dom_DOMAccessor_initialize
(JNIEnv *env, jclass)
{
if (!JavaDOMGlobals::log) {
JavaDOMGlobals::Initialize(env);
}
}

View File

@ -1,75 +1,69 @@
/*
The contents of this file are subject to the Mozilla Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is mozilla.org code.
The Initial Developer of the Original Code is Sun Microsystems,
Inc. Portions created by Sun are
Copyright (C) 1999 Sun Microsystems, Inc. All
Rights Reserved.
Contributor(s):
*/
#ifndef __nsIJavaDOM_h__
#define __nsIJavaDOM_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIDocumentLoaderObserver.h"
#include "jni.h"
class nsIURI;
/* {9cc0ca50-0e31-11d3-8a61-0004ac56c4a5} */
#define NS_IJAVADOM_IID_STR "9cc0ca50-0e31-11d3-8a61-0004ac56c4a5"
#define NS_IJAVADOM_IID \
{0x9cc0ca50, 0x0e31, 0x11d3, \
{ 0x8a, 0x61, 0x00, 0x04, 0xac, 0x56, 0xc4, 0xa5 }}
#define NS_JAVADOM_CID \
{0xd6b2e820, 0x9113, 0x11d3, \
{ 0x9c, 0x11, 0x0, 0x10, 0x5a , 0xe3, 0x80 , 0x1e }}
class nsIJavaDOM : public nsIDocumentLoaderObserver {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJAVADOM_IID)
/* nsIDocumentLoaderObserver methods */
NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader,
nsIURI* aURL,
const char* aCommand) = 0;
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader,
nsIRequest* request,
nsresult aStatus) = 0;
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader,
nsIRequest* request) = 0;
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader,
nsIRequest* request,
PRUint32 aProgress,
PRUint32 aProgressMax) = 0;
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader,
nsIRequest* request,
nsString& aMsg) = 0;
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader,
nsIRequest* request,
nsresult aStatus) = 0;
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
nsIChannel* channel,
const char *aContentType,
const char *aCommand) = 0;
};
#endif /* __nsIJavaDOM_h__ */
/*
The contents of this file are subject to the Mozilla Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is mozilla.org code.
The Initial Developer of the Original Code is Sun Microsystems,
Inc. Portions created by Sun are
Copyright (C) 1999 Sun Microsystems, Inc. All
Rights Reserved.
Contributor(s):
*/
#ifndef __nsIJavaDOM_h__
#define __nsIJavaDOM_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIWebProgressListener.h"
#include "jni.h"
class nsIURI;
/* {9cc0ca50-0e31-11d3-8a61-0004ac56c4a5} */
#define NS_IJAVADOM_IID_STR "9cc0ca50-0e31-11d3-8a61-0004ac56c4a5"
#define NS_IJAVADOM_IID \
{0x9cc0ca50, 0x0e31, 0x11d3, \
{ 0x8a, 0x61, 0x00, 0x04, 0xac, 0x56, 0xc4, 0xa5 }}
#define NS_JAVADOM_CID \
{0xd6b2e820, 0x9113, 0x11d3, \
{ 0x9c, 0x11, 0x0, 0x10, 0x5a , 0xe3, 0x80 , 0x1e }}
class nsIJavaDOM : public nsIWebProgressListener {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJAVADOM_IID)
NS_IMETHOD OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest,
PRInt32 aStateFlags, PRUint32 aStatus) = 0;
NS_IMETHOD OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress) = 0;
NS_IMETHOD OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, nsIURI *location) = 0;
NS_IMETHOD OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest,
nsresult aStatus, const PRUnichar *aMessage) = 0;
NS_IMETHOD OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, PRInt32 state) = 0;
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
nsIChannel* channel,
const char *aContentType,
const char *aCommand) = 0;
};
#endif /* __nsIJavaDOM_h__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,77 +1,67 @@
#ifndef __nsJavaDOMImpl_h__
#define __nsJavaDOMImpl_h__
#include "jni.h"
#include "nsIJavaDOM.h"
#ifdef JAVA_DOM_OJI_ENABLE
#include "nsJVMManager.h"
#include "JavaDOMSecurityContext.h"
#endif
class nsIURI;
class nsIDOMDocument;
class nsIDocumentLoader;
class nsJavaDOMImpl : public nsIJavaDOM {
NS_DECL_ISUPPORTS
public:
nsJavaDOMImpl();
virtual ~nsJavaDOMImpl();
/* nsIDocumentLoaderObserver methods */
NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader,
nsIURI* aURL,
const char* aCommand);
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader,
nsIRequest* request,
nsresult aStatus);
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader,
nsIRequest* channel);
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader,
nsIRequest* request,
PRUint32 aProgress,
PRUint32 aProgressMax);
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader,
nsIRequest* request,
nsString& aMsg);
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader,
nsIRequest* request,
nsresult aStatus);
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
nsIChannel* channel,
const char *aContentType,
const char *aCommand);
private:
#ifdef JAVA_DOM_OJI_ENABLE
static nsJVMManager* jvmManager;
static JavaDOMSecurityContext* securityContext;
#else
static JavaVM* jvm;
#endif
static jclass domAccessorClass;
static jmethodID startURLLoadMID;
static jmethodID endURLLoadMID;
static jmethodID progressURLLoadMID;
static jmethodID statusURLLoadMID;
static jmethodID startDocumentLoadMID;
static jmethodID endDocumentLoadMID;
static JNIEnv* GetJNIEnv(void);
static void StartJVM(void);
static PRBool Init(JNIEnv**);
// cleanup after a JNI method invocation
static PRBool Cleanup(JNIEnv* env);
nsIDOMDocument* GetDocument(nsIDocumentLoader* loader);
};
#endif /* __nsJavaDOMImpl_h__ */
#ifndef __nsJavaDOMImpl_h__
#define __nsJavaDOMImpl_h__
#include "jni.h"
#include "nsIJavaDOM.h"
#ifdef JAVA_DOM_OJI_ENABLE
#include "nsJVMManager.h"
#include "JavaDOMSecurityContext.h"
#endif
class nsIURI;
class nsIDOMDocument;
class nsIDocumentLoader;
class nsJavaDOMImpl : public nsIJavaDOM {
NS_DECL_ISUPPORTS
public:
nsJavaDOMImpl();
virtual ~nsJavaDOMImpl();
NS_DECL_NSIWEBPROGRESSLISTENER
NS_IMETHOD HandleUnknownContentType(nsIDocumentLoader* loader,
nsIChannel* channel,
const char *aContentType,
const char *aCommand);
protected:
/**
* Called from our nsIWebProgressListener.OnStateChanged()
*/
NS_IMETHOD doStartDocumentLoad(const PRUnichar *documentName);
NS_IMETHOD doStartUrlLoad(const PRUnichar *documentName);
NS_IMETHOD doEndDocumentLoad(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, PRUint32 aStatus);
private:
#ifdef JAVA_DOM_OJI_ENABLE
static nsJVMManager* jvmManager;
static JavaDOMSecurityContext* securityContext;
#else
static JavaVM* jvm;
#endif
static jclass domAccessorClass;
static jmethodID startURLLoadMID;
static jmethodID endURLLoadMID;
static jmethodID progressURLLoadMID;
static jmethodID statusURLLoadMID;
static jmethodID startDocumentLoadMID;
static jmethodID endDocumentLoadMID;
static JNIEnv* GetJNIEnv(void);
static void StartJVM(void);
static PRBool Init(JNIEnv**);
// cleanup after a JNI method invocation
static PRBool Cleanup(JNIEnv* env);
nsIDOMDocument* GetDocument(nsIDocumentLoader* loader);
};
#endif /* __nsJavaDOMImpl_h__ */

View File

@ -1,277 +1,277 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
*/
package org.mozilla.webclient.wrapper_native;
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import org.mozilla.webclient.BrowserControl;
import org.mozilla.webclient.CurrentPage;
import org.mozilla.webclient.WindowControl;
import org.mozilla.webclient.WrapperFactory;
import java.util.Properties;
import java.io.*;
import java.net.*;
import org.w3c.dom.Document;
import org.mozilla.webclient.UnimplementedException;
import org.mozilla.dom.DOMAccessor;
public class CurrentPageImpl extends ImplObjectNative implements CurrentPage
{
//
// Protected Constants
//
//
// Class Variables
//
private static boolean domInitialized = false;
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public CurrentPageImpl(WrapperFactory yourFactory,
BrowserControl yourBrowserControl)
{
super(yourFactory, yourBrowserControl);
// force the class to be loaded, thus loading the JNI library
if (!domInitialized) {
// DOMAccessor.initialize();
}
}
//
// Class methods
//
//
// General Methods
//
//
// Methods from CurrentPage
//
public void copyCurrentSelectionToSystemClipboard()
{
myFactory.throwExceptionIfNotInitialized();
Assert.assert(-1 != nativeWebShell);
synchronized(myBrowserControl) {
nativeCopyCurrentSelectionToSystemClipboard(nativeWebShell);
}
}
public void findInPage(String stringToFind, boolean forward, boolean matchCase)
{
ParameterCheck.nonNull(stringToFind);
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
nativeFindInPage(nativeWebShell, stringToFind, forward, matchCase);
}
}
public void findNextInPage()
{
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
nativeFindNextInPage(nativeWebShell);
}
}
public String getCurrentURL()
{
String result = null;
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
result = nativeGetCurrentURL(nativeWebShell);
}
return result;
}
public Document getDOM()
{
Document result = nativeGetDOM(nativeWebShell);
return result;
}
public Properties getPageInfo()
{
Properties result = null;
/* synchronized(myBrowserControl) {
result = nativeGetPageInfo(nativeWebShell);
}
return result;
*/
throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::getPageInfo has not yet been implemented.\n");
}
public String getSource()
{
myFactory.throwExceptionIfNotInitialized();
String HTMLContent;
String currURL = getCurrentURL();
System.out.println("\nThe Current URL is -- " + currURL);
try {
URL aURL = new URL(currURL);
URLConnection connection = aURL.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
boolean more = true;
while (more)
{
String line = in.readLine();
if (line == null) more = false;
else
{
HTMLContent = HTMLContent + line;
}
}
}
catch (Throwable e)
{
System.out.println("Error occurred while establishing connection -- \n ERROR - " + e);
}
return HTMLContent;
}
public byte [] getSourceBytes()
{
byte [] result = null;
myFactory.throwExceptionIfNotInitialized();
String HTMLContent;
String currURL = getCurrentURL();
System.out.println("\nThe Current URL is -- " + currURL);
try {
URL aURL = new URL(currURL);
URLConnection connection = aURL.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
boolean more = true;
while (more)
{
String line = in.readLine();
if (line == null) more = false;
else
{
HTMLContent = HTMLContent + line;
}
}
}
catch (Throwable e)
{
System.out.println("Error occurred while establishing connection -- \n ERROR - " + e);
}
result = HTMLContent.getBytes();
return result;
}
public void resetFind()
{
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
nativeResetFind(nativeWebShell);
}
}
public void selectAll()
{
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
nativeSelectAll(nativeWebShell);
}
}
//
// Native methods
//
native public void nativeCopyCurrentSelectionToSystemClipboard(int webShellPtr);
native public void nativeFindInPage(int webShellPtr, String stringToFind, boolean forward, boolean matchCase);
native public void nativeFindNextInPage(int webShellPtr);
native public String nativeGetCurrentURL(int webShellPtr);
native public Document nativeGetDOM(int webShellPtr);
// webclient.PageInfo getPageInfo();
/* PENDING(ashuk): remove this from here and in the motif directory
* native public String nativeGetSource();
* native public byte [] nativeGetSourceBytes(int webShellPtr, boolean viewMode);
*/
native public void nativeResetFind(int webShellPtr);
native public void nativeSelectAll(int webShellPtr);
// ----VERTIGO_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
Log.setApplicationName("CurrentPageImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.13 2001-05-08 16:58:36 ashuk%eng.sun.com Exp $");
}
// ----VERTIGO_TEST_END
} // end of class CurrentPageImpl
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
*/
package org.mozilla.webclient.wrapper_native;
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import org.mozilla.webclient.BrowserControl;
import org.mozilla.webclient.CurrentPage;
import org.mozilla.webclient.WindowControl;
import org.mozilla.webclient.WrapperFactory;
import java.util.Properties;
import java.io.*;
import java.net.*;
import org.w3c.dom.Document;
import org.mozilla.webclient.UnimplementedException;
import org.mozilla.dom.DOMAccessor;
public class CurrentPageImpl extends ImplObjectNative implements CurrentPage
{
//
// Protected Constants
//
//
// Class Variables
//
private static boolean domInitialized = false;
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public CurrentPageImpl(WrapperFactory yourFactory,
BrowserControl yourBrowserControl)
{
super(yourFactory, yourBrowserControl);
// force the class to be loaded, thus loading the JNI library
if (!domInitialized) {
DOMAccessor.initialize();
}
}
//
// Class methods
//
//
// General Methods
//
//
// Methods from CurrentPage
//
public void copyCurrentSelectionToSystemClipboard()
{
myFactory.throwExceptionIfNotInitialized();
Assert.assert(-1 != nativeWebShell);
synchronized(myBrowserControl) {
nativeCopyCurrentSelectionToSystemClipboard(nativeWebShell);
}
}
public void findInPage(String stringToFind, boolean forward, boolean matchCase)
{
ParameterCheck.nonNull(stringToFind);
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
nativeFindInPage(nativeWebShell, stringToFind, forward, matchCase);
}
}
public void findNextInPage()
{
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
nativeFindNextInPage(nativeWebShell);
}
}
public String getCurrentURL()
{
String result = null;
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
result = nativeGetCurrentURL(nativeWebShell);
}
return result;
}
public Document getDOM()
{
Document result = nativeGetDOM(nativeWebShell);
return result;
}
public Properties getPageInfo()
{
Properties result = null;
/* synchronized(myBrowserControl) {
result = nativeGetPageInfo(nativeWebShell);
}
return result;
*/
throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::getPageInfo has not yet been implemented.\n");
}
public String getSource()
{
myFactory.throwExceptionIfNotInitialized();
String HTMLContent;
String currURL = getCurrentURL();
System.out.println("\nThe Current URL is -- " + currURL);
try {
URL aURL = new URL(currURL);
URLConnection connection = aURL.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
boolean more = true;
while (more)
{
String line = in.readLine();
if (line == null) more = false;
else
{
HTMLContent = HTMLContent + line;
}
}
}
catch (Throwable e)
{
System.out.println("Error occurred while establishing connection -- \n ERROR - " + e);
}
return HTMLContent;
}
public byte [] getSourceBytes()
{
byte [] result = null;
myFactory.throwExceptionIfNotInitialized();
String HTMLContent;
String currURL = getCurrentURL();
System.out.println("\nThe Current URL is -- " + currURL);
try {
URL aURL = new URL(currURL);
URLConnection connection = aURL.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
boolean more = true;
while (more)
{
String line = in.readLine();
if (line == null) more = false;
else
{
HTMLContent = HTMLContent + line;
}
}
}
catch (Throwable e)
{
System.out.println("Error occurred while establishing connection -- \n ERROR - " + e);
}
result = HTMLContent.getBytes();
return result;
}
public void resetFind()
{
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
nativeResetFind(nativeWebShell);
}
}
public void selectAll()
{
myFactory.throwExceptionIfNotInitialized();
synchronized(myBrowserControl) {
nativeSelectAll(nativeWebShell);
}
}
//
// Native methods
//
native public void nativeCopyCurrentSelectionToSystemClipboard(int webShellPtr);
native public void nativeFindInPage(int webShellPtr, String stringToFind, boolean forward, boolean matchCase);
native public void nativeFindNextInPage(int webShellPtr);
native public String nativeGetCurrentURL(int webShellPtr);
native public Document nativeGetDOM(int webShellPtr);
// webclient.PageInfo getPageInfo();
/* PENDING(ashuk): remove this from here and in the motif directory
* native public String nativeGetSource();
* native public byte [] nativeGetSourceBytes(int webShellPtr, boolean viewMode);
*/
native public void nativeResetFind(int webShellPtr);
native public void nativeSelectAll(int webShellPtr);
// ----VERTIGO_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
Log.setApplicationName("CurrentPageImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.14 2001-05-08 20:34:31 edburns%acm.org Exp $");
}
// ----VERTIGO_TEST_END
} // end of class CurrentPageImpl