1999-08-06 00:28:53 +00:00
|
|
|
/*
|
1999-11-06 02:47:15 +00:00
|
|
|
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/
|
1999-08-06 00:28:53 +00:00
|
|
|
|
1999-11-06 02:47:15 +00:00
|
|
|
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.
|
1999-08-06 00:28:53 +00:00
|
|
|
|
1999-11-06 02:47:15 +00:00
|
|
|
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):
|
1999-08-06 00:28:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "nsIDOMProcessingInstruction.h"
|
1999-09-25 02:35:56 +00:00
|
|
|
#include "nsDOMError.h"
|
1999-08-06 00:28:53 +00:00
|
|
|
#include "javaDOMGlobals.h"
|
|
|
|
#include "org_mozilla_dom_ProcessingInstructionImpl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_mozilla_dom_ProcessingInstructionImpl
|
|
|
|
* Method: getData
|
|
|
|
* Signature: ()Ljava/lang/String;
|
|
|
|
*/
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_getData
|
|
|
|
(JNIEnv *env, jobject jthis)
|
|
|
|
{
|
|
|
|
nsIDOMProcessingInstruction* pi = (nsIDOMProcessingInstruction*)
|
|
|
|
env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);
|
|
|
|
if (!pi) {
|
1999-09-25 02:35:56 +00:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"ProcessingInstruction.getData: NULL pointer");
|
1999-08-06 00:28:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString ret;
|
|
|
|
nsresult rv = pi->GetData(ret);
|
|
|
|
if (NS_FAILED(rv)) {
|
1999-09-25 02:35:56 +00:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"ProcessingInstruction.getData: failed", rv);
|
1999-08-06 00:28:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-09-14 21:25:47 +00:00
|
|
|
jstring jret = env->NewString(ret.GetUnicode(), ret.Length());
|
1999-08-06 00:28:53 +00:00
|
|
|
if (!jret) {
|
1999-09-25 02:35:56 +00:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"ProcessingInstruction.getData: NewString failed");
|
1999-08-06 00:28:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_mozilla_dom_ProcessingInstructionImpl
|
|
|
|
* Method: getTarget
|
|
|
|
* Signature: ()Ljava/lang/String;
|
|
|
|
*/
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_getTarget
|
|
|
|
(JNIEnv *env, jobject jthis)
|
|
|
|
{
|
|
|
|
nsIDOMProcessingInstruction* pi = (nsIDOMProcessingInstruction*)
|
|
|
|
env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);
|
|
|
|
if (!pi) {
|
1999-09-25 02:35:56 +00:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"ProcessingInstruction.getTarget: NULL pointer");
|
1999-08-06 00:28:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString ret;
|
1999-10-30 02:14:28 +00:00
|
|
|
nsresult rv = pi->GetTarget(ret);
|
1999-08-06 00:28:53 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-09-25 02:35:56 +00:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"ProcessingInstruction.getTarget: failed", rv);
|
1999-08-06 00:28:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-09-14 21:25:47 +00:00
|
|
|
jstring jret = env->NewString(ret.GetUnicode(), ret.Length());
|
1999-08-06 00:28:53 +00:00
|
|
|
if (!jret) {
|
1999-09-25 02:35:56 +00:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"ProcessingInstruction.getTarget: NewString failed");
|
1999-08-06 00:28:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_mozilla_dom_ProcessingInstructionImpl
|
|
|
|
* Method: setData
|
|
|
|
* Signature: (Ljava/lang/String;)V
|
|
|
|
*/
|
|
|
|
JNIEXPORT void JNICALL Java_org_mozilla_dom_ProcessingInstructionImpl_setData
|
|
|
|
(JNIEnv *env, jobject jthis, jstring jdata)
|
|
|
|
{
|
|
|
|
nsIDOMProcessingInstruction* pi = (nsIDOMProcessingInstruction*)
|
|
|
|
env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);
|
2000-02-11 07:58:12 +00:00
|
|
|
if (!pi || !jdata) {
|
1999-09-25 02:35:56 +00:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"ProcessingInstruction.setData: NULL pointer");
|
1999-08-06 00:28:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-13 21:22:35 +00:00
|
|
|
nsString* data = JavaDOMGlobals::GetUnicode(env, jdata);
|
|
|
|
if (!data)
|
2000-02-11 07:58:12 +00:00
|
|
|
return;
|
1999-10-30 02:14:28 +00:00
|
|
|
|
2000-06-13 21:22:35 +00:00
|
|
|
nsresult rv = pi->SetData(*data);
|
|
|
|
nsString::Recycle(data);
|
2000-06-05 18:08:39 +00:00
|
|
|
|
1999-08-06 00:28:53 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-09-25 02:35:56 +00:00
|
|
|
JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;
|
2000-02-10 01:13:57 +00:00
|
|
|
if (rv == NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR) {
|
1999-09-25 02:35:56 +00:00
|
|
|
exceptionType = JavaDOMGlobals::EXCEPTION_DOM;
|
|
|
|
}
|
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"ProcessingInstruction.setData: failed", rv, exceptionType);
|
1999-08-06 00:28:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|