upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Filesystem / FilesystemUtils.cpp
index 38fdac1..fc9e888 100755 (executable)
@@ -22,7 +22,7 @@
 #include <Commons/Exception.h>
 #include <API/Filesystem/Enums.h>
 #include <API/Filesystem/IManager.h>
-#include <Commons/WrtWrapper/WrtWrappersMgr.h>
+#include <Commons/WrtAccess/WrtAccess.h>
 #include <WidgetDB/WidgetDBMgr.h>
 #include "FilesystemUtils.h"
 
@@ -78,11 +78,11 @@ const PathToRootMap& getPathToRootMap()
 IPathPtr fromVirtualPath(JSContextRef context,
                          const std::string& arg)
 {
-       IWrtWrapperPtr wrt = WrtWrappersMgr::getInstance().getWrtWrapper(context);
-       Assert(wrt && "WrtWrapper not found, not a GLOBAL context supplied?");
+       LogDebug("arg:[" << arg << "]");
 
        if (!isPathValid(arg)) {
-               ThrowMsg(Commons::NotFoundException, "Not found path component.");
+               LogDebug("virtual path is invalid:[" << arg << "]");
+               ThrowMsg(Commons::ConversionException, "Not found path component.");
        }
 
        std::string root;
@@ -95,13 +95,14 @@ IPathPtr fromVirtualPath(JSContextRef context,
                root = arg;
        }
 
-    WidgetDB::Api::IWidgetDBPtr widgetDB =
-        WidgetDB::Api::getWidgetDB(wrt->getWidgetId());
+/*    int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+      WidgetDB::Api::IWidgetDBPtr widgetDB =
+        WidgetDB::Api::getWidgetDB(widgetId);*/
 
        RootToPathMap rootToPath = getRootToPathMap();
-       rootToPath["wgt-package"] = widgetDB->getWidgetInstallationPath();
+/*     rootToPath["wgt-package"] = widgetDB->getWidgetInstallationPath();
        rootToPath["wgt-private"] = widgetDB->getWidgetPersistentStoragePath();
-       rootToPath["wgt-private-tmp"] = widgetDB->getWidgetTemporaryStoragePath();
+       rootToPath["wgt-private-tmp"] = widgetDB->getWidgetTemporaryStoragePath();*/
        RootToPathMapIterator it = rootToPath.find(root);
        if (it == rootToPath.end()) {
                ThrowMsg(Commons::NotFoundException, "Location not found.");
@@ -116,11 +117,10 @@ IPathPtr fromVirtualPath(JSContextRef context,
 }
 
 std::string toVirtualPath(JSContextRef context, const std::string& arg) {
-       IWrtWrapperPtr wrt = WrtWrappersMgr::getInstance().getWrtWrapper(context);
-       Assert(wrt && "WrtWrapper not found, not a GLOBAL context supplied?");
 
+    int widgetId = WrtAccessSingleton::Instance().getWidgetId();
     WidgetDB::Api::IWidgetDBPtr widgetDB =
-        WidgetDB::Api::getWidgetDB(wrt->getWidgetId());
+        WidgetDB::Api::getWidgetDB(widgetId);
 
        PathToRootMap pathToRoot = getPathToRootMap();
        pathToRoot[widgetDB->getWidgetInstallationPath()] = "wgt-package";
@@ -140,27 +140,21 @@ std::string toVirtualPath(JSContextRef context, const std::string& arg) {
 }
 
 bool isPathValid(const std::string& path) {
-       static const std::string currentDirBegin(
-               PATH_INVALID_COMPONENT_CURRENT_DIR +
-               Api::Filesystem::IPath::getSeparator());
-       static const std::string parentDirBegin(
-               PATH_INVALID_COMPONENT_PARENT_DIR +
-               Api::Filesystem::IPath::getSeparator());
-       static const std::string currentDirMiddle(
-               Api::Filesystem::IPath::getSeparator() +
-               PATH_INVALID_COMPONENT_CURRENT_DIR +
-               Api::Filesystem::IPath::getSeparator());
-       static const std::string parentDirMiddle(
-               Api::Filesystem::IPath::getSeparator() +
-               PATH_INVALID_COMPONENT_PARENT_DIR +
+       static const std::string currentDirBegin(PATH_INVALID_COMPONENT_CURRENT_DIR + Api::Filesystem::IPath::getSeparator());
+       static const std::string parentDirBegin(PATH_INVALID_COMPONENT_PARENT_DIR +
                Api::Filesystem::IPath::getSeparator());
+       static const std::string currentDirMiddle(Api::Filesystem::IPath::getSeparator() +
+               PATH_INVALID_COMPONENT_CURRENT_DIR +Api::Filesystem::IPath::getSeparator());
+       static const std::string parentDirMiddle(Api::Filesystem::IPath::getSeparator() +
+               PATH_INVALID_COMPONENT_PARENT_DIR +Api::Filesystem::IPath::getSeparator());
 
        if (path.find(parentDirBegin) == 0 ||
-               path.find(currentDirBegin) == 0 ||
+                       path.find(currentDirBegin) == 0 ||
                path.find(parentDirMiddle) != std::string::npos ||
                path.find(currentDirMiddle) != std::string::npos) {
                return false;
        }
+
        return true;
 }