~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to bindings/corba/orbitcpp/swordorb-impl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
ImportĀ upstreamĀ versionĀ 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "swordorb-impl.hpp"
 
2
#include <iostream>
 
3
#include <swmgr.h>
 
4
#include <versekey.h>
 
5
#include <treekeyidx.h>
 
6
#include <swbuf.h>
 
7
 
 
8
/*
 
9
char* swordorb::SWModule_impl::helloWorld(const char* greeting) throw(CORBA::SystemException) {
 
10
  std::cout << "Server: Greeting was \"" << greeting << "\"" << std::endl;
 
11
  return CORBA::string_dup("Hello client, from server!");
 
12
}
 
13
*/
 
14
 
 
15
using sword::VerseKey;
 
16
using sword::SWBuf;
 
17
using sword::TreeKeyIdx;
 
18
 
 
19
namespace swordorb {
 
20
 
 
21
sword::RawText NULLMod("/dev/null", SWNULL, SWNULL);
 
22
 
 
23
ModInfoList *SWMgr_impl::getModInfoList() throw(CORBA::SystemException) {
 
24
 
 
25
        ModInfoList *milist = new ModInfoList;
 
26
        sword::SWModule *module = 0;
 
27
        int size = 0;
 
28
        for (sword::ModMap::iterator it = delegate->Modules.begin(); it != delegate->Modules.end(); it++) {
 
29
                if ((!(it->second->getConfigEntry("CipherKey"))) || (*(it->second->getConfigEntry("CipherKey"))))
 
30
                        size++;
 
31
        }
 
32
        milist->length(size);
 
33
        int i = 0;
 
34
        for (sword::ModMap::iterator it = delegate->Modules.begin(); it != delegate->Modules.end(); it++) {
 
35
                module = it->second;
 
36
                if ((!(module->getConfigEntry("CipherKey"))) || (*(module->getConfigEntry("CipherKey")))) {
 
37
                        SWBuf type = module->Type();
 
38
                        SWBuf cat = module->getConfigEntry("Category");
 
39
                        if (cat.length() > 0)
 
40
                                type = cat;
 
41
                        (*milist)[i].name = CORBA::string_dup(module->Name());
 
42
                        (*milist)[i].description = CORBA::string_dup(module->Description());
 
43
                        (*milist)[i].category = CORBA::string_dup(type.c_str());
 
44
                        (*milist)[i++].language = CORBA::string_dup(module->Lang());
 
45
                }
 
46
        }
 
47
        return milist;
 
48
}
 
49
 
 
50
 
 
51
 
 
52
SWModule_ptr SWMgr_impl::getModuleByName(const char *name) throw(CORBA::SystemException) {
 
53
        SWModuleMap::iterator it;
 
54
        SWModule_ptr retVal;
 
55
        sword::SWModule *mod = delegate->Modules[name];
 
56
        it = moduleImpls.find((mod)?name:SWNULL);
 
57
        if (it == moduleImpls.end()) {
 
58
                moduleImpls[(mod)?name:SWNULL] = new SWModule_impl((mod)?mod:&NULLMod);
 
59
                it = moduleImpls.find((mod)?name:SWNULL);
 
60
        }
 
61
        if (it != moduleImpls.end()) {
 
62
                retVal = it->second->_this();
 
63
        }
 
64
        return ::swordorb::SWModule::_duplicate(retVal);
 
65
}
 
66
 
 
67
 
 
68
StringList *SWMgr_impl::getGlobalOptions() throw(CORBA::SystemException) {
 
69
        sword::StringList options = delegate->getGlobalOptions();
 
70
        StringList *retVal = new StringList;
 
71
        int count = 0;
 
72
        for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
 
73
                count++;
 
74
        }
 
75
        retVal->length(count);
 
76
        count = 0;
 
77
        for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
 
78
                (*retVal)[count++] = CORBA::string_dup(it->c_str());
 
79
        }
 
80
        return retVal;
 
81
}
 
82
 
 
83
 
 
84
StringList *SWMgr_impl::getGlobalOptionValues(const char *option) throw(CORBA::SystemException) {
 
85
        sword::StringList options = delegate->getGlobalOptionValues(option);
 
86
        StringList *retVal = new StringList;
 
87
        int count = 0;
 
88
        for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
 
89
                count++;
 
90
        }
 
91
        retVal->length(count);
 
92
        count = 0;
 
93
        for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) {
 
94
                (*retVal)[count++] = CORBA::string_dup(it->c_str());
 
95
        }
 
96
        return retVal;
 
97
}
 
98
 
 
99
void SWMgr_impl::terminate() throw(CORBA::SystemException) {
 
100
        exit(0);
 
101
}
 
102
 
 
103
 
 
104
CORBA::Boolean SWMgr_impl::testConnection() throw(CORBA::SystemException) {
 
105
        return true;
 
106
}
 
107
 
 
108
 
 
109
char *SWModule_impl::getCategory() throw(CORBA::SystemException) {
 
110
        SWBuf type = delegate->Type();
 
111
        SWBuf cat = delegate->getConfigEntry("Category");
 
112
        if (cat.length() > 0)
 
113
                type = cat;
 
114
        return CORBA::string_dup((char *)type.c_str());
 
115
}
 
