harvester/contentinfodb/src/ccontentinfodbparser.cpp
changeset 23 d4d56f5e7c55
equal deleted inserted replaced
20:556534771396 23:d4d56f5e7c55
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Implementation of xml parser for contentinfodb 
       
    15  *
       
    16  */
       
    17 #include "contentinfodbparser.h"
       
    18 #include <qdom.h>
       
    19 #include <qfile.h> 
       
    20 // ---------------------------------------------------------------------------
       
    21 // ContentInfoDbParser::ContentInfoDbParser()
       
    22 // ---------------------------------------------------------------------------
       
    23 //
       
    24 ContentInfoDbParser::ContentInfoDbParser()
       
    25     {
       
    26     }
       
    27 // ---------------------------------------------------------------------------
       
    28 // ContentInfoDbParser::~ContentInfoDbParser()
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 ContentInfoDbParser::~ContentInfoDbParser()
       
    32     {
       
    33 
       
    34     }
       
    35 // ---------------------------------------------------------------------------
       
    36 // ContentInfoDbParser::parse()
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 bool ContentInfoDbParser::parse(QString path)
       
    40     {
       
    41     QDomDocument doc;
       
    42     
       
    43     QFile file(path);    
       
    44     QMap<QString, QString> catDetails;
       
    45     QMap<QString, QString> uriDetails;
       
    46 
       
    47     if (!file.open(QFile::ReadOnly))
       
    48         return false;
       
    49     
       
    50     QByteArray array = file.readAll();
       
    51     
       
    52     if (!doc.setContent(array, true))
       
    53         {
       
    54         file.close();
       
    55         return false;
       
    56         }
       
    57     file.close();
       
    58     
       
    59     QDomElement docElem = doc.documentElement();
       
    60 
       
    61     QDomNode n = docElem.firstChild();
       
    62 
       
    63     /*
       
    64      * Sending the category details before the other details to prepare the table,
       
    65      * update of other details are not possible because the 'PRIMARYKEY' has to be there in db 
       
    66      */
       
    67     while (!n.isNull())
       
    68         {
       
    69         QDomElement e = n.toElement();
       
    70         if (!e.isNull())
       
    71             {
       
    72             catDetails.insert(e.tagName(), e.text());
       
    73             }
       
    74         n = n.nextSibling();
       
    75         }
       
    76     emit categoryDetails(catDetails);
       
    77 
       
    78     n = docElem.firstChild();// repositioning the node to get the other details
       
    79 
       
    80     while (!n.isNull())
       
    81         {
       
    82         QDomElement e = n.toElement(); // try to convert the node to an element.
       
    83         if (!e.isNull())
       
    84             {
       
    85             if (e.tagName() == TAGACTIONURI) // details of activity uri list
       
    86                 {
       
    87                 QDomNodeList uriNodeList = n.toElement().childNodes();
       
    88                 for (int i = 0; i < uriNodeList.count(); i++)
       
    89                     {
       
    90                     QDomNode uriNode = uriNodeList.item(i);
       
    91                     QDomNodeList uriItemsList =
       
    92                             uriNode.toElement().childNodes();
       
    93                     for (int i = 0; i < uriItemsList.count(); i++)
       
    94                         {
       
    95                         QDomNode uriitems = uriItemsList.item(i);
       
    96                         e = uriitems.toElement();
       
    97                         uriDetails.insert(e.tagName(), e.text());
       
    98                         }
       
    99                     emit actionUri(uriDetails);
       
   100                     }
       
   101                 }
       
   102             else if (e.tagName() == TAGFIELDMAP)// details of activity uri mapped with particular field
       
   103                 {
       
   104                 QDomNodeList uriNodeList = n.toElement().childNodes();
       
   105                 QString tagfield;
       
   106                 QStringList urilist;
       
   107                 for (int i = 0; i < uriNodeList.count(); i++)
       
   108                     {
       
   109                     QDomNode uriNode = uriNodeList.item(i);
       
   110                     QDomNodeList uriItemsList =
       
   111                             uriNode.toElement().childNodes();
       
   112                     tagfield = QString();
       
   113                     urilist.clear();
       
   114                     for (int i = 0; i < uriItemsList.count(); i++)
       
   115                         {
       
   116                         QDomNode uriitems = uriItemsList.item(i);
       
   117                         e = uriitems.toElement();
       
   118                         if (e.tagName() == TAGFIELD)
       
   119                             {
       
   120                             tagfield = e.text();
       
   121                             }
       
   122                         else if (e.tagName() == TAGAURI)
       
   123                             {
       
   124                             urilist.append(e.text());
       
   125                             }
       
   126                         }
       
   127                     emit filedMapping(tagfield, urilist);
       
   128                     }
       
   129                 }
       
   130             else if (e.tagName() == TAGRESULTFIRSTLINE) // details of what to show on firstline of result screen in search ui 
       
   131                 {
       
   132                 QDomNodeList uriNodeList = n.toElement().childNodes();
       
   133                 QStringList urilist;                
       
   134                 for (int i = 0; i < uriNodeList.count(); i++)
       
   135                     {
       
   136                     QDomNode uriNode = uriNodeList.item(i);
       
   137                     QDomNodeList uriItemsList =
       
   138                             uriNode.toElement().childNodes();
       
   139                     urilist.clear();
       
   140                     for (int i = 0; i < uriItemsList.count(); i++)
       
   141                         {
       
   142                         QDomNode uriitems = uriItemsList.item(i);
       
   143                         e = uriitems.toElement();
       
   144                         if (e.tagName() == TAGFIELD)
       
   145                             {
       
   146                             urilist.append(e.text());
       
   147                             }
       
   148                         }
       
   149                     emit firstLineMapping(urilist);
       
   150                     }
       
   151                 }
       
   152             else if (e.tagName() == TAGRELEVANCY) // boost factor details,   
       
   153                 {
       
   154                 QDomNodeList uriNodeList = n.toElement().childNodes();
       
   155                 QString field;
       
   156                 QString boostvalue;
       
   157                 for (int i = 0; i < uriNodeList.count(); i++)
       
   158                     {
       
   159                     QDomNode uriNode = uriNodeList.item(i);
       
   160                     QDomNodeList uriItemsList =
       
   161                             uriNode.toElement().childNodes();
       
   162                     field = QString();
       
   163                     boostvalue = QString();
       
   164                     for (int i = 0; i < uriItemsList.count(); i++)
       
   165                         {
       
   166                         QDomNode uriitems = uriItemsList.item(i);
       
   167                         e = uriitems.toElement();
       
   168                         if (e.tagName() == TAGFIELD)
       
   169                             {
       
   170                             field = e.text();
       
   171                             }
       
   172                         else if (e.tagName() == TAGBOOSTVALUE)
       
   173                             {
       
   174                             boostvalue = e.text();
       
   175                             }
       
   176                         }
       
   177                     emit relevancyMapping(field, boostvalue);
       
   178                     }
       
   179                 }
       
   180             }
       
   181         n = n.nextSibling();
       
   182         }
       
   183     return true;
       
   184     }