1999-08-06 04:28:53 +04:00
|
|
|
/*
|
1999-11-06 05:47:15 +03: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/
|
|
|
|
|
|
|
|
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):
|
1999-08-06 04:28:53 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "nsIDOMText.h"
|
1999-09-25 06:35:56 +04:00
|
|
|
#include "nsDOMError.h"
|
1999-08-06 04:28:53 +04:00
|
|
|
#include "javaDOMGlobals.h"
|
|
|
|
#include "org_mozilla_dom_TextImpl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_mozilla_dom_TextImpl
|
|
|
|
* Method: splitText
|
|
|
|
* Signature: (I)Lorg/w3c/dom/Text;
|
|
|
|
*/
|
|
|
|
JNIEXPORT jobject JNICALL Java_org_mozilla_dom_TextImpl_splitText
|
|
|
|
(JNIEnv *env, jobject jthis, jint joffset)
|
|
|
|
{
|
1999-10-16 01:25:56 +04:00
|
|
|
if (joffset < 0 || joffset > JavaDOMGlobals::javaMaxInt) {
|
2000-02-10 04:13:57 +03:00
|
|
|
JavaDOMGlobals::ThrowException(env, "Text.splitText: failed",
|
1999-10-16 01:25:56 +04:00
|
|
|
NS_ERROR_DOM_INDEX_SIZE_ERR,
|
|
|
|
JavaDOMGlobals::EXCEPTION_DOM);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-08-06 04:28:53 +04:00
|
|
|
nsIDOMText* text = (nsIDOMText*)
|
|
|
|
env->GetLongField(jthis, JavaDOMGlobals::nodePtrFID);
|
|
|
|
if (!text) {
|
1999-09-25 06:35:56 +04:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"Text.splitText: NULL pointer");
|
1999-08-06 04:28:53 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMText* ret = nsnull;
|
|
|
|
nsresult rv = text->SplitText((PRUint32) joffset, &ret);
|
|
|
|
if (NS_FAILED(rv) || !ret) {
|
1999-09-25 06:35:56 +04:00
|
|
|
JavaDOMGlobals::ExceptionType exceptionType = JavaDOMGlobals::EXCEPTION_RUNTIME;
|
|
|
|
if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM &&
|
2000-02-10 04:13:57 +03:00
|
|
|
(rv == NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR ||
|
|
|
|
rv == NS_ERROR_DOM_INDEX_SIZE_ERR)) {
|
1999-09-25 06:35:56 +04:00
|
|
|
exceptionType = JavaDOMGlobals::EXCEPTION_DOM;
|
|
|
|
}
|
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"Text.splitText: failed", rv, exceptionType);
|
1999-08-06 04:28:53 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jret = env->AllocObject(JavaDOMGlobals::textClass);
|
|
|
|
if (!jret) {
|
1999-09-25 06:35:56 +04:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"Text.splitText: failed to allocate object");
|
1999-08-06 04:28:53 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->SetLongField(jret, JavaDOMGlobals::nodePtrFID, (jlong) ret);
|
|
|
|
if (env->ExceptionOccurred()) {
|
1999-09-25 06:35:56 +04:00
|
|
|
JavaDOMGlobals::ThrowException(env,
|
|
|
|
"Text.splitText: failed to set node ptr");
|
1999-08-06 04:28:53 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->AddRef();
|
|
|
|
return jret;
|
|
|
|
}
|