wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Messaging / AttachmentFactory.cpp
old mode 100755 (executable)
new mode 100644 (file)
index ca73e0d..a258062
 // limitations under the License.
 //
 
-#include <dpl/log/log.h>
 #include <Commons/Exception.h>
 #include "AttachmentFactory.h"
 #include "Attachments.h"
 #include "Attachment.h"
 #include <Commons/WrtAccess/WrtAccess.h>
 #include <WidgetDB/WidgetDBMgr.h>
+#include <Logger.h>
 
 using namespace std;
 using namespace WrtDeviceApis;
@@ -59,7 +59,7 @@ const char AttachmentFactory::m_pathSeparator = '/';
 IAttachmentPtr AttachmentFactory::createAttachment(const std::string& fullPath,
         bool isVirtualPath)
 {
-    LogDebug("enter");
+    LoggerD("enter");
     IAttachmentPtr attachment(new Attachment(fullPath, isVirtualPath));
     if (!attachment->getIsCreatedProperly()) {
         ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,
@@ -71,7 +71,7 @@ IAttachmentPtr AttachmentFactory::createAttachment(const std::string& fullPath,
 IAttachmentPtr AttachmentFactory::createAttachment(const std::string& path,
         const std::string& mimeType)
 {
-    LogDebug("enter");
+    LoggerD("enter");
 
     //check virtualPath
     bool isVirtualPath = true;
@@ -90,7 +90,7 @@ IAttachmentPtr AttachmentFactory::createAttachment(const std::string& path,
 std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context, 
        const std::string& real_path)
 {
-       LogDebug("path = " << real_path);       
+       LoggerD("path = " << real_path);        
 
        //find virtual root
        std::string root;
@@ -103,7 +103,7 @@ std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context,
        {
                std::string vroot(PATH_DOWNLOADS);
                tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
-               LogDebug("tail = " << tail);
+               LoggerD("tail = " << tail);
                vroot=VPATH_DOWNLOADS;
                std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
 
@@ -116,7 +116,7 @@ std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context,
        {
                std::string vroot(PATH_DOCUMENTS);
                tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
-               LogDebug("tail = " << tail);
+               LoggerD("tail = " << tail);
                vroot=VPATH_DOCUMENTS;
                std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
 
@@ -129,7 +129,7 @@ std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context,
        {
                std::string vroot(PATH_SOUNDS);
                tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
-               LogDebug("tail = " << tail);
+               LoggerD("tail = " << tail);
                vroot=VPATH_SOUNDS;
                std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
 
@@ -142,10 +142,10 @@ std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context,
        {
                std::string vroot(PATH_IMAGES);
                tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
-               LogDebug("tail = " << tail);
+               LoggerD("tail = " << tail);
                vroot=VPATH_IMAGES;
                std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
-               LogDebug("virtualpath = " << virtualpath);
+               LoggerD("virtualpath = " << virtualpath);
                return virtualpath;
        }
 
@@ -155,10 +155,10 @@ std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context,
        {
                std::string vroot(PATH_VIDEOS);
                tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
-               LogDebug("tail = " << tail);
+               LoggerD("tail = " << tail);
                vroot=VPATH_VIDEOS;
                std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
-               LogDebug("virtualpath = " << virtualpath);
+               LoggerD("virtualpath = " << virtualpath);
                return virtualpath;
        }
 
@@ -172,10 +172,10 @@ std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context,
        {
                std::string vroot(widgetDB->getWidgetInstallationPath());
                tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
-               LogDebug("tail = " << tail);
+               LoggerD("tail = " << tail);
                vroot=VPATH_WGT_PACKAGE;
                std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
-               LogDebug("virtualpath = " << virtualpath);
+               LoggerD("virtualpath = " << virtualpath);
                return virtualpath;
        }       
        
@@ -185,10 +185,10 @@ std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context,
        {
                std::string vroot(widgetDB->getWidgetPersistentStoragePath());
                tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
-               LogDebug("tail = " << tail);
+               LoggerD("tail = " << tail);
                vroot=VPATH_WGT_PRIVATE;
                std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
-               LogDebug("virtualpath = " << virtualpath);
+               LoggerD("virtualpath = " << virtualpath);
                return virtualpath;
        }
 
@@ -198,10 +198,10 @@ std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context,
        {
                std::string vroot(widgetDB->getWidgetTemporaryStoragePath());
                tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
-               LogDebug("tail = " << tail);
+               LoggerD("tail = " << tail);
                vroot=VPATH_WGT_PRIVATE_TEMP;
                std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
-               LogDebug("virtualpath = " << virtualpath);
+               LoggerD("virtualpath = " << virtualpath);
                return virtualpath;
        }
 
@@ -215,7 +215,7 @@ std::string AttachmentFactory::getVirtualPathFromEmailServiceFolder(JSContextRef
 
        //another folder
        //copy
-       LogDebug("path = " << real_path);       
+       LoggerD("path = " << real_path);        
 
        int widgetId = WrtAccessSingleton::Instance().getWidgetId();
        int error = 0;
@@ -233,14 +233,14 @@ std::string AttachmentFactory::getVirtualPathFromEmailServiceFolder(JSContextRef
 
        size_t pos = real_path.find_last_of("/");
        if ((pos + 1) >= real_path.size()) {
-           LogError("Problem with short name creation");
+           LoggerE("Problem with short name creation");
            Throw(InvalidArgumentException);
        }
        std::string attachShortName = real_path.substr(pos + 1);
        std::string privat_dir = widgetDB->getWidgetPersistentStoragePath();
        if ( privat_dir.empty())
        {
-               LogError("Problem with short name creation");
+               LoggerE("Problem with short name creation");
                Throw(InvalidArgumentException);
        }
 
@@ -248,16 +248,16 @@ std::string AttachmentFactory::getVirtualPathFromEmailServiceFolder(JSContextRef
        mode_t mask = umask(S_IWGRP | S_IWOTH);
        error = mkstemp(buf);
        umask(mask);
-       LogDebug("mkstemp =" << error);
+       LoggerD("mkstemp =" << error);
        
-       LogDebug("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
+       LoggerD("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
        
        std::stringstream mkdir_cmd;
        mkdir_cmd << MKDIR_COMMAND_NAME;
        mkdir_cmd << " " << MKDIR_COMMAND_SWITCH_RECURSIVE;
         mkdir_cmd << " \"" << privat_dir << buf  << AttachmentFactory::m_pathSeparator << "\"";
 
-       LogDebug("mkdir path=" << mkdir_cmd.str());
+       LoggerD("mkdir path=" << mkdir_cmd.str());
 
        int result = system(mkdir_cmd.str().c_str());
        if (-1 != result) {
@@ -267,7 +267,7 @@ std::string AttachmentFactory::getVirtualPathFromEmailServiceFolder(JSContextRef
        cp_cmd << " \"" << real_path << "\"";
        cp_cmd << " \"" << privat_dir << buf  << AttachmentFactory::m_pathSeparator << attachShortName << "\"";
        
-       LogDebug("cp path=" << cp_cmd.str());
+       LoggerD("cp path=" << cp_cmd.str());
 
                result = system(cp_cmd.str().c_str());
        if (-1 != result) {
@@ -298,7 +298,7 @@ std::string AttachmentFactory::getDummyFileFromRealPath(JSContextRef context,
                const std::string& real_path)
 {
        //This file is not in list of root locations
-       LogDebug("path = " << real_path);       
+       LoggerD("path = " << real_path);        
 
        int widgetId = WrtAccessSingleton::Instance().getWidgetId();
        int error = 0;
@@ -308,14 +308,14 @@ std::string AttachmentFactory::getDummyFileFromRealPath(JSContextRef context,
 
        size_t pos = real_path.find_last_of("/");
        if ((pos + 1) >= real_path.size()) {
-           LogError("Problem with short name creation");
+           LoggerE("Problem with short name creation");
            Throw(InvalidArgumentException);
        }
        std::string attachShortName = real_path.substr(pos + 1);
        std::string privat_dir = widgetDB->getWidgetPersistentStoragePath();
        if ( privat_dir.empty())
        {
-               LogError("Problem with short name creation");
+               LoggerE("Problem with short name creation");
                Throw(InvalidArgumentException);
        }
 
@@ -323,16 +323,16 @@ std::string AttachmentFactory::getDummyFileFromRealPath(JSContextRef context,
        mode_t mask = umask(S_IWGRP | S_IWOTH);
        error = mkstemp(buf);
        umask(mask);
-       LogDebug("mkstemp =" << error);
+       LoggerD("mkstemp =" << error);
                
-       LogDebug("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
+       LoggerD("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
 
        std::stringstream mkdir_cmd;
        mkdir_cmd << MKDIR_COMMAND_NAME;
        mkdir_cmd << " " << MKDIR_COMMAND_SWITCH_RECURSIVE;
        mkdir_cmd << " \"" << privat_dir << buf  << AttachmentFactory::m_pathSeparator << "\"";
 
-       LogDebug("mkdir path=" << mkdir_cmd.str());
+       LoggerD("mkdir path=" << mkdir_cmd.str());
 
        int result = system(mkdir_cmd.str().c_str());   //make folder in the wgt-private.
        if (-1 != result) {
@@ -342,7 +342,7 @@ std::string AttachmentFactory::getDummyFileFromRealPath(JSContextRef context,
                cp_cmd << " \"" << real_path << "\"";
                cp_cmd << " \"" << privat_dir << buf  << AttachmentFactory::m_pathSeparator << attachShortName << "\"";
                
-               LogDebug("cp path=" << cp_cmd.str());
+               LoggerD("cp path=" << cp_cmd.str());
 
                result = system(cp_cmd.str().c_str());  //copy
                if (-1 != result) {
@@ -372,7 +372,7 @@ std::string AttachmentFactory::getDummyFileFromRealPath(JSContextRef context,
 std::string AttachmentFactory::getRealPathFromVirtualPath(JSContextRef context, 
        const std::string& path)
 {
-       LogDebug("path = " << path);    
+       LoggerD("path = " << path);     
 
        std::string root;
        std::string tail;
@@ -383,8 +383,8 @@ std::string AttachmentFactory::getRealPathFromVirtualPath(JSContextRef context,
        } else {
                root = path;
        }
-       LogDebug("root = " << root);
-       LogDebug("tail = " << tail);
+       LoggerD("root = " << root);
+       LoggerD("tail = " << tail);
 
     int widgetId = WrtAccessSingleton::Instance().getWidgetId();
        WidgetDB::Api::IWidgetDBPtr widgetDB =
@@ -426,7 +426,7 @@ std::string AttachmentFactory::getRealPathFromVirtualPath(JSContextRef context,
        }
        else
        {       //exception
-               LogDebug("Can't find root path");
+               LoggerD("Can't find root path");
                ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,
                  "Attachment couldn't be created");
        }
@@ -448,18 +448,18 @@ bool AttachmentFactory::removeDummyFile(const std::string& dummyFilePath)
                        //remove folder
                        size_t pos = dummyFilePath.find_last_of("/");
                        if ((pos + 1) >= dummyFilePath.size()) {
-                           LogError("Problem with short name creation");
+                           LoggerE("Problem with short name creation");
                        }
                        std::string folder = dummyFilePath.substr(0, pos);
-                       LogDebug("remove folder : " << folder);
+                       LoggerD("remove folder : " << folder);
                        if ( 0 != remove(folder.c_str()))
                        {
-                               LogError("Remove Error");
+                               LoggerE("Remove Error");
                        }
                }
                else 
                {
-                       LogDebug("remove file error : " << dummyFilePath);
+                       LoggerD("remove file error : " << dummyFilePath);
                }
        }