metaproxy  1.21.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
metaproxy_1::filter::Sort::Record Class Reference
Collaboration diagram for metaproxy_1::filter::Sort::Record:
Collaboration graph

Public Member Functions

 Record (Z_NamePlusRecord *n, const char *namespaces, const char *expr, bool debug)
 
 ~Record ()
 
bool operator< (const Record &rhs) const
 

Private Member Functions

void get_xpath (xmlDoc *doc, const char *namespaces, const char *expr, bool debug)
 
bool register_namespaces (xmlXPathContextPtr xpathCtx, const char *nsList)
 

Private Attributes

Z_NamePlusRecord * npr
 
std::string score
 

Friends

class RecordList
 

Detailed Description

Definition at line 61 of file filter_sort.cpp.

Constructor & Destructor Documentation

◆ Record()

mp::filter::Sort::Record::Record ( Z_NamePlusRecord *  n,
const char *  namespaces,
const char *  expr,
bool  debug 
)

Definition at line 261 of file filter_sort.cpp.

264  : npr(n)
265 {
266  if (npr->which == Z_NamePlusRecord_databaseRecord)
267  {
268  Z_External *ext = npr->u.databaseRecord;
269 
270  if (ext->which == Z_External_octet &&
271  !oid_oidcmp(ext->direct_reference, yaz_oid_recsyn_xml))
272  {
273  xmlDoc *doc = xmlParseMemory(
274  (const char *) ext->u.octet_aligned->buf,
275  ext->u.octet_aligned->len);
276  if (doc)
277  {
278  get_xpath(doc, namespaces, expr, debug);
279  xmlFreeDoc(doc);
280  }
281  }
282  }
283 }
void get_xpath(xmlDoc *doc, const char *namespaces, const char *expr, bool debug)

References get_xpath(), and npr.

Here is the call graph for this function:

◆ ~Record()

mp::filter::Sort::Record::~Record ( )

Definition at line 285 of file filter_sort.cpp.

286 {
287 }

Member Function Documentation

◆ get_xpath()

void mp::filter::Sort::Record::get_xpath ( xmlDoc *  doc,
const char *  namespaces,
const char *  expr,
bool  debug 
)
private

Definition at line 218 of file filter_sort.cpp.

220 {
221  xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
222  if (xpathCtx)
223  {
224  register_namespaces(xpathCtx, namespaces);
225  xmlXPathObjectPtr xpathObj =
226  xmlXPathEvalExpression((const xmlChar *) expr, xpathCtx);
227  if (xpathObj)
228  {
229  xmlNodeSetPtr nodes = xpathObj->nodesetval;
230  if (debug)
231  print_xpath_nodes(nodes, yaz_log_file());
232  if (nodes)
233  {
234  int i;
235  for (i = 0; i < nodes->nodeNr; i++)
236  {
237  std::string content;
238  xmlNode *ptr = nodes->nodeTab[i];
239  if (ptr->type == XML_ELEMENT_NODE ||
240  ptr->type == XML_ATTRIBUTE_NODE)
241  {
242  content = mp::xml::get_text(ptr->children);
243  }
244  else if (ptr->type == XML_TEXT_NODE)
245  {
246  content = mp::xml::get_text(ptr);
247  }
248  if (content.length())
249  {
250  score = content;
251  break;
252  }
253  }
254  }
255  xmlXPathFreeObject(xpathObj);
256  }
257  xmlXPathFreeContext(xpathCtx);
258  }
259 }
bool register_namespaces(xmlXPathContextPtr xpathCtx, const char *nsList)
static void print_xpath_nodes(xmlNodeSetPtr nodes, FILE *output)

References print_xpath_nodes().

Referenced by Record().

Here is the call graph for this function:

◆ operator<()

bool mp::filter::Sort::Record::operator< ( const Record rhs) const

Definition at line 289 of file filter_sort.cpp.

290 {
291  if (strcmp(this->score.c_str(), rhs.score.c_str()) < 0)
292  return true;
293  return false;
294 }

References score.

◆ register_namespaces()

bool mp::filter::Sort::Record::register_namespaces ( xmlXPathContextPtr  xpathCtx,
const char *  nsList 
)
private

Definition at line 164 of file filter_sort.cpp.

166 {
167  xmlChar* nsListDup;
168  xmlChar* prefix;
169  xmlChar* href;
170  xmlChar* next;
171 
172  assert(xpathCtx);
173  assert(nsList);
174 
175  nsListDup = xmlStrdup((const xmlChar *) nsList);
176  if (!nsListDup)
177  return false;
178 
179  next = nsListDup;
180  while (next)
181  {
182  /* skip spaces */
183  while (*next == ' ')
184  next++;
185  if (*next == '\0')
186  break;
187 
188  /* find prefix */
189  prefix = next;
190  next = (xmlChar *) xmlStrchr(next, '=');
191  if (next == NULL)
192  {
193  xmlFree(nsListDup);
194  return false;
195  }
196  *next++ = '\0';
197 
198  /* find href */
199  href = next;
200  next = (xmlChar*)xmlStrchr(next, ' ');
201  if (next)
202  *next++ = '\0';
203 
204  /* do register namespace */
205  if (xmlXPathRegisterNs(xpathCtx, prefix, href) != 0)
206  {
207  xmlFree(nsListDup);
208  return false;
209  }
210  }
211 
212  xmlFree(nsListDup);
213  return true;
214 }

Friends And Related Function Documentation

◆ RecordList

friend class RecordList
friend

Definition at line 62 of file filter_sort.cpp.

Member Data Documentation

◆ npr

Z_NamePlusRecord* metaproxy_1::filter::Sort::Record::npr
private

Definition at line 63 of file filter_sort.cpp.

Referenced by Record().

◆ score

std::string metaproxy_1::filter::Sort::Record::score
private

Definition at line 64 of file filter_sort.cpp.

Referenced by operator<().


The documentation for this class was generated from the following file: