--- /dev/null
+Jaegyu Jung <pang at samsung dot com>
+Kyungeun Park <kyung-eun.park at samsung dot com>
+Seongjun Yim <se201.yim at samsung dot com>
+Hyun Lee <hyunn.lee at samsung dot com>
+Hyunseok Yang <hs0219.yang at samsung dot com>
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output)
+
+SET (this_target osp-json)
+
+INCLUDE_DIRECTORIES(
+ inc
+ src
+ /usr/include/boost
+ /usr/include/osp
+ /usr/include/osp/app
+ /usr/include/osp/base
+ /usr/include/osp/io
+ /usr/include/osp/security
+ )
+
+SET (${this_target}_SOURCE_FILES
+ src/FWebJson_JsonUtils.cpp
+ src/FWebJsonJsonArray.cpp
+ src/FWebJsonJsonBool.cpp
+ src/FWebJsonJsonNull.cpp
+ src/FWebJsonJsonNumber.cpp
+ src/FWebJsonJsonObject.cpp
+ src/FWebJsonJsonString.cpp
+ src/FWebJsonJsonParser.cpp
+ src/FWebJson_JsonParserImpl.cpp
+ src/FWebJsonJsonWriter.cpp
+ src/FWebJson_JsonWriterImpl.cpp
+)
+
+## Definitions
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
+
+## SET LINKER FLAGS
+SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined -Wl,--as-needed")
+
+TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw" )
+
+SET_TARGET_PROPERTIES(${this_target}
+ PROPERTIES
+ VERSION ${FULLVER}
+ SOVERSION ${MAJORVER}
+ CLEAN_DIRECT_OUTPUT 1
+ )
+
+ADD_CUSTOM_COMMAND(TARGET ${this_target}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER}
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${MAJORVER}
+ COMMAND ${CMAKE_STRIP} --strip-unneeded ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}
+ COMMENT "strip ${this_target}"
+ )
+
+INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/ DESTINATION lib/osp
+ FILES_MATCHING PATTERN "*.so*"
+ PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
+ GROUP_EXECUTE GROUP_READ
+ WORLD_EXECUTE WORLD_READ)
+INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/debug/ DESTINATION lib/osp/debug
+ FILES_MATCHING PATTERN "*"
+ PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
+ GROUP_EXECUTE GROUP_READ
+ WORLD_EXECUTE WORLD_READ)
+
+
+
+INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/inc/ DESTINATION include/osp FILES_MATCHING PATTERN "*.h")
+
+# pkgconfig file
+CONFIGURE_FILE(${this_target}.pc.in ${CMAKE_SOURCE_DIR}/${this_target}.pc @ONLY)
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/${this_target}.pc DESTINATION lib/pkgconfig)
+
--- /dev/null
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ 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.
+
+ 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,
+ 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 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 in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) 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
+
+ (d) 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 Apache License to your work.
+
+ To apply the Apache 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 Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+
+ 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.
--- /dev/null
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE file for Apache License terms and conditions.
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJson.h
+ * @brief This is the header file for the %Json namespace.
+ *
+ * This header file contains the introduction of the %Json namespace.
+ */
+#ifndef _FWEB_JSON_H_
+#define _FWEB_JSON_H_
+
+#include <FWebJsonJsonArray.h>
+#include <FWebJsonJsonBool.h>
+#include <FWebJsonJsonNull.h>
+#include <FWebJsonJsonNumber.h>
+#include <FWebJsonJsonObject.h>
+#include <FWebJsonJsonParser.h>
+#include <FWebJsonJsonString.h>
+#include <FWebJsonJsonWriter.h>
+
+/**
+ * @namespace Tizen::Web::Json
+ * @brief This namespace contains interfaces to manipulate the JSON documents.
+ * @since 2.0
+ *
+ * @remarks @b Header @b %file: @b \#include @b <FWebJson.h> @n
+ * @b Library : @b osp-web
+ *
+ * The %Json namespace contains interfaces to manipulate the JSON documents.
+ * @n
+ * For more information on the %Json namespace features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+ *
+ * The following diagram illustrates the relationships between the classes belonging to the %Json namespace.
+ *
+ * @image html web_json_classdiagram.png
+ *
+ */
+namespace Tizen { namespace Web { namespace Json
+{
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonIJsonValue.h
+ * @brief This is the header file for the %IJsonValue interface for the JSON (generic) value.
+ *
+ * This header file contains the definitions of the basic JSON types and declarations for
+ * getting the type of a JSON value.
+ */
+#ifndef _FWEB_JSON_IJSON_VALUE_H_
+#define _FWEB_JSON_IJSON_VALUE_H_
+
+#include <FOspConfig.h>
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+/**
+ * @enum JsonType
+ *
+ * Defines the JSON value types.
+ *
+ * @since 2.0
+ */
+enum JsonType
+{
+ JSON_TYPE_STRING, /**< The JSON string type*/
+ JSON_TYPE_NUMBER, /**< The JSON number type*/
+ JSON_TYPE_OBJECT, /**< The JSON object type*/
+ JSON_TYPE_ARRAY, /**< The JSON array type*/
+ JSON_TYPE_BOOL, /**< The JSON bool type*/
+ JSON_TYPE_NULL /**< The JSON null type*/
+};
+
+/**
+ * @interface IJsonValue
+ * @brief This interface represents a Json value.
+ *
+ * @since 2.0
+ *
+ * The %IJsonValue interface abstracts a Json value class of a Json value type (string, bool, number, array, object, and null type).
+ * @n
+ * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+ */
+class _OSP_EXPORT_ IJsonValue
+{
+public:
+ /**
+ * This polymorphic destructor should be overridden if required. This way, the destructors of the derived classes are called when the destructor of this interface is called.
+ *
+ * @since 2.0
+ */
+ virtual ~IJsonValue(void) {}
+
+ /**
+ * Gets the type of the object contained.
+ *
+ * @since 2.0
+ *
+ * @return The JSON type
+ */
+ virtual JsonType GetType(void) const = 0;
+
+protected:
+ //
+ // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application.
+ //
+ // Gets the Impl instance.
+ //
+ // @since 2.0
+ //
+ virtual void IJsonValue_Reserved1(void) {}
+
+ //
+ // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application.
+ //
+ // Gets the Impl instance.
+ //
+ // @since 2.0
+ //
+ virtual void IJsonValue_Reserved2(void) {}
+
+ //
+ // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application.
+ //
+ // Gets the Impl instance.
+ //
+ // @since 2.0
+ //
+ virtual void IJsonValue_Reserved3(void) {}
+
+ //
+ // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application.
+ //
+ // Gets the Impl instance.
+ //
+ // @since 2.0
+ //
+ virtual void IJsonValue_Reserved4(void) {}
+
+ //
+ // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application.
+ //
+ // Gets the Impl instance.
+ //
+ // @since 2.0
+ //
+ virtual void IJsonValue_Reserved5(void) {}
+
+}; // IJsonValue
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_IJSON_VALUE_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonArray.h
+ * @brief This is the header file for the %JsonArray class.
+ *
+ * This header file contains the declarations of the %JsonArray class.
+ */
+#ifndef _FWEB_JSON_JSON_ARRAY_H_
+#define _FWEB_JSON_JSON_ARRAY_H_
+
+#include <FBaseColArrayListT.h>
+#include <FBaseColICollectionT.h>
+#include <FWebJsonIJsonValue.h>
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Woverloaded-virtual"
+#endif
+
+namespace Tizen { namespace Web { namespace Json
+{
+class _JsonArrayImpl;
+}}} // Tizen::Web::Json
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+/**
+ * @class JsonArray
+ * @brief This class represents the JSON value of type array.
+ *
+ * @since 2.0
+ *
+ * @final This class is not intended for extension.
+ *
+ * The %JsonArray class represents the JSON value of type array.
+ * @n
+ * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+ *
+ * The following example shows how to create and initialize a %JsonArray instance and how to use its methods.
+ *
+ * @code
+ * #include <FWebJson.h>
+ *
+ * using namespace Tizen::Base;
+ * using namespace Tizen::Base::Collection;
+ * using namespace Tizen::Web::Json;
+ *
+ * void
+ * MyClass::JsonArraySample(void)
+ * {
+ * // Creates an instance of JsonArray
+ * JsonArray *pJsonArray = new JsonArray();
+ *
+ * // Must call Construct() for JasonArray
+ * pJsonArray->Construct();
+ *
+ * // Creates value instances
+ * JsonString *pJsonstr = new JsonString(L"myname");
+ * JsonNumber *pJsonNum = new JsonNumber(99);
+ * JsonBool *pJsonBool = new JsonBool(true);
+ *
+ * // Adds the string to the JsonArray
+ * pJsonArray->Add(pJsonstr);
+ * // Adds the number to the JsonArray
+ * pJsonArray->Add(pJsonNum);
+ * // Adds the boolean to the JsonArray
+ * pJsonArray->Add(pJsonBool);
+ *
+ * // Gets the value at the given position(index) in the JsonArray
+ * IJsonValue* pValue = null;
+ * pJsonArray->GetAt(0, pValue);
+ *
+ * // Finds the index of the given value in the JsonArray
+ * JsonString *pJsonstrcheck = new JsonString(L"myname");
+ * int index;
+ * pJsonArray->IndexOf(pJsonstrcheck, index);
+ *
+ * // Uses enumerator to access elements in the JsonArray
+ * IEnumeratorT<IJsonValue*>* pEnum = pJsonArray->GetEnumeratorN();
+ * if(pEnum)
+ * {
+ * while( pEnum->MoveNext() == E_SUCCESS )
+ * {
+ * IJsonValue* pJsonValue = null;
+ *
+ * //Uses the pJsonValue
+ * pEnum->GetCurrent( pJsonValue );
+ * }
+ * delete pEnum;
+ * }
+ *
+ * // Removes the value in the JsonArray
+ * pJsonArray->RemoveAt(index, true);
+ *
+ * // Removes all the remaining values
+ * pJsonArray->RemoveAll(true);
+ * delete pJsonArray;
+ * }
+ * @endcode
+ */
+class _OSP_EXPORT_ JsonArray
+ : public IJsonValue
+ , public Tizen::Base::Collection::ArrayListT<IJsonValue*>
+{
+public:
+ /**
+ * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
+ *
+ * @since 2.0
+ */
+ JsonArray(void);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object().
+ *
+ * @since 2.0
+ */
+ virtual ~JsonArray(void);
+
+ /**
+ * Initializes the instance of %JsonArray.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ * @exception E_INVALID_OPERATION This instance has already been constructed.
+ */
+ result Construct(void);
+
+ /**
+ * Returns the type of this class. @n
+ * In this case, it is always @c JSON_ARRAY.
+ *
+ * @since 2.0
+ *
+ * @return The JSON type
+ * @see JsonType
+ */
+ JsonType GetType(void) const;
+
+ /**
+ * Adds the specified element to end of the list.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pJsonValue A pointer to JsonValue to be added to the list
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified input parameter is invalid.
+ * @see Remove()
+ */
+ virtual result Add(IJsonValue* const& pJsonValue);
+
+ /**
+ * Searches for an element in this list. @n
+ * Gets the index of the element if it is found.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pJsonValue A pointer to the JsonValue class to be located
+ * @param[out] index The index of the element
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_OBJ_NOT_FOUND The @c pJsonValue is not found.
+ * @see LastIndexOf()
+ */
+ virtual result IndexOf(IJsonValue* const& pJsonValue, int& index) const;
+
+ /**
+ * Searches for an element starting from the specified index. @n
+ * Gets the index of the element if it is found.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pJsonValue A pointer to the JsonValue class to be located
+ * @param[in] startIndex The starting index for the search @n
+ * It must be less than the number of elements in the array.
+ * @param[out] index The index of the element
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or the specified @c startIndex is either equal to or greater than the number of elements or less than @c 0.
+ * @exception E_OBJ_NOT_FOUND The specified @c pJsonValue is not found.
+ * @see LastIndexOf()
+ */
+ virtual result IndexOf(IJsonValue* const& pJsonValue, int startIndex, int& index) const;
+
+ /**
+ * Searches for an element within the specified range. @n
+ * Gets the index of the element if it is found.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pJsonValue A pointer to the JsonValue class to be located
+ * @param[in] startIndex The starting index of the range
+ * @param[in] count The number of elements to be read
+ * @param[out] index The index of the element
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
+ * - The specified index is outside the bounds of the data structure. @n
+ * - The specified @c startIndex is either greater than or equal to the number of elements or less than @c 0. @n
+ * - The specified @c count is either greater than the number of elements starting from @c startIndex or less than @c 0.
+ * @exception E_OBJ_NOT_FOUND The @c pJsonValue is not found.
+ * @see LastIndexOf()
+ */
+ virtual result IndexOf(IJsonValue* const& pJsonValue, int startIndex, int count, int& index) const;
+
+ /**
+ * Searches for the last occurrence of an element in this list. @n
+ * Gets the index of the element if it is found.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pJsonValue A pointer to the JsonValue class to be located
+ * @param[out] index The index of the last occurrence of the specified element
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_OBJ_NOT_FOUND The specified @c pJsonValue is not found.
+ * @see IndexOf()
+ */
+ virtual result LastIndexOf(IJsonValue* const& pJsonValue, int& index) const;
+
+ /**
+ * Checks whether the list contains the specified @c JsonValue.
+ *
+ * @since 2.0
+ *
+ * @return @c true if the specified @c JsonValue is present in the list, @n
+ * else @c false
+ * @param[in] pJsonValue A pointer to the JsonValue class to be located
+ */
+ virtual bool Contains(IJsonValue* const& pJsonValue) const;
+
+ /**
+ * Checks whether value of the specified instance equals to value of the current instance of @c %JsonArray.
+ *
+ * @since 2.0
+ *
+ * @return @c true if value of the current instance equals to value of the specified instance, @n
+ * else @c false
+ * @param[in] obj The element to be compared with the current instance of @c %JsonArray
+ * @remarks The method returns @c false if the specified element is not @c %JsonArray.
+ * @see Object::Equals()
+ */
+ virtual bool Equals(const Object& obj) const;
+
+ /**
+ * Gets the hash value of the current instance.
+ *
+ * @since 2.0
+ *
+ * @return An integer value indicating the hash value of the current instance
+ * @remarks The two equal instances must return the same hash value. For better performance,
+ * the used hash function must generate a random distribution for all inputs.
+ * The default implementation of this method returns the address of the current instance.
+ */
+ virtual int GetHashCode(void) const;
+
+ /**
+ * Removes the first occurrence of the specified element.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pJsonValue A pointer to the %JsonValue class to be removed
+ * @param[in] deallocate Set to @c true to deallocate the @c JsonValue, @n
+ * else @c false
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_OBJ_NOT_FOUND The @c pJsonValue is not found.
+ * @see Add(), RemoveAt(), RemoveAll()
+ */
+ virtual result Remove(IJsonValue* const& pJsonValue, bool deallocate = false);
+
+ /**
+ * Removes all the elements of the specified collection from the list.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] collection The collection to be removed from this list
+ * @param[in] deallocate Set to @c true to deallocate the @c JsonValues, @n
+ * else @c false
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation. @n
+ * The @c collection is modified during the operation of this method.
+ */
+ virtual result RemoveItems(const Tizen::Base::Collection::ICollectionT<IJsonValue*>& collection, bool deallocate = false);
+
+ /**
+ * Removes an element from the specified location.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] index The index of the element to be removed
+ * @param[in] deallocate Set to @c true to deallocate the @c JsonValue, @n
+ * else @c false
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or the specified @c index is greater than or equal to the number of elements or less than @c 0.
+ * @remarks The elements that follow the deleted element move up the list to occupy the empty location.
+ */
+ virtual result RemoveAt(int index, bool deallocate = false);
+
+ /**
+ * Removes all the elements within a specified range.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] startIndex The starting index of the range
+ * @param[in] count The number of elements to remove
+ * @param[in] deallocate Set to @c true to deallocate the JsonValue, @n
+ * else @c false
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
+ * - The specified index is outside the bounds. @n
+ * - The specified @c startIndex is either greater than or equal to the number of elements or less than @c 0. @n
+ * - The specified @c count is either greater than the number of elements starting from @c startIndex or less than @c 0.
+ * @remarks The elements that follow the deleted elements move up the list to occupy the empty locations.
+ */
+ virtual result RemoveItems(int startIndex, int count, bool deallocate = false);
+
+ /**
+ * Removes all the elements in the %JsonArray class.
+ *
+ * @since 2.0
+ *
+ * @param[in] deallocate Set to @c true to deallocate all the elements, @n
+ * else @c false
+ */
+ virtual void RemoveAll(bool deallocate = false);
+
+ /**
+ * Replaces the element at the specified index with the specified element.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pJsonValue A pointer to the JsonValue class to be set
+ * @param[in] index The index at which the element must be set
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid.
+ * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or the specified @c index is either equal to or greater than the number of elements or less than @c 0.
+ * @see GetAt()
+ */
+ virtual result SetAt(IJsonValue* const& pJsonValue, int index);
+
+ /**
+ * Replaces the element at the specified index with the specified element.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pJsonValue A pointer to the JsonValue class to be set
+ * @param[in] index The index at which the element must be set
+ * @param[in] deallocate Set to @c true to deallocate the @c JsonValue, @n
+ * else @c false
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid.
+ * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or the specified @c index is either equal to or greater than the number of elements or less than @c 0.
+ * @see GetAt()
+ */
+ virtual result SetAt(IJsonValue* const& pJsonValue, int index, bool deallocate);
+
+ /**
+ * Returns a new cloned %JsonArray instance.
+ *
+ * @since 2.0
+ *
+ * @return A new cloned %JsonArray
+ * @exception E_SUCCESS The memory is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ JsonArray* CloneN(void) const;
+
+private:
+ //
+ // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @param[in] item The instance of the %JsonArray class to copy from
+ // @remarks This constructor is hidden.
+ //
+ JsonArray(const JsonArray& item);
+
+ //
+ // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @param[in] item The instance of the %JsonArray class to assign from
+ // @remarks This operator is hidden.
+ //
+ JsonArray& operator =(const JsonArray& item);
+
+private:
+ _JsonArrayImpl* __pJsonArrayImpl;
+
+ friend class _JsonArrayImpl;
+}; // JsonArray
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_JSON_ARRAY_H_
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonBool.h
+ * @brief This is the header file for the %JsonBool class.
+ *
+ * This header file contains the declarations of the %JsonBool class.
+ * This class represents the JSON value of type @c bool.
+ */
+#ifndef _FWEB_JSON_JSON_BOOL_H_
+#define _FWEB_JSON_JSON_BOOL_H_
+
+#include <FBaseBoolean.h>
+#include <FBaseString.h>
+#include <FWebJsonIJsonValue.h>
+
+namespace Tizen { namespace Web { namespace Json
+{
+class _JsonBoolImpl;
+}}} // Tizen::Web::Json
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+/**
+ * @class JsonBool
+ * @brief This class represents the JSON value of type @c bool.
+ *
+ * @since 2.0
+ *
+ * @final This class is not intended for extension.
+ *
+ * The %JsonBool class represents the JSON value of type @c bool.
+ * @n
+ * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+ *
+ *
+ */
+class _OSP_EXPORT_ JsonBool
+ : public IJsonValue
+ , public Tizen::Base::Boolean
+{
+public:
+ /**
+ * Initializes this instance of %JsonBool with the specified parameter.
+ *
+ * @since 2.0
+ *
+ * @param[in] value The input bool value to initialize the %JsonBool object
+ */
+ JsonBool(bool value);
+
+ /**
+ * Initializes a new boolean object to the input string represented by the @c value. @n
+ * If the input string is "true" (value is case insensitive), the object is initialized to @c true,
+ * else, the value is initialized to @c false.
+ *
+ * @since 2.0
+ *
+ * @param[in] value An instance of String
+ */
+ JsonBool(const Tizen::Base::String& value);
+
+ /**
+ * Initializes this instance of %JsonBool with the specified parameter.
+ *
+ * @since 2.0
+ *
+ * @param[in] value A boolean value to initialize the %JsonBool instance
+ */
+ JsonBool(const Boolean& value);
+
+ /**
+ * Copying of objects using this copy constructor is allowed. @n
+ * Initializes a new instance of the %JsonBool class to the specified @c value.
+ *
+ * @since 2.0
+ *
+ * @param[in] value An instance of %JsonBool
+ */
+ JsonBool(const JsonBool& value);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object().
+ *
+ * @since 2.0
+ */
+ virtual ~JsonBool(void);
+
+ /**
+ * Gets the type of this class (always JSON_BOOL).
+ *
+ * @since 2.0
+ *
+ * @return The JSON type
+ * @see JsonType
+ */
+ JsonType GetType(void) const;
+
+ /**
+ * Copying of objects using this copy assignment operator is allowed.
+ *
+ * @since 2.0
+ *
+ * @param[in] rhs An instance of %JsonBool
+ */
+ JsonBool& operator =(const JsonBool& rhs);
+
+private:
+ _JsonBoolImpl* __pJsonBoolImpl;
+
+ friend class _JsonBoolImpl;
+}; // JsonBool
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_JSON_BOOL_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonNull.h
+ * @brief This is the header file for the %JsonNull class.
+ *
+ * This header file contains the declarations of the %JsonNull class.
+ * The class represents the JSON value of type @c null.
+ */
+#ifndef _FWEB_JSON_JSON_NULL_H_
+#define _FWEB_JSON_JSON_NULL_H_
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FWebJsonIJsonValue.h>
+
+namespace Tizen { namespace Web { namespace Json
+{
+class _JsonNullImpl;
+}}} // Tizen::Web::Json
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+/**
+ * @class JsonNull
+ * @brief This class represents the JSON value of type @c null.
+ *
+ * @since 2.0
+ *
+ * @final This class is not intended for extension.
+ *
+ * The %JsonNull class represents the JSON value of type @c null.
+ * @n
+ * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+
+ *
+ */
+class _OSP_EXPORT_ JsonNull
+ : public IJsonValue
+ , public Tizen::Base::Object
+{
+public:
+ /**
+ * This is the default constructor for this class.
+ *
+ * @since 2.0
+ */
+ JsonNull(void);
+
+ /**
+ * Copying of objects using this copy constructor is allowed. @n
+ * Initializes a new instance of %JsonNull to the specified @c value.
+ *
+ * @since 2.0
+ *
+ * @param[in] value An instance of %JsonNull
+ */
+ JsonNull(const JsonNull& value);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object().
+ *
+ * @since 2.0
+ */
+ virtual ~JsonNull(void);
+
+ /**
+ * Checks whether the value of the specified instance equals the value of the current instance.
+ *
+ * @since 2.0
+ *
+ * @return @c true if the value of the current instance equals the value of the specified instance, @n
+ else @c false
+ * @param[in] obj The object to compare with the current instance of %JsonNull
+ * @remarks The method returns @c false if the specified object is not %JsonNull.
+ * @see Object::Equals()
+ */
+ virtual bool Equals(const Object& obj) const;
+
+ /**
+ * Gets the hash value of the current instance.
+ *
+ * @since 2.0
+ *
+ * @return An integer value indicating the hash value of the current instance
+ * @remarks The two equal instances should return the same hash value. For better performance,
+ * the used hash function must generate a random distribution for all inputs.
+ * @n
+ * The default implementation of this method returns the address of the current instance.
+ */
+ virtual int GetHashCode(void) const;
+
+ /**
+ * Gets the type of the object (Always JSON_NULL)
+ *
+ * @since 2.0
+ *
+ * @return The JSON type
+ */
+ JsonType GetType(void) const;
+
+ /**
+ * Converts the value of the calling object from %JsonNull to a string.
+ *
+ * @since 2.0
+ *
+ * @return A string representing the value of the current instance.
+ */
+ Tizen::Base::String ToString(void) const;
+
+ /**
+ * Assigns the value of the specified instance of %JsonNull to the current instance of %JsonNull.
+ *
+ * @since 2.0
+ *
+ * @param[in] rhs An instance of %JsonNull
+ */
+ JsonNull& operator =(const JsonNull& rhs);
+
+ /**
+ * Checks whether the values of the two %JsonNull objects are equal.
+ *
+ * @since 2.0
+ *
+ * @return @c true if the values of the objects are equal, @n
+ else @c false
+ * @param[in] rhs A %JsonNull instance to compare with the current instance
+ */
+ bool operator ==(const JsonNull& rhs) const;
+
+
+ /**
+ * Checks whether the values of the two %JsonNull objects are not equal.
+ *
+ * @since 2.0
+ *
+ * @return @c true if the values of the objects are not equal, @n
+ else @c false
+ * @param[in] rhs A %JsonNull instance to compare with the current instance
+ */
+ bool operator !=(const JsonNull& rhs) const;
+
+private:
+ _JsonNullImpl* __pJsonNullImpl;
+
+ friend class _JsonNullImpl;
+}; // JsonNull
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_JSON_NULL_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonNumber.h
+ * @brief This is the header file for the %JsonNumber class.
+ *
+ * This header file contains the declarations of the %JsonNumber class.
+ * The class represents the JSON value of type number.
+ *
+ */
+#ifndef _FWEB_JSON_JSON_NUMBER_H_
+#define _FWEB_JSON_JSON_NUMBER_H_
+
+#include <FBaseDouble.h>
+#include <FWebJsonIJsonValue.h>
+
+namespace Tizen { namespace Web { namespace Json
+{
+class _JsonNumberImpl;
+}}} // Tizen::Web::Json
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+/**
+ * @class JsonNumber
+ * @brief This class represents the JSON value of type number.
+ *
+ * @since 2.0
+ *
+ * @final This class is not intended for extension.
+ *
+ * The %JsonNumber class represents the type of the JSON number.
+ * @n
+ * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+
+ *
+ */
+class _OSP_EXPORT_ JsonNumber
+ : public IJsonValue
+ , public Tizen::Base::Double
+{
+public:
+ /**
+ * Initializes this instance of %JsonNumber with the specified parameter.
+ *
+ * @since 2.0
+ *
+ * @param[in] value The value of type @c double
+ */
+ JsonNumber(double value = 0.0L);
+
+ /**
+ * Initializes this instance of %JsonNumber with the specified parameter.
+ *
+ * @since 2.0
+ *
+ * @param[in] value The value of type integer
+ */
+ JsonNumber(int value);
+
+ /**
+ * Copying of objects using this copy constructor is allowed. @n
+ * This constructor initializes a new instance of the %JsonNumber class with the value from another instance.
+ *
+ * @since 2.0
+ *
+ * @param[in] value An instance of JsonNumber
+ */
+ JsonNumber(const JsonNumber& value);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object().
+ *
+ * @since 2.0
+ */
+ virtual ~JsonNumber(void);
+
+ /**
+ * Gets the type of JSON number.
+ *
+ * @since 2.0
+ *
+ * @return The type of JSON number
+ * @see JsonType
+ */
+ JsonType GetType(void) const;
+
+ /**
+ * Copying of objects using this copy assignment operator is allowed.
+ *
+ * @since 2.0
+ *
+ * @param[in] rhs An instance of %JsonNumber
+ */
+ JsonNumber& operator =(const JsonNumber& rhs);
+
+private:
+ _JsonNumberImpl* __pJsonNumberImpl;
+
+ friend class _JsonNumberImpl;
+}; // JsonNumber
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_JSON_NUMBER_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonObject.h
+ * @brief This is the header file for the %JsonObject class.
+ *
+ * This header file contains the declarations of the %JsonObject class.
+ * The class represents the JSON value of type object.
+ */
+#ifndef _FWEB_JSON_JSON_OBJECT_H_
+#define _FWEB_JSON_JSON_OBJECT_H_
+
+#include <FBaseColHashMapT.h>
+#include <FBaseString.h>
+#include <FWebJsonIJsonValue.h>
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Woverloaded-virtual"
+#endif
+
+namespace Tizen { namespace Web { namespace Json
+{
+class _JsonObjectImpl;
+class _JsonObjectComparer;
+class _JsonObjectHashCodeProvider;
+}}} // Tizen::Web::Json
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+/**
+ * @class JsonObject
+ * @brief This class represents the JSON value of type object.
+ *
+ * @since 2.0
+ *
+ * @final This class is not intended for extension.
+ *
+ * The %JsonObject class represents the JSON value of type object.
+ * @n
+ * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+ *
+ * The following example shows how to create and initialize a %JsonObject instance and how to use its methods.
+ *
+ * @code
+ * #include <FWebJson.h>
+ *
+ * using namespace Tizen::Base;
+ * using namespace Tizen::Base::Collection;
+ * using namespace Tizen::Web::Json;
+ *
+ * void
+ * MyClass::JsonObjectSample(void)
+ * {
+ * //Creates an instance of JsonObject
+ * JsonObject *pJsonObj = new JsonObject();
+ *
+ * //Construct() must be called for JsonObject
+ * pJsonObj->Construct();
+ *
+ * //Creates keys, the pointer to string is the key for the element of the JsonObject
+ * String *pStrFNKey = new String(L"firstName");
+ * String *pStrAgeKey = new String(L"age");
+ *
+ * //Creates values, the pointer to any JsonValue is the value for the element of the JsonObject
+ * JsonString *pStrFNVal = new JsonString(L"John");
+ * JsonNumber *pNumAge = new JsonNumber(25);
+ *
+ * //Adds key-value pairs to object
+ * pJsonObj->Add(pStrFNKey, pStrFNVal);
+ * pJsonObj->Add(pStrAgeKey, pNumAge);
+ *
+ * // Gets the value with the specified key
+ * IJsonValue* pValue = null;
+ * pJsonObj->GetValue(pStrFNKey, pValue);
+ *
+ * // Uses enumerator to access elements in the map
+ * const String* pKey = null;
+ * IMapEnumeratorT<const String*, IJsonValue*>* pMapEnum = null;
+ * pMapEnum = pJsonObj->GetMapEnumeratorN();
+ * if( pMapEnum )
+ * {
+ * while (pMapEnum->MoveNext() == E_SUCCESS)
+ * {
+ * pMapEnum->GetKey(pKey);
+ * pMapEnum->GetValue(pValue);
+ * }
+ * delete pMapEnum;
+ * }
+ *
+ * // Removes a key-value pair with memory deallocation
+ * pJsonObj->Remove(pStrAgeKey, true);
+ *
+ * // Removes all remaining key-value pairs with memory deallocation
+ * pJsonObj->RemoveAll(true);
+ * delete pJsonObj;
+ * }
+ * @endcode
+ */
+class _OSP_EXPORT_ JsonObject
+ : public IJsonValue
+ , public Tizen::Base::Collection::HashMapT<const Tizen::Base::String*, IJsonValue*>
+{
+public:
+ /**
+ * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
+ *
+ * @since 2.0
+ */
+ JsonObject(void);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object()..
+ *
+ * @since 2.0
+ */
+ virtual ~JsonObject(void);
+
+ /**
+ * Initializes this instance of %JsonObject.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ * @exception E_INVALID_OPERATION The Construct() method cannot be called twice.
+ */
+ result Construct(void);
+
+ /**
+ * Gets the type of the JSON object.
+ *
+ * @since 2.0
+ *
+ * @return The type of the JSON object
+ * @see JsonType
+ */
+ JsonType GetType(void) const;
+
+ /**
+ * Adds the specified key-value pair to a JSON object.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pKey A pointer to the key-value to add
+ * @param[in] pJsonValue A pointer to the value to add
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid, or the key comparison has failed.
+ * @exception E_OBJ_ALREADY_EXIST The specified @c pKey already exists.
+ * @see Remove()
+ */
+ virtual result Add(const Tizen::Base::String* const& pKey, Tizen::Web::Json::IJsonValue* const& pJsonValue);
+
+
+ /**
+ * Gets the value associated with a specified key.
+ *
+ * @since 2.0
+ *
+ * @return The value associated with the key, @n
+ * else @c null if an exception occurs
+ * @param[in] pKey A pointer to the key to locate
+ * @param[out] pJsonValue A pointer to the value associated with the key
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid, or the key comparison has failed.
+ * @exception E_OBJ_NOT_FOUND The specified @c pKey is not found.
+ * @see SetValue()
+ */
+ virtual result GetValue(const Tizen::Base::String* const& pKey, Tizen::Web::Json::IJsonValue*& pJsonValue) const;
+
+ /**
+ * Checks whether a JSON object contains the specified value.
+ *
+ * @since 2.0
+ *
+ * @return @c true if the JSON object contains the specified value, @n
+ * else @c false
+ * @param[in] pJsonValue A pointer to a value to locate
+ */
+ virtual bool ContainsValue(IJsonValue* const& pJsonValue) const;
+
+ /**
+ * Checks whether the value of the specified instance equals the value of the current instance of %JsonObject.
+ *
+ * @since 2.0
+ *
+ * @return @c true if the value of the current instance equals the value of the specified instance, @n
+ else @c false
+ * @param[in] obj The object to compare @n
+ * This object is compared with the current instance of %JsonObject.
+ * @remarks This method returns @c false if the specified object is not of type JSON object.
+ * @see Object::Equals()
+ */
+ virtual bool Equals(const Object& obj) const;
+
+ /**
+ * Gets the hash value of the current instance.
+ *
+ * @since 2.0
+ *
+ * @return An integer value indicating the hash value of the current instance
+ * @remarks The two equal instances should return the same hash value. For better performance,
+ * the used hash function must generate a random distribution for all inputs.
+ * @n
+ * The default implementation of this method returns the address of the current instance.
+ */
+ virtual int GetHashCode(void) const;
+
+ /**
+ * Removes the value associated with a specified key.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pKey A pointer to the key to remove
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid, or the key comparison has failed.
+ * @exception E_OBJ_NOT_FOUND The specified @c pKey is not found.
+ */
+ virtual result Remove(const Tizen::Base::String* const& pKey);
+
+ /**
+ * Removes the value associated with a specified key.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pKey A pointer to the key to remove
+ * @param[in] deallocate Set to @c true to deallocate the JSON value, @n
+ * else @c false
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid, or the key comparison has failed.
+ * @exception E_OBJ_NOT_FOUND The specified @c pKey is not found.
+ */
+ virtual result Remove(const Tizen::Base::String* const& pKey, bool deallocate);
+
+ /**
+ * Removes all the key-value pairs in %JsonObject.
+ *
+ * @since 2.0
+ *
+ * @param[in] deallocate Set to @c true to deallocate the JSON value, @n
+ * else @c false
+ */
+ virtual void RemoveAll(bool deallocate = false);
+
+ /**
+ * Sets a new value to a specified key.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pKey A pointer to the key for which the value is to be replaced
+ * @param[in] pJsonValue A pointer to the new value to be set
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid, or the key comparison has failed.
+ * @exception E_OBJ_NOT_FOUND The specified @c pKey is not found.
+ * @remarks Use the Add() method to add a new key-value pair.
+ */
+ virtual result SetValue(const Tizen::Base::String* const& pKey, Tizen::Web::Json::IJsonValue* const& pJsonValue);
+
+ /**
+ * Sets a new value to a specified key.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pKey A pointer to the key for which the value is to be replaced
+ * @param[in] pJsonValue A pointer to the new value to be set
+ * @param[in] deallocate Set to @c true to deallocate the JSON value, @n
+ * else @c false
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid, or the key comparison has failed.
+ * @exception E_OBJ_NOT_FOUND The specified @c pKey is not found.
+ * @remarks Use the Add() method to add a new key-value pair.
+ */
+ virtual result SetValue(const Tizen::Base::String* const& pKey, Tizen::Web::Json::IJsonValue* const& pJsonValue, bool deallocate);
+
+ /**
+ * Checks whether a JSON object contains the specified key.
+ *
+ * @since 2.0
+ *
+ * @return An error code
+ * @param[in] pKey The key to locate
+ * @param[out] out @c true if the JSON object contains the specified key, @n
+ * else @c false
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid, or the key comparison has failed.
+ */
+ virtual result ContainsKey(const Tizen::Base::String* const& pKey, bool& out) const;
+
+ /**
+ * Return a new cloned %JsonObject instance.
+ *
+ * @since 2.0
+ *
+ * @return a new cloned %JsonObject
+ * @exception E_SUCCESS The memory is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ JsonObject* CloneN(void) const;
+
+private:
+ //
+ // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @param[in] item The instance of the %JsonObject class to copy from
+ // @remarks This constructor is hidden.
+ //
+ JsonObject(const JsonObject& item);
+
+ //
+ // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
+ //
+ // @param[in] item The instance of the %JsonObject class to assign from
+ // @remarks This operator is hidden.
+ //
+ JsonObject& operator =(const JsonObject& item);
+
+private:
+ _JsonObjectImpl* __pJsonObjectImpl;
+ _JsonObjectComparer* __pJsonObjectComparer;
+ _JsonObjectHashCodeProvider* __pJsonObjectHashCodeProvider;
+ friend class _JsonObjectImpl;
+}; // JsonObject
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_JSON_OBJECT_H_
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonParser.h
+ * @brief This header file for the %JsonParser class.
+ *
+ * This header file contains the declarations of the JSON functionalities for parsing the JSON-encoded file.
+ */
+#ifndef _FWEB_JSON_JSON_PARSER_H_
+#define _FWEB_JSON_JSON_PARSER_H_
+
+#include <FBaseByteBuffer.h>
+
+namespace Tizen { namespace Web { namespace Json
+{
+class IJsonValue;
+class _JsonParserImpl;
+}}} // Tizen::Web::Json
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+/**
+ * @class JsonParser
+ * @brief This class contains the declarations of JSON functionalities for parsing JSON-encoded file.
+ *
+ * @since 2.0
+ *
+ * The %JsonParser class contains the declarations of the JSON functionalities for parsing JSON-encoded files.
+ * @n
+ * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+ *
+ * The following example shows how to use %JsonParser methods.
+ *
+ * @code
+ * Sample Data - JsonSample.json
+ * {"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"},
+ * {"transperancy":"80"}
+ * ]
+ * }}
+ *
+ * #include <FWebJson.h>
+ *
+ * using namespace Tizen::Base;
+ * using namespace Tizen::Base::Utility;
+ * using namespace Tizen::Web::Json;
+ *
+ * void
+ * MyClass::JsonParserSample(void)
+ * {
+ * //Parses from File
+ * String fileName(L"/Home/JsonSample.json");
+ * IJsonValue* pValue = JsonParser::ParseN(fileName);
+ * if( pValue == null )
+ * {
+ * AppLog("ErrorCode %s", GetLastResult());
+ * }
+ * else
+ * {
+ * //Uses the pValue to know what is the type
+ * if( pValue->GetType() == JSON_TYPE_OBJECT )
+ * {
+ * JsonObject* pJsonObj = static_cast<JsonObject*>(pValue);//use pJsonObj to access key-value pairs
+ * pJsonObj->RemoveAll(true);
+ * }
+ * else if( pValue->GetType() == JSON_TYPE_ARRAY )
+ * {
+ * JsonArray* pJsonArray = static_cast<JsonArray*>(pValue);//use pJsonArray to access values
+ * pJsonArray->RemoveAll(true);
+ * }
+ * delete pValue;
+ * }
+ *
+ * //Parses from char*
+ * const char* jBuf = "{\"Key\":1,\"Key1\":{\"Key2\":\"val\",\"Key3\":\"val1\"},\"Key4\":[\"val2\",\"val3\"]}";
+ * String str(jBuf);
+ * int length = str.GetLength();
+ * IJsonValue* pValue1 = JsonParser::ParseN(jBuf, length);
+ *
+ * // Converts the pValue1 to JsonObject
+ * JsonObject* pJsonObject = static_cast<JsonObject*>(pValue1);
+ * pJsonObject->RemoveAll(true);
+ * delete pJsonObject;
+ *
+ * //Parses from ByteBuffer
+ * ByteBuffer *pBuf = StringUtil::StringToUtf8N( str );
+ * IJsonValue* pValue2 = JsonParser::ParseN(*pBuf);
+ *
+ * // Converts the pValue2 to JsonObject
+ * pJsonObject = static_cast<JsonObject*>(pValue2);
+ * pJsonObject->RemoveAll(true);
+ * delete pJsonObject;
+ * delete pBuf;
+ * }
+ * @endcode
+ */
+class _OSP_EXPORT_ JsonParser
+{
+public:
+ /**
+ * Parses a JSON-encoded file to IJsonValue (node).
+ *
+ * @if OSPCOMPAT
+ * @brief <i> [Compatibility] </i>
+ * @endif
+ * @since 2.0
+ * @if OSPCOMPAT
+ * @compatibility This method has compatibility issues with OSP compatible applications. @n
+ * For more information, see @ref CompIoPathPage "here".
+ * @endif
+ *
+ * @return A JSON value of type JsonArray or JsonObject, @n
+ * else @c null if the JSON data of the file is invalid
+ * @param[in] filePath The path of the JSON-encoded file
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG The specified file path is incorrect, or the file is not found.
+ * @exception E_INVALID_DATA The input JSON data is invalid.
+ * @exception E_MAX_EXCEEDED The input JSON data exceeds the maximum length.
+ * @exception E_UNKNOWN An unknown error has occurred.
+ *
+ * @remarks The specific error code can be accessed using the GetLastResult() method.
+ */
+ static IJsonValue* ParseN(const Tizen::Base::String& filePath);
+
+ /**
+ * Parses a JSON-encoded buffer to %IJsonValue (node).
+ *
+ * @since 2.0
+ *
+ * @return A JSON value of type JsonArray or JsonObject, @n
+ * else @c null if the JSON data of the file is invalid
+ * @param[in] pBuffer A JSON-encoded buffer
+ * @param[in] bufferLength A JSON-encoded buffer length
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_DATA The input JSON data is invalid, or the buffer is empty.
+ * @exception E_MAX_EXCEEDED The input JSON data exceeds the maximum length.
+ * @exception E_UNKNOWN An unknown error has occurred.
+ *
+ * @remarks The specific error code can be accessed using the GetLastResult() method.
+ */
+ static IJsonValue* ParseN(const void* pBuffer, int bufferLength);
+
+ /**
+ * Parses a JSON-encoded ByteBuffer to IJsonValue (node).
+ *
+ * @since 2.0
+ *
+ * @return A JSON value of type JsonArray or JsonObject, @n
+ * else @c null if the JSON data of the file is invalid
+ * @param[in] buffer A JSON-encoded byte buffer
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_DATA The input JSON data is invalid, or the buffer is empty.
+ * @exception E_MAX_EXCEEDED The input JSON data exceeds the maximum length.
+ * @exception E_UNKNOWN An unknown error has occurred.
+ *
+ * @remarks The specific error code can be accessed using the GetLastResult() method.
+ */
+ static IJsonValue* ParseN(const Tizen::Base::ByteBuffer& buffer);
+
+private:
+ //
+ // This default constructor is intentionally declared as private because this class cannot be constructed.
+ //
+ // @remarks This constructor is hidden.
+ //
+ JsonParser(void);
+
+ //
+ // This is the destructor for this class.
+ //
+ // @remarks This constructor is hidden.
+ //
+ virtual ~JsonParser(void);
+
+private:
+ _JsonParserImpl* __pJsonParserImpl;
+
+ friend class _JsonParserImpl;
+}; // JsonParser
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_JSON_PARSER_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonString.h
+ * @brief This is the header file for the %JsonString class.
+ *
+ * This header file contains the declarations of the %JsonString class.
+ * The class represents the JSON value of type string.
+ */
+#ifndef _FWEB_JSON_JSON_STRING_H_
+#define _FWEB_JSON_JSON_STRING_H_
+
+#include <FBaseString.h>
+#include <FWebJsonIJsonValue.h>
+
+namespace Tizen { namespace Web { namespace Json
+{
+class _JsonStringImpl;
+}}} // Tizen::Web::Json
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+/**
+ * @class JsonString
+ * @brief This class represents the JSON value of type string.
+ *
+ * @since 2.0
+ *
+ * @final This class is not intended for extension.
+ *
+ * The %JsonString class represents the JSON value of type string.
+ * @n
+ * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+
+ *
+ */
+class _OSP_EXPORT_ JsonString
+ : public IJsonValue
+ , public Tizen::Base::String
+{
+public:
+ /**
+ * Initializes this instance of %JsonString with the specified parameter.
+ *
+ * @since 2.0
+ *
+ * @param[in] pValue A pointer to an array of UTF-8 characters
+ */
+ JsonString(const char* pValue);
+
+ /**
+ * Initializes this instance of %JsonString with the specified parameter.
+ *
+ * @since 2.0
+ *
+ * @param[in] value A reference to %String
+ */
+ JsonString(const Tizen::Base::String& value);
+
+ /**
+ * Initializes this instance of %JsonString with the specified Unicode string.
+ *
+ * @since 2.0
+ *
+ * @param[in] pValue A pointer to an array of Unicode characters
+ */
+ JsonString(const wchar_t* pValue);
+
+ /**
+ * Copying of objects using this copy constructor is allowed.
+ *
+ * @since 2.0
+ *
+ * @param[in] rhs An instance of %JsonString
+ */
+ JsonString(const Tizen::Web::Json::JsonString& rhs);
+
+ /**
+ * This destructor overrides Tizen::Base::Object::~Object().
+ *
+ * @since 2.0
+ */
+ virtual ~JsonString(void);
+
+ /**
+ * Gets the type of the JSON string.
+ *
+ * @since 2.0
+ *
+ * @return The type of the JSON string
+ * @see JsonType
+ */
+ JsonType GetType(void) const;
+
+ /**
+ * Copying of objects using this copy assignment operator is allowed.
+ *
+ * @since 2.0
+ *
+ * @param[in] rhs A reference to the %JsonString instance to copy
+ */
+ JsonString& operator =(const Tizen::Web::Json::JsonString& rhs);
+
+private:
+ _JsonStringImpl* __pJsonStringImpl;
+
+ friend class _JsonStringImpl;
+}; // JsonString
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_JSON_STRING_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonWriter.h
+ * @brief This is the header file for composing a JSON-encoded file.
+ *
+ * This header file contains the declarations of JSON functionalities for composing JSON-encoded file.
+ */
+#ifndef _FWEB_JSON_JSON_WRITER_H_
+#define _FWEB_JSON_JSON_WRITER_H_
+
+#include <FBaseString.h>
+#include <FBaseByteBuffer.h>
+
+namespace Tizen { namespace Web { namespace Json
+{
+class IJsonValue;
+class _JsonWriterImpl;
+}}} // Tizen::Web::Json
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+/**
+ * @class JsonWriter
+ * @brief This class contains the declarations of the JSON functionalities for composing JSON-encoded file.
+ *
+ * @since 2.0
+ *
+ * The %JsonWriter class contains the declarations of JSON functionalities for composing JSON-encoded files.
+ * @n
+ * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
+ *
+ * The following example shows how to use %JsonWriter methods.
+ *
+ * @code
+ * #include <FWebJson.h>
+ *
+ * using namespace Tizen::Base;
+ * using namespace Tizen::Web::Json;
+ *
+ * void
+ * MyClass::JsonWriterSample(void)
+ * {
+ * String *pKey1 = new String(L"Key1");
+ * String *pKey2 = new String(L"Key2");
+ * JsonString *pJsonValue1 = new JsonString(L"Value1");
+ * JsonString *pJsonValue2 = new JsonString(L"Value2");
+ * JsonObject *pJsonObject = new JsonObject();
+ * pJsonObject->Construct();
+ * pJsonObject->Add(pKey1, pJsonValue1);
+ * pJsonObject->Add(pKey2, pJsonValue2);
+ *
+ * //Composes to File
+ * String fileName(L"/Home/JsonComposeSample.json");
+ * result r = JsonWriter::Compose( pJsonObject, fileName );
+ * if( r != E_SUCCESS )
+ * {
+ * AppLog("Compose failed");
+ * }
+ *
+ * //Composes to char*
+ * char* pComposeBuf = new char[40];
+ * r = JsonWriter::Compose( pJsonObject, pComposeBuf, 40 );
+ *
+ * //Composes to ByteBuffer
+ * ByteBuffer *pBuffer = new ByteBuffer();
+ * pBuffer->Construct(40);
+ * r = JsonWriter::Compose(pJsonObject, *pBuffer);
+ *
+ * pJsonObject->RemoveAll(true);
+ * delete pJsonObject;
+ * delete pBuffer;
+ * }
+ * @endcode
+ */
+class _OSP_EXPORT_ JsonWriter
+{
+public:
+ /**
+ * Serializes the JSON-encoded data from %IJsonValue to a file.
+ *
+ * @if OSPCOMPAT
+ * @brief <i> [Compatibility] </i>
+ * @endif
+ * @since 2.0
+ * @if OSPCOMPAT
+ * @compatibility This method has compatibility issues with OSP compatible applications. @n
+ * For more information, see @ref CompIoPathPage "here".
+ * @endif
+ *
+ * @param[in] pValue JSON value to be encoded.
+ * @param[out] filePath The JSON file path
+ * @return An error code
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_DATA The specified @c pValue is @c null.
+ * @exception E_INVALID_ARG The specified @c filePath is incorrect.
+ * @exception E_FAILURE The method has failed.
+ */
+ static result Compose(const IJsonValue* pValue, Tizen::Base::String& filePath);
+
+ /**
+ * Serializes the JSON-encoded data from %IJsonValue to a buffer
+ *
+ * @since 2.0
+ *
+ * @param[in] pValue JSON value to be encoded.
+ * @param[in] bufferLength Json encoded data buffer length.
+ * @param[out] pBuffer The buffer with Json encoded data.
+ * @return An error code
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_DATA The specified @c pValue is @c null.
+ * @exception E_FAILURE The method has failed.
+ */
+ static result Compose(const IJsonValue* pValue, void* pBuffer, int bufferLength);
+
+ /**
+ * Serializes the JSON-encoded data from %IJsonValue to %ByteBuffer.
+ *
+ * @since 2.0
+ *
+ * @param[in] pValue JSON value to be encoded.
+ * @param[out] buffer The buffer with JSON-encoded data
+ * @return An error code
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_DATA The specified @c pValue is @c null.
+ * @exception E_FAILURE The method has failed.
+ * @remarks ByteBuffer parameter has to be constructed with a non zero capacity before calling this method.
+ */
+ static result Compose(const IJsonValue* pValue, Tizen::Base::ByteBuffer& buffer);
+
+private:
+ //
+ // This default constructor is intentionally declared as private because this class cannot be constructed
+ //
+ // @remarks This constructor is hidden.
+ //
+ JsonWriter(void);
+
+ //
+ // This is the destructor for this class.
+ //
+ // @remarks This constructor is hidden.
+ //
+ virtual ~JsonWriter(void);
+
+private:
+ _JsonWriterImpl* __pJsonWriterImpl;
+
+ friend class _JsonWriterImpl;
+}; // JsonWriter
+
+}}} // Tizen::Web::Json
+#endif // _FWEB_JSON_JSON_WRITER_H_
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
\ No newline at end of file
--- /dev/null
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=/usr/lib/osp
+includedir=/usr/include/osp
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir}
+
--- /dev/null
+%define debug_package %{nil}
+%define __strip /bin/true
+
+Name: osp-json
+Summary: osp json library
+Version: 1.2.0.0
+Release: 2
+Group: System/Libraries
+License: TO_BE/FILLED_IN
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(osp-appfw)
+BuildRequires: osp-appfw-internal-devel
+
+# runtime requires
+Requires: osp-appfw
+
+%description
+osp json library
+
+%package devel
+Summary: osp json library (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+osp json library (DEV)
+
+%package debug
+Summary: osp json library (Development)
+Group: TO_BE/FILLED_IN
+Requires: %{name} = %{version}-%{release}
+
+%description debug
+osp json library (DEV)
+
+%prep
+%setup -q
+
+%build
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%ifarch %{ix86}
+CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+%else
+CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+%endif
+
+# Call make instruction with smp support
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}/usr/share/license
+cat %{_builddir}/%{name}-%{version}/LICENSE.APLv2.0 >> %{buildroot}/usr/share/license/%{name}
+
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest osp-json.manifest
+/usr/share/license/%{name}
+%{_libdir}/osp/libosp-json.so*
+
+%files devel
+%{_includedir}/osp/*.h
+%{_libdir}/pkgconfig/osp-json.pc
+
+%files debug
+%{_libdir}/osp/debug/libosp-json.so.*
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonArray.cpp
+ * @brief This is the implementation file for JsonArray class.
+ *
+ * This file contains the definition of JsonArray class.
+ */
+#include <new>
+#include <unique_ptr.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FBaseSysLog.h>
+#include <FWebJsonIJsonValue.h>
+#include <FWebJsonJsonArray.h>
+#include <FWebJsonJsonBool.h>
+#include <FWebJsonJsonNull.h>
+#include <FWebJsonJsonNumber.h>
+#include <FWebJsonJsonObject.h>
+#include <FWebJsonJsonString.h>
+#include "FWebJson_JsonUtils.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+JsonArray::JsonArray(void)
+ : ArrayListT<IJsonValue*>()
+ , __pJsonArrayImpl(null)
+{
+}
+
+
+JsonArray::~JsonArray(void)
+{
+}
+
+
+result
+JsonArray::Construct(void)
+{
+ result r = E_SUCCESS;
+
+ r = ArrayListT<IJsonValue*>::Construct();
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ return r;
+}
+
+
+JsonType
+JsonArray::GetType(void) const
+{
+ return JSON_TYPE_ARRAY;
+}
+
+
+result
+JsonArray::Add(IJsonValue* const& pJsonValue)
+{
+ SysTryReturnResult(NID_WEB_JSON, pJsonValue, E_INVALID_ARG, "[%s] Input parameter is null", GetErrorMessage(E_INVALID_ARG));
+
+ return ArrayListT<IJsonValue*>::Add(pJsonValue);
+}
+
+
+result
+JsonArray::IndexOf(IJsonValue* const& pJsonValue, int& index) const
+{
+ int valCount = GetCount();
+
+ return IndexOf(pJsonValue, 0, valCount, index);
+}
+
+
+result
+JsonArray::IndexOf(IJsonValue* const& pJsonValue, int startIndex, int& index) const
+{
+ int valCount = GetCount();
+
+ return IndexOf(pJsonValue, startIndex, (valCount - startIndex), index);
+}
+
+
+result
+JsonArray::IndexOf(IJsonValue* const& pJsonValue, int startIndex, int count, int& index) const
+{
+ result r = E_SUCCESS;
+ SysTryReturnResult(NID_WEB_JSON, pJsonValue, E_OBJ_NOT_FOUND, "[%s] Value to be found is null", GetErrorMessage(E_OBJ_NOT_FOUND));
+
+ int valCount = GetCount();
+ SysTryReturnResult(NID_WEB_JSON, valCount > 0, E_OBJ_NOT_FOUND, "[%s] array has zero elements", GetErrorMessage(E_OBJ_NOT_FOUND));
+ SysTryReturnResult(NID_WEB_JSON, startIndex >= 0 && count >= 0, E_OUT_OF_RANGE, "[%s] Both of the startIndex(%d) and count(%d) MUST be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE), startIndex, count);
+ SysTryReturnResult(NID_WEB_JSON, startIndex < valCount, E_OUT_OF_RANGE, "[%s] The startIndex(%d) MUST be less than the number of elements(%d).", GetErrorMessage(E_OUT_OF_RANGE), startIndex, valCount);
+ SysTryReturnResult(NID_WEB_JSON, count <= valCount && (startIndex + count <= valCount), E_OUT_OF_RANGE, "[%s] The startIndex(%d) + count(%d) MUST be less than or equal to the number of elements(%d).", GetErrorMessage(E_OUT_OF_RANGE), startIndex, count, valCount);
+
+ for (int i = startIndex; i < (startIndex + count); i++)
+ {
+ IJsonValue* pValue = null;
+ r = GetAt(i, pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ Object* pArrayVal = dynamic_cast<Object*>(pValue);
+ Object* pOtherVal = dynamic_cast<Object*>(pJsonValue);
+ SysAssertf(pArrayVal && pOtherVal, "dynamic_cast failure");
+
+ if (pArrayVal->Equals(*pOtherVal) == true)
+ {
+ index = i;
+ SysLog(NID_WEB_JSON, "index : %d", index);
+ return E_SUCCESS;
+ }
+ }
+
+ return E_OBJ_NOT_FOUND;
+}
+
+
+result
+JsonArray::LastIndexOf(IJsonValue* const& pJsonValue, int& index) const
+{
+ result r = E_SUCCESS;
+ SysTryReturnResult(NID_WEB_JSON, pJsonValue, E_OBJ_NOT_FOUND, "[%s] Value to be found is null", GetErrorMessage(E_OBJ_NOT_FOUND));
+
+ int valCount = GetCount();
+ SysTryReturnResult(NID_WEB_JSON, valCount > 0, E_OBJ_NOT_FOUND, "[%s] Count in Array is Zero", GetErrorMessage(E_OBJ_NOT_FOUND));
+
+ for (int i = (valCount - 1); i >= 0; i--)
+ {
+ IJsonValue* pValue = null;
+ r = GetAt(i, pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ Object* pArrayVal = dynamic_cast<Object*>(pValue);
+ Object* pOtherVal = dynamic_cast<Object*>(pJsonValue);
+ SysAssertf(pArrayVal && pOtherVal, "dynamic_cast failure");
+
+ if (pArrayVal->Equals(*pOtherVal) == true)
+ {
+ index = i;
+ SysLog(NID_WEB_JSON, "LastIndex : %d", index);
+ return E_SUCCESS;
+ }
+ }
+
+ return E_OBJ_NOT_FOUND;
+}
+
+
+bool
+JsonArray::Contains(IJsonValue* const& pJsonValue) const
+{
+ ClearLastResult();
+
+ result r = E_SUCCESS;
+ SysTryReturn(NID_WEB_JSON, pJsonValue, false, E_OBJ_NOT_FOUND, "[%s] Value to be found is null", GetErrorMessage(E_OBJ_NOT_FOUND));
+
+ int valCount = GetCount();
+ SysTryReturn(NID_WEB_JSON, valCount > 0, false, E_OBJ_NOT_FOUND, "[%s] Count in Array is Zero", GetErrorMessage(E_OBJ_NOT_FOUND));
+
+ for (int i = 0; i < valCount; i++)
+ {
+ IJsonValue* pValue = null;
+ r = GetAt(i, pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ Object* pArrayVal = dynamic_cast<Object*>(pValue);
+ Object* pOtherVal = dynamic_cast<Object*>(pJsonValue);
+ SysAssertf(pArrayVal && pOtherVal, "dynamic_cast failure");
+
+ if (pArrayVal->Equals(*pOtherVal))
+ {
+ SysLog(NID_WEB_JSON, "JsonArray contains given value");
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+bool
+JsonArray::Equals(const Object& obj) const
+{
+ ClearLastResult();
+
+ result r = E_SUCCESS;
+
+ const JsonArray* pOther = dynamic_cast<const JsonArray*>(&obj);
+ SysTryReturn(NID_WEB_JSON, pOther, false, E_INVALID_ARG, "[%s] input parameter is not a JsonArray", GetErrorMessage(E_INVALID_ARG));
+
+ if (pOther == this)
+ {
+ SysLog(NID_WEB_JSON, "same JsonArray is given as input");
+ return true;
+ }
+
+ //if number of key value pairs are same, we can compare element by element else they are not equal
+ int count = GetCount();
+ SysTryReturn(NID_WEB_JSON, count == pOther->GetCount(), false, E_SUCCESS, "[%s] count is not same in JsonArrays", GetErrorMessage(E_SUCCESS));
+
+ for (int i = 0; i < count; i++)
+ {
+ IJsonValue* pValue = null;
+ IJsonValue* pOtherValue = null;
+
+ r = GetAt(i, pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
+ r = pOther->GetAt(i, pOtherValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ Object* pObj = dynamic_cast<Object*>(pValue);
+ Object* pOtherObj = dynamic_cast<Object*>(pOtherValue);
+ SysAssertf(pObj && pOtherObj, "dynamic_cast failure");
+
+ if (pObj->Equals(*pOtherObj) == false)
+ {
+ SysLog(NID_WEB_JSON, "values at index [%d] are not same, arrays are not equal", i);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+int
+JsonArray::GetHashCode(void) const
+{
+ ClearLastResult();
+
+ unique_ptr<JsonValueEnumerator> pArrayEnum(GetEnumeratorN());
+ SysTryReturn(NID_WEB_JSON, pArrayEnum.get(), (int)this, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ int hash = 0;
+ IJsonValue* pArrayVal = null;
+ result r = E_SUCCESS;
+
+ //traverse through array to get array values
+ while (pArrayEnum->MoveNext() == E_SUCCESS)
+ {
+ //Get array value
+ r = pArrayEnum->GetCurrent(pArrayVal);
+ SysTryReturn(NID_WEB_JSON, pArrayVal, hash = (int)this, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ Object* pObj = dynamic_cast<Object*>(pArrayVal);
+ SysAssertf(pObj, "dynamic_cast failure");
+
+ //Get hash of value
+ hash += pObj->GetHashCode();
+ }
+ //calculate combined hash
+ hash = hash ^ (hash >> 12);
+
+ return hash;
+}
+
+
+result
+JsonArray::Remove(IJsonValue* const& pJsonValue, bool deallocate)
+{
+ int index = -1;
+ result r = E_SUCCESS;
+
+ r = IndexOf(pJsonValue, index);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ return RemoveAt(index, deallocate);
+}
+
+
+result
+JsonArray::RemoveItems(const ICollectionT <IJsonValue*>& collection, bool deallocate)
+{
+ result r = E_SUCCESS;
+ ICollectionT<IJsonValue*>* pCol = const_cast<ICollectionT<IJsonValue*>*> (&collection);
+
+ unique_ptr<JsonValueEnumerator> pEnum(pCol->GetEnumeratorN());
+ SysTryReturn(NID_WEB_JSON, pEnum.get() != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ while (pEnum->MoveNext() == E_SUCCESS)
+ {
+ IJsonValue* pTemp = null;
+ int index = -1;
+
+ r = pEnum->GetCurrent(pTemp);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ r = IndexOf(pTemp, index);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ r = RemoveAt(index, deallocate);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+ }
+
+ return r;
+}
+
+
+result
+JsonArray::RemoveAt(int index, bool deallocate)
+{
+ result r = E_OBJ_NOT_FOUND;
+ IJsonValue* pValue = null;
+ r = GetAt(index, pValue);
+
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS && pValue, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ r = ArrayListT<IJsonValue*>::RemoveAt(index);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (deallocate == true)
+ {
+ _JsonUtils::DeallocateItem(pValue);
+ }
+ return r;
+}
+
+
+result
+JsonArray::RemoveItems(int startIndex, int count, bool deallocate)
+{
+ result r = E_OBJ_NOT_FOUND;
+ int valCount = GetCount();
+
+ SysTryReturnResult(NID_WEB_JSON, valCount > 0, E_OBJ_NOT_FOUND, "count is zero");
+
+ unique_ptr<JsonValueList> pList(GetItemsN(startIndex, count));
+ SysTryReturn(NID_WEB_JSON, pList.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ r = ArrayListT<IJsonValue*>::RemoveItems(startIndex, count);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (deallocate == true)
+ {
+ for (int i = count-1; i >= 0; i--)
+ {
+ IJsonValue* pValue = null;
+ r = pList->GetAt(i, pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS && pValue, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ _JsonUtils::DeallocateItem(pValue);
+ }
+ }
+
+ return r;
+}
+
+
+void
+JsonArray::RemoveAll(bool deallocate)
+{
+ ClearLastResult();
+
+ int count = GetCount();
+ SysTryReturnVoidResult(NID_WEB_JSON, count > 0, E_SUCCESS, "[E_SUCCESS] Count is zero.");
+
+ if (deallocate == true)
+ {
+ unique_ptr<JsonValueList> pList(GetItemsN(0, count));
+ SysTryReturnVoidResult(NID_WEB_JSON, pList.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+ result r = E_SUCCESS;
+ for (int i = count-1; i >= 0 ; i--)
+ {
+ IJsonValue* pValue = null;
+ r = pList->GetAt(i, pValue);
+ SysTryReturnVoidResult(NID_WEB_JSON, pValue, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ _JsonUtils::DeallocateItem(pValue);
+ }
+ }
+ //Call Base class function
+ ArrayListT<IJsonValue*>::RemoveAll();
+}
+
+
+result
+JsonArray::SetAt(IJsonValue* const& pJsonValue, int index)
+{
+ return SetAt(pJsonValue, index, false);
+}
+
+
+result
+JsonArray::SetAt(IJsonValue* const& pJsonValue, int index, bool deallocate)
+{
+ SysTryReturnResult(NID_WEB_JSON, pJsonValue, E_INVALID_ARG, "Input argument pJsonValue is null.");
+
+ int valCount = GetCount();
+ SysTryReturnResult(NID_WEB_JSON, index >= 0 && index < valCount, E_OUT_OF_RANGE, "The index(%d) MUST be greater than or equal to 0, less than the number of elements(%d).", index, valCount);
+
+ IJsonValue* pValue = null;
+ result r = GetAt(index, pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS && pValue, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ //Call base class function
+ r = ArrayListT<IJsonValue*>::SetAt(pJsonValue, index);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (deallocate == true)
+ {
+ _JsonUtils::DeallocateItem(pValue);
+ }
+
+ return r;
+}
+
+
+JsonArray*
+JsonArray::CloneN(void) const
+{
+ ClearLastResult();
+
+ unique_ptr<JsonArray, AllElementsDeleter> pJsonArray(new (std::nothrow) JsonArray());
+ SysTryReturn(NID_WEB_JSON, pJsonArray.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = pJsonArray->Construct();
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ IJsonValue* pValue = null;
+ IJsonValue* pNewValue = null;
+
+ for (int i = 0; i < GetCount(); i++)
+ {
+ r = GetAt(i, pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ switch (pValue->GetType())
+ {
+ case JSON_TYPE_STRING:
+ pNewValue = new (std::nothrow) JsonString(static_cast<JsonString*>(pValue)->GetPointer());
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_NUMBER:
+ pNewValue = new (std::nothrow) JsonNumber(static_cast<JsonNumber*>(pValue)->ToDouble());
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_OBJECT:
+ pNewValue = static_cast<JsonObject*>(pValue)->CloneN();
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_ARRAY:
+ pNewValue = static_cast<JsonArray*>(pValue)->CloneN();
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_BOOL:
+ pNewValue = new (std::nothrow) JsonBool(static_cast<JsonBool*>(pValue)->ToBool());
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_NULL:
+ pNewValue = new (std::nothrow) JsonNull();
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ default:
+ SysAssertf(false, "unknown Json type.");
+ break;
+ }
+
+ r = pJsonArray->Add(pNewValue);
+ if (IsFailed(r))
+ {
+ _JsonUtils::DeallocateItem(pNewValue);
+ SysLogException(NID_WEB_JSON, r, "[%s] Propagated.", GetErrorMessage(r));
+ return null;
+ }
+ }
+
+ return pJsonArray.release();
+}
+
+
+}}} // Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonBool.cpp
+ * @brief This is the implementation file for JsonBool class.
+ *
+ * This file contains the definition of JsonBool class
+ */
+#include <FBaseSysLog.h>
+#include <FWebJsonJsonBool.h>
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+JsonBool::JsonBool(bool value)
+ : Boolean(value)
+ , __pJsonBoolImpl(null)
+{
+
+}
+
+
+JsonBool::JsonBool(const String& value)
+ : Boolean(value)
+ , __pJsonBoolImpl(null)
+{
+
+}
+
+
+JsonBool::JsonBool(const Boolean& value)
+ : Boolean(value)
+ , __pJsonBoolImpl(null)
+{
+
+}
+
+
+JsonBool::JsonBool(const JsonBool& value)
+ : Boolean(value)
+ , __pJsonBoolImpl(null)
+{
+
+}
+
+
+JsonBool::~JsonBool(void)
+{
+
+}
+
+
+JsonType
+JsonBool::GetType(void) const
+{
+ return JSON_TYPE_BOOL;
+}
+
+
+JsonBool&
+JsonBool::operator =(const JsonBool& rhs)
+{
+ if (this != &rhs)
+ {
+ Boolean::operator =(rhs);
+ }
+ return *this;
+}
+
+
+}}} // Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonNull.cpp
+ * @brief This is the implementation file for JsonNull class.
+ *
+ * This file contains the definition of JsonNull class
+ */
+#include <FBaseSysLog.h>
+#include <FWebJsonJsonNull.h>
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+JsonNull::JsonNull(void)
+ : Object()
+ , __pJsonNullImpl(null)
+{
+
+}
+
+
+JsonNull::JsonNull(const JsonNull& value)
+ : Object()
+ , __pJsonNullImpl(null)
+{
+
+}
+
+
+JsonNull::~JsonNull(void)
+{
+
+}
+
+
+JsonType
+JsonNull::GetType(void) const
+{
+ return JSON_TYPE_NULL;
+}
+
+
+bool
+JsonNull::Equals(const Object& obj) const
+{
+ const JsonNull* pOther = dynamic_cast <const JsonNull*>(&obj);
+
+ if (pOther)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+
+int
+JsonNull::GetHashCode(void) const
+{
+ String str = L"null";
+ int hash = str.GetHashCode();
+
+ return (hash ^ (hash >> 8));
+}
+
+
+String
+JsonNull::ToString(void) const
+{
+ return String(L"null");
+}
+
+
+JsonNull&
+JsonNull::operator =(const JsonNull& rhs)
+{
+ if (this != &rhs)
+ {
+ //empty statement
+ }
+ return *this;
+}
+
+
+bool
+JsonNull::operator ==(const JsonNull& rhs) const
+{
+ return true;
+}
+
+
+bool
+JsonNull::operator !=(const JsonNull& rhs) const
+{
+ return false;
+}
+
+
+}}} // Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonNumber.cpp
+ * @brief This is the implementation file for JsonNumber class.
+ *
+ * This file contains the definition of JsonNumber class.
+ */
+#include <FBaseSysLog.h>
+#include <FWebJsonJsonNumber.h>
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+JsonNumber::JsonNumber(double value)
+ : Double(value)
+ , __pJsonNumberImpl(null)
+{
+
+}
+
+
+JsonNumber::JsonNumber(int value)
+ : Double(static_cast <double>(value))
+ , __pJsonNumberImpl(null)
+{
+
+}
+
+
+JsonNumber::JsonNumber(const JsonNumber& value)
+ : Double(value)
+ , __pJsonNumberImpl(null)
+{
+
+}
+
+
+JsonNumber::~JsonNumber(void)
+{
+
+}
+
+
+JsonType
+JsonNumber::GetType(void) const
+{
+ return JSON_TYPE_NUMBER;
+}
+
+
+JsonNumber&
+JsonNumber::operator =(const JsonNumber& rhs)
+{
+ if (this != &rhs)
+ {
+ Double::operator =(rhs);
+ }
+ return *this;
+}
+
+
+}}} //Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonObject.cpp
+ * @brief This is the implementation file for JsonObject class.
+ *
+ * This file contains the definition of JsonObject class.
+ */
+#include <new>
+#include <unique_ptr.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FBaseColIComparerT.h>
+#include <FBaseColIHashCodeProviderT.h>
+#include <FBaseSysLog.h>
+#include <FWebJsonIJsonValue.h>
+#include <FWebJsonJsonArray.h>
+#include <FWebJsonJsonBool.h>
+#include <FWebJsonJsonNull.h>
+#include <FWebJsonJsonNumber.h>
+#include <FWebJsonJsonObject.h>
+#include <FWebJsonJsonString.h>
+#include "FWebJson_JsonUtils.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+//
+//HashCodeProvider implementation
+//
+class _JsonObjectHashCodeProvider
+ : public IHashCodeProviderT <StringKey>
+{
+public:
+ _JsonObjectHashCodeProvider(void){}
+
+ int
+ GetHashCode(const StringKey& obj) const
+ {
+ SysTryReturn(NID_WEB_JSON, obj, -1, E_INVALID_ARG, "[E_INVALID_ARG] input parameter is null");
+ return (*obj).GetHashCode();
+ }
+
+ ~_JsonObjectHashCodeProvider(void) {}
+};
+
+
+//
+//Comparer implementation
+//
+class _JsonObjectComparer
+ : public IComparerT <StringKey>
+{
+public:
+ _JsonObjectComparer(void){}
+
+ result
+ Compare(const StringKey& obj1, const StringKey& obj2, int& cmp) const
+ {
+ SysTryReturnResult(NID_WEB_JSON, obj1 && obj2, E_INVALID_ARG, "Input parameters are null");
+
+ if (*obj1 == *obj2)
+ {
+ cmp = 0;
+ }
+ else
+ {
+ cmp = 1;
+ }
+ return E_SUCCESS;
+ }
+
+ ~_JsonObjectComparer(void) {}
+};
+
+
+JsonObject::JsonObject(void)
+ : HashMapT<const String*, IJsonValue*>()
+ , __pJsonObjectImpl(null)
+ , __pJsonObjectComparer(null)
+ , __pJsonObjectHashCodeProvider(null)
+{
+}
+
+
+JsonObject::~JsonObject(void)
+{
+ delete __pJsonObjectHashCodeProvider;
+ __pJsonObjectHashCodeProvider = null;
+
+ delete __pJsonObjectComparer;
+ __pJsonObjectComparer = null;
+
+}
+
+
+result
+JsonObject::Construct(void)
+{
+ SysAssertf(__pJsonObjectComparer == null && __pJsonObjectHashCodeProvider == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
+
+ //Create comparer and provider to be given to HashMap
+ unique_ptr<_JsonObjectComparer> pJsonObjectComparer(new (std::nothrow) _JsonObjectComparer());
+ SysTryReturnResult(NID_WEB_JSON, pJsonObjectComparer.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ unique_ptr<_JsonObjectHashCodeProvider> pJsonObjectHashCodeProvider(new (std::nothrow) _JsonObjectHashCodeProvider());
+ SysTryReturnResult(NID_WEB_JSON, pJsonObjectHashCodeProvider.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ //base class construct called to make hashmap ready
+ result r = HashMapT<const String*, IJsonValue*>::Construct(0, 0.0, *pJsonObjectHashCodeProvider, *pJsonObjectComparer);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ __pJsonObjectHashCodeProvider = pJsonObjectHashCodeProvider.release();
+ __pJsonObjectComparer = pJsonObjectComparer.release();
+ return r;
+}
+
+
+JsonType
+JsonObject::GetType(void) const
+{
+ return JSON_TYPE_OBJECT;
+}
+
+
+result
+JsonObject::Add(const String* const& pKey, IJsonValue* const& pJsonValue)
+{
+ SysTryReturnResult(NID_WEB_JSON, pKey && pJsonValue, E_INVALID_ARG, "Input argument is null");
+
+ return HashMapT<const String*, IJsonValue*>::Add(pKey, pJsonValue);
+}
+
+
+result
+JsonObject::GetValue(const String* const& pKey, IJsonValue*& pJsonValue) const
+{
+ SysTryReturnResult(NID_WEB_JSON, pKey, E_INVALID_ARG, "Input argument is null");
+
+ return HashMapT<const String*, IJsonValue*>::GetValue(pKey, pJsonValue);
+}
+
+
+bool
+JsonObject::ContainsValue(IJsonValue* const& pJsonValue) const
+{
+ ClearLastResult();
+
+ SysTryReturn(NID_WEB_JSON, pJsonValue, false, E_INVALID_ARG, "[%s] Input argument is null", GetErrorMessage(E_INVALID_ARG));
+
+ int count = GetCount();
+ if (count <= 0)
+ {
+ SysLog(NID_WEB_JSON, "JsonObject does not contain given value, count is [%d]", count);
+ return false;
+ }
+
+ unique_ptr<JsonKeyList> pKeyList(GetKeysN());
+ SysTryReturn(NID_WEB_JSON, pKeyList.get(), false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ //traverse through hashmap to know whether the value is present or not
+ result r = E_SUCCESS;
+ for (int i = 0; i < count; i++)
+ {
+ const String* pStr = null;
+ r = pKeyList->GetAt(i, pStr);
+ SysTryReturn(NID_WEB_JSON, pStr, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ IJsonValue* pValue = null;
+ r = GetValue(pStr, pValue);
+ SysTryReturn(NID_WEB_JSON, pValue, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ Object* pObj = dynamic_cast<Object*>(pValue);
+ Object* pObj1 = dynamic_cast<Object*>(pJsonValue);
+ SysAssertf(pObj && pObj1, "dynamic_cast failure");
+
+ if (pObj->Equals(*pObj1))
+ {
+ SysLog(NID_WEB_JSON, "JsonObject Contains given value");
+ return true;
+ }
+ }
+
+ SysLog(NID_WEB_JSON, "JsonObject does not contain given value");
+ return false;
+}
+
+
+bool
+JsonObject::Equals(const Object& obj) const
+{
+ ClearLastResult();
+
+ const JsonObject* pOther = dynamic_cast<const JsonObject*>(&obj);
+ SysTryReturn(NID_WEB_JSON, pOther, false, E_INVALID_ARG, "[%s] input parameter is not a JsonObject", GetErrorMessage(E_INVALID_ARG));
+
+ if (pOther == this)
+ {
+ SysLog(NID_WEB_JSON, "same JsonObject is given as input");
+ return true;
+ }
+
+ int count = GetCount();
+ //if number of key value pairs are same, we can compare element by element else they are not equal
+ SysTryReturn(NID_WEB_JSON, count == pOther->GetCount(), false, E_SUCCESS, "[%s] pair count is not same in jsonobjects", GetErrorMessage(E_SUCCESS));
+
+ if (count == 0)
+ {
+ return true;
+ }
+
+ unique_ptr<JsonKeyList> pKeyList(GetKeysN());
+ SysTryReturn(NID_WEB_JSON, pKeyList.get(), false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ //traverse through all key value pairs to check equality
+ result r = E_SUCCESS;
+ for (int i = 0; i < count; i++)
+ {
+ const String* pStr = null;
+ r = pKeyList->GetAt(i, pStr);
+ SysTryReturn(NID_WEB_JSON, pStr, false, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ IJsonValue* pValue = null;
+ IJsonValue* pOtherValue = null;
+
+ GetValue(pStr, pValue);
+ pOther->GetValue(pStr, pOtherValue);
+ //if both do not have same kay value pairs, they are not equal
+ if (!pValue || !pOtherValue)
+ {
+ SysLog(NID_WEB_JSON, "keys are not same in both objects");
+ return false;
+ }
+
+ Object* pObj = dynamic_cast<Object*>(pValue);
+ Object* pOtherObj = dynamic_cast<Object*>(pOtherValue);
+ SysAssertf(pObj && pOtherObj, "dynamic_cast failure");
+
+ //even One un equal key value pair is enough to say they are not equal
+ if (pObj->Equals(*pOtherObj) == false)
+ {
+ SysLog(NID_WEB_JSON, "key value pairs are not same in both objects");
+ return false;
+ }
+ }
+
+ SysLog(NID_WEB_JSON, "josnobjects are equal");
+ return true;
+}
+
+
+int
+JsonObject::GetHashCode(void) const
+{
+ ClearLastResult();
+
+ // Use enumerator to access elements in map
+ unique_ptr<JsonMapEnumerator> pMapEnum(GetMapEnumeratorN());
+ SysTryReturn(NID_WEB_JSON, pMapEnum.get(), (int)this, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ IJsonValue* pObjectVal = null;
+ const String* pKey = null;
+
+ int hash = 0;
+
+ while (pMapEnum->MoveNext() == E_SUCCESS)
+ {
+ int keyHash = 0;
+ int valHash = 0;
+ Object* pObj = null;
+
+ //Get KeyValue Pair
+ pMapEnum->GetKey(pKey);
+ pMapEnum->GetValue(pObjectVal);
+ SysAssertf(pObjectVal && pKey, "One of KeyValue pair is NULL!! Malformed");
+
+ //Get Key hash
+ keyHash = pKey->GetHashCode();
+ pObj = dynamic_cast<Object*>(pObjectVal);
+ SysAssertf(pObj, "dynamic cast failure");
+
+ //Get Value hash
+ valHash = pObj->GetHashCode();
+ hash += keyHash + valHash;
+ }
+ //Calculate hash from Combined hash
+ hash = hash ^ (hash >> 16);
+
+ return hash;
+}
+
+
+result
+JsonObject::Remove(const Tizen::Base::String* const& pKey)
+{
+ return Remove(pKey, false);
+}
+
+
+result
+JsonObject::Remove(const String* const& pKey, bool deallocate)
+{
+ SysTryReturnResult(NID_WEB_JSON, pKey, E_INVALID_ARG, "Input Argument is null");
+
+ int count = GetCount();
+ SysTryReturnResult(NID_WEB_JSON, count > 0, E_OBJ_NOT_FOUND, "Count is zero");
+
+ IJsonValue* pValue = null;
+ result r = E_SUCCESS;
+
+ r = GetValue(pKey, pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS && pValue, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ unique_ptr<JsonKeyList> pKeyList(GetKeysN());
+ SysTryReturnResult(NID_WEB_JSON, pKeyList.get(), E_OBJ_NOT_FOUND, "[%s] Propagating.", GetErrorMessage(E_OBJ_NOT_FOUND));
+
+ //Remove from Base class
+ r = HashMapT<const String*, IJsonValue*>::Remove(pKey);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (deallocate == true)
+ {
+ for (int i = 0; i < count; i++)
+ {
+ const String* pStr = null;
+ pKeyList->GetAt(i, pStr);
+ if (*pStr == *pKey)
+ {
+ delete pStr;
+ break;
+ }
+ }
+ _JsonUtils::DeallocateItem(pValue);
+ }
+
+ return r;
+}
+
+
+void
+JsonObject::RemoveAll(bool deallocate)
+{
+ ClearLastResult();
+
+ int paircount = GetCount();
+
+ if (paircount <= 0)
+ {
+ return;
+ }
+
+ if (deallocate == true)
+ {
+ const String* pKey = null;
+ IJsonValue* pValue = null;
+
+ unique_ptr<JsonKeyList> pKeyList(GetKeysN());
+ SysTryReturnVoidResult(NID_WEB_JSON, pKeyList.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ result r = E_SUCCESS;
+ for (int i = 0; i < paircount; i++)
+ {
+ //get value and key
+ r = pKeyList->GetAt(i, pKey);
+ SysTryReturnVoidResult(NID_WEB_JSON, pKey, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ r = GetValue(pKey, pValue);
+ SysTryReturnVoidResult(NID_WEB_JSON, pValue, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ //Remove entry from base class
+ HashMapT<const String*, IJsonValue*>::Remove(pKey);
+
+ //free key and value memory
+ delete pKey;
+ _JsonUtils::DeallocateItem(pValue);
+ }
+ }
+ //Call Baseclass function
+ HashMapT<const String*, IJsonValue*>::RemoveAll();
+}
+
+
+result
+JsonObject::SetValue(const String* const& pKey, IJsonValue* const& pJsonValue)
+{
+ return SetValue(pKey, pJsonValue, false);
+}
+
+
+result
+JsonObject::SetValue(const String* const& pKey, IJsonValue* const& pJsonValue, bool deallocate)
+{
+ SysTryReturnResult(NID_WEB_JSON, pKey && pJsonValue, E_INVALID_ARG, "Input Argument is null");
+
+ int count = GetCount();
+ SysTryReturnResult(NID_WEB_JSON, count > 0, E_OBJ_NOT_FOUND, "number of elements are zero");
+
+ result r = E_OBJ_NOT_FOUND;
+ IJsonValue* pValue = null;
+
+ r = GetValue(pKey, pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS && pValue, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ //SetValue in base class
+ r = HashMapT<const String*, IJsonValue*>::SetValue(pKey, pJsonValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (deallocate == true)
+ {
+ _JsonUtils::DeallocateItem(pValue);
+ }
+ return r;
+}
+
+
+result
+JsonObject::ContainsKey(const String* const& pKey, bool& out) const
+{
+ SysTryReturnResult(NID_WEB_JSON, pKey, E_INVALID_ARG, "Input parameter pKey is null");
+
+ out = false;
+
+ return HashMapT<const String*, IJsonValue*>::ContainsKey(pKey, out);
+}
+
+
+JsonObject*
+JsonObject::CloneN(void) const
+{
+ ClearLastResult();
+
+ result r = E_SUCCESS;
+
+ unique_ptr<JsonObject, AllElementsDeleter> pJsonObject(new (std::nothrow) JsonObject());
+ SysTryReturn(NID_WEB_JSON, pJsonObject, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ r = pJsonObject->Construct();
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ const String* pKey = null;
+ IJsonValue* pValue = null;
+ unique_ptr<String> pNewKey;
+ IJsonValue* pNewValue = null;
+ unique_ptr<JsonMapEnumerator> pMapEnum(GetMapEnumeratorN());
+
+ if (pMapEnum.get())
+ {
+ while (pMapEnum->MoveNext() == E_SUCCESS)
+ {
+ r = pMapEnum->GetKey(pKey);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ r = pMapEnum->GetValue(pValue);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ pNewKey = unique_ptr<String>(new (std::nothrow) String(*pKey));
+ SysTryReturn(NID_WEB_JSON, pNewKey.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ switch (pValue->GetType())
+ {
+ case JSON_TYPE_STRING:
+ pNewValue = new (std::nothrow) JsonString(static_cast<JsonString*>(pValue)->String::GetPointer());
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_NUMBER:
+ pNewValue = new (std::nothrow) JsonNumber(static_cast<JsonNumber*>(pValue)->ToDouble());
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_OBJECT:
+ pNewValue = static_cast<JsonObject*>(pValue)->CloneN();
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_ARRAY:
+ pNewValue = static_cast<JsonArray*>(pValue)->CloneN();
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_BOOL:
+ pNewValue = new (std::nothrow) JsonBool(static_cast<JsonBool*>(pValue)->ToBool());
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ case JSON_TYPE_NULL:
+ pNewValue = new (std::nothrow) JsonNull();
+ SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ break;
+ default:
+ SysAssertf(false, "unknown Json type.");
+ break;
+ }
+
+ r = pJsonObject->Add(pNewKey.get(), pNewValue);
+ if (IsFailed(r))
+ {
+ _JsonUtils::DeallocateItem(pNewValue);
+ SysLogException(NID_WEB_JSON, r, "[%s] Propagated.", GetErrorMessage(r));
+ return null;
+ }
+
+ pNewKey.release();
+ }
+ }
+
+ return pJsonObject.release();
+}
+
+
+}}} // Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonParser.cpp
+ * @brief The file contains the definition of JsonParser class.
+ *
+ * This file contains the definition of JsonParser class.
+ */
+#include <FBaseSysLog.h>
+#include <FWebJsonJsonParser.h>
+#include "FWebJson_JsonParserImpl.h"
+
+
+using namespace Tizen::Base;
+
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+JsonParser::JsonParser(void)
+ : __pJsonParserImpl(null)
+{
+
+}
+
+
+JsonParser::~JsonParser(void)
+{
+
+}
+
+
+IJsonValue*
+JsonParser::ParseN(const String& filePath)
+{
+ ClearLastResult();
+
+ SysLog(NID_WEB_JSON, "filePath : %ls", filePath.GetPointer());
+
+ return _JsonParserImpl::ParseN(filePath);
+}
+
+
+IJsonValue*
+JsonParser::ParseN(const void* pBuffer, int bufferLength)
+{
+ ClearLastResult();
+
+ SysLog(NID_WEB_JSON, "input pBuffer : %x, bufferLength : %d", pBuffer, bufferLength);
+
+ return _JsonParserImpl::ParseN(pBuffer, bufferLength);
+}
+
+
+IJsonValue*
+JsonParser::ParseN(const ByteBuffer& buffer)
+{
+ ClearLastResult();
+
+ return _JsonParserImpl::ParseN(buffer);
+}
+
+
+}}} // Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonString.cpp
+ * @brief This is the implementation file for JsonString class.
+ *
+ * This file contains the definition of JsonString class.
+ */
+#include <FBaseSysLog.h>
+#include <FWebJsonJsonString.h>
+
+using namespace Tizen::Base;
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+JsonString::JsonString(const char* pValue)
+ : String(pValue)
+ , __pJsonStringImpl(null)
+{
+
+}
+
+
+JsonString::JsonString(const String& value)
+ : String(value)
+ , __pJsonStringImpl(null)
+{
+
+}
+
+
+JsonString::JsonString(const wchar_t* pValue)
+ : String(pValue)
+ , __pJsonStringImpl(null)
+{
+
+}
+
+
+JsonString::JsonString(const JsonString& rhs)
+ : String(rhs)
+ , __pJsonStringImpl(null)
+{
+
+}
+
+
+JsonString::~JsonString(void)
+{
+
+}
+
+
+JsonType
+JsonString::GetType(void) const
+{
+ return JSON_TYPE_STRING;
+}
+
+
+JsonString&
+JsonString::operator =(const JsonString& rhs)
+{
+ if (this != &rhs)
+ {
+ String::operator =(rhs);
+ }
+
+ return *this;
+}
+
+
+}}} //Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJsonJsonWriter.cpp
+ * @brief The file contains the definition of JsonWriter class.
+ *
+ * This file contains the definition of JsonWriter class.
+ */
+#include <FBaseSysLog.h>
+#include <FWebJsonJsonWriter.h>
+#include "FWebJson_JsonWriterImpl.h"
+
+
+using namespace Tizen::Base;
+
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+JsonWriter::JsonWriter(void)
+ : __pJsonWriterImpl(null)
+{
+
+}
+
+
+JsonWriter::~JsonWriter(void)
+{
+
+}
+
+
+result
+JsonWriter::Compose(const IJsonValue* pValue, String& filePath)
+{
+ SysLog(NID_WEB_JSON, "pValue : %x, filePath : %ls", pValue, filePath.GetPointer());
+
+ return _JsonWriterImpl::Compose(pValue, filePath);
+}
+
+
+result
+JsonWriter::Compose(const IJsonValue* pValue, void* pBuffer, int bufferLength)
+{
+ SysLog(NID_WEB_JSON, "pValue : %x, pBuffer : %x, bufferLength : %d", pValue, pBuffer, bufferLength);
+
+ return _JsonWriterImpl::Compose(pValue, pBuffer, bufferLength);
+}
+
+
+result
+JsonWriter::Compose(const IJsonValue* pValue, ByteBuffer& buffer)
+{
+ SysLog(NID_WEB_JSON, "pValue : %x", pValue);
+
+ return _JsonWriterImpl::Compose(pValue, buffer);
+}
+
+
+}}} // Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJson_JsonParserImpl.cpp
+ * @brief The file contains the definition of _JsonParserImpl class.
+ *
+ * This file contains the definition of _JsonParserImpl class.
+ */
+#include <new>
+#include <unique_ptr.h>
+#include <FBaseColAllElementsDeleter.h>
+#include <FBaseSysLog.h>
+#include <FBaseUtilStringUtil.h>
+#include <FIoFile.h>
+#include <FWebJsonIJsonValue.h>
+#include <FWebJsonJsonArray.h>
+#include <FWebJsonJsonBool.h>
+#include <FWebJsonJsonNull.h>
+#include <FWebJsonJsonNumber.h>
+#include <FWebJsonJsonObject.h>
+#include <FWebJsonJsonParser.h>
+#include <FWebJsonJsonString.h>
+#include "FWebJson_JsonParserImpl.h"
+#include "FWebJson_JsonUtils.h"
+
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Io;
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+_JsonParserImpl::_JsonParserImpl(void)
+ : __pJsonData(null)
+ , __parserPosition(0)
+ , __size(0)
+{
+
+}
+
+
+_JsonParserImpl::~_JsonParserImpl(void)
+{
+
+}
+
+
+IJsonValue*
+_JsonParserImpl::ParseN(const String& filePath)
+{
+ File file;
+ result r = file.Construct(filePath, L"r");
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ FileAttributes attributes;
+ r = File::GetAttributes(filePath, attributes);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ long long size = attributes.GetFileSize();
+ SysTryReturn(NID_WEB_JSON, size > 0, null, E_INVALID_DATA, "[E_INVALID_DATA] size of file is invalid [%ld].", size);
+
+ unique_ptr<byte[]> pBuffer(new (std::nothrow) byte[size]);
+ SysTryReturn(NID_WEB_JSON, pBuffer.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ file.Seek(FILESEEKPOSITION_BEGIN, 0);
+ size = file.Read(pBuffer.get(), size);
+ r = GetLastResult();
+ SysTryReturn(NID_WEB_JSON, size > 0, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ unique_ptr<_JsonParserImpl> pParserImpl(_JsonParserImpl::CreateInstanceN());
+ SysTryReturn(NID_WEB_JSON, pParserImpl.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ IJsonValue* pRetValue = pParserImpl->ParseJsonBufferN((const char*)pBuffer.get(), size);
+ SysTryReturn(NID_WEB_JSON, pRetValue, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ return pRetValue;
+}
+
+
+IJsonValue*
+_JsonParserImpl::ParseN(const void* pBuffer, int bufferLength)
+{
+ SysTryReturn(NID_WEB_JSON, pBuffer && bufferLength > 0, null, E_INVALID_DATA, "[E_INVALID_DATA] Invalid input data");
+
+ unique_ptr<_JsonParserImpl> pParserImpl(_JsonParserImpl::CreateInstanceN());
+ SysTryReturn(NID_WEB_JSON, pParserImpl.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ IJsonValue* pRetValue = pParserImpl->ParseJsonBufferN((const char*)pBuffer, bufferLength);
+ SysTryReturn(NID_WEB_JSON, pRetValue, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ return pRetValue;
+}
+
+
+IJsonValue*
+_JsonParserImpl::ParseN(const ByteBuffer& buffer)
+{
+ int size = buffer.GetLimit();
+ SysTryReturn(NID_WEB_JSON, size > 0, null, E_INVALID_DATA, "[E_INVALID_DATA] buffer is empty.");
+
+ const byte* pBuffer = buffer.GetPointer();
+ SysTryReturn(NID_WEB_JSON, pBuffer, null, E_INVALID_DATA, "[E_INVALID_DATA] The buffer is empty.");
+
+ unique_ptr<_JsonParserImpl> pParserImpl(_JsonParserImpl::CreateInstanceN());
+ SysTryReturn(NID_WEB_JSON, pParserImpl.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ IJsonValue* pRetValue = pParserImpl->ParseJsonBufferN((const char*)pBuffer, size);
+ SysTryReturn(NID_WEB_JSON, pRetValue, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ return pRetValue;
+}
+
+
+_JsonParserImpl*
+_JsonParserImpl::CreateInstanceN(void)
+{
+ _JsonParserImpl* pJsonParserImpl = new (std::nothrow) _JsonParserImpl();
+ SysTryReturn(NID_WEB_JSON, pJsonParserImpl, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ return pJsonParserImpl;
+}
+
+
+IJsonValue*
+_JsonParserImpl::ParseJsonBufferN(const char* pBuffer, long long size)
+{
+ SysTryReturn(NID_WEB_JSON, pBuffer && size > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] input char buffer is null");
+
+ __pJsonData = pBuffer;
+ __size = size;
+
+ return ParseRootN();
+}
+
+
+IJsonValue*
+_JsonParserImpl::ParseRootN(void)
+{
+ SysTryReturn(NID_WEB_JSON, __pJsonData, null, E_INVALID_DATA, "[E_INVALID_DATA] Json data pointer is null");
+ SysTryReturn(NID_WEB_JSON, __size > 0, null, E_INVALID_DATA, "[E_INVALID_DATA] invalid size specified [%ld]", __size);
+ SysTryReturn(NID_WEB_JSON, GoToNextTokenPosition(), null, E_INVALID_DATA, "[E_INVALID_DATA] only white spaces");
+
+ IJsonValue* pRoot = null;
+
+ switch (__pJsonData[__parserPosition])
+ {
+ case '{':
+ pRoot = ParseObjectN();
+ SysLog(NID_WEB_JSON, "root is object");
+ break;
+ case '[':
+ pRoot = ParseArrayN();
+ SysLog(NID_WEB_JSON, "root is array");
+ break;
+ default:
+ SysLogException(NID_WEB_JSON, E_INVALID_DATA, "[E_INVALID_DATA] root is malformed [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+ return null;
+ }
+
+ SysTryReturn(NID_WEB_JSON, pRoot, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ if (GoToNextTokenPosition())
+ {
+ //there could be invalid character after valid data
+ SysTryCatch(NID_WEB_JSON, __pJsonData[__parserPosition] == '\0', , E_INVALID_DATA,
+ "[E_INVALID_DATA] Expected EOF, Invalid character [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+ }
+ return pRoot;
+
+CATCH:
+ _JsonUtils::DeallocateItem(pRoot);
+ SetLastResult(E_INVALID_DATA);
+ return null;
+}
+
+
+IJsonValue*
+_JsonParserImpl::ParseValueN(void)
+{
+ SysTryReturn(NID_WEB_JSON, __parserPosition < __size, null, E_INVALID_DATA, "[E_INVALID_DATA] current __parserPosition is beyond bounds");
+
+ IJsonValue* pJsonValue = null;
+
+ switch (__pJsonData[__parserPosition])
+ {
+ case '\"':
+ pJsonValue = ParseStringN();
+ break;
+ case '-':
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ pJsonValue = ParseNumberN();
+ break;
+ case '{':
+ pJsonValue = ParseObjectN();
+ break;
+ case '[':
+ pJsonValue = ParseArrayN();
+ break;
+ case 't':
+ case 'f':
+ pJsonValue = ParseBoolN();
+ break;
+ case 'n':
+ pJsonValue = ParseNullN();
+ break;
+ default:
+ SysLogException(NID_WEB_JSON, E_INVALID_DATA, "[E_INVALID_DATA] invalid character [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+ break;
+ }
+
+ return pJsonValue;
+}
+
+
+JsonObject*
+_JsonParserImpl::ParseObjectN(void)
+{
+ SysTryReturn(NID_WEB_JSON, GoToNextTokenPosition(true), null, E_INVALID_DATA, "[E_INVALID_DATA] object incomplete at [%d]", __parserPosition);
+
+ unique_ptr<JsonObject, AllElementsDeleter> pJsonObject(new (std::nothrow) JsonObject());
+ SysTryReturn(NID_WEB_JSON, pJsonObject.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = pJsonObject->Construct();
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (__pJsonData[__parserPosition] == '}')
+ {
+ GoToNextTokenPosition(true);
+ return pJsonObject.release();
+ }
+
+ while (true)
+ {
+ //add key value pair
+ r = AddPairToObject(*pJsonObject);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (__pJsonData[__parserPosition] != ',')
+ {
+ break;
+ }
+
+ SysTryReturn(NID_WEB_JSON, GoToNextTokenPosition(true), null, E_INVALID_DATA, "[E_INVALID_DATA] object incomplete at [%d]", __parserPosition);
+ }
+
+ SysTryReturn(NID_WEB_JSON, __pJsonData[__parserPosition] == '}', null, E_INVALID_DATA, "[E_INVALID_DATA] data malfored [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+
+ GoToNextTokenPosition(true);
+ return pJsonObject.release();
+}
+
+
+JsonArray*
+_JsonParserImpl::ParseArrayN(void)
+{
+ SysTryReturn(NID_WEB_JSON, GoToNextTokenPosition(true), null, E_INVALID_DATA, "[E_INVALID_DATA] array incomplete at [%d]", __parserPosition);
+
+ unique_ptr<JsonArray, AllElementsDeleter> pJsonArray(new (std::nothrow) JsonArray());
+ SysTryReturn(NID_WEB_JSON, pJsonArray.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = pJsonArray->Construct();
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (__pJsonData[__parserPosition] == ']')
+ {
+ GoToNextTokenPosition(true);
+ return pJsonArray.release();
+ }
+
+ while (true)
+ {
+ //add value to array
+ r = AddValueToArray(*pJsonArray);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (__pJsonData[__parserPosition] != ',')
+ {
+ break;
+ }
+
+ SysTryReturn(NID_WEB_JSON, GoToNextTokenPosition(true), null, E_INVALID_DATA, "[E_INVALID_DATA] array incomplete at [%d]", __parserPosition);
+ }
+
+ SysTryReturn(NID_WEB_JSON, __pJsonData[__parserPosition] == ']', null, E_INVALID_DATA, "[E_INVALID_DATA] data malfored [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+
+ GoToNextTokenPosition(true);
+ return pJsonArray.release();
+}
+
+
+JsonNumber*
+_JsonParserImpl::ParseNumberN(void)
+{
+ String numString;
+ bool exp = false;
+ bool fraction = false;
+ bool created = false;
+
+ //negative sign check
+ if (__pJsonData[__parserPosition] == '-')
+ {
+ numString.Append(__pJsonData[__parserPosition++]);
+ SysTryReturn(NID_WEB_JSON, __parserPosition < __size, null, E_INVALID_DATA, "[E_INVALID_DATA] Incomplete number at [%d]", __parserPosition);
+ }
+
+ if (__pJsonData[__parserPosition] >= '0' && __pJsonData[__parserPosition] <= '9')
+ {
+ int digits = 0;
+ if (__pJsonData[__parserPosition] == '0')
+ {
+ numString.Append(__pJsonData[__parserPosition++]);
+ ++digits;
+ }
+ else
+ {
+ if (__pJsonData[__parserPosition] >= '1' && __pJsonData[__parserPosition] <= '9')
+ {
+ do
+ {
+ numString.Append(__pJsonData[__parserPosition++]);
+ ++digits;
+ }
+ while (__parserPosition < __size && __pJsonData[__parserPosition] >= '0' && __pJsonData[__parserPosition] <= '9');
+ }
+ }
+
+ //number of digits before fraction should not be zero
+ SysTryReturn(NID_WEB_JSON, digits && GoToNextTokenPosition(), null, E_INVALID_DATA, "[E_INVALID_DATA] Input data malformed at [%d]", __parserPosition);
+
+ switch (__pJsonData[__parserPosition])
+ {
+ case '.':
+ fraction = true;
+ numString.Append(__pJsonData[__parserPosition++]);
+ break;
+ case 'e':
+ case 'E':
+ exp = true;
+ numString.Append(__pJsonData[__parserPosition++]);
+ break;
+ case '}':
+ case ']':
+ case ',':
+ //number ends here (int)
+ created = true;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (fraction && !created)
+ {
+ int digitsAfterFraction = 0;
+ while (__parserPosition < __size && __pJsonData[__parserPosition] >= '0' && __pJsonData[__parserPosition] <= '9')
+ {
+ numString.Append(__pJsonData[__parserPosition++]);
+ ++digitsAfterFraction;
+ }
+
+ //number of digits after fraction should not be zero
+ SysTryReturn(NID_WEB_JSON, digitsAfterFraction && GoToNextTokenPosition(), null, E_INVALID_DATA, "[E_INVALID_DATA] Input data malformed at [%d]", __parserPosition);
+
+ switch (__pJsonData[__parserPosition])
+ {
+ case 'e':
+ case 'E':
+ exp = true;
+ numString.Append(__pJsonData[__parserPosition++]);
+ break;
+ case '}':
+ case ']':
+ case ',':
+ //number ends here (int fraction digits)
+ created = true;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (exp && !created)
+ {
+ int digitsAfterExp = 0;
+
+ if (__parserPosition < __size && (__pJsonData[__parserPosition] == '-' || __pJsonData[__parserPosition] == '+'))
+ {
+ numString.Append(__pJsonData[__parserPosition++]);
+ }
+
+ while (__parserPosition < __size && __pJsonData[__parserPosition] >= '0' && __pJsonData[__parserPosition] <= '9')
+ {
+ numString.Append(__pJsonData[__parserPosition++]);
+ ++digitsAfterExp;
+ }
+
+ //number of digits after exponential (e or E) should not be zero
+ SysTryReturn(NID_WEB_JSON, digitsAfterExp && GoToNextTokenPosition(), null, E_INVALID_DATA, "[E_INVALID_DATA] Input data malformed at [%d]", __parserPosition);
+
+ switch (__pJsonData[__parserPosition])
+ {
+ case '}':
+ case ']':
+ case ',':
+ //number ends here (int fraction digits exp +/- digits)
+ created = true;
+ break;
+ default:
+ break;
+ }
+ }
+
+ SysTryReturn(NID_WEB_JSON, created, null, E_INVALID_DATA, "[E_INVALID_DATA] Input data malformed [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+
+ double number = 0.0;
+ JsonNumber* pJsonNumber = null;
+
+ result r = Double::Parse(numString, number);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] parse double from string failed", GetErrorMessage(r));
+
+ pJsonNumber = new (std::nothrow) JsonNumber(number);
+ SysTryReturn(NID_WEB_JSON, pJsonNumber, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ return pJsonNumber;
+}
+
+
+JsonBool*
+_JsonParserImpl::ParseBoolN(void)
+{
+ bool boolValue = true;
+
+ if (__pJsonData[__parserPosition] == 't')
+ {
+ SysTryReturn(NID_WEB_JSON, __parserPosition+4 < __size, null, E_INVALID_DATA, "[E_INVALID_DATA] Incomplete bool true at [%d]", __parserPosition);
+ SysTryReturn(NID_WEB_JSON, strncmp(__pJsonData+__parserPosition, "true", 4) == 0, null, E_INVALID_DATA, "[E_INVALID_DATA] expected true at [%d]", __parserPosition);
+ __parserPosition += 4;
+ }
+ else if (__pJsonData[__parserPosition] == 'f')
+ {
+ SysTryReturn(NID_WEB_JSON, __parserPosition+5 < __size, null, E_INVALID_DATA, "[E_INVALID_DATA] Incomplete bool false at [%d]", __parserPosition);
+ SysTryReturn(NID_WEB_JSON, strncmp(__pJsonData+__parserPosition, "false", 5) == 0, null, E_INVALID_DATA, "[E_INVALID_DATA] expected false at [%d]", __parserPosition);
+ boolValue = false;
+ __parserPosition += 5;
+ }
+ else
+ {
+ SysLogException(NID_WEB_JSON, E_INVALID_DATA, "[E_INVALID_DATA] expected t or f but not [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+ return null;
+ }
+
+ JsonBool* pJsonBool = null;
+ pJsonBool = new JsonBool(boolValue);
+ SysTryReturn(NID_WEB_JSON, pJsonBool, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ return pJsonBool;
+}
+
+
+JsonNull*
+_JsonParserImpl::ParseNullN(void)
+{
+ SysTryReturn(NID_WEB_JSON, __parserPosition+4 < __size, null, E_INVALID_DATA, "[E_INVALID_DATA] Incomplete null at [%d]", __parserPosition);
+ SysTryReturn(NID_WEB_JSON, strncmp(__pJsonData+__parserPosition, "null", 4) == 0, null, E_INVALID_DATA, "[E_INVALID_DATA] expected null at [%d]", __parserPosition);
+
+ JsonNull* pJsonNull = new (std::nothrow) JsonNull();
+ SysTryReturn(NID_WEB_JSON, pJsonNull, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ __parserPosition += 4;
+ return pJsonNull;
+}
+
+
+JsonString*
+_JsonParserImpl::ParseStringN(void)
+{
+ SysTryReturn(NID_WEB_JSON, __parserPosition < __size, null, E_INVALID_DATA, "[E_INVALID_DATA] current __parserPosition is not valid");
+ SysTryReturn(NID_WEB_JSON, __pJsonData[__parserPosition] == '\"', null, E_INVALID_DATA, "[E_INVALID_DATA] Input is not a json string");
+
+ String json;
+ unique_ptr<JsonString> pJsonString(new (std::nothrow) JsonString(json));
+ SysTryReturn(NID_WEB_JSON, pJsonString.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = GetString(*pJsonString);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ return pJsonString.release();
+}
+
+
+String*
+_JsonParserImpl::ParseKeyN(void)
+{
+ SysTryReturn(NID_WEB_JSON, __parserPosition < __size, null, E_INVALID_DATA, "[E_INVALID_DATA] current __parserPosition is not valid");
+ SysTryReturn(NID_WEB_JSON, __pJsonData[__parserPosition] == '\"', null, E_INVALID_DATA, "[E_INVALID_DATA] Input is not a json string");
+
+ unique_ptr<String> pString(new (std::nothrow) String());
+ SysTryReturn(NID_WEB_JSON, pString.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ result r = GetString(*pString);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ return pString.release();
+}
+
+
+result
+_JsonParserImpl::AddPairToObject(JsonObject& pJsonObject)
+{
+ unique_ptr<String> pKey(ParseKeyN());
+ SysTryReturnResult(NID_WEB_JSON, pKey.get(), GetLastResult(), "Propagating.");
+
+ SysTryReturnResult(NID_WEB_JSON, GoToNextTokenPosition(), E_INVALID_DATA, "[E_INVALID_DATA] object incomplete at [%d]", __parserPosition);
+ SysTryReturnResult(NID_WEB_JSON, __pJsonData[__parserPosition] == ':', E_INVALID_DATA, "[E_INVALID_DATA] data malfored [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+ SysTryReturnResult(NID_WEB_JSON, GoToNextTokenPosition(true), E_INVALID_DATA, "[E_INVALID_DATA] object incomplete at [%d]", __parserPosition);
+
+ IJsonValue* pValue = ParseValueN();
+ SysTryReturnResult(NID_WEB_JSON, pValue, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ result r = pJsonObject.Add(pKey.get(), pValue);
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+ pKey.release();
+ SysTryReturnResult(NID_WEB_JSON, GoToNextTokenPosition(), E_INVALID_DATA, "object incomplete at [%d]", __parserPosition);
+
+ return r;
+
+CATCH:
+ _JsonUtils::DeallocateItem(pValue);
+ return r;
+}
+
+
+result
+_JsonParserImpl::AddValueToArray(JsonArray& pJsonArray)
+{
+ result r = E_SUCCESS;
+
+ IJsonValue* pValue = ParseValueN();
+ SysTryReturnResult(NID_WEB_JSON, pValue, GetLastResult(), "Propagating.");
+
+ r = pJsonArray.Add(pValue);
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
+ SysTryReturnResult(NID_WEB_JSON, GoToNextTokenPosition(), E_INVALID_DATA, "array incomplete at [%d]", __parserPosition);
+
+ return r;
+
+CATCH:
+ _JsonUtils::DeallocateItem(pValue);
+ return r;
+}
+
+
+result
+_JsonParserImpl::ParseUnicode(String& uniString)
+{
+ char unicodebuf[5] = {'\0',};
+ int ucharcount = 0;
+
+ while (__parserPosition < __size)
+ {
+ if (((__pJsonData[__parserPosition] >= '0') && (__pJsonData[__parserPosition] <= '9'))
+ || ((__pJsonData[__parserPosition] >= 'a') && (__pJsonData[__parserPosition] <= 'f'))
+ || ((__pJsonData[__parserPosition] >= 'A') && (__pJsonData[__parserPosition] <= 'F')))
+ {
+ unicodebuf[ucharcount++] = __pJsonData[__parserPosition++];
+ if (ucharcount == 4)
+ {
+ unsigned int hexval = 0;
+ int bytes = 0;
+
+ sscanf(unicodebuf, "%4x", &hexval);
+ if ((hexval >= 0xDC00 && hexval <= 0xDFFF) || hexval == 0)
+ {
+ //invalid unicode. skip
+ SysLog(NID_WEB_JSON, "skip invalid unicode [%4x] at[%d]", hexval, __parserPosition);
+ break;
+ }
+
+ if (hexval < 0x80)
+ {
+ bytes = 1;
+ }
+ else if (hexval < 0x800)
+ {
+ bytes = 2;
+ }
+ else if (hexval < 0x10000)
+ {
+ if (hexval < 0xD800 || 0xDBFF < hexval)
+ {
+ bytes = 3;
+ }
+ else
+ {
+ unsigned int leadSurrogate = hexval; // 0xD800 to 0xDBFF
+ unsigned int trailSurrogate = 0; // 0xDC00 to 0xDFFF
+
+ if (__parserPosition+1 >= __size || __pJsonData[__parserPosition] != '\\' || __pJsonData[__parserPosition+1] != 'u')
+ {
+ // missing trailSurrogate. skip
+ SysLog(NID_WEB_JSON, "skip missing trailSurrogate at [%d]", __parserPosition);
+ break;
+ }
+
+ char srgtBuf[5] = {'\0',};
+ __parserPosition += 2;
+ int srgtCount = 0;
+ while (__parserPosition < __size && srgtCount < 4)
+ {
+ srgtBuf[srgtCount++] = __pJsonData[__parserPosition++];
+ }
+
+ SysTryReturnResult(NID_WEB_JSON, srgtCount == 4, E_INVALID_DATA, "invalid surrogate unicode at [%d]", __parserPosition);
+
+ srgtBuf[srgtCount] = '\0';
+ sscanf(srgtBuf, "%4x", &trailSurrogate);
+
+ if (trailSurrogate < 0xDC00 || trailSurrogate > 0xDFFF)
+ {
+ // invalid trailSurrogate. skip
+ SysLog(NID_WEB_JSON, "skipping invalid trailSurrogate at [%d]", __parserPosition);
+ break;
+ }
+
+ leadSurrogate -= 0xD800;
+ trailSurrogate -= 0xDC00;
+
+ hexval = (leadSurrogate << 10) + (trailSurrogate) + 0x10000;
+ bytes = 4;
+ }
+ }
+ else
+ {
+ //unsupported unicode
+ SysLog(NID_WEB_JSON, "skip invalid unicode [%4x] at [%d]", hexval, __parserPosition);
+ break;
+ }
+
+ switch (bytes)
+ {
+ case 4:
+ {
+ unsigned char buf[5] = {0xF0, 0x80, 0x80, 0x80, '\0'};
+ buf[3] += (hexval & 0x3F);
+ hexval >>= 6;
+ buf[2] += (hexval & 0x3F);
+ hexval >>= 6;
+ buf[1] += (hexval & 0x3F);
+ hexval >>= 6;
+ buf[0] += (hexval & 0x7);
+ uniString.Append((char*)buf);
+ break;
+ }
+ case 3:
+ {
+ unsigned char buf[4] = {0xE0, 0x80, 0x80, '\0'};
+ buf[2] += (hexval & 0x3F);
+ hexval >>= 6;
+ buf[1] += (hexval & 0x3F);
+ hexval >>= 6;
+ buf[0] += (hexval & 0xF);
+ uniString.Append((char*)buf);
+ break;
+ }
+ case 2:
+ {
+ unsigned char buf[3] = {0xC0, 0x80, '\0'};
+ buf[1] += (hexval & 0x3F);
+ hexval >>= 6;
+ buf[0] += (hexval & 0x1F);
+ uniString.Append((char*)buf);
+ break;
+ }
+ case 1:
+ uniString.Append((char)hexval);
+ break;
+ }
+ break;
+ }
+ }
+ else
+ {
+ SysTryReturnResult(NID_WEB_JSON, false, E_INVALID_DATA, "unicode [%x] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+ }
+ }
+ return E_SUCCESS;
+}
+
+
+result
+_JsonParserImpl::GetString(Tizen::Base::String& parsedString)
+{
+ ++__parserPosition;
+
+ bool created = false;
+
+ while (!created && __parserPosition < __size)
+ {
+ switch (__pJsonData[__parserPosition])
+ {
+ case '\\':
+ //escaped character sequence
+ if (++__parserPosition >= __size)
+ {
+ //incomplete data
+ break;
+ }
+ switch (__pJsonData[__parserPosition])
+ {
+ case '\\':
+ case '\"':
+ case '/':
+ parsedString.Append(__pJsonData[__parserPosition]);
+ break;
+ case 'b':
+ parsedString.Append('\b');
+ break;
+ case 'f':
+ parsedString.Append('\f');
+ break;
+ case 'n':
+ parsedString.Append('\n');
+ break;
+ case 'r':
+ parsedString.Append('\r');
+ break;
+ case 't':
+ parsedString.Append('\t');
+ break;
+ case 'u':
+ {
+ ++__parserPosition;
+ SysTryReturnResult(NID_WEB_JSON, __parserPosition < __size, E_INVALID_DATA, "string incomplete at [%d]", __parserPosition);
+
+ result r = ParseUnicode(parsedString);
+ SysTryReturnResult(NID_WEB_JSON, r == E_SUCCESS, r, "unicode parse failed");
+ --__parserPosition;
+ break;
+ }
+ default:
+ SysLogException(NID_WEB_JSON, E_INVALID_DATA, "[E_INVALID_DATA] escaped char [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+ return E_INVALID_DATA;
+ }
+ break;
+ case '\"':
+ //end of string
+ created = true;
+ break;
+ default:
+ SysTryReturnResult(NID_WEB_JSON, (__pJsonData[__parserPosition] < 1) || (__pJsonData[__parserPosition] > 31), E_INVALID_DATA,
+ "char [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+
+ if (__pJsonData[__parserPosition] > 127 || __pJsonData[__parserPosition] < 0)
+ {
+ //Extended ASCII range
+ wchar_t wc[2] = {L"\0",};
+ if (mbtowc(wc, &__pJsonData[__parserPosition], 1) != 0)
+ {
+ parsedString.Append(wc);
+ }
+ else
+ {
+ parsedString.Append(__pJsonData[__parserPosition]);
+ }
+ }
+ else
+ {
+ //Normal ASCII range
+ parsedString.Append(__pJsonData[__parserPosition]);
+ }
+ break;
+ }
+ ++__parserPosition;
+ }
+
+ SysTryReturnResult(NID_WEB_JSON, created, E_INVALID_DATA, "incomplete string [%d]", __parserPosition);
+
+ return E_SUCCESS;
+}
+
+
+bool
+_JsonParserImpl::GoToNextTokenPosition(bool skipAfterIncrement)
+{
+ if (skipAfterIncrement)
+ {
+ ++__parserPosition;
+ }
+
+ while (__parserPosition < __size)
+ {
+ switch (__pJsonData[__parserPosition])
+ {
+ case 0x20:
+ case 0x09:
+ case 0x0A:
+ case 0x0D:
+ //Insignificant white spaces are skipped here
+ ++__parserPosition;
+ break;
+ default:
+ return (__parserPosition < __size) ? true : false;
+ }
+ }
+ return (__parserPosition < __size) ? true : false;
+}
+
+
+}}} // Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJson_JsonParserImpl.h
+ * @brief This is the header file for _JsonParserImpl Class.
+ */
+
+#ifndef _FWEB_JSON_INTERNAL_JSON_PARSER_IMPL_H_
+#define _FWEB_JSON_INTERNAL_JSON_PARSER_IMPL_H_
+
+#include <FBaseByteBuffer.h>
+#include <FBaseObject.h>
+#include <FBaseString.h>
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+class IJsonValue;
+class JsonParser;
+class JsonObject;
+class JsonArray;
+class JsonNumber;
+class JsonBool;
+class JsonString;
+class JsonNull;
+
+class _JsonParserImpl
+ : public Tizen::Base::Object
+{
+public:
+ /**
+ * This is the default destructor for this class.
+ *
+ */
+ virtual ~_JsonParserImpl(void);
+
+ /**
+ * This function parses a JSON encoded file to a IJsonValue (node)
+ *
+ * @since 2.0
+ * @param[in] filePath Path of Json encoded file
+ * @return IJsonValue
+ * @see IJsonValue
+ */
+ static IJsonValue* ParseN(const Tizen::Base::String& filePath);
+
+ /**
+ * This function parses a JSON encoded buffer to a IJsonValue (node)
+ *
+ * @since 2.0
+ * @param[in] pBuffer A Json encoded buffer
+ * @param[in] bufferLength Json encoded buffer length
+ * @return IJsonValue
+ * @see IJsonValue
+ */
+ static IJsonValue* ParseN(const void* pBuffer, int bufferLength);
+
+ /**
+ * This function parses a JSON encoded byte buffer to a IJsonValue (node)
+ *
+ * @since 2.0
+ * @param[in] buffer A Json encoded byte buffer
+ * @return IJsonValue
+ * @see IJsonValue
+ */
+ static IJsonValue* ParseN(const Tizen::Base::ByteBuffer& buffer);
+
+ static _JsonParserImpl* CreateInstanceN(void);
+
+ IJsonValue* ParseJsonBufferN(const char* pJsonData, long long size);
+
+private:
+ /**
+ * This is the default constructor for this class.
+ *
+ * @remarks This constructor is hidden.
+ */
+ _JsonParserImpl(void);
+
+ _JsonParserImpl(const _JsonParserImpl&);
+
+ _JsonParserImpl& operator =(const _JsonParserImpl&);
+
+ IJsonValue* ParseRootN(void);
+
+ IJsonValue* ParseValueN(void);
+
+ JsonObject* ParseObjectN(void);
+
+ JsonArray* ParseArrayN(void);
+
+ JsonNumber* ParseNumberN(void);
+
+ JsonBool* ParseBoolN(void);
+
+ JsonNull* ParseNullN(void);
+
+ JsonString* ParseStringN(void);
+
+ Tizen::Base::String* ParseKeyN(void);
+
+ result AddPairToObject(JsonObject& pObject);
+
+ result AddValueToArray(JsonArray& pArray);
+
+ result ParseUnicode(Tizen::Base::String&);
+
+ result GetString(Tizen::Base::String&);
+
+ bool GoToNextTokenPosition(bool skipAfterIncrement = false);
+
+private:
+ const char* __pJsonData;
+ long long __parserPosition;
+ long long __size;
+}; // _JsonParserImpl
+
+}}} // Tizen::Web::Json
+#endif // _FWEBJSON_INTERNAL_JSON_PARSER_IMPL_H_
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJson_JsonUtils.cpp
+ * @brief This is the implementation file for JsonUtilities.
+ */
+#include <FWebJsonIJsonValue.h>
+#include <FWebJsonJsonArray.h>
+#include <FWebJsonJsonObject.h>
+#include "FWebJson_JsonUtils.h"
+
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+void
+_JsonUtils::DeallocateItem(IJsonValue* pJsonValue)
+{
+ if (pJsonValue)
+ {
+ JsonType type = pJsonValue->GetType();
+ if (type == JSON_TYPE_OBJECT)
+ {
+ JsonObject* pObject = static_cast<JsonObject*>(pJsonValue);
+ pObject->RemoveAll(true);
+ }
+ else if (type == JSON_TYPE_ARRAY)
+ {
+ JsonArray* pArray = static_cast<JsonArray*>(pJsonValue);
+ pArray->RemoveAll(true);
+ }
+ delete pJsonValue;
+ }
+}
+
+
+}}} // Tizen::Web::Json
--- /dev/null
+// \r
+// Open Service Platform\r
+// Copyright (c) 2012 Samsung Electronics Co., Ltd. \r
+// \r
+// Licensed under the Apache License, Version 2.0 (the License);\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+\r
+/**\r
+ * @file FWebJson_JsonUtils.h\r
+ * @brief This is the header file for JsonUtilities.\r
+ */\r
+\r
+#ifndef _FWEB_JSON_INTERNAL_JSON_UTILS_H_\r
+#define _FWEB_JSON_INTERNAL_JSON_UTILS_H_\r
+\r
+\r
+namespace Tizen { namespace Web { namespace Json\r
+{\r
+\r
+class IJsonValue;\r
+\r
+typedef const Tizen::Base::String* StringKey;\r
+typedef Tizen::Base::Collection::IMapEnumeratorT<StringKey, IJsonValue*> JsonMapEnumerator;\r
+typedef Tizen::Base::Collection::IListT<StringKey> JsonKeyList;\r
+typedef Tizen::Base::Collection::IEnumeratorT<IJsonValue*> JsonValueEnumerator;\r
+typedef Tizen::Base::Collection::IListT<IJsonValue*> JsonValueList;\r
+\r
+class _JsonUtils\r
+{\r
+public:\r
+\r
+ static void DeallocateItem(IJsonValue* pJsonValue);\r
+\r
+private:\r
+\r
+ _JsonUtils(void);\r
+\r
+ ~_JsonUtils(void);\r
+\r
+ _JsonUtils(const _JsonUtils&);\r
+\r
+ _JsonUtils& operator =(const _JsonUtils&);\r
+\r
+}; // _JsonUtils\r
+\r
+}}} // Tizen::Web::Json\r
+#endif // _FWEBJSON_INTERNAL_JSON_UTILS_H_\r
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJson_JsonWriterImpl.cpp
+ * @brief The file contains the definition of _JsonWriterImpl class.
+ *
+ * This file contains the definition of _JsonWriterImpl class.
+ */
+#include <new>
+#include <unique_ptr.h>
+#include <FBaseByteBuffer.h>
+#include <FBaseColIEnumeratorT.h>
+#include <FBaseColIMapEnumeratorT.h>
+#include <FBaseSysLog.h>
+#include <FBaseString.h>
+#include <FBaseUtilMath.h>
+#include <FBaseUtilStringUtil.h>
+#include <FIoFile.h>
+#include <FWebJsonIJsonValue.h>
+#include <FWebJsonJsonArray.h>
+#include <FWebJsonJsonBool.h>
+#include <FWebJsonJsonNull.h>
+#include <FWebJsonJsonNumber.h>
+#include <FWebJsonJsonObject.h>
+#include <FWebJsonJsonString.h>
+#include <FBase_StringConverter.h>
+#include "FWebJson_JsonWriterImpl.h"
+#include "FWebJson_JsonUtils.h"
+
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Io;
+
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+
+static const char COMMA = ',';
+static const char QUOTE = '\"';
+static const char COLON = ':';
+static const char OBJECT_BEGIN = '{';
+static const char OBJECT_END = '}';
+static const char ARRAY_BEGIN = '[';
+static const char ARRAY_END = ']';
+
+
+result
+_JsonWriterImpl::Compose(const IJsonValue* pValue, String& filePath)
+{
+ SysTryReturnResult(NID_WEB_JSON, pValue, E_INVALID_DATA, "There is no data in IJsonValue.");
+
+ result r = E_SUCCESS;
+ File file;
+ String output;
+
+ r = ConvertIJsonToString(const_cast<IJsonValue*>(pValue), output);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ SysLog(NID_WEB_JSON, "file path: [%ls]", filePath.GetPointer());
+ r = file.Construct(filePath, "w+");
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ r = file.Write(output);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ return r;
+}
+
+
+result
+_JsonWriterImpl::Compose(const IJsonValue* pValue, void* pBuffer, int bufferLength)
+{
+ SysTryReturnResult(NID_WEB_JSON, pValue, E_INVALID_DATA, "Invalid Input parameter.");
+ SysTryReturnResult(NID_WEB_JSON, pBuffer && bufferLength >= 0, E_INVALID_ARG, "Invalid buffer parameter.");
+
+ String output;
+ result r = ConvertIJsonToString(const_cast<IJsonValue*>(pValue), output);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(output));
+ r = GetLastResult();
+ SysTryReturn(NID_WEB_JSON, pText.get(), r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ int charCount = strlen(pText.get());
+ charCount = (charCount <= bufferLength) ? charCount : bufferLength;
+ SysLog(NID_WEB_JSON, "[%d] characters written to given buffer", charCount);
+ memcpy(pBuffer, pText.get(), charCount);
+
+ return r;
+}
+
+
+result
+_JsonWriterImpl::Compose(const IJsonValue* pValue, ByteBuffer& buffer)
+{
+ SysTryReturnResult(NID_WEB_JSON, pValue, E_INVALID_DATA, "Invalid Input parameter.");
+
+ String output;
+ result r = ConvertIJsonToString(const_cast<IJsonValue*>(pValue), output);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ unique_ptr<ByteBuffer> pByteBuf(StringUtil::StringToUtf8N(output));
+ r = GetLastResult();
+ SysTryReturn(NID_WEB_JSON, pByteBuf.get(), r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (buffer.GetPointer())
+ {
+ int givenCapacity = buffer.GetCapacity();
+ int requiredCapacity = pByteBuf->GetCapacity();
+
+ if (givenCapacity < requiredCapacity)
+ {
+ r = buffer.ExpandCapacity(requiredCapacity);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+ }
+
+ buffer.Clear();
+ r = buffer.CopyFrom(*pByteBuf);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+ }
+ else
+ {
+ r = buffer.Construct(*pByteBuf);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+ }
+
+ return r;
+}
+
+
+result
+_JsonWriterImpl::ConvertIJsonToString(IJsonValue* pValue, String& outString)
+{
+ SysTryReturnResult(NID_WEB_JSON, pValue, E_INVALID_ARG, "input JsonValue pointer is null");
+
+ result r = E_SUCCESS;
+
+ switch (pValue->GetType())
+ {
+ case JSON_TYPE_OBJECT:
+ {
+ outString.Append(OBJECT_BEGIN);
+
+ const String* pKey = null;
+ IJsonValue* pObjectValue = null;
+ JsonObject* pObject = static_cast<JsonObject*>(pValue);
+
+ unique_ptr<JsonMapEnumerator> pMapEnum(pObject->GetMapEnumeratorN());
+ r = GetLastResult();
+ SysTryReturn(NID_WEB_JSON, pMapEnum.get(), r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ int itemCount = pObject->GetCount();
+
+ while (pMapEnum->MoveNext() == E_SUCCESS)
+ {
+ r = pMapEnum->GetKey(pKey);
+ SysTryReturn(NID_WEB_JSON, pKey, r, r, "[%s]Propagating.", GetErrorMessage(r));
+
+ String escString;
+ r = ToEscString(*pKey, escString);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ outString.Append(QUOTE);
+ outString.Append(escString);
+ outString.Append(QUOTE);
+
+ r = pMapEnum->GetValue(pObjectValue);
+ SysTryReturn(NID_WEB_JSON, pObjectValue, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ outString.Append(COLON);
+ r = ConvertIJsonToString(pObjectValue, outString);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (--itemCount)
+ {
+ outString.Append(COMMA);
+ }
+ }
+ outString.Append(OBJECT_END);
+ }
+ break;
+
+ case JSON_TYPE_ARRAY:
+ {
+ outString.Append(ARRAY_BEGIN);
+
+ IJsonValue* pArrayValue = null;
+ JsonArray* pArray = static_cast<JsonArray*>(pValue);
+ int itemCount = pArray->GetCount() - 1;
+
+ for (int index = 0; index <= itemCount; index++)
+ {
+ r = pArray->GetAt(index, pArrayValue);
+ SysTryReturn(NID_WEB_JSON, pArrayValue, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ r = ConvertIJsonToString(pArrayValue, outString);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (index != itemCount)
+ {
+ outString.Append(COMMA);
+ }
+ }
+
+ outString.Append(ARRAY_END);
+ }
+ break;
+
+ case JSON_TYPE_STRING:
+ {
+ String escString;
+ r = ToEscString(*(static_cast<JsonString*>(pValue)), escString);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ outString.Append(QUOTE);
+ outString.Append(escString);
+ outString.Append(QUOTE);
+ }
+ break;
+
+ case JSON_TYPE_NUMBER:
+ {
+ String out;
+ double val1 = static_cast<JsonNumber*>(pValue)->ToDouble();
+ double val2 = Math::Floor(val1);
+
+ r = (Double::Compare(val1, val2) == 0) ? out.Format(15, L"%g", val1) : out.Format(15, L"%f", val1);
+ SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ outString.Append(out);
+ }
+ break;
+
+ case JSON_TYPE_BOOL:
+ outString.Append((static_cast<JsonBool*>(pValue))->ToString());
+ break;
+
+ case JSON_TYPE_NULL:
+ outString.Append((static_cast<JsonNull*>(pValue))->ToString());
+ break;
+
+ default:
+ SysLogException(NID_WEB_JSON, E_INVALID_DATA, "[E_INVALID_DATA] reached default of ConvertIJsonToString");
+ return E_INVALID_DATA;
+ }
+
+ return r;
+}
+
+
+result
+_JsonWriterImpl::ToEscString(const String& unEscStr, String& escString)
+{
+ const wchar_t* pUnEscBuf = unEscStr.GetPointer();
+ SysTryReturn(NID_WEB_JSON, pUnEscBuf, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ int length = unEscStr.GetLength();
+
+ for (int i = 0; i < length; i++)
+ {
+ switch (pUnEscBuf[i])
+ {
+ case '\\':
+ escString.Append(L"\\\\");
+ break;
+ case '\"':
+ escString.Append(L"\\\"");
+ break;
+ case '/':
+ escString.Append(L"\\/");
+ break;
+ case '\b':
+ escString.Append(L"\\b");
+ break;
+ case '\f':
+ escString.Append(L"\\f");
+ break;
+ case '\n':
+ escString.Append(L"\\n");
+ break;
+ case '\r':
+ escString.Append(L"\\r");
+ break;
+ case '\t':
+ escString.Append(L"\\t");
+ break;
+ default:
+ if (pUnEscBuf[i] < 0x80)
+ {
+ escString.Append(pUnEscBuf[i]);
+ }
+ else
+ {
+ String uni;
+ uni.Format(7, L"\\u%04x", pUnEscBuf[i]);
+ escString.Append(uni);
+ }
+ break;
+ }
+ }
+
+ return E_SUCCESS;
+}
+
+
+}}} // Tizen::Web::Json
--- /dev/null
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+//
+
+/**
+ * @file FWebJson_JsonWriterImpl.h
+ * @brief This is the header file for _JsonWriterImpl Class.
+ */
+
+#ifndef _FWEB_JSON_INTERNAL_JSON_WRITER_IMPL_H_
+#define _FWEB_JSON_INTERNAL_JSON_WRITER_IMPL_H_
+
+#include <FBaseByteBuffer.h>
+#include <FBaseObject.h>
+#include <FBaseString.h>
+
+namespace Tizen { namespace Web { namespace Json
+{
+class IJsonValue;
+class JsonWriter;
+}}} // Tizen::Web::Json
+
+namespace Tizen { namespace Web { namespace Json
+{
+
+class _JsonWriterImpl
+ : public Tizen::Base::Object
+{
+public:
+ /**
+ * This functionality is used to serialize json encoded data from JSON value to a string object
+ *
+ * @since 2.0
+ * @param[in] value JSON value
+ * @param[out] string File path of JSON file
+ * @return An error code
+ * @exception E_SUCCESS The method was successful.
+ * @exception E_FAILURE In case of error.
+ */
+ static result Compose(const IJsonValue* pValue, Tizen::Base::String& filePath);
+
+ /**
+ * This functionality is used to serialize json encoded data from JSON value to a buffer
+ *
+ * @since 2.0
+ * @param[in] value A JSON encoded string.
+ * @param[in] bufferLength Json encoded data buffer length.
+ * @param[out] pBuffer Buffer with Json encoded data.
+ * @return An error code
+ * @exception E_SUCCESS The method was successful.
+ * @exception E_FAILURE In case of error.
+ */
+ static result Compose(const IJsonValue* pValue, void* pBuffer, int bufferLength);
+
+ /**
+ * This functionality is used to serialize json encoded data from JSON value to a byte buffer
+ *
+ * @since 2.0
+ * @param[in] value A JSON encoded string.
+ * @param[out] buffer Buffer with Json encoded data
+ * @return An error code
+ * @exception E_SUCCESS The method was successful.
+ * @exception E_FAILURE In case of error.
+ */
+ static result Compose(const IJsonValue* pValue, Tizen::Base::ByteBuffer& buffer);
+
+private:
+ /**
+ * This is the default constructor for this class.
+ *
+ * @remarks This constructor is hidden.
+ */
+ _JsonWriterImpl(void){}
+
+ /**
+ * This is the default destructor for this class.
+ *
+ * @remarks This constructor is hidden.
+ */
+ virtual ~_JsonWriterImpl(void){}
+
+ static result ConvertIJsonToString(IJsonValue* pValue, Tizen::Base::String& outString);
+
+ static result ToEscString(const Tizen::Base::String& unEscStr, Tizen::Base::String& escString);
+
+}; // _JsonWriterImpl
+
+}}} // Tizen::Web::Json
+#endif // _FWEBJSON_INTERNAL_JSON_WRITER_IMPL_H_