/* Copyright 2005 The Apache Software Foundation or its licensors, as * applicable. * * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include "lcn_document.h" #include "document.hxx" #include "field.hxx" #include "../util/exception.h" using namespace org::apache::lucene::document; extern "C" { struct document_create_baton { lcn_document_t **d; apr_pool_t *pool; }; static void document_create_internal (void *b) { document_create_baton *dcb = static_cast(b); *dcb->d = static_cast(apr_pcalloc (dcb->pool, sizeof (*dcb->d))); (*dcb->d)->impl = new Document; } lcn_error_t * lcn_document_create (lcn_document_t **d, apr_pool_t *pool) { document_create_baton dcb; dcb.d = d; dcb.pool = pool; return lcn__swallow_exception (document_create_internal, &dcb); } struct document_add_field_baton { lcn_document_t *doc; lcn_field_t *field; }; static void document_add_field_internal (void *b) { document_add_field_baton *dafb = static_cast(b); dafb->doc->impl->add (dafb->field->impl); } lcn_error_t * lcn_document_add_field (lcn_document_t *doc, lcn_field_t *field) { document_add_field_baton dafb; dafb.doc = doc; dafb.field = field; return lcn__swallow_exception (document_add_field_internal, &dafb); } struct document_get_field_by_name_baton { lcn_field_t **field; lcn_document_t *doc; const char *fieldname; apr_pool_t *pool; }; static void document_get_field_by_name_internal (void *b) { document_get_field_by_name_baton *bat = static_cast(b); *bat->field = static_cast(apr_palloc (bat->pool, sizeof (lcn_field_t))); jstring fieldname = JvNewStringUTF (bat->fieldname); (*bat->field)->impl = bat->doc->impl->getField (fieldname); } lcn_error_t * lcn_document_get_field_by_name (lcn_field_t **field, lcn_document_t *doc, const char *fieldname, apr_pool_t *pool) { document_get_field_by_name_baton bat; bat.field = field; bat.doc = doc; bat.fieldname = fieldname; bat.pool = pool; lcn_error_t *err = lcn__swallow_exception (document_get_field_by_name_internal, &bat); if (! err && *bat.field == NULL) return lcn_error_create (LCN_ERR_NOT_FOUND, "field not found in document"); return err; } } // extern "C"