// // Tizen C++ SDK // Copyright (c) 2012 Samsung Electronics Co., Ltd. // // Licensed under the Flora License, Version 1.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.tizenopensource.org/license // // 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 #include #include #include #include #include #include "XmlReader.h" using namespace Tizen::App; using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Graphics; using namespace Tizen::Io; using namespace Tizen::Ui; using namespace Tizen::Ui::Controls; using namespace Tizen::Ui::Scenes; XmlReader::XmlReader(void) : _pList(null) , _pItemList(null) { } XmlReader::~XmlReader(void) { } bool XmlReader::Initialize(void) { Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_INDICATOR); return true; } void XmlReader::XmlReaderRun(void) { int xmlreadType = 0; int ret = 0; //Create xml text reader String filepath = App::GetInstance()->GetAppRootPath() + L"data/continents.xml"; ByteBuffer* pBuf = Tizen::Base::Utility::StringUtil::StringToUtf8N(filepath); TryReturnVoid(pBuf, "ByteBuffer is null"); xmlTextReaderPtr reader = xmlReaderForFile((const char*) pBuf->GetPointer(), NULL, XML_PARSE_HUGE); TryCatch(reader, , "xmlTextReaderPtr is null"); TryCatch(_pList, xmlFreeTextReader(reader), "_pList is null"); ret = xmlTextReaderRead(reader); while (ret == 1) { const xmlChar* value = null; const xmlChar* name = xmlTextReaderConstName(reader); //read node name if (xmlTextReaderHasValue(reader)) { value = xmlTextReaderConstValue(reader); //read value } xmlreadType = xmlTextReaderNodeType(reader); //read Node type /* Ignore #Text node */ if (xmlStrcasecmp(name, (const xmlChar*) "#Text") != 0 && xmlreadType != XML_READER_TYPE_END_ELEMENT) { String* nodeName = new (std::nothrow) String; //Carries node name Tizen::Base::Utility::StringUtil::Utf8ToString((char*) name, *nodeName); _pItemList->Add(*nodeName); } /* Add value if node is not of type XML_READER_TYPE_SIGNIFICANT_WHITESPACE */ if ((xmlreadType != XML_READER_TYPE_SIGNIFICANT_WHITESPACE) && (value != null)) { String* nodeValue = new (std::nothrow) String; //Carries node value if (value != null) { Tizen::Base::Utility::StringUtil::Utf8ToString((char*) value, *nodeValue); } _pItemList->Add(*nodeValue); } ret = xmlTextReaderRead(reader); } _pList->UpdateList(); xmlFreeTextReader(reader); CATCH: delete pBuf; } result XmlReader::OnInitializing(void) { result r = E_SUCCESS; Header* pHeader = GetHeader(); pHeader->SetTitleText("XML Reader"); Footer* pFooter = GetFooter(); pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON); pFooter->SetBackButton(); SetFormBackEventListener(this); _pList = new (std::nothrow) ListView(); _pList->Construct(Rectangle(0, 0, LIST_WIDTH, LIST_HEIGHT), true); _pList->SetItemProvider(*this); _pList->AddListViewItemEventListener(*this); _pList->SetTextOfEmptyList(L""); AddControl(*_pList); _pItemList = new (std::nothrow) ArrayList(); _pItemList->Construct(); XmlReaderRun(); return r; } int XmlReader::GetItemCount(void) { TryReturn(_pItemList, 0, "_pItemList is null"); return _pItemList->GetCount(); } Tizen::Ui::Controls::ListItemBase* XmlReader::CreateItem(int index, int itemWidth) { ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL; SimpleItem* pItem = new (std::nothrow) SimpleItem(); pItem->Construct(Tizen::Graphics::Dimension(itemWidth, ITEM_HEIGHT), style); Tizen::Base::String* key = static_cast< String* >(_pItemList->GetAt(index)); TryReturn(key, null, "Key value is empty for %d", index); pItem->SetElement(*key, null); return pItem; } bool XmlReader::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth) { delete pItem; pItem = null; return true; } void XmlReader::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status) { } void XmlReader::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction) { } void XmlReader::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state) { } void XmlReader::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) { } result XmlReader::OnTerminating(void) { result r = E_SUCCESS; if (_pItemList) { _pItemList->RemoveAll(true); delete _pItemList; _pItemList = null; } return r; } void XmlReader::OnFormBackRequested(Tizen::Ui::Controls::Form& source) { SceneManager* pSceneManager = SceneManager::GetInstance(); pSceneManager->GoBackward(BackwardSceneTransition()); }