From 7c2070727bd2ed107c403889afee3463f5e894be Mon Sep 17 00:00:00 2001 From: HyungKyu Song Date: Sat, 16 Feb 2013 00:57:22 +0900 Subject: Tizen 2.0 Release --- LICENSE | 206 +++++++++ NOTICE | 4 + description.xml | 11 + project/data/continents.xml | 23 + project/data/map.xml | 23 + project/data/tizen.html | 17 + project/inc/FormFactory.h | 21 + project/inc/HtmlParser.h | 73 +++ project/inc/MainListForm.h | 51 ++ project/inc/XmlParser.h | 83 ++++ project/inc/XmlParserApp.h | 74 +++ project/inc/XmlReader.h | 70 +++ project/inc/XmlWriter.h | 72 +++ project/manifest.xml | 30 ++ project/res/eng-GB.xml | 5 + project/res/screen-size-normal/IDF_FORM1.xml | 24 + project/shared/data/nofile.dummy | 0 .../shared/res/screen-density-xhigh/mainmenu.png | Bin 0 -> 17581 bytes project/shared/trusted/nofile.dummy | 0 project/src/FormFactory.cpp | 63 +++ project/src/HtmlParser.cpp | 203 ++++++++ project/src/MainListForm.cpp | 112 +++++ project/src/XmlParser.cpp | 511 +++++++++++++++++++++ project/src/XmlParserApp.cpp | 103 +++++ project/src/XmlParserAppEntry.cpp | 60 +++ project/src/XmlReader.cpp | 201 ++++++++ project/src/XmlWriter.cpp | 297 ++++++++++++ sample.xml | 34 ++ screenshot.png | Bin 0 -> 8765 bytes 29 files changed, 2371 insertions(+) create mode 100644 LICENSE create mode 100644 NOTICE create mode 100755 description.xml create mode 100755 project/data/continents.xml create mode 100755 project/data/map.xml create mode 100755 project/data/tizen.html create mode 100644 project/inc/FormFactory.h create mode 100755 project/inc/HtmlParser.h create mode 100755 project/inc/MainListForm.h create mode 100755 project/inc/XmlParser.h create mode 100644 project/inc/XmlParserApp.h create mode 100755 project/inc/XmlReader.h create mode 100755 project/inc/XmlWriter.h create mode 100644 project/manifest.xml create mode 100755 project/res/eng-GB.xml create mode 100755 project/res/screen-size-normal/IDF_FORM1.xml create mode 100644 project/shared/data/nofile.dummy create mode 100755 project/shared/res/screen-density-xhigh/mainmenu.png create mode 100644 project/shared/trusted/nofile.dummy create mode 100644 project/src/FormFactory.cpp create mode 100644 project/src/HtmlParser.cpp create mode 100755 project/src/MainListForm.cpp create mode 100644 project/src/XmlParser.cpp create mode 100644 project/src/XmlParserApp.cpp create mode 100644 project/src/XmlParserAppEntry.cpp create mode 100644 project/src/XmlReader.cpp create mode 100644 project/src/XmlWriter.cpp create mode 100755 sample.xml create mode 100755 screenshot.png diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..917b21e --- /dev/null +++ b/LICENSE @@ -0,0 +1,206 @@ +Flora License + +Version 1.0, May, 2012 + +http://www.tizenopensource.org/license + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and +all other entities that control, are controlled by, or are +under common control with that entity. For the purposes of +this definition, "control" means (i) the power, direct or indirect, +to cause the direction or management of such entity, +whether by contract or otherwise, or (ii) ownership of fifty percent (50%) +or more of the outstanding shares, or (iii) beneficial ownership of +such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice +that is included in or attached to the work (an example is provided +in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, +as a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, +or merely link (or bind by name) to the interfaces of, the Work and +Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor +for inclusion in the Work by the copyright owner or by an individual or +Legal Entity authorized to submit on behalf of the copyright owner. +For the purposes of this definition, "submitted" means any form of +electronic, verbal, or written communication sent to the Licensor or +its representatives, including but not limited to communication on +electronic mailing lists, source code control systems, and issue +tracking systems that are managed by, or on behalf of, the Licensor +for the purpose of discussing and improving the Work, but excluding +communication that is conspicuously marked or otherwise designated +in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +"Tizen Certified Platform" shall mean a software platform that complies +with the standards set forth in the Compatibility Definition Document +and passes the Compatibility Test Suite as defined from time to time +by the Tizen Technical Steering Group and certified by the Tizen +Association or its designated agent. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work +solely as incorporated into a Tizen Certified Platform, where such +license applies only to those patent claims licensable by such +Contributor that are necessarily infringed by their Contribution(s) +alone or by combination of their Contribution(s) with the Work solely +as incorporated into a Tizen Certified Platform to which such +Contribution(s) was submitted. If You institute patent litigation +against any entity (including a cross-claim or counterclaim +in a lawsuit) alleging that the Work or a Contribution incorporated +within the Work constitutes direct or contributory patent infringement, +then any patent licenses granted to You under this License for that +Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof pursuant to the copyright license +above, in any medium, with or without modifications, and in Source or +Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works + a copy of this License; and + 2. You must cause any modified files to carry prominent notices stating + that You changed the files; and + 3. You must retain, in the Source form of any Derivative Works that + You distribute, all copyright, patent, trademark, and attribution + notices from the Source form of the Work, excluding those notices + that do not pertain to any part of the Derivative Works; and + 4. If the Work includes a "NOTICE" text file as part of its distribution, + then any Derivative Works that You distribute must include a readable + copy of the attribution notices contained within such NOTICE file, + excluding those notices that do not pertain to any part of + the Derivative Works, in at least one of the following places: + within a NOTICE text file distributed as part of the Derivative Works; + within the Source form or documentation, if provided along with the + Derivative Works; or, within a display generated by the Derivative Works, + if and wherever such third-party notices normally appear. + The contents of the NOTICE file are for informational purposes only + and do not modify the License. + +You may add Your own attribution notices within Derivative Works +that You distribute, alongside or as an addendum to the NOTICE text +from the Work, provided that such additional attribution notices +cannot be construed as modifying the License. You may add Your own +copyright statement to Your modifications and may provide additional or +different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works +as a whole, provided Your use, reproduction, and distribution of +the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Flora License to your work + +To apply the Flora License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..3997999 --- /dev/null +++ b/NOTICE @@ -0,0 +1,4 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Flora License, Version 1. +Please, see the LICENSE file for Flora License terms and conditions. + diff --git a/description.xml b/description.xml new file mode 100755 index 0000000..cc326b9 --- /dev/null +++ b/description.xml @@ -0,0 +1,11 @@ + + + + + XmlParserApp + 1.0 + screenshot.png + + This sample application demonstrates the features supported by Tizen XML. + + diff --git a/project/data/continents.xml b/project/data/continents.xml new file mode 100755 index 0000000..9be078d --- /dev/null +++ b/project/data/continents.xml @@ -0,0 +1,23 @@ + + + + + + South Korea + Seoul + Won + + + + France + Paris + Euro + + + + Canada + Ottawa + Dollar + + + \ No newline at end of file diff --git a/project/data/map.xml b/project/data/map.xml new file mode 100755 index 0000000..c305faf --- /dev/null +++ b/project/data/map.xml @@ -0,0 +1,23 @@ + + + + + United Arab Emirates + Abu Dhabi + + + + Nigeria + Abuja + + + + Ghana + Accra + + + + Pitcairn Islands + Adamstown + + \ No newline at end of file diff --git a/project/data/tizen.html b/project/data/tizen.html new file mode 100755 index 0000000..1b27e5d --- /dev/null +++ b/project/data/tizen.html @@ -0,0 +1,17 @@ + + + + +