116
 
 
117
 
 
118
SearchHitList *SWModule_impl::search(const char *istr, SearchType searchType, CORBA::Long flags, const char *scope) throw(CORBA::SystemException) {
 
119
        int stype = 2;
 
120
        sword::ListKey lscope;
 
121
        sword::VerseKey parser;
 
122
        if (searchType == REGEX) stype = 0;
 
123
        if (searchType == PHRASE) stype = -1;
 
124
        if (searchType == MULTIWORD) stype = -2;
 
125
        sword::ListKey result;
 
126
 
 
127
        if ((scope) && (strlen(scope)) > 0) {
 
128
                lscope = parser.ParseVerseList(scope, parser, true);
 
129
                result = delegate->Search(istr, stype, flags, &lscope);
 
130
        }
 
131
        else    result = delegate->Search(istr, stype, flags);
 
132
 
 
133
        SearchHitList *retVal = new SearchHitList;
 
134
        int count = 0;
 
135
        for (result = sword::TOP; !result.Error(); result++) count++;
 
136
        retVal->length(count);
 
137
        int i = 0;
 
138
        for (result = sword::TOP; !result.Error(); result++) {
 
139
                (*retVal)[i].modName = CORBA::string_dup(delegate->Name());
 
140
                (*retVal)[i].key = CORBA::string_dup((const char *)result);
 
141
                (*retVal)[i++].score = (long)result.getElement()->userData;
 
142
        }
 
143
 
 
144
        return retVal;
 
145
}
 
146
 
 
147
 
 
148
 
 
149
StringList *SWModule_impl::getEntryAttribute(const char *level1, const char *level2, const char *level3) throw(CORBA::SystemException) {
 
150
        delegate->RenderText(); // force parse
 
151
        sword::AttributeTypeList &entryAttribs = delegate->getEntryAttributes();
 
152
        sword::AttributeTypeList::iterator i1 = entryAttribs.find(level1);
 
153
        sword::AttributeList::iterator i2;
 
154
        sword::AttributeValue::iterator i3, j3;
 
155
        StringList *retVal = new StringList;
 
156
        int count = 0;
 
157
 
 
158
        if (i1 != entryAttribs.end()) {
 
159
                i2 = i1->second.find(level2);
 
160
                if (i2 != i1->second.end()) {
 
161
                        i3 = i2->second.find(level3);
 
162
                        if (i3 != i2->second.end()) {
 
163
                                for (j3 = i3; j3 != i2->second.end(); j3++)
 
164
                                        count++;
 
165
                                retVal->length(count);
 
166
                                count = 0;
 
167
                                for (j3 = i3; j3 != i2->second.end(); j3++) {
 
168
                                        (*retVal)[count++] = CORBA::string_dup(i3->second.c_str());
 
169
                                }
 
170
                        }
 
171
                }
 
172
        }
 
173
        if (!count)
 
174
                retVal->length(count);
 
175
 
 
176
        return retVal;
 
177
}
 
178
 
 
179
 
 
180
StringList *SWModule_impl::getKeyChildren() throw(CORBA::SystemException) {
 
181
        sword::SWKey *key = delegate->getKey();
 
182
        StringList *retVal = new StringList;
 
183
        int count = 0;
 
184
 
 
185
        sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
 
186
        if (vkey) {
 
187
                retVal->length(6);
 
188
                SWBuf num;
 
189
                num.appendFormatted("%d", vkey->Testament());
 
190
                (*retVal)[0] = CORBA::string_dup(num.c_str());
 
191
                num = "";
 
192
                num.appendFormatted("%d", vkey->Book());
 
193
                (*retVal)[1] = CORBA::string_dup(num.c_str());
 
194
                num = "";
 
195
                num.appendFormatted("%d", vkey->Chapter());
 
196
                (*retVal)[2] = CORBA::string_dup(num.c_str());
 
197
                num = "";
 
198
                num.appendFormatted("%d", vkey->Verse());
 
199
                (*retVal)[3] = CORBA::string_dup(num.c_str());
 
200
                num = "";
 
201
                num.appendFormatted("%d", vkey->books[vkey->Testament()-1][vkey->Book()-1].chapmax);
 
202
                (*retVal)[4] = CORBA::string_dup(num.c_str());
 
203
                num = "";
 
204
                num.appendFormatted("%d", vkey->books[vkey->Testament()-1][vkey->Book()-1].versemax[vkey->Chapter()-1]);
 
205
                (*retVal)[5] = CORBA::string_dup(num.c_str());
 
206
        }
 
207
        else {
 
208
                TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key);
 
209
                if (tkey) {
 
210
                        if (tkey->firstChild()) {
 
211
                                do {
 
212
                                        count++;
 
213
                                }
 
214
                                while (tkey->nextSibling());
 
215
                                tkey->parent();
 
216
                        }
 
217
                        retVal->length(count);
 
218
                        count = 0;
 
219
                        if (tkey->firstChild()) {
 
220
                                do {
 
221
                                        (*retVal)[count++] = CORBA::string_dup(tkey->getLocalName());
 
222
                                }
 
223
                                while (tkey->nextSibling());
 
224
                                tkey->parent();
 
225
                        }
 
226
                }
 
227
        }
 
228
        return retVal;
 
229
}
 
230
 
 
231
}