gecko-dev/java/dom/jni/org_mozilla_dom_ProcessingInstructionImpl.cpp
1999-09-25 02:35:56 +00:00

129 lines
3.8 KiB
C++

/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems,
Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems,
Inc. All Rights Reserved.
*/
#include "prlog.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsDOMError.h"
#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) {
JavaDOMGlobals::ThrowException(env,
"ProcessingInstruction.getData: NULL pointer");
return NULL;
}
nsString ret;
nsresult rv = pi->GetData(ret);
if (NS_FAILED(rv)) {
JavaDOMGlobals::ThrowException(env,
"ProcessingInstruction.getData: failed", rv);
return NULL;
}
jstring jret = env->NewString(ret.GetUnicode(), ret.Length());
if (!jret) {
JavaDOMGlobals::ThrowException(env,
"ProcessingInstruction.getData: NewString failed");
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) {
JavaDOMGlobals::ThrowException(env,
"ProcessingInstruction.getTarget: NULL pointer");
return NULL;
}
nsString ret;
nsresult rv = pi->GetData(ret);
if (NS_FAILED(rv)) {
JavaDOMGlobals::ThrowException(env,
"ProcessingInstruction.getTarget: failed", rv);
return NULL;
}
jstring jret = env->NewString(ret.GetUnicode(), ret.Length());
if (!jret) {
JavaDOMGlobals::ThrowException(env,
"ProcessingInstruction.getTarget: NewString failed");
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);
if (!pi) {
JavaDOMGlobals::ThrowException(env,
"ProcessingInstruction.setData: NULL pointer");
return;
}
jboolean iscopy = JNI_FALSE;
const char* data = env->GetStringUTFChars(jdata, &iscopy);
if (!data) {
JavaDOMGlobals::ThrowException(env,
"ProcessingInstruction.setData: GetStringUTFChars failed");
return;
}
nsresult rv = pi->SetData(data);
if (iscopy == JNI_TRUE)
env->ReleaseStringUTFChars(jdata, data);
if (NS_FAILED(rv)) {
JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;
if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM &&
NS_ERROR_GET_CODE(rv) == NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR) {
exceptionType = JavaDOMGlobals::EXCEPTION_DOM;
}
JavaDOMGlobals::ThrowException(env,
"ProcessingInstruction.setData: failed", rv, exceptionType);
return;
}
}