Tizen Store

+


+


+ +
+Entertainment!
+Games!
+Social!
+Widgets!
+Education!
+Navigation!
+
+ diff --git a/project/inc/FormFactory.h b/project/inc/FormFactory.h new file mode 100644 index 0000000..0be8e11 --- /dev/null +++ b/project/inc/FormFactory.h @@ -0,0 +1,21 @@ +/* + * FormFactory.h + * + * Created on: Sep 25, 2012 + * Author: lsw2000.lee + */ + +#ifndef _FORM_FACTORY_H_ +#define _FORM_FACTORY_H_ + +#include + +class FormFactory: public Tizen::Ui::Scenes::IFormFactory { +public: + FormFactory(); + virtual ~FormFactory(); + + virtual Tizen::Ui::Controls::Form* CreateFormN(const Tizen::Base::String &formId, const Tizen::Ui::Scenes::SceneId &sceneId); +}; + +#endif /* _FORM_FACTORY_H_ */ diff --git a/project/inc/HtmlParser.h b/project/inc/HtmlParser.h new file mode 100755 index 0000000..8a46f2a --- /dev/null +++ b/project/inc/HtmlParser.h @@ -0,0 +1,73 @@ +// +// 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. +// + +#ifndef _HTML_PARSER_H_ +#define _HTML_PARSER_H_ + +#include +#include + +#include +#include +#include + +class HtmlParser + : public Tizen::Ui::Controls::Form + , public Tizen::Ui::Controls::IListViewItemEventListener + , public Tizen::Ui::Controls::IListViewItemProvider + , public Tizen::Ui::IActionEventListener + , public Tizen::Ui::Controls::IFormBackEventListener +{ +public: + HtmlParser(void); + virtual ~HtmlParser(void); + + bool Initialize(void); + + void RunHtmlParser(void); + void ExtractHyperLinks(htmlNodePtr pRoot); + virtual result OnInitializing(void); + virtual result OnTerminating(void); + + //IActionEventListener + virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + + // IListViewItemEventListener + virtual void OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state); + virtual void OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status); + virtual void OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction); + + //IListViewItemProvider + virtual Tizen::Ui::Controls::ListItemBase* CreateItem(int index, int itemWidth); + virtual bool DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth); + virtual int GetItemCount(void); + + //IFormBackEventListener + virtual void OnFormBackRequested(Tizen::Ui::Controls::Form& source); + +protected: + Tizen::Ui::Controls::ListView* _pList; + Tizen::Base::Collection::ArrayList* _pItemList; + +private: + static const int LIST_WIDTH = 720; + static const int LIST_HEIGHT = 640; + + static const int ITEM_HEIGHT = 112; +}; + +#endif //_HTML_PARSER_H_ diff --git a/project/inc/MainListForm.h b/project/inc/MainListForm.h new file mode 100755 index 0000000..bfb1fef --- /dev/null +++ b/project/inc/MainListForm.h @@ -0,0 +1,51 @@ +// +// 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. +// + +#ifndef _MAINLISTFORM_H_ +#define _MAINLISTFORM_H_ + +#include +#include + +class MainListForm + : public Tizen::Ui::Controls::Form + , public Tizen::Ui::IActionEventListener +{ +public: + MainListForm(void); + virtual ~MainListForm(void); + bool Initialize(void); + + virtual result OnInitializing(void); + virtual result OnTerminating(void); + virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + +protected: + static const int ID_BUTTON_XMLReader = 102; + static const int ID_BUTTON_HTMLParser = 103; + static const int ID_BUTTON_XMLParser = 104; + static const int ID_BUTTON_XMLWriter = 105; + +private: + static const int BUTTON_LEFT_RIGHT_MARGIN = 128; + static const int BUTTON_TOP_MARGIN = 112; + static const int BUTTON_BOTTOM_MARGIN = 38; + static const int BUTTON_WIDTH = 480; + static const int BUTTON_HEIGHT = 74; +}; + +#endif //_MAINLISTFORM_H_ diff --git a/project/inc/XmlParser.h b/project/inc/XmlParser.h new file mode 100755 index 0000000..2c137f9 --- /dev/null +++ b/project/inc/XmlParser.h @@ -0,0 +1,83 @@ +// +// 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. +// +#ifndef _XML_PARSER_H_ +#define _XML_PARSER_H_ + +#include +#include + +class XmlParser + : public Tizen::Ui::Controls::Form + , public Tizen::Ui::Controls::IListViewItemEventListener + , public Tizen::Ui::Controls::IListViewItemProvider + , public Tizen::Ui::IActionEventListener + , public Tizen::Ui::Controls::IFormBackEventListener +{ +public: + XmlParser(void); + virtual ~XmlParser(void); + bool Initialize(void); + + virtual result OnInitializing(void); + virtual result OnTerminating(void); + + result SAXParse(void); + result SAXParseMemory(void); + + //IActionEventListener + virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + + // IListViewItemEventListener + virtual void OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state); + virtual void OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status); + virtual void OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction); + + //IListViewItemProvider + virtual Tizen::Ui::Controls::ListItemBase* CreateItem(int index, int itemWidth); + virtual bool DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth); + virtual int GetItemCount(void); + + //IFormBackEventListener + virtual void OnFormBackRequested(Tizen::Ui::Controls::Form& source); + + bool IsFound(void){ return __found;} + bool IsCheckContent(void){ return __checkContent;} + bool IsPrintCapital(void){ return __printCapital;} + void SetFound(bool found){ __found = found;} + void SetCheckContent(bool checkContent){ __checkContent = checkContent;} + void SetPrintCapital(bool printCapital){ __printCapital = printCapital;} + +private: + static const int LABEL_WIDTH = 330; + static const int LABEL_HEIGHT = 96; + static const int LABEL_BOTTOM_MARGIN = 64; + + static const int LIST_HEIGHT = 640; + + static const int ITEM_HEIGHT = 112; + + bool __found; + bool __checkContent; + bool __printCapital; + Tizen::Ui::Controls::ListView* __pList; + Tizen::Base::Collection::ArrayList* __pItemList; + Tizen::Ui::Controls::Label* __pLabel; + Tizen::Base::String __filePath; + Tizen::Base::ByteBuffer* __pPath; +}; + +#endif //_XML_PARSER_H_ diff --git a/project/inc/XmlParserApp.h b/project/inc/XmlParserApp.h new file mode 100644 index 0000000..f9de4c7 --- /dev/null +++ b/project/inc/XmlParserApp.h @@ -0,0 +1,74 @@ +// +// 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. +// + +#ifndef _XML_PARSER_APP_H_ +#define _XML_PARSER_APP_H_ + +#include +#include +#include +#include + +/** + * [XmlParserApp] application must inherit from Application class + * which provides basic features necessary to define an application. + */ +class XmlParserApp + : public Tizen::App::Application + , public Tizen::System::IScreenEventListener +{ +public: + /** + * [XmlParserApp] application must have a factory method that creates an instance of itself. + */ + static Tizen::App::Application* CreateInstance(void); + + +public: + XmlParserApp(void); + ~XmlParserApp(void); + + +public: + // Called when the application is initializing. + virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry); + + // Called when the application is terminating. + virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false); + + + // Called when the application's frame moves to the top of the screen. + virtual void OnForeground(void); + + + // Called when this application's frame is moved from top of the screen to the background. + virtual void OnBackground(void); + + // Called when the system memory is not sufficient to run the application any further. + virtual void OnLowMemory(void); + + // Called when the battery level changes. + virtual void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel); + + // Called when the screen turns on. + virtual void OnScreenOn(void); + + // Called when the screen turns off. + virtual void OnScreenOff(void); +}; + +#endif //_XML_PARSER_APP_H_ diff --git a/project/inc/XmlReader.h b/project/inc/XmlReader.h new file mode 100755 index 0000000..39537af --- /dev/null +++ b/project/inc/XmlReader.h @@ -0,0 +1,70 @@ +// +// 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. +// + +#ifndef _XML_READER_H_ +#define _XML_READER_H_ + +#include +#include +#include + +class XmlReader + : public Tizen::Ui::Controls::Form + , public Tizen::Ui::Controls::IListViewItemEventListener + , public Tizen::Ui::Controls::IListViewItemProvider + , public Tizen::Ui::IActionEventListener + , public Tizen::Ui::Controls::IFormBackEventListener +{ + +public: + XmlReader(void); + virtual ~XmlReader(void); + bool Initialize(void); + + void XmlReaderRun(void); + + virtual result OnInitializing(void); + virtual result OnTerminating(void); + + //IActionEventListener + virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + + // IListViewItemEventListener + virtual void OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state); + virtual void OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status); + virtual void OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction); + + //IListViewItemProvider + virtual Tizen::Ui::Controls::ListItemBase* CreateItem(int index, int itemWidth); + virtual bool DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth); + virtual int GetItemCount(void); + + //IFormBackEventListener + virtual void OnFormBackRequested(Tizen::Ui::Controls::Form& source); + +protected: + Tizen::Ui::Controls::ListView* _pList; + Tizen::Base::Collection::ArrayList* _pItemList; + +private: + static const int LIST_WIDTH = 720; + static const int LIST_HEIGHT = 640; + + static const int ITEM_HEIGHT = 112; +}; + +#endif //_XML_READER_H_ diff --git a/project/inc/XmlWriter.h b/project/inc/XmlWriter.h new file mode 100755 index 0000000..97fc9fd --- /dev/null +++ b/project/inc/XmlWriter.h @@ -0,0 +1,72 @@ +// +// 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. +// + +#ifndef _XML_WRITER_H_ +#define _XML_WRITER_H_ + +#include +#include + +class XmlWriter + : public Tizen::Ui::Controls::Form + , public Tizen::Ui::Controls::IListViewItemEventListener + , public Tizen::Ui::Controls::IListViewItemProvider + , public Tizen::Ui::IActionEventListener + , public Tizen::Ui::Controls::IFormBackEventListener +{ + +public: + XmlWriter(void); + virtual ~XmlWriter(void); + bool Initialize(void); + + result RunXMLWrite(void); + void RunXMLParseandDisplay(void); + virtual result OnInitializing(void); + virtual result OnTerminating(void); + + //IActionEventListener + virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); + + // IListViewItemEventListener + virtual void OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state); + virtual void OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status); + virtual void OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction); + + //IFormBackEventListener + virtual void OnFormBackRequested(Tizen::Ui::Controls::Form& source); + + //IListViewItemProvider + virtual Tizen::Ui::Controls::ListItemBase* CreateItem(int index, int itemWidth); + virtual bool DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth); + virtual int GetItemCount(void); + +protected: + Tizen::Ui::Controls::ListView* _pList; + Tizen::Base::Collection::ArrayList* _pItemList; + static const int ID_BUTTON_WRITE = 905; + +private: + static const int LIST_WIDTH = 720; + static const int LIST_HEIGHT = 640; + + static const int ITEM_HEIGHT = 112; + + bool __display; +}; + +#endif //_XML_WRITER_H_ diff --git a/project/manifest.xml b/project/manifest.xml new file mode 100644 index 0000000..1f16b7d --- /dev/null +++ b/project/manifest.xml @@ -0,0 +1,30 @@ + + + $(manifestAppId) + 1.0.0 + C++App + + + + + + x86 + vfpv3 + + + 2.0 + + + + + + $(projectName) + + + mainmenu.png + + + + + + diff --git a/project/res/eng-GB.xml b/project/res/eng-GB.xml new file mode 100755 index 0000000..08a9a95 --- /dev/null +++ b/project/res/eng-GB.xml @@ -0,0 +1,5 @@ + + + diff --git a/project/res/screen-size-normal/IDF_FORM1.xml b/project/res/screen-size-normal/IDF_FORM1.xml new file mode 100755 index 0000000..7f4862a --- /dev/null +++ b/project/res/screen-size-normal/IDF_FORM1.xml @@ -0,0 +1,24 @@ + + + + + +
+ + + + +
+ +
+
+ +
+ +
diff --git a/project/shared/data/nofile.dummy b/project/shared/data/nofile.dummy new file mode 100644 index 0000000..e69de29 diff --git a/project/shared/res/screen-density-xhigh/mainmenu.png b/project/shared/res/screen-density-xhigh/mainmenu.png new file mode 100755 index 0000000..983c883 Binary files /dev/null and b/project/shared/res/screen-density-xhigh/mainmenu.png differ diff --git a/project/shared/trusted/nofile.dummy b/project/shared/trusted/nofile.dummy new file mode 100644 index 0000000..e69de29 diff --git a/project/src/FormFactory.cpp b/project/src/FormFactory.cpp new file mode 100644 index 0000000..5baded5 --- /dev/null +++ b/project/src/FormFactory.cpp @@ -0,0 +1,63 @@ +/* + * FormFactory.cpp + * + * Created on: Sep 25, 2012 + * Author: lsw2000.lee + */ +#include +#include "FormFactory.h" +#include "MainListForm.h" +#include "XmlReader.h" +#include "HtmlParser.h" +#include "XmlParser.h" +#include "XmlWriter.h" + +using namespace Tizen::Ui::Controls; + +FormFactory::FormFactory() { + // TODO Auto-generated constructor stub + +} + +FormFactory::~FormFactory() { + // TODO Auto-generated destructor stub +} + +Form* +FormFactory::CreateFormN(const Tizen::Base::String &formId, const Tizen::Ui::Scenes::SceneId &sceneId) +{ + Form* pNewForm = null; + + if (formId == L"MainListForm") + { + MainListForm* pForm = new (std::nothrow) MainListForm(); + pForm->Initialize(); + pNewForm = pForm; + } + else if (formId == L"XmlReaderForm") + { + XmlReader* pForm = new (std::nothrow) XmlReader(); + pForm->Initialize(); + pNewForm = pForm; + } + else if (formId == L"HtmlParserForm") + { + HtmlParser* pForm = new (std::nothrow) HtmlParser(); + pForm->Initialize(); + pNewForm = pForm; + } + else if (formId == L"XmlParserForm") + { + XmlParser* pForm = new (std::nothrow) XmlParser(); + pForm->Initialize(); + pNewForm = pForm; + } + else if (formId == L"XmlWriterForm") + { + XmlWriter* pForm = new (std::nothrow) XmlWriter(); + pForm->Initialize(); + pNewForm = pForm; + } + + return pNewForm; +} diff --git a/project/src/HtmlParser.cpp b/project/src/HtmlParser.cpp new file mode 100644 index 0000000..c3000e3 --- /dev/null +++ b/project/src/HtmlParser.cpp @@ -0,0 +1,203 @@ +// +// 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 "HtmlParser.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; + +HtmlParser::HtmlParser(void) + : _pList(null) + , _pItemList(null) +{ +} + +HtmlParser::~HtmlParser(void) +{ +} + +bool +HtmlParser::Initialize(void) +{ + Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_INDICATOR); + return true; +} + +result +HtmlParser::OnInitializing(void) +{ + result r = E_SUCCESS; + Rectangle clientRect = GetClientAreaBounds(); + Header* pHeader = GetHeader(); + pHeader->SetTitleText("HTML Parser"); + + 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(); + + RunHtmlParser(); + + return r; +} + +int +HtmlParser::GetItemCount(void) +{ + TryReturn(_pItemList, 0, "_pItemList is null."); + return _pItemList->GetCount(); +} + +Tizen::Ui::Controls::ListItemBase* +HtmlParser::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* pKey = static_cast< String* >(_pItemList->GetAt(index)); + TryReturn(pKey, null, "key is empty for index %d",index); + + pItem->SetElement(*pKey, null); + return pItem; +} + +bool +HtmlParser::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth) +{ + delete pItem; + pItem = null; + return true; +} + + +void +HtmlParser::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status) +{ +} + +void +HtmlParser::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction) +{ +} + +void +HtmlParser::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state) +{ +} + + +void +HtmlParser::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) +{ +} + +void +HtmlParser::RunHtmlParser(void) +{ + //Parse html file and build a tree + String filepath = App::GetInstance()->GetAppRootPath() + L"data/tizen.html"; + ByteBuffer* pBuf = Tizen::Base::Utility::StringUtil::StringToUtf8N(filepath); + TryReturnVoid(pBuf, "StringToUtf8N failed."); + + htmlNodePtr pRoot =null; + htmlDocPtr pDoc = htmlParseFile((const char*) pBuf->GetPointer(), (const char*) "utf-8"); + TryCatch(pDoc, , "htmlParseFile failed."); + + //Get the root element of the document + pRoot = xmlDocGetRootElement(pDoc); + TryCatch(pRoot, xmlFreeDoc(pDoc), "xmlDocGetRootElement failed."); + + ExtractHyperLinks(pRoot); + _pList->UpdateList(); + xmlFreeDoc(pDoc); + +CATCH: + delete pBuf; +} + +/* this functions extracts links present in HTML file and displays*/ +void +HtmlParser::ExtractHyperLinks(htmlNodePtr pRoot) +{ + xmlNodePtr pCurrentElement = null; + xmlAttrPtr attr = null; + + for (pCurrentElement = pRoot; pCurrentElement; pCurrentElement = pCurrentElement->next) + { + if (pCurrentElement->type != XML_ELEMENT_NODE) + { + continue; + } + if (xmlStrcasecmp(pCurrentElement->name, (const xmlChar*) "A") == 0) + { + for (attr = pCurrentElement->properties; attr != null; attr = attr->next) + { + if (xmlStrcasecmp(attr->name, (const xmlChar*) "HREF") == 0) + { + String* nodeName = new (std::nothrow) String; + Tizen::Base::Utility::StringUtil::Utf8ToString((char*) pCurrentElement->children->content, *nodeName); + _pItemList->Add(*nodeName); + } + } + } + if (pCurrentElement->children != null) + { + ExtractHyperLinks(pCurrentElement->children); + } + } +} + +result +HtmlParser::OnTerminating(void) +{ + if (_pItemList) + { + _pItemList->RemoveAll(true); + delete _pItemList; + _pItemList = null; + } + + return E_SUCCESS; +} + +void +HtmlParser::OnFormBackRequested(Tizen::Ui::Controls::Form& source) +{ + SceneManager* pSceneManager = SceneManager::GetInstance(); + pSceneManager->GoBackward(BackwardSceneTransition()); +} diff --git a/project/src/MainListForm.cpp b/project/src/MainListForm.cpp new file mode 100755 index 0000000..e1ec1d0 --- /dev/null +++ b/project/src/MainListForm.cpp @@ -0,0 +1,112 @@ +// +// 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 "MainListForm.h" +#include "XmlReader.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Graphics; +using namespace Tizen::Ui; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Ui::Scenes; + +MainListForm::MainListForm(void) +{ +} + +MainListForm::~MainListForm(void) +{ +} + +bool +MainListForm::Initialize(void) +{ + Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_INDICATOR); + return true; +} + +result +MainListForm::OnInitializing(void) +{ + result r = E_SUCCESS; + + Header* pHeader = GetHeader(); + pHeader->SetTitleText("XML PARSER APP"); + + //For xmlreader + Button* pXmlReader = new (std::nothrow) Button(); + pXmlReader->Construct(Rectangle(BUTTON_LEFT_RIGHT_MARGIN, BUTTON_TOP_MARGIN, BUTTON_WIDTH, BUTTON_HEIGHT), L"XML Reader"); + pXmlReader->AddActionEventListener(*this); + pXmlReader->SetActionId(ID_BUTTON_XMLReader); + AddControl(*pXmlReader); + + //For htmlparser + Button* pHtmlParser = new (std::nothrow) Button(); + pHtmlParser->Construct(Rectangle(BUTTON_LEFT_RIGHT_MARGIN, BUTTON_TOP_MARGIN + ( BUTTON_HEIGHT + BUTTON_BOTTOM_MARGIN ), BUTTON_WIDTH, BUTTON_HEIGHT), L"HTML Parser"); + pHtmlParser->AddActionEventListener(*this); + pHtmlParser->SetActionId(ID_BUTTON_HTMLParser); + AddControl(*pHtmlParser); + + //For xmlparser + Button* pXmlParser = new (std::nothrow) Button(); + pXmlParser->Construct(Rectangle(BUTTON_LEFT_RIGHT_MARGIN, BUTTON_TOP_MARGIN + 2 * ( BUTTON_HEIGHT + BUTTON_BOTTOM_MARGIN ), BUTTON_WIDTH, BUTTON_HEIGHT), L"XML Parser"); + pXmlParser->AddActionEventListener(*this); + pXmlParser->SetActionId(ID_BUTTON_XMLParser); + AddControl(*pXmlParser); + + //For xmlwriter + Button* pXmlWriter = new (std::nothrow) Button(); + pXmlWriter->Construct(Rectangle(BUTTON_LEFT_RIGHT_MARGIN, BUTTON_TOP_MARGIN + 3 * ( BUTTON_HEIGHT + BUTTON_BOTTOM_MARGIN ), BUTTON_WIDTH, BUTTON_HEIGHT), L"XML Writer"); + pXmlWriter->AddActionEventListener(*this); + pXmlWriter->SetActionId(ID_BUTTON_XMLWriter); + AddControl(*pXmlWriter); + return r; +} + +result +MainListForm::OnTerminating(void) +{ + result r = E_SUCCESS; + return r; +} + +void +MainListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) +{ + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + + switch (actionId) + { + case ID_BUTTON_XMLReader: + pSceneManager->GoForward(ForwardSceneTransition(L"XmlReaderScene")); + break; + case ID_BUTTON_HTMLParser: + pSceneManager->GoForward(ForwardSceneTransition(L"HtmlParserScene")); + break; + case ID_BUTTON_XMLParser: + pSceneManager->GoForward(ForwardSceneTransition(L"XmlParserScene")); + break; + case ID_BUTTON_XMLWriter: + pSceneManager->GoForward(ForwardSceneTransition(L"XmlWriterScene")); + break; + default: + break; + } +} diff --git a/project/src/XmlParser.cpp b/project/src/XmlParser.cpp new file mode 100644 index 0000000..8ebb748 --- /dev/null +++ b/project/src/XmlParser.cpp @@ -0,0 +1,511 @@ +// +// 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 "XmlParser.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; + +xmlParserInputPtr ResolveEntitySAXFunc(void* ctx, const xmlChar* publicId, const xmlChar* systemId); +void InternalSubsetSAXFunc(void* ctx, const xmlChar* name, const xmlChar* ExternalID, const xmlChar* SystemID); +void ExternalSubsetSAXFunc(void* ctx, const xmlChar* name, const xmlChar* ExternalID, const xmlChar* SystemID); +xmlEntityPtr GetEntitySAXFunc(void* ctx, const xmlChar* name); +xmlEntityPtr GetParameterEntitySAXFunc(void* ctx, const xmlChar* name); +void EntityDeclSAXFunc(void* ctx, const xmlChar* name, int type, const xmlChar* publicId, const xmlChar* systemId, xmlChar* content); +void NotationDeclSAXFunc(void* ctx, const xmlChar* name, const xmlChar* publicId, const xmlChar* systemId); +void AttributeDeclSAXFunc(void* ctx, const xmlChar* elem, const xmlChar* fullname, int type, int def, const xmlChar* defaultValue, xmlEnumerationPtr tree); +void ElementDeclSAXFunc(void* ctx, const xmlChar* name, int type, xmlElementContentPtr content); +void UnparsedEntityDeclSAXFunc(void* ctx, const xmlChar* name, const xmlChar* publicId, const xmlChar* systemId, const xmlChar* notationName); +void SetDocumentLocatorSAXFunc(void* ctx, xmlSAXLocatorPtr loc); +void StartDocumentSAXFunc(void* ctx); +void EndDocumentSAXFunc(void* ctx); +void StartElementSAXFunc(void* ctx, const xmlChar* name, const xmlChar** atts); +void EndElementSAXFunc(void* ctx, const xmlChar* name); +void AttributeSAXFunc(void* ctx, const xmlChar* name, const xmlChar* value); +void ReferenceSAXFunc(void* ctx, const xmlChar* name); +void CharactersSAXFunc(void* ctx, const xmlChar* ch, int len); +void IgnorableWhitespaceSAXFunc(void* ctx, const xmlChar* ch, int len); +void ProcessingInstructionSAXFunc(void* ctx, const xmlChar* target, const xmlChar* data); +void CommentSAXFunc(void* ctx, const xmlChar* value); +void CdataBlockSAXFunc(void* ctx, const xmlChar* value, int len); +void WarningSAXFunc(void* ctx, const char* msg, ...); +void ErrorSAXFunc(void* ctx, const char* msg, ...); +void FatalErrorSAXFunc(void* ctx, const char* msg, ...); +int IsStandaloneSAXFunc(void* ctx); +int HasInternalSubsetSAXFunc(void* ctx); +int HasExternalSubsetSAXFunc(void* ctx); + + +xmlSAXHandler mySaxHandler = +{ +InternalSubsetSAXFunc, +IsStandaloneSAXFunc, +HasInternalSubsetSAXFunc, +HasExternalSubsetSAXFunc, +ResolveEntitySAXFunc, +GetEntitySAXFunc, +EntityDeclSAXFunc, +NotationDeclSAXFunc, +AttributeDeclSAXFunc, +ElementDeclSAXFunc, +UnparsedEntityDeclSAXFunc, +SetDocumentLocatorSAXFunc, +StartDocumentSAXFunc, +EndDocumentSAXFunc, +StartElementSAXFunc, +EndElementSAXFunc, +ReferenceSAXFunc, +CharactersSAXFunc, +IgnorableWhitespaceSAXFunc, +ProcessingInstructionSAXFunc, +CommentSAXFunc, +WarningSAXFunc, +ErrorSAXFunc, +FatalErrorSAXFunc, +GetParameterEntitySAXFunc, +CdataBlockSAXFunc, +ExternalSubsetSAXFunc, +0, +null, +null, +null, +null +}; + +XmlParser::XmlParser(void) + : __found(false) + , __checkContent(false) + , __printCapital(false) + , __pList(null) + , __pItemList(null) + , __pLabel(null) + , __pPath(null) +{ +} + +XmlParser::~XmlParser(void) +{ + delete __pPath; +} + +bool +XmlParser::Initialize(void) +{ + Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_INDICATOR); + return true; +} + +result +XmlParser::OnInitializing(void) +{ + Rectangle clientRect = GetClientAreaBounds(); + Header* pHeader = GetHeader(); + pHeader->SetTitleText("XML Parser"); + result r = E_FAILURE; + + Footer* pFooter = GetFooter(); + pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON); + pFooter->SetBackButton(); + SetFormBackEventListener(this); + + __pLabel = new Label(); + __pLabel->Construct(Rectangle((clientRect.width - LABEL_WIDTH) / 2, clientRect.height - LABEL_BOTTOM_MARGIN - LABEL_HEIGHT, LABEL_WIDTH, LABEL_HEIGHT), L""); + AddControl(*__pLabel); + + // Create xml document + __filePath = App::GetInstance()->GetAppRootPath() + L"data/map.xml"; + __pPath = Tizen::Base::Utility::StringUtil::StringToUtf8N(__filePath); + TryReturn(__pPath, GetLastResult(), "Path conversion failed."); + + xmlDocPtr pDocument = xmlParseFile((const char*) __pPath->GetPointer()); + TryReturn(pDocument, E_FAILURE, "xmlDocPtr conversion failed."); + + xmlNodePtr pRoot = xmlDocGetRootElement(pDocument); + TryCatch(pRoot, , "xmlNodePtr conversion failed."); + + __pList = new ListView(); + __pList->Construct(Rectangle(0, 0, clientRect.width, LIST_HEIGHT), true); + __pList->SetItemProvider(*this); + __pList->AddListViewItemEventListener(*this); + __pList->SetTextOfEmptyList(L""); + AddControl(*__pList); + + __pItemList = new ArrayList(); + __pItemList->Construct(); + + for (xmlNodePtr pCurrentElement = pRoot->children; pCurrentElement; pCurrentElement = pCurrentElement->next) + { + xmlNodePtr pChildElement = null; + + if (pCurrentElement->type == XML_ELEMENT_NODE) + { + // Get element from element + pChildElement = pCurrentElement->children->next; + + if (pChildElement) + { + String* countryName = new String; + // Get content from XML_TEXT_NODE + Tizen::Base::Utility::StringUtil::Utf8ToString((char*) pChildElement->children->content, *countryName); + __pItemList->Add(*countryName); + AppLog("country : %ls\n", (*countryName).GetPointer()); + } + } + } + __pList->UpdateList(); + r = E_SUCCESS; + +CATCH: + xmlFreeDoc(pDocument); + return r; +} + +void +XmlParser::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status) +{ + String key(L"/map/item[]/capital"); + ByteBuffer* pExpr = null; + String capital; + + xmlDocPtr pDocument = null; + xmlXPathContextPtr pXpathCtx = null; + xmlXPathObjectPtr pXpathObj = null; + xmlChar* pContent = null; + + // Create xml document + pDocument = xmlParseFile((const char*) __pPath->GetPointer()); + + // Create xpath context + pXpathCtx = xmlXPathNewContext(pDocument); + + key.Insert(index + 1, 10); + // Get an element + pExpr = Tizen::Base::Utility::StringUtil::StringToUtf8N(key); + pXpathObj = xmlXPathEvalExpression((xmlChar*) pExpr->GetPointer(), pXpathCtx); + delete pExpr; + + pContent = pXpathObj->nodesetval->nodeTab[0]->children->content; + Tizen::Base::Utility::StringUtil::Utf8ToString((char*) pContent, capital); + + // Clean up + xmlXPathFreeObject(pXpathObj); + xmlXPathFreeContext(pXpathCtx); + xmlFreeDoc(pDocument); + + __pLabel->SetText(capital); + + __pLabel->Draw(); +} + +void +XmlParser::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction) +{ + +} + +void +XmlParser::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state) +{ + +} + +int +XmlParser::GetItemCount(void) +{ + TryReturn(__pItemList, 0, "__pItemList is null"); + return __pItemList->GetCount(); +} + +Tizen::Ui::Controls::ListItemBase* +XmlParser::CreateItem(int index, int itemWidth) +{ + ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL; + SimpleItem* pItem = new SimpleItem(); + + pItem->Construct(Tizen::Graphics::Dimension(itemWidth, ITEM_HEIGHT), style); + Tizen::Base::String* pKey = static_cast< String* >(__pItemList->GetAt(index)); + + TryReturn(pKey, null, "Key value is empty for %d", index); + pItem->SetElement(*pKey, null); + return pItem; +} + +bool +XmlParser::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth) +{ + delete pItem; + pItem = null; + return true; +} + +result +XmlParser::OnTerminating(void) +{ + result r = E_SUCCESS; + if (__pItemList) + { + __pItemList->RemoveAll(true); + delete __pItemList; + __pItemList = null; + } + + // TODO: Add your termination code here + + return r; +} + +result +XmlParser::SAXParse(void) +{ + xmlSAXHandlerPtr pMySaxhandler = &mySaxHandler; + __found = false; + __checkContent = false; + __printCapital = false; + + xmlSAXUserParseFile(pMySaxhandler, null, (const char*) __pPath->GetPointer()); + + return E_SUCCESS; +} + + +result +XmlParser::SAXParseMemory(void) +{ + xmlDocPtr pDoc = null; + result r = E_SUCCESS; + File file; + FileAttributes fileAttribute; + ByteBuffer buffer; + + r = File::GetAttributes(__filePath, fileAttribute); + TryCatch(r == E_SUCCESS, , "Fail to get file attribute"); + + r = buffer.Construct((int) fileAttribute.GetFileSize()); + TryCatch(r == E_SUCCESS, , "Fail to construct buffer"); + + r = file.Construct(__filePath, L"r"); + r = file.Read(buffer); + TryCatch(r == E_SUCCESS, , "Fail to read file"); + + pDoc = xmlSAXParseMemory(null, (const char*) (buffer.GetPointer()), (int) fileAttribute.GetFileSize(), 0); + TryCatch(pDoc != null, , "document is null"); + + return E_SUCCESS; + +CATCH: + return E_FAILURE; +} + +xmlParserInputPtr +ResolveEntitySAXFunc(void* ctx, const xmlChar* publicId, const xmlChar* systemId) +{ + return null; +} + +void +InternalSubsetSAXFunc(void* ctx, const xmlChar* name, const xmlChar* ExternalID, const xmlChar* SystemID) +{ +} + +void +ExternalSubsetSAXFunc(void* ctx, const xmlChar* name, const xmlChar* ExternalID, const xmlChar* SystemID) +{ +} + +xmlEntityPtr +GetEntitySAXFunc(void* ctx, const xmlChar* name) +{ + return null; +} + +xmlEntityPtr +GetParameterEntitySAXFunc(void* ctx, const xmlChar* name) +{ + return null; +} + +void +EntityDeclSAXFunc(void* ctx, const xmlChar* name, int type, const xmlChar* publicId, const xmlChar* systemId, xmlChar* content) +{ +} + +void +NotationDeclSAXFunc(void* ctx, const xmlChar* name, const xmlChar* publicId, const xmlChar* systemId) +{ +} + +void +AttributeDeclSAXFunc(void* ctx, const xmlChar* elem, const xmlChar* fullname, int type, int def, const xmlChar* defaultValue, xmlEnumerationPtr tree) +{ +} + +void +ElementDeclSAXFunc(void* ctx, const xmlChar* name, int type, xmlElementContentPtr content) +{ +} + +void +UnparsedEntityDeclSAXFunc(void* ctx, const xmlChar* name, const xmlChar* publicId, const xmlChar* systemId, const xmlChar* notationName) +{ +} + +void +SetDocumentLocatorSAXFunc(void* ctx, xmlSAXLocatorPtr loc) +{ +} + +void +StartDocumentSAXFunc(void* ctx) +{ + +} + +void +EndDocumentSAXFunc(void* ctx) +{ +} + +void +StartElementSAXFunc(void* ctx, const xmlChar* name, const xmlChar** atts) +{ + XmlParser* pXmlParser = static_cast< XmlParser* >(ctx); + if (xmlStrcmp(name, (xmlChar*) "country") == 0) + { + pXmlParser->SetCheckContent(true); + } + else if (xmlStrcmp(name, (xmlChar*) "capital") == 0) + { + pXmlParser->SetPrintCapital(true); + } + else + { + pXmlParser->SetCheckContent(false); + pXmlParser->SetPrintCapital(false); + } +} + +void +EndElementSAXFunc(void* ctx, const xmlChar* name) +{ +} + +void +AttributeSAXFunc(void* ctx, const xmlChar* name, const xmlChar* value) +{ +} + +void +ReferenceSAXFunc(void* ctx, const xmlChar* name) +{ +} + +void +CharactersSAXFunc(void* ctx, const xmlChar* ch, int len) +{ + XmlParser* pXmlParser = static_cast< XmlParser* >(ctx); + if (pXmlParser->IsCheckContent()) + { + if (xmlStrncmp(ch, (xmlChar*) "Ghana", len) == 0) + { + pXmlParser->SetFound(true); + } + } + if (pXmlParser->IsFound() && pXmlParser->IsPrintCapital()) + { + AppLog("The capital of Chana is %ls\n", ch); + } +} + +void +IgnorableWhitespaceSAXFunc(void* ctx, const xmlChar* ch, int len) +{ +} + +void +ProcessingInstructionSAXFunc(void* ctx, const xmlChar* target, const xmlChar* data) +{ +} + +void +CommentSAXFunc(void* ctx, const xmlChar* value) +{ +} + +void +CdataBlockSAXFunc(void* ctx, const xmlChar* value, int len) +{ +} + +void +WarningSAXFunc(void* ctx, const char* msg, ...) +{ +} + +void +ErrorSAXFunc(void* ctx, const char* msg, ...) +{ +} + +void +FatalErrorSAXFunc(void* ctx, const char* msg, ...) +{ +} + +int +IsStandaloneSAXFunc(void* ctx) +{ + return 1; +} + +int +HasInternalSubsetSAXFunc(void* ctx) +{ + return 0; +} + + +int +HasExternalSubsetSAXFunc(void* ctx) +{ + return 0; +} + +void +XmlParser::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) +{ +} + +void +XmlParser::OnFormBackRequested(Tizen::Ui::Controls::Form& source) +{ + SceneManager* pSceneManager = SceneManager::GetInstance(); + pSceneManager->GoBackward(BackwardSceneTransition()); +} diff --git a/project/src/XmlParserApp.cpp b/project/src/XmlParserApp.cpp new file mode 100644 index 0000000..cc3408b --- /dev/null +++ b/project/src/XmlParserApp.cpp @@ -0,0 +1,103 @@ +// +// 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 "XmlParserApp.h" +#include "MainListForm.h" +#include "XmlReader.h" +#include "FormFactory.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::System; +using namespace Tizen::Ui; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Ui::Scenes; + +XmlParserApp::XmlParserApp(void) +{ +} + +XmlParserApp::~XmlParserApp(void) +{ +} + +Application* +XmlParserApp::CreateInstance(void) +{ + return new XmlParserApp(); +} + +bool +XmlParserApp::OnAppInitializing(AppRegistry& appRegistry) +{ + Frame* pAppFrame = new Frame(); + pAppFrame->Construct(); + AddFrame(*pAppFrame); + + SceneManager* pSceneManager = SceneManager::GetInstance(); + AppAssert(pSceneManager); + static FormFactory formFactory; + pSceneManager->RegisterFormFactory(formFactory); + pSceneManager->RegisterScene(L"MainListScene", L"MainListForm", L""); + pSceneManager->RegisterScene(L"XmlReaderScene", L"XmlReaderForm", L""); + pSceneManager->RegisterScene(L"HtmlParserScene", L"HtmlParserForm", L""); + pSceneManager->RegisterScene(L"XmlParserScene", L"XmlParserForm", L""); + pSceneManager->RegisterScene(L"XmlWriterScene", L"XmlWriterForm", L""); + + if (pSceneManager->GoForward(ForwardSceneTransition(L"MainListScene")) != E_SUCCESS) + { + return false; + } + + return true; +} + +bool +XmlParserApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination) +{ + return true; +} + +void +XmlParserApp::OnForeground(void) +{ +} + +void +XmlParserApp::OnBackground(void) +{ +} + +void +XmlParserApp::OnLowMemory(void) +{ +} + +void +XmlParserApp::OnBatteryLevelChanged(BatteryLevel batteryLevel) +{ +} + +void +XmlParserApp::OnScreenOn(void) +{ +} + +void +XmlParserApp::OnScreenOff(void) +{ +} diff --git a/project/src/XmlParserAppEntry.cpp b/project/src/XmlParserAppEntry.cpp new file mode 100644 index 0000000..3170902 --- /dev/null +++ b/project/src/XmlParserAppEntry.cpp @@ -0,0 +1,60 @@ +// +// 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. +// + +/** + * This file contains the Tizen C++ application entry point. + */ +#include "XmlParserApp.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +_EXPORT_ int OspMain(int argc, char* pArgv[]); + + +/** + * The entry function of Tizen C++ application called by the operating system. + */ +int +OspMain(int argc, char* pArgv[]) +{ + result r = E_SUCCESS; + + AppLog("Application started."); + ArrayList args; + args.Construct(); + for (int i = 0; i < argc; i++) + { + args.Add(*(new (std::nothrow) String(pArgv[i]))); + } + + r = Tizen::App::Application::Execute(XmlParserApp::CreateInstance, &args); + TryLog(r == E_SUCCESS, "Application execution failed-[%s].", GetErrorMessage(r)); + + args.RemoveAll(true); + AppLog("Application finished."); + + return static_cast< int >(r); +} +#ifdef __cplusplus +} +#endif // __cplusplus diff --git a/project/src/XmlReader.cpp b/project/src/XmlReader.cpp new file mode 100644 index 0000000..b8d993f --- /dev/null +++ b/project/src/XmlReader.cpp @@ -0,0 +1,201 @@ +// +// 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()); +} diff --git a/project/src/XmlWriter.cpp b/project/src/XmlWriter.cpp new file mode 100644 index 0000000..7e55235 --- /dev/null +++ b/project/src/XmlWriter.cpp @@ -0,0 +1,297 @@ +// +// 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 "XmlWriter.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; + +XmlWriter::XmlWriter(void) + : _pList(null) + , _pItemList(null) + , __display(false) +{ +} + +XmlWriter::~XmlWriter(void) +{ +} + +bool +XmlWriter::Initialize(void) +{ + Construct(FORM_STYLE_NORMAL | FORM_STYLE_FOOTER | FORM_STYLE_HEADER | FORM_STYLE_INDICATOR); + return true; +} + +result +XmlWriter::OnInitializing(void) +{ + result r = E_SUCCESS; + Header* pHeader = GetHeader(); + pHeader->SetTitleText("XML Writer"); + + Footer* pFooter = GetFooter(); + pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT); + + FooterItem writeButton; + writeButton.Construct(ID_BUTTON_WRITE); + writeButton.SetText("Write"); + pFooter->AddItem(writeButton); + + pFooter->SetBackButton(); + pFooter->AddActionEventListener(*this); + 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(); + + return r; +} + +int +XmlWriter::GetItemCount(void) +{ + TryReturn(_pItemList, 0, "_pItemList is null"); + return _pItemList->GetCount(); +} + +Tizen::Ui::Controls::ListItemBase* +XmlWriter::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 null for index %d", index); + + pItem->SetElement(*key, null); + return pItem; +} + +bool +XmlWriter::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth) +{ + delete pItem; + pItem = null; + return true; +} + + +void +XmlWriter::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status) +{ + +} + +void +XmlWriter::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction) +{ + +} + +void +XmlWriter::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state) +{ + +} + +void +XmlWriter::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) +{ + result err; + switch (actionId) + { + case ID_BUTTON_WRITE: + { + err = RunXMLWrite(); + TryReturnVoid(E_SUCCESS == err , "RunXMLWrite failed.%S", GetErrorMessage(err)); + + if(__display && _pItemList) + { + _pItemList->RemoveAll(true); + } + __display = false; + RunXMLParseandDisplay(); + Draw(); + } + break; + } +} + + +result +XmlWriter::RunXMLWrite(void) +{ + int rc; + result r = E_FAILURE; + + // Create xml document + const String filepath = App::GetInstance()->GetAppRootPath() + L"data/writemap.xml"; + + ByteBuffer* pBuf = Tizen::Base::Utility::StringUtil::StringToUtf8N(filepath); + TryReturn(pBuf, r, "String to ByteBuffer conversion failed."); + + xmlTextWriterPtr writer = xmlNewTextWriterFilename((const char*) pBuf->GetPointer(), 0); + TryCatch(writer, , "xmlNewTextWriterFilename Failed!"); + + rc = xmlTextWriterStartDocument(writer, null, "ISO-8859-1", null); + TryCatch(rc >= 0, , "xmlTextWriterStartDocument Failed!"); + + rc = xmlTextWriterStartElement(writer, (xmlChar*) "map"); + TryCatch(rc >= 0, , "xmlTextWriterStartElement Failed!"); + + rc = xmlTextWriterStartElement(writer, (xmlChar*) "item"); + TryCatch(rc >= 0, , "xmlTextWriterStartElement Failed!"); + + rc = xmlTextWriterWriteElement(writer, (xmlChar*) "Country", (xmlChar*) "America"); + TryCatch(rc >= 0, , "xmlTextWriterWriteElement Failed!"); + + rc = xmlTextWriterWriteElement(writer, (xmlChar*) "Capital", (xmlChar*) "Washington D.C."); + TryCatch(rc >= 0, , "xmlTextWriterWriteElement Failed!"); + + rc = xmlTextWriterEndElement(writer); + TryCatch(rc >= 0, , "xmlTextWriterEndElement Failed!"); + + rc = xmlTextWriterStartElement(writer, (xmlChar*) "item"); + TryCatch(rc >= 0, , "xmlTextWriterStartElement Failed!"); + + rc = xmlTextWriterWriteElement(writer, (xmlChar*) "Country", (xmlChar*) "England"); + TryCatch(rc >= 0, , "xmlTextWriterWriteElement Failed!"); + + rc = xmlTextWriterWriteElement(writer, (xmlChar*) "Capital", (xmlChar*) "London"); + TryCatch(rc >= 0, , "xmlTextWriterWriteElement Failed!"); + + rc = xmlTextWriterEndElement(writer); + TryCatch(rc >= 0, , "xmlTextWriterEndElement Failed!"); + + rc = xmlTextWriterStartElement(writer, (xmlChar*) "item"); + TryCatch(rc >= 0, , "xmlTextWriterStartElement Failed!"); + + rc = xmlTextWriterWriteElement(writer, (xmlChar*) "Country", (xmlChar*) "India"); + TryCatch(rc >= 0, , "xmlTextWriterWriteElement Failed!"); + + rc = xmlTextWriterWriteElement(writer, (xmlChar*) "Capital", (xmlChar*) "Delhi"); + TryCatch(rc >= 0, , "xmlTextWriterWriteElement Failed!"); + + rc = xmlTextWriterEndElement(writer); + TryCatch(rc >= 0, , "xmlTextWriterEndElement Failed!"); + + rc = xmlTextWriterEndElement(writer); + TryCatch(rc >= 0, , "xmlTextWriterEndElement Failed!"); + + rc = xmlTextWriterEndDocument(writer); + TryCatch(rc >= 0, , "xmlTextWriterEndDocument Failed!"); + + r = E_SUCCESS; + +CATCH: + delete pBuf; + pBuf = null; + if (writer) + { + xmlFreeTextWriter(writer); + } + return r; +} + +void +XmlWriter::RunXMLParseandDisplay(void) +{ + + const String filepath = App::GetInstance()->GetAppRootPath() + L"data/writemap.xml"; + xmlNodePtr pRoot = null; + + ByteBuffer* pBuf = Tizen::Base::Utility::StringUtil::StringToUtf8N(filepath); + TryReturnVoid(pBuf, "StringToUtf8N failed."); + + xmlDocPtr pDocument = xmlParseFile((const char*) pBuf->GetPointer()); + TryCatch(pBuf, , "xmlParseFile failed."); + + pRoot = xmlDocGetRootElement(pDocument); + TryCatch(pRoot, xmlFreeDoc(pDocument), "xmlDocGetRootElement failed."); + + TryCatch(_pList, xmlFreeDoc(pDocument), "_pList is null."); + + for (xmlNodePtr pCurrentElement = pRoot->children; pCurrentElement; pCurrentElement = pCurrentElement->next) + { + xmlNodePtr pChildElement = null; + + if (pCurrentElement->type == XML_ELEMENT_NODE) + { + // Get element from element + pChildElement = pCurrentElement->children; + + for (; pChildElement; pChildElement = pChildElement->next) + { + String* textName = new String; + Tizen::Base::Utility::StringUtil::Utf8ToString((char*) pChildElement->children->content, *textName); + _pItemList->Add(*textName); + } + } + } + + _pList->UpdateList(); + __display = true; + xmlFreeDoc(pDocument); +CATCH: + delete pBuf; + pBuf = null; + +} + +result +XmlWriter::OnTerminating(void) +{ + result r = E_SUCCESS; + if (_pItemList) + { + _pItemList->RemoveAll(true); + delete _pItemList; + _pItemList = null; + } + return r; +} + +void +XmlWriter::OnFormBackRequested(Tizen::Ui::Controls::Form& source) +{ + SceneManager* pSceneManager = SceneManager::GetInstance(); + pSceneManager->GoBackward(BackwardSceneTransition()); +} diff --git a/sample.xml b/sample.xml new file mode 100755 index 0000000..b724960 --- /dev/null +++ b/sample.xml @@ -0,0 +1,34 @@ + + diff --git a/screenshot.png b/screenshot.png new file mode 100755 index 0000000..98fb245 Binary files /dev/null and b/screenshot.png differ -- cgit v1.2.3