From: HyungKyu Song Date: Fri, 15 Feb 2013 15:56:23 +0000 (+0900) Subject: Tizen 2.0 Release X-Git-Tag: submit/tizen_2.0/20130215.192257^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_2.0;p=samples%2Fnative%2FJsonParserApp.git Tizen 2.0 Release --- 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 100644 index 0000000..add99d7 --- /dev/null +++ b/description.xml @@ -0,0 +1,11 @@ + + + + + JsonParserApp + 1.0 + screenshot.png + + This sample application demonstrates the JSON parsing functionality. + + diff --git a/project/data/jsonSample.json b/project/data/jsonSample.json new file mode 100755 index 0000000..307fc51 --- /dev/null +++ b/project/data/jsonSample.json @@ -0,0 +1,23 @@ +{"List": { + "debug": "on", + "window": { + "title": "Is an Icon List", + "name": "main_window", + "width": 500, + "height": 500 + }, + "image": { + "src": "Images/fun.png", + "name": "fun1" + }, + "text": { + "data": "Click Here", + "size": 36, + "style": "bold", + "name": "text1" + }, + "properties" : [ + {"alignment" : "center"}, + {"transparency":"80"} + ] +}} diff --git a/project/inc/JsonForm.h b/project/inc/JsonForm.h new file mode 100755 index 0000000..06a014c --- /dev/null +++ b/project/inc/JsonForm.h @@ -0,0 +1,85 @@ +// +// 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 _JSON_FORM_H_ +#define _JSON_FORM_H_ + +#include +#include +#include +#include +#include +#include + +using namespace Tizen::Web::Json; + +class JsonForm + : public Tizen::Ui::Controls::Form + , public Tizen::Ui::Controls::IListViewItemEventListener + , public Tizen::Ui::Controls::IListViewItemProvider + , public Tizen::Ui::Controls::IFastScrollListener + , public Tizen::Ui::IActionEventListener +{ + +// Construction +public: + JsonForm(void); + virtual ~JsonForm(void); + bool Initialize(void); + void TraverseFunction(IJsonValue* pValue); + void ParseAndDisplay(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); + + //IFastScrollListener + virtual void OnFastScrollIndexSelected(Tizen::Ui::Control& source, Tizen::Base::String& index); + +protected: + Tizen::Ui::Controls::ListView* _pList; + Tizen::Ui::Controls::Label* _pLabel; + Tizen::Base::Collection::IList* _pValueList; + Tizen::Base::Collection::ArrayList* _pJsonKeyList; + Tizen::Ui::Controls::Button* _pButton; + int _isArray; + +private: + static const int ACTION_PRESS = 101; + static const int ID_FORMAT_STRING = 102; + + static const int LABEL_LEFT_RIGHT_MARGIN = 75; + static const int LABEL_BOTTOM_MARGIN = 112; + static const int LABEL_WIDTH = 570; + static const int LABEL_HEIGHT = 112; + + static const int LIST_HEIGHT = 640; +}; + +#endif //_JSON_FORM_H_ diff --git a/project/inc/JsonParserApp.h b/project/inc/JsonParserApp.h new file mode 100644 index 0000000..31ae02a --- /dev/null +++ b/project/inc/JsonParserApp.h @@ -0,0 +1,69 @@ +// +// 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 _JSON_PARSER_APP_H_ +#define _JSON_PARSER_APP_H_ + +#include +#include +#include +#include + +/** + * [JsonParserApp] application must inherit from Application class + * which provides basic features necessary to define an application. + */ +class JsonParserApp + : public Tizen::App::Application + , public Tizen::System::IScreenEventListener +{ +public: + JsonParserApp(void); + ~JsonParserApp(void); + + /** + * [JsonParserApp] application must have a factory method that creates an instance of itself. + */ + static Tizen::App::Application* CreateInstance(void); + + // 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 //_JSON_PARSER_APP_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_JSONFORM.xml b/project/res/screen-size-normal/IDF_JSONFORM.xml new file mode 100755 index 0000000..683faa4 --- /dev/null +++ b/project/res/screen-size-normal/IDF_JSONFORM.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/JsonForm.cpp b/project/src/JsonForm.cpp new file mode 100755 index 0000000..b1a9ad4 --- /dev/null +++ b/project/src/JsonForm.cpp @@ -0,0 +1,342 @@ +// +// 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 "JsonForm.h" + +using namespace Tizen::Base; +using namespace Tizen::System; +using namespace Tizen::Base::Runtime; +using namespace Tizen::Base::Utility; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; +using namespace Tizen::App; +using namespace Tizen::Ui; +using namespace Tizen::Ui::Controls; +using namespace Tizen::Web::Json; +using namespace Tizen::Graphics; + +JsonForm::JsonForm(void) + : _pList(null) + , _pLabel(null) + , _pValueList(null) + , _pJsonKeyList(null) + , _pButton(null) + , _isArray(0) +{ +} + +JsonForm::~JsonForm(void) +{ +} + +bool +JsonForm::Initialize(void) +{ + Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_INDICATOR); + return true; +} + +result +JsonForm::OnInitializing(void) +{ + result r = E_SUCCESS; + Rectangle clientRect = GetClientAreaBounds(); + AppLog("%d, %d, %d, %d", clientRect.x, clientRect.y, clientRect.width, clientRect.height); + Header* pHeader = GetHeader(); + pHeader->SetTitleText("JSON PARSER"); + Footer* pFooter = GetFooter(); + pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT); + pFooter->AddActionEventListener(*this); + + FooterItem footerItem; + footerItem.Construct(ACTION_PRESS); + footerItem.SetText(L"START"); + + pFooter->AddItem(footerItem); + + _pLabel = new (std::nothrow) Label(); + _pLabel->Construct(Rectangle(LABEL_LEFT_RIGHT_MARGIN, clientRect.height - LABEL_HEIGHT -LABEL_BOTTOM_MARGIN, LABEL_WIDTH, LABEL_HEIGHT), L""); + AddControl(*_pLabel); + + _pList = new (std::nothrow) ListView(); + _pList->Construct(Rectangle(0, 0, clientRect.width, LIST_HEIGHT), true); + _pList->SetItemProvider(*this); + _pList->AddFastScrollListener(*this); + _pList->AddListViewItemEventListener(*this); + _pList->SetTextOfEmptyList(L""); + AddControl(*_pList); + + _pValueList = new (std::nothrow) LinkedList(); + + _pJsonKeyList = new (std::nothrow) ArrayList(); + _pJsonKeyList->Construct(); + return r; +} + +void +JsonForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status) +{ + String* pVal = static_cast< String* >(_pValueList->GetAt(index)); + TryReturnVoid(pVal, "listitem at index [%d] is null", index); + + _pLabel->SetText(*pVal); + _pLabel->RequestRedraw(); +} + +void +JsonForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction) +{ + +} + +void +JsonForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state) +{ + +} + +int +JsonForm::GetItemCount(void) +{ + TryReturn(_pJsonKeyList, 0, "JsonKeyList is null"); + + return _pJsonKeyList->GetCount(); +} + +Tizen::Ui::Controls::ListItemBase* +JsonForm::CreateItem(int index, int itemWidth) +{ + ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL; + SimpleItem* pItem = new (std::nothrow) SimpleItem(); + + pItem->Construct(Tizen::Graphics::Dimension(itemWidth, LABEL_HEIGHT), style); + Tizen::Base::String* key = static_cast< String* >(_pJsonKeyList->GetAt(index)); + pItem->SetElement(*key, null); + return pItem; +} + +bool +JsonForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth) +{ + delete pItem; + pItem = null; + return true; +} + +//Recursively traverse IJsonValue obtained by parser (using ParseN) +void +JsonForm::TraverseFunction(IJsonValue* pValue) +{ + TryReturnVoid(_pList, "_pList is null"); + + TryReturnVoid(pValue, "input jsonvalue pointer is null"); + + switch (pValue->GetType()) + { + case JSON_TYPE_OBJECT: + { + JsonObject* pObject = static_cast< JsonObject* >(pValue); + IMapEnumeratorT< const String*, IJsonValue* >* pMapEnum = pObject->GetMapEnumeratorN(); + while (pMapEnum->MoveNext() == E_SUCCESS) + { + const String* key = null; + IJsonValue* value = null; + pMapEnum->GetKey(key); + String* pListKey = new (std::nothrow) String(*key); + _pJsonKeyList->Add(*pListKey); + + String* pStr = null; + _isArray = 0; + pMapEnum->GetValue(value); + if (value->GetType() == JSON_TYPE_OBJECT) + { + pStr = new (std::nothrow) String("Value is an Object"); + _pValueList->Add(*pStr); + } + else if (value->GetType() == JSON_TYPE_ARRAY) + { + pStr = new (std::nothrow) String("Value is an Array"); + _pValueList->Add(*pStr); + } + TraverseFunction(value); + } + delete pMapEnum; + } + break; + + case JSON_TYPE_STRING: + { + JsonString* pVal = static_cast< JsonString* >(pValue); + if (_isArray == 0) + { + String* pStr = new (std::nothrow) String(*pVal); + _pValueList->Add(*pStr); + } + } + break; + + case JSON_TYPE_ARRAY: + { + JsonArray* pJsonArray = static_cast< JsonArray* >(pValue); + pJsonArray->GetCount(); + IEnumeratorT< IJsonValue* >* pEnum = pJsonArray->GetEnumeratorN(); + while (pEnum->MoveNext() == E_SUCCESS) + { + IJsonValue* pValue = null; + pEnum->GetCurrent(pValue); + if ((pValue->GetType() == JSON_TYPE_STRING) || (pValue->GetType() == JSON_TYPE_NUMBER) || (pValue->GetType() == JSON_TYPE_BOOL) || (pValue->GetType() == JSON_TYPE_NULL)) + _isArray = 1; + TraverseFunction(pValue); + } + delete pEnum; + } + break; + + case JSON_TYPE_NUMBER: + { + JsonNumber* pVal = static_cast< JsonNumber* >(pValue); + String* pStr = new (std::nothrow) String((pVal->ToString())); + if (_isArray == 0) + _pValueList->Add(*pStr); + } + break; + + case JSON_TYPE_BOOL: + { + String* pStr = null; + JsonBool* pVal = static_cast< JsonBool* >(pValue); + if (*pVal == true) + pStr = new (std::nothrow) String("true"); + else + pStr = new (std::nothrow) String("false"); + if (_isArray == 0) + _pValueList->Add(*pStr); + } + break; + + case JSON_TYPE_NULL: + { + String* pStr = null; + pStr = new (std::nothrow) String("null"); + if (_isArray == 0) + _pValueList->Add(*pStr); + } + break; + + default: + break; + } + _pList->UpdateList(); +} + +void +JsonForm::ParseAndDisplay(void) +{ + //Clear older values on label, if any + _pLabel->SetText(L""); + _pLabel->RequestRedraw(); + + File file; + String filePath = App::GetInstance()->GetAppRootPath() + L"data/jsonSample.json"; + + //Read File Content into buffer + result r = file.Construct(filePath, L"r"); + TryReturnVoid(r == E_SUCCESS, "file construction failure with [%s]", GetErrorMessage(r)); + + FileAttributes att; + r = File::GetAttributes(filePath, att); + TryReturnVoid(r == E_SUCCESS, "file GetAttributes failure with [%s]", GetErrorMessage(r)); + + long long size = att.GetFileSize(); + TryReturnVoid(size > 0, "file does not contain valid data, size of file [%ld]", size); + + ByteBuffer buf; + r = buf.Construct(size + 1); + TryReturnVoid(r == E_SUCCESS, "bytebuffer construct failure with [%s]", GetErrorMessage(r)); + + r = file.Read(buf); + TryReturnVoid(r == E_SUCCESS, "file read failure with [%s]", GetErrorMessage(r)); + + //Call Json Parser + IJsonValue* pJson = JsonParser::ParseN(buf); + TryCatch(pJson, r = GetLastResult(), "ParseN failed with [%s]", GetErrorMessage(r)); + + AppLog("Before traverse %d", _pList->GetItemCount()); + _pJsonKeyList->RemoveAll(true); + _pValueList->RemoveAll(true); + TraverseFunction(pJson); + AppLog("After traverse"); + + //clean up allocated jsonValues + if (pJson->GetType() == JSON_TYPE_OBJECT) + { + JsonObject* pObject = static_cast< JsonObject* >(pJson); + pObject->RemoveAll(true); + } + else if (pJson->GetType() == JSON_TYPE_ARRAY) + { + JsonArray* pArray = static_cast< JsonArray* >(pJson); + pArray->RemoveAll(true); + } + delete pJson; + _pList->ScrollToItem(0); + Draw(); + return; + +CATCH: + _pLabel->SetText(L"CORRUPTED INPUT DATA"); + _pLabel->RequestRedraw(); + return; +} + +void +JsonForm::OnFastScrollIndexSelected(Tizen::Ui::Control& source, Tizen::Base::String& index) +{ + +} + +result +JsonForm::OnTerminating(void) +{ + if (_pValueList) + { + _pValueList->RemoveAll(true); + delete _pValueList; + _pValueList = null; + } + + if (_pJsonKeyList) + { + _pJsonKeyList->RemoveAll(true); + delete _pJsonKeyList; + _pJsonKeyList = null; + } + + return E_SUCCESS; +} + +void +JsonForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId) +{ + switch (actionId) + { + case ACTION_PRESS: + { + ParseAndDisplay(); + } + break; + } +} diff --git a/project/src/JsonParserApp.cpp b/project/src/JsonParserApp.cpp new file mode 100644 index 0000000..61f3697 --- /dev/null +++ b/project/src/JsonParserApp.cpp @@ -0,0 +1,100 @@ +// +// 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 "JsonParserApp.h" +#include "JsonForm.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::System; +using namespace Tizen::Ui; +using namespace Tizen::Ui::Controls; + +JsonParserApp::JsonParserApp(void) +{ +} + +JsonParserApp::~JsonParserApp(void) +{ +} + +Application* +JsonParserApp::CreateInstance(void) +{ + // Create the instance through the constructor. + return new JsonParserApp(); +} + +bool +JsonParserApp::OnAppInitializing(AppRegistry& appRegistry) +{ + Frame* pAppFrame = new (std::nothrow) Frame(); + pAppFrame->Construct(); + AddFrame(*pAppFrame); + + // Create a form + JsonForm* pJsonForm = new (std::nothrow) JsonForm(); + pJsonForm->Initialize(); + + // Add the form to the frame + Frame* pFrame = GetAppFrame()->GetFrame(); + pFrame->AddControl(*pJsonForm); + + // Set the current form + pFrame->SetCurrentForm(*pJsonForm); + + // Draw the form + pJsonForm->Draw(); + + return true; +} + +bool +JsonParserApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination) +{ + return true; +} + +void +JsonParserApp::OnForeground(void) +{ +} + +void +JsonParserApp::OnBackground(void) +{ +} + +void +JsonParserApp::OnLowMemory(void) +{ +} + +void +JsonParserApp::OnBatteryLevelChanged(BatteryLevel batteryLevel) +{ +} + +void +JsonParserApp::OnScreenOn(void) +{ +} + +void +JsonParserApp::OnScreenOff(void) +{ +} diff --git a/project/src/JsonParserAppEntry.cpp b/project/src/JsonParserAppEntry.cpp new file mode 100644 index 0000000..9e3f21e --- /dev/null +++ b/project/src/JsonParserAppEntry.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 "JsonParserApp.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(JsonParserApp::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/sample.xml b/sample.xml new file mode 100644 index 0000000..89481bb --- /dev/null +++ b/sample.xml @@ -0,0 +1,34 @@ + + diff --git a/screenshot.png b/screenshot.png new file mode 100755 index 0000000..d00bab0 Binary files /dev/null and b/screenshot.png differ