Subversion Repositories tpanel

Rev

Rev 65 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 65 Rev 78
Line 16... Line 16...
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
17
 */
18
 
18
 
19
#include <string>
19
#include <string>
20
#include "tpagelist.h"
20
#include "tpagelist.h"
21
#include "treadxml.h"
21
#include "texpat++.h"
22
#include "tconfig.h"
22
#include "tconfig.h"
23
#include "terror.h"
23
#include "terror.h"
24
 
24
 
25
using std::string;
25
using std::string;
26
using std::vector;
26
using std::vector;
-
 
27
using namespace Expat;
27
 
28
 
28
TPageList::TPageList()
29
TPageList::TPageList()
29
{
30
{
30
    DECL_TRACER("TPageList::TPageList()");
31
    DECL_TRACER("TPageList::TPageList()");
31
    mProject = makeFileName(TConfig::getProjectPath(), "prj.xma");
32
    mProject = makeFileName(TConfig::getProjectPath(), "prj.xma");
Line 59... Line 60...
59
        TError::setErrorMsg("Empty or invalid project file! <" + mProject + ">");
60
        TError::setErrorMsg("Empty or invalid project file! <" + mProject + ">");
60
        MSG_ERROR(TError::getErrorMsg());
61
        MSG_ERROR(TError::getErrorMsg());
61
        return;
62
        return;
62
    }
63
    }
63
 
64
 
64
    TReadXML reader(mProject);
65
    TExpat xml(mProject);
-
 
66
    xml.setEncoding(ENC_CP1250);
65
 
67
 
66
    if (TError::isError())
68
    if (!xml.parse())
67
    {
-
 
68
        MSG_DEBUG("Stopped scanning the page list due to previous errors!");
-
 
69
        return;
69
        return;
70
    }
-
 
71
 
70
 
72
    string value = reader.findElement("pageList", "type");
71
    int depth = 0;
73
    string attribute = reader.getAttribute();
72
    size_t index = 0;
74
 
73
 
75
    if (attribute.empty())
-
 
76
    {
-
 
77
        TError::setErrorMsg("Missing element \"pageList\" in file " + mProject);
74
    if ((index = xml.getElementIndex("pageList", &depth)) == TExpat::npos)
78
        MSG_ERROR(TError::getErrorMsg());
-
 
79
        return;
-
 
80
    }
-
 
81
    else if (attribute.compare("page") != 0 && attribute.compare("subpage") != 0)
-
 
82
    {
75
    {
83
        TError::setErrorMsg("Invalid page type " + attribute + " found!");
76
        MSG_ERROR("Couldn't find the section \"pageList\" in file!");
84
        MSG_ERROR(TError::getErrorMsg());
77
        TError::setError();
85
        return;
78
        return;
86
    }
79
    }
87
 
80
 
88
    while (!attribute.empty())
81
    do
89
    {
82
    {
90
        mxml_node_t *nodeFirst = reader.getFirstChild();
83
        vector<ATTRIBUTE_t> attrs = xml.getAttributes();
-
 
84
        string attribute = xml.getAttribute("type", attrs);
-
 
85
 
-
 
86
        if (attribute.empty())
-
 
87
        {
-
 
88
            TError::setErrorMsg("Missing element \"pageList\" in file " + mProject);
-
 
89
            MSG_ERROR(TError::getErrorMsg());
-
 
90
            return;
-
 
91
        }
-
 
92
        else if (attribute.compare("page") != 0 && attribute.compare("subpage") != 0)
-
 
93
        {
-
 
94
            TError::setErrorMsg("Invalid page type " + attribute + " found!");
-
 
95
            MSG_ERROR(TError::getErrorMsg());
91
        mxml_node_t *n = nodeFirst;
96
            return;
-
 
97
        }
92
 
98
 
93
        while (n)
99
        while ((index = xml.getNextElementIndex("pageEntry", depth+1)) != TExpat::npos)
94
        {
100
        {
95
            mxml_node_t *item = reader.getFirstChild(n);
-
 
96
            PAGELIST_T pl;
101
            PAGELIST_T pl;
97
            SUBPAGELIST_T spl;
102
            SUBPAGELIST_T spl;
98
 
103
 
99
            pl.clear();
104
            pl.clear();
100
            spl.clear();
105
            spl.clear();
-
 
106
            string e, content;
101
 
107
 
102
            while (item)
108
            while ((index = xml.getNextElementFromIndex(index, &e, &content, nullptr)) != TExpat::npos)
103
            {
109
            {
104
                string e = reader.getElementName(item);
-
 
105
 
-
 
106
                if (attribute.compare("page") == 0)
110
                if (attribute.compare("page") == 0)
107
                {
111
                {
108
                    if (e.compare("name") == 0)
112
                    if (e.compare("name") == 0)
109
                        pl.name = reader.getTextFromNode(item);
113
                        pl.name = content;
110
                    else if (e.compare("pageID") == 0)
114
                    else if (e.compare("pageID") == 0)
111
                        pl.pageID = reader.getIntFromNode(item);
115
                        pl.pageID = xml.convertElementToInt(content);
112
                    else if (e.compare("file") == 0)
116
                    else if (e.compare("file") == 0)
113
                        pl.file = reader.getTextFromNode(item);
117
                        pl.file = content;
114
                    else if (e.compare("isValid") == 0)
118
                    else if (e.compare("isValid") == 0)
115
                        pl.isValid = reader.getIntFromNode(item);
119
                        pl.isValid = xml.convertElementToInt(content);
116
                }
120
                }
117
                else if (attribute.compare("subpage") == 0)
121
                else if (attribute.compare("subpage") == 0)
118
                {
122
                {
119
                    if (e.compare("name") == 0)
123
                    if (e.compare("name") == 0)
120
                        spl.name = reader.getTextFromNode(item);
124
                        spl.name = content;
121
                    else if (e.compare("pageID") == 0)
125
                    else if (e.compare("pageID") == 0)
122
                        spl.pageID = reader.getIntFromNode(item);
126
                        spl.pageID = xml.convertElementToInt(content);
123
                    else if (e.compare("file") == 0)
127
                    else if (e.compare("file") == 0)
124
                        spl.file = reader.getTextFromNode(item);
128
                        spl.file = content;
125
                    else if (e.compare("group") == 0)
129
                    else if (e.compare("group") == 0)
126
                        spl.group = reader.getTextFromNode(item);
130
                        spl.group = content;
127
                    else if (e.compare("isValid") == 0)
131
                    else if (e.compare("isValid") == 0)
128
                        spl.isValid = reader.getIntFromNode(item);
132
                        spl.isValid = xml.convertElementToInt(content);
129
                    else if (e.compare("popupType") == 0)
133
                    else if (e.compare("popupType") == 0)
130
                        spl.popupType = reader.getIntFromNode(item);
134
                        spl.popupType = xml.convertElementToInt(content);
131
                }
135
                }
132
 
-
 
133
                item = reader.getNextChild(item);
-
 
134
            }
136
            }
135
 
137
 
136
            if (attribute.compare("page") == 0)
138
            if (attribute.compare("page") == 0)
137
            {
139
            {
138
                MSG_TRACE("Added page " << pl.pageID << ", " << pl.name << " to page list.");
140
                MSG_TRACE("Added page " << pl.pageID << ", " << pl.name << " to page list.");
Line 141... Line 143...
141
            else if (attribute.compare("subpage") == 0)
143
            else if (attribute.compare("subpage") == 0)
142
            {
144
            {
143
                MSG_TRACE("Added subpage " << spl.pageID << ", " << spl.name << " to subpage list.");
145
                MSG_TRACE("Added subpage " << spl.pageID << ", " << spl.name << " to subpage list.");
144
                mSubPageList.push_back(spl);
146
                mSubPageList.push_back(spl);
145
            }
147
            }
146
 
-
 
147
            n = reader.getNextChild();
-
 
148
        }
148
        }
149
 
149
 
150
        value = reader.findNextElement("pageList", "type");
-
 
151
 
-
 
152
        if (reader.success())
150
        attribute.clear();
153
            attribute = reader.getAttribute();
-
 
154
        else
-
 
155
            attribute.clear();
151
        attrs.clear();
156
    }
152
    }
-
 
153
    while ((index = xml.getNextElementIndex("pageList", depth)) != TExpat::npos);
157
}
154
}
158
 
155
 
159
PAGELIST_T TPageList::findPage(const std::string& name)
156
PAGELIST_T TPageList::findPage(const std::string& name)
160
{
157
{
161
    DECL_TRACER("TPageList::findPage(const std::string& name)");
158
    DECL_TRACER("TPageList::findPage(const std::string& name)");