summaryrefslogtreecommitdiff
path: root/extensions/source/oooimprovement/logstorage.cxx
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2009-02-13 11:55:44 +0000
committerOliver Bolte <obo@openoffice.org>2009-02-13 11:55:44 +0000
commit1b38e7bda335071e7c4ac6c92c907dfff44b11cd (patch)
tree152bbe658662e91bf94bc70098ce57de03876f06 /extensions/source/oooimprovement/logstorage.cxx
parentb0c0a556bce6ed79eff9e362fd5b806951c8cba6 (diff)
CWS-TOOLING: integrate CWS oooimprovement2
2009-01-28 14:35:33 +0100 b_michaelsen r267059 : #i98555# fixed help url 2009-01-27 12:47:40 +0100 b_michaelsen r266982 : #159112# fixed enabling vcl part of usage tracking in an running session 2009-01-27 12:28:58 +0100 b_michaelsen r266980 : #159129# deiniting eventlogger in vcl if it was inited, not if it was enabled (the logger can be disabled inbetween 2009-01-27 12:22:45 +0100 b_michaelsen r266978 : whitespace fixes 2009-01-27 10:32:02 +0100 b_michaelsen r266962 : #i94949# disposing of uploader thread 2009-01-23 17:00:57 +0100 b_michaelsen r266839 : #159112# enabling/disabling of usage tracking takes effect without restart 2009-01-23 16:58:59 +0100 b_michaelsen r266837 : #159112# enabling/disabling of usage tracking takes effect without restart 2009-01-23 01:08:49 +0100 b_michaelsen r266761 : #159081# fixed buildid in oooimprovement 2009-01-22 22:51:16 +0100 b_michaelsen r266759 : #i90370# including build id 2009-01-22 15:37:05 +0100 b_michaelsen r266727 : #i90370# fixing precompiled headers for win32 2009-01-22 15:34:05 +0100 b_michaelsen r266722 : #i90370# initializing startup counter 2009-01-22 15:30:52 +0100 b_michaelsen r266720 : #i90370# enabling startup counter 2009-01-21 13:52:56 +0100 b_michaelsen r266666 : #i98143# adjusted smoketest for usage tracking 2009-01-20 18:34:12 +0100 b_michaelsen r266617 : #i90370# 2009-01-20 15:08:45 +0100 is r266587 : #i90370# new improvement feature 2009-01-20 14:42:39 +0100 b_michaelsen r266583 : #i90370# changing delivered job registration location 2009-01-20 12:35:31 +0100 is r266567 : #i90370# new improvement feature 2009-01-20 12:33:51 +0100 is r266566 : #i90370# new improvement feature 2009-01-20 12:33:20 +0100 is r266565 : #i90370# new improvement feature 2009-01-20 11:47:13 +0100 b_michaelsen r266559 : #i90370# updating Usage Tracking Info Url 2009-01-20 11:28:37 +0100 b_michaelsen r266558 : #i90370# packing Usage Tracking config schema (xcs) 2009-01-20 11:19:00 +0100 b_michaelsen r266557 : #i90370# adding Usage Tracking config schema (xcs) 2009-01-19 18:16:34 +0100 b_michaelsen r266518 : #i90370# adding job registration (xcu) 2009-01-19 17:26:02 +0100 b_michaelsen r266513 : #i90370# adding liboooimprovement
Diffstat (limited to 'extensions/source/oooimprovement/logstorage.cxx')
-rw-r--r--extensions/source/oooimprovement/logstorage.cxx149
1 files changed, 149 insertions, 0 deletions
diff --git a/extensions/source/oooimprovement/logstorage.cxx b/extensions/source/oooimprovement/logstorage.cxx
new file mode 100644
index 000000000000..d4d0dea8d01c
--- /dev/null
+++ b/extensions/source/oooimprovement/logstorage.cxx
@@ -0,0 +1,149 @@
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: logstorage.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_extensions.hxx"
+
+#include "logstorage.hxx"
+#include "config.hxx"
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
+#include <com/sun/star/util/XStringSubstitution.hpp>
+
+
+using namespace com::sun::star::io;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::util;
+using ::com::sun::star::ucb::XSimpleFileAccess;
+using ::rtl::OUString;
+using ::std::vector;
+
+
+namespace
+{
+ using namespace oooimprovement;
+
+ static const OUString CSSU_PATHSUB = OUString::createFromAscii("com.sun.star.util.PathSubstitution");
+
+ static OUString getLogPathFromCfg(const Reference<XMultiServiceFactory>& sf)
+ {
+ Config config(sf);
+ OUString result=config.getLogPath();
+ Reference<XStringSubstitution> path_sub(
+ sf->createInstance(CSSU_PATHSUB),
+ UNO_QUERY);
+ if(path_sub.is())
+ result = path_sub->substituteVariables(result, sal_False);
+ return result;
+ }
+
+ static bool isZipfile(const OUString& fileurl)
+ {
+ static const OUString file_extension = OUString::createFromAscii(".zip");
+ return fileurl.match(file_extension, fileurl.getLength()-file_extension.getLength());
+ };
+
+ static bool isLogfile(const OUString& fileurl)
+ {
+ static const OUString file_extension = OUString::createFromAscii(".csv");
+ static const OUString current = OUString::createFromAscii("Current.csv");
+ return
+ fileurl.match(file_extension, fileurl.getLength()-file_extension.getLength())
+ && !fileurl.match(current, fileurl.getLength()-current.getLength());
+ };
+
+ static bool isZipOrLogFile(const OUString& fileurl)
+ {
+ return isZipfile(fileurl) || isLogfile(fileurl);
+ }
+
+ static Sequence<OUString> getAllLogStoragefiles(const Reference<XMultiServiceFactory>& sf)
+ {
+ Reference<XSimpleFileAccess> file_access(
+ sf->createInstance(OUString::createFromAscii("com.sun.star.ucb.SimpleFileAccess")),
+ UNO_QUERY_THROW);
+ return file_access->getFolderContents(
+ getLogPathFromCfg(sf),
+ false);
+ };
+
+ static vector<OUString> getLogStoragefiles(
+ const Reference<XMultiServiceFactory>& sf,
+ bool (*condition)(const OUString& path))
+ {
+ Sequence<OUString> candidates = getAllLogStoragefiles(sf);
+ vector<OUString> result;
+ result.reserve(candidates.getLength());
+ for(sal_Int32 idx=0; idx<candidates.getLength(); ++idx)
+ if(condition(candidates[idx]))
+ result.push_back(candidates[idx]);
+ return result;
+ };
+
+ static void assureLogStorageExists(const Reference<XMultiServiceFactory>& sf)
+ {
+ Reference<XSimpleFileAccess> file_access(
+ sf->createInstance(OUString::createFromAscii("com.sun.star.ucb.SimpleFileAccess")),
+ UNO_QUERY_THROW);
+ OUString log_path(getLogPathFromCfg(sf));
+ if(!file_access->isFolder(log_path))
+ file_access->createFolder(log_path);
+ };
+}
+
+namespace oooimprovement
+{
+
+ LogStorage::LogStorage(const Reference<XMultiServiceFactory>& sf)
+ : m_ServiceFactory(sf)
+ {}
+
+ void LogStorage::assureExists()
+ {
+ assureLogStorageExists(m_ServiceFactory);
+ }
+
+ void LogStorage::clear()
+ {
+ Reference<XSimpleFileAccess> file_access(
+ m_ServiceFactory->createInstance(OUString::createFromAscii("com.sun.star.ucb.SimpleFileAccess")),
+ UNO_QUERY_THROW);
+ vector<OUString> files_to_kill = getLogStoragefiles(m_ServiceFactory, &isZipOrLogFile);
+ for(vector<OUString>::iterator item = files_to_kill.begin();
+ item != files_to_kill.end();
+ item++)
+ file_access->kill(*item);
+ }
+
+ const vector<OUString> LogStorage::getUnzippedLogFiles() const
+ { return getLogStoragefiles(m_ServiceFactory, &isLogfile); }
+
+ const vector<OUString> LogStorage::getZippedLogFiles() const
+ { return getLogStoragefiles(m_ServiceFactory, &isZipfile); }
+}