Adds encoding features of Resource/ResourceManager 67/40667/5
authorYongseop Kim <yons.kim@samsung.com>
Mon, 8 Jun 2015 05:31:06 +0000 (14:31 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Tue, 9 Jun 2015 01:28:21 +0000 (18:28 -0700)
Change-Id: Id82c40efd67d4ffd235668d844cbb9e38edd5993

src/common/resource_manager.cc
src/common/resource_manager.h

index cf83e4c..9fc3475 100755 (executable)
@@ -55,6 +55,9 @@ const char* kDefaultStartFiles[] = {
   "index.xht"
 };
 
+// Default Encoding
+const char* kDefaultEncoding = "UTF-8";
+
 static std::string GetMimeFromUri(const std::string& uri) {
   // checking passed uri is local file
   std::string file_uri_case(kSchemeTypeFile);
@@ -200,15 +203,15 @@ static void GetURLInfo(const std::string& url,
 }  // namespace
 
 ResourceManager::Resource::Resource(const std::string& uri)
-  : uri_(uri), should_reset_(true) {}
+  : uri_(uri), should_reset_(true), encoding_(kDefaultEncoding) {}
 
-ResourceManager::Resource::Resource(const std::string& uri,
-                                    const std::string& mime)
-  : uri_(uri), mime_(mime), should_reset_(true) {}
+ResourceManager::Resource::Resource(const std::string& uri, bool should_reset)
+  : uri_(uri), should_reset_(should_reset), encoding_(kDefaultEncoding) {}
 
 ResourceManager::Resource::Resource(const std::string& uri,
-                                    const std::string& mime, bool should_reset)
-  : uri_(uri), mime_(mime), should_reset_(should_reset) {}
+                                    const std::string& mime,
+                                    const std::string& encoding)
+  : uri_(uri), should_reset_(true), mime_(mime), encoding_(encoding) {}
 
 ResourceManager::Resource::Resource(const ResourceManager::Resource& res) {
   *this = res;
@@ -219,12 +222,14 @@ ResourceManager::Resource& ResourceManager::Resource::operator=(
   this->uri_ = res.uri();
   this->mime_ = res.mime();
   this->should_reset_ = res.should_reset();
+  this->encoding_ = res.encoding();
   return *this;
 }
 
 bool ResourceManager::Resource::operator==(const Resource& res) {
   if (this->uri_ == res.uri() && this->mime_ == res.mime()
-     && this->should_reset_ == res.should_reset()) {
+     && this->should_reset_ == res.should_reset()
+     && this->encoding_ == res.encoding()) {
     return true;
   } else {
     return false;
@@ -246,39 +251,49 @@ ResourceManager::ResourceManager(ApplicationData* application_data,
   }
 }
 
-std::string ResourceManager::GetDefaultOrEmpty() {
+std::unique_ptr<ResourceManager::Resource>
+ResourceManager::GetDefaultOrEmpty() {
   std::string default_src;
+  std::string type;
+  std::string encoding = kDefaultEncoding;
 
-  // content src
   auto content_info = application_data_->content_info();
   if (content_info) {
     default_src = content_info->src();
+    // TODO(yons.kim): uncomment below codes after implementing
+    //                 content info handler
+    //type = content_info->type();
+    //encoding = (content_info->encoding())
+    //           ? content_info->encoding() : kDefaultEncoding;
   } else {
     LOGGER(WARN) << "ContentInfo is NULL.";
   }
 
   if (!default_src.empty()) {
-    return InsertPrefixPath(default_src);
-  }
-
-  // if there is no content src, find reserved index files
-  for (auto& start_file : kDefaultStartFiles) {
-    if (utils::Exists(resource_base_path_ + start_file)) {
-      default_src = start_file;
+    default_src = InsertPrefixPath(default_src);
+  } else {
+    // if there is no content src, find reserved index files
+    for (auto& start_file : kDefaultStartFiles) {
+      if (utils::Exists(resource_base_path_ + start_file)) {
+        default_src = start_file;
+        break;
+      }
     }
   }
 
-  return InsertPrefixPath(default_src);
+  return std::unique_ptr<Resource>(new Resource(default_src, type, encoding));
 }
 
-std::string ResourceManager::GetMatchedSrcOrUri(
-    const AppControlInfo& app_control_info) {
+std::unique_ptr<ResourceManager::Resource> ResourceManager::GetMatchedSrcOrUri(
+    const AppControlInfo& app_control_info, bool should_reset) {
   if (!app_control_info.src().empty()) {
-    return InsertPrefixPath(app_control_info.src());
+    return std::unique_ptr<Resource>(new Resource(
+      InsertPrefixPath(app_control_info.src()), should_reset));
   }
 
   if (!app_control_info.uri().empty()) {
-    return InsertPrefixPath(app_control_info.uri());
+    return std::unique_ptr<Resource>(new Resource(
+      InsertPrefixPath(app_control_info.uri()), should_reset));
   }
 
   return GetDefaultOrEmpty();
@@ -289,7 +304,7 @@ std::unique_ptr<ResourceManager::Resource> ResourceManager::GetStartResource(
   std::string operation = app_control->operation();
   if (operation.empty()) {
     LOGGER(ERROR) << "operation(mandatory) is NULL";
-    return std::unique_ptr<Resource>(new Resource(GetDefaultOrEmpty()));
+    return std::unique_ptr<Resource>(GetDefaultOrEmpty());
   }
 
   std::string mime = app_control->mime();
@@ -305,7 +320,7 @@ std::unique_ptr<ResourceManager::Resource> ResourceManager::GetStartResource(
 
   if (application_data_ == NULL ||
       application_data_->app_control_info_list() == NULL) {
-    return std::unique_ptr<Resource>(new Resource(GetDefaultOrEmpty()));
+    return GetDefaultOrEmpty();
   }
 
   AppControlList app_control_list =
@@ -317,14 +332,12 @@ std::unique_ptr<ResourceManager::Resource> ResourceManager::GetStartResource(
       CompareMimeAndUri(app_control_list, mime, uri);
     if (iter != app_control_list.end()) {
       // TODO(jh5.cho) : following comment will be added after SRPOL implement
-      return std::unique_ptr<Resource>(
-        new Resource(GetMatchedSrcOrUri(*iter), iter->mime()
-                   /*, iter->should_reset()*/));
+      return GetMatchedSrcOrUri(*iter/*, iter->should_reset()*/);
     } else {
-    return std::unique_ptr<Resource>(new Resource(GetDefaultOrEmpty()));
+    return GetDefaultOrEmpty();
     }
   } else {
-    return std::unique_ptr<Resource>(new Resource(GetDefaultOrEmpty()));
+    return GetDefaultOrEmpty();
   }
 }
 
index fed0c65..0394315 100755 (executable)
@@ -42,9 +42,9 @@ class ResourceManager {
   class Resource {
    public:
     explicit Resource(const std::string& uri);
-    Resource(const std::string& uri, const std::string& mime);
+    Resource(const std::string& uri, bool should_reset);
     Resource(const std::string& uri, const std::string& mime,
-             bool should_reset);
+             const std::string& encoding);
     Resource(const Resource& res);
     ~Resource() {}
 
@@ -54,15 +54,18 @@ class ResourceManager {
     void set_uri(const std::string& uri) { uri_ = uri; }
     void set_mime(const std::string& mime) { mime_ = mime; }
     void set_should_reset(bool should_reset) { should_reset_ = should_reset; }
+    void set_encoding(const std::string& encoding) { encoding_ = encoding; }
 
     std::string uri() const { return uri_; }
     std::string mime() const { return mime_; }
     bool should_reset() const { return should_reset_; }
+    std::string encoding() const { return encoding_; }
 
    private:
     std::string uri_;
     std::string mime_;
     bool should_reset_;
+    std::string encoding_;
   };
 
   ResourceManager(ApplicationData* application_data,
@@ -79,8 +82,10 @@ class ResourceManager {
   void set_base_resource_path(const std::string& base_path);
 
  private:
-  std::string GetMatchedSrcOrUri(const wgt::parse::AppControlInfo&);
-  std::string GetDefaultOrEmpty();
+  std::unique_ptr<Resource> GetMatchedSrcOrUri(
+    const wgt::parse::AppControlInfo&,bool should_reset = true);
+  std::unique_ptr<Resource> GetDefaultOrEmpty();
+
   // for localization
   bool Exists(const std::string& path);
   bool CheckWARP(const std::string& url);