Hi,
attached is a patch which (almost) fixes the l7dtestcase.
It includes moving the File::read() method to a new class
FileInputStream (IMHO the same makes sense for the write()
method, because the File class (if we are Thinking in Java) should
not contain read/write methods).
The thing which remains is fixing the place holders {...},
but the ResourceBundle part should work well again.
Best Regards,
Andreas
--
Andreas Fester
mailto:[EMAIL PROTECTED]
WWW: http://www.littletux.net
ICQ: 326674288
diff -urN log4cxx-0.9.8.org/Makefile.am log4cxx-0.9.8/Makefile.am
--- log4cxx-0.9.8.org/Makefile.am 2005-09-23 03:05:12.000000000 +0200
+++ log4cxx-0.9.8/Makefile.am 2005-09-27 21:50:59.000000000 +0200
@@ -1,2 +1,2 @@
SUBDIRS = docs src include simplesocketserver tests performance examples
-EXTRA_DIST = autogen.sh license.apl find_apr.m4 build.xml apr-build.xml
aprutil-build.xml apr-1.1.0.patch
+EXTRA_DIST = autogen.sh aclocal.m4 license.apl find_apr.m4 find_apu.m4
build.xml apr-build.xml aprutil-build.xml apr-1.1.0.patch
diff -urN log4cxx-0.9.8.org/include/log4cxx/file.h
log4cxx-0.9.8/include/log4cxx/file.h
--- log4cxx-0.9.8.org/include/log4cxx/file.h 2005-06-01 21:11:12.000000000
+0200
+++ log4cxx-0.9.8/include/log4cxx/file.h 2005-09-27 23:46:53.000000000
+0200
@@ -57,8 +57,7 @@
return osName;
}
- LogString read(log4cxx::helpers::Pool& pool) const;
-
+ // @deprecated Use FileOutputStream instead
log4cxx_status_t write(const LogString& src,
log4cxx::helpers::Pool& p) const;
log4cxx_status_t open(apr_file_t** file, int flags,
diff -urN log4cxx-0.9.8.org/include/log4cxx/helpers/fileinputstream.h
log4cxx-0.9.8/include/log4cxx/helpers/fileinputstream.h
--- log4cxx-0.9.8.org/include/log4cxx/helpers/fileinputstream.h 1970-01-01
01:00:00.000000000 +0100
+++ log4cxx-0.9.8/include/log4cxx/helpers/fileinputstream.h 2005-09-27
23:52:23.000000000 +0200
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2003,2005 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+#ifndef _LOG4CXX_HELPERS_FILEINPUTSTREAM_H
+#define _LOG4CXX_HELPERS_FILEINPUTSTREAM_H
+
+#include <log4cxx/helpers/inputstream.h>
+#include <log4cxx/file.h>
+#include <log4cxx/helpers/pool.h>
+
+
+namespace log4cxx
+{
+
+ namespace helpers {
+
+ /**
+ * InputStream implemented on top of APR file IO.
+ * @since 0.9.8
+ */
+ class LOG4CXX_EXPORT FileInputStream : public InputStream
+ {
+ private:
+ Pool pool;
+ void* fileptr;
+
+ public:
+ DECLARE_ABSTRACT_LOG4CXX_OBJECT(FileInputStream)
+ BEGIN_LOG4CXX_CAST_MAP()
+ LOG4CXX_CAST_ENTRY(FileInputStream)
+ LOG4CXX_CAST_ENTRY_CHAIN(InputStream)
+ END_LOG4CXX_CAST_MAP()
+
+ FileInputStream(const LogString& filename);
+
+ FileInputStream(const File& aFile);
+
+ virtual ~FileInputStream();
+
+ virtual void close();
+
+ LogString read(log4cxx::helpers::Pool& pool) const;
+
+ private:
+
+ FileInputStream(const FileInputStream&);
+
+ FileInputStream& operator=(const FileInputStream&);
+
+ };
+
+ typedef helpers::ObjectPtrT<FileInputStream> FileInputStreamPtr;
+ } // namespace helpers
+
+} //namespace log4cxx
+
+#endif //_LOG4CXX_HELPERS_FILEINPUTSTREAM_H
diff -urN log4cxx-0.9.8.org/include/log4cxx/helpers/inputstream.h
log4cxx-0.9.8/include/log4cxx/helpers/inputstream.h
--- log4cxx-0.9.8.org/include/log4cxx/helpers/inputstream.h 1970-01-01
01:00:00.000000000 +0100
+++ log4cxx-0.9.8/include/log4cxx/helpers/inputstream.h 2005-09-27
23:52:08.000000000 +0200
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2003,2005 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+#ifndef _LOG4CXX_HELPERS_INPUTSTREAM_H
+#define _LOG4CXX_HELPERS_INPUTSTREAM_H
+
+#include <log4cxx/helpers/objectimpl.h>
+
+namespace log4cxx
+{
+
+ namespace helpers {
+ class ByteBuffer;
+
+ /**
+ * Abstract class for reading from character streams.
+ * @since 0.9.8
+ */
+ class LOG4CXX_EXPORT InputStream : public ObjectImpl
+ {
+ public:
+ DECLARE_ABSTRACT_LOG4CXX_OBJECT(InputStream)
+ BEGIN_LOG4CXX_CAST_MAP()
+ LOG4CXX_CAST_ENTRY(InputStream)
+ END_LOG4CXX_CAST_MAP()
+
+ protected:
+ InputStream();
+
+ virtual ~InputStream();
+
+ public:
+ virtual LogString read(log4cxx::helpers::Pool& pool) const =
0;
+
+ virtual void close() = 0;
+
+ private:
+ InputStream(const InputStream&);
+ InputStream& operator=(const InputStream&);
+ };
+
+ typedef helpers::ObjectPtrT<InputStream> InputStreamPtr;
+ } // namespace helpers
+
+} //namespace log4cxx
+
+#endif //_LOG4CXX_HELPERS_INPUTSTREAM_H
diff -urN log4cxx-0.9.8.org/include/log4cxx/helpers/loader.h
log4cxx-0.9.8/include/log4cxx/helpers/loader.h
--- log4cxx-0.9.8.org/include/log4cxx/helpers/loader.h 2005-02-16
00:55:59.000000000 +0100
+++ log4cxx-0.9.8/include/log4cxx/helpers/loader.h 2005-09-27
23:48:09.000000000 +0200
@@ -20,7 +20,9 @@
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/exception.h>
+#include <log4cxx/helpers/inputstream.h>
+#include <apr_lib.h>
namespace log4cxx
{
@@ -34,8 +36,9 @@
static const Class& loadClass(const LogString& clazz);
// TODO
// static LogString getResource(const LogString& name);
-// static void* getResourceAsStream(const LogString& name,
-// apr_size_t* size, log4cxx::helpers::Pool& pool);
+
+ static InputStreamPtr getResourceAsStream(
+ const LogString&
name);
};
} // namespace helpers
} // namespace log4cxx
diff -urN log4cxx-0.9.8.org/include/log4cxx/helpers/properties.h
log4cxx-0.9.8/include/log4cxx/helpers/properties.h
--- log4cxx-0.9.8.org/include/log4cxx/helpers/properties.h 2005-02-16
00:55:59.000000000 +0100
+++ log4cxx-0.9.8/include/log4cxx/helpers/properties.h 2005-09-27
22:31:20.000000000 +0200
@@ -20,6 +20,7 @@
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/objectimpl.h>
+#include <log4cxx/helpers/inputstream.h>
#include <map>
#include <vector>
#include <istream>
@@ -112,6 +113,9 @@
@throw IOException if an error occurred when reading
from the input
stream.
*/
+ void load(InputStreamPtr inStream);
+
+ // @deprecated
void load(LogString& inStream);
/**
diff -urN log4cxx-0.9.8.org/include/log4cxx/helpers/propertyresourcebundle.h
log4cxx-0.9.8/include/log4cxx/helpers/propertyresourcebundle.h
--- log4cxx-0.9.8.org/include/log4cxx/helpers/propertyresourcebundle.h
2004-12-15 01:38:47.000000000 +0100
+++ log4cxx-0.9.8/include/log4cxx/helpers/propertyresourcebundle.h
2005-09-27 23:47:35.000000000 +0200
@@ -19,6 +19,7 @@
#include <log4cxx/helpers/resourcebundle.h>
#include <log4cxx/helpers/properties.h>
+#include <log4cxx/helpers/inputstream.h>
namespace log4cxx
{
@@ -47,8 +48,12 @@
@throw IOException if an error occurred when reading
from the
input stream.
*/
+ PropertyResourceBundle(InputStreamPtr inStream);
+
+ // @deprecated Use
PropertyResourceBundle(InputStreamPtr) instead
PropertyResourceBundle(LogString& inStream);
+
virtual LogString getString(const LogString& key)
const;
protected:
diff -urN log4cxx-0.9.8.org/src/Makefile.am log4cxx-0.9.8/src/Makefile.am
--- log4cxx-0.9.8.org/src/Makefile.am 2005-09-23 03:05:12.000000000 +0200
+++ log4cxx-0.9.8/src/Makefile.am 2005-09-27 22:13:48.000000000 +0200
@@ -37,6 +37,7 @@
file.cpp \
fileappender.cpp \
filedatepatternconverter.cpp \
+ fileinputstream.cpp \
filelocationpatternconverter.cpp \
fileoutputstream.cpp \
filerenameaction.cpp \
@@ -49,6 +50,7 @@
hierarchy.cpp \
htmllayout.cpp \
inetaddress.cpp \
+ inputstream.cpp \
integer.cpp \
integerpatternconverter.cpp \
layout.cpp\
diff -urN log4cxx-0.9.8.org/src/file.cpp log4cxx-0.9.8/src/file.cpp
--- log4cxx-0.9.8.org/src/file.cpp 2005-06-01 21:11:13.000000000 +0200
+++ log4cxx-0.9.8/src/file.cpp 2005-09-27 23:50:17.000000000 +0200
@@ -133,57 +133,6 @@
// Current implementation is limited to MBCS files
//
//
-LogString File::read(Pool& p) const {
- LogString output;
- apr_file_t* f = NULL;
- apr_status_t rv = open(&f, APR_READ, APR_OS_DEFAULT, p);
- if (rv != APR_SUCCESS) {
- throw IOException(rv);
- } else {
- const size_t BUFSIZE = 4096;
- char* buf = p.palloc(BUFSIZE);
- char* contents = buf;
- apr_size_t contentLength = 0;
- do {
- apr_size_t bytesRead = BUFSIZE;
- rv = apr_file_read(f, buf, &bytesRead);
- contentLength += bytesRead;
- if (APR_STATUS_IS_EOF(rv) || (rv == APR_SUCCESS && bytesRead <
BUFSIZE)) {
- //
- // finished file
- // transcode and exit
- Transcoder::decode(contents, contentLength, output);
-//
-// TODO - assertion here when called from Compare
-//
-// rv = apr_file_close(f);
-// assert(rv == APR_SUCCESS);
- return output;
- } else if (rv == APR_SUCCESS) {
- //
- // file was larger than the buffer
- // realloc a bigger buffer
- char* newContents = p.palloc(contentLength + BUFSIZE);
- buf = newContents + contentLength;
- memcpy(newContents, contents, contentLength);
- //
- // we would free contents here if you did that sort of thing
- //
- contents = newContents;
- }
- } while(rv == APR_SUCCESS);
- rv = apr_file_close(f);
- assert(rv == APR_SUCCESS);
- }
- return output;
-}
-
-
-
-//
-// Current implementation is limited to MBCS files
-//
-//
log4cxx_status_t File::write(const LogString& src, Pool& p) const {
LogString output;
apr_file_t* f = NULL;
diff -urN log4cxx-0.9.8.org/src/fileinputstream.cpp
log4cxx-0.9.8/src/fileinputstream.cpp
--- log4cxx-0.9.8.org/src/fileinputstream.cpp 1970-01-01 01:00:00.000000000
+0100
+++ log4cxx-0.9.8/src/fileinputstream.cpp 2005-09-27 23:48:55.000000000
+0200
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2003,2005 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+#include <log4cxx/helpers/fileinputstream.h>
+#include <log4cxx/helpers/exception.h>
+#include <log4cxx/helpers/bytebuffer.h>
+#include <apr_file_io.h>
+#include <log4cxx/helpers/transcoder.h>
+#include <log4cxx/helpers/aprinitializer.h>
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+IMPLEMENT_LOG4CXX_OBJECT(FileInputStream)
+
+FileInputStream::FileInputStream(const LogString& filename) {
+ apr_fileperms_t perm = APR_OS_DEFAULT;
+ apr_int32_t flags = APR_READ;
+ LOG4CXX_ENCODE_CHAR(fn, filename);
+ apr_status_t stat = apr_file_open((apr_file_t**) &fileptr,
+ fn.c_str(), flags, perm, (apr_pool_t*) pool.getAPRPool());
+ if (stat != APR_SUCCESS) {
+ throw IOException(stat);
+ }
+}
+
+
+FileInputStream::FileInputStream(const File& aFile) {
+ apr_fileperms_t perm = APR_OS_DEFAULT;
+ apr_int32_t flags = APR_READ;
+ LOG4CXX_ENCODE_CHAR(fn, aFile.getName());
+ apr_status_t stat = apr_file_open((apr_file_t**) &fileptr,
+ fn.c_str(), flags, perm, (apr_pool_t*) pool.getAPRPool());
+ if (stat != APR_SUCCESS) {
+ throw IOException(stat);
+ }
+}
+
+
+FileInputStream::~FileInputStream() {
+ if (fileptr != NULL && !APRInitializer::isDestructed) {
+ apr_file_close((apr_file_t*) fileptr);
+ }
+}
+
+
+void FileInputStream::close() {
+ apr_status_t stat = apr_file_close((apr_file_t*) fileptr);
+ if (stat == APR_SUCCESS) {
+ fileptr = NULL;
+ } else {
+ throw IOException(stat);
+ }
+}
+
+
+//
+// Current implementation is limited to MBCS files
+//
+//
+LogString FileInputStream::read(Pool& p) const {
+ LogString output;
+ apr_status_t rv = APR_SUCCESS;
+ const size_t BUFSIZE = 4096;
+ char* buf = p.palloc(BUFSIZE);
+ char* contents = buf;
+ apr_size_t contentLength = 0;
+ do {
+ apr_size_t bytesRead = BUFSIZE;
+ rv = apr_file_read((apr_file_t*) fileptr, buf, &bytesRead);
+ contentLength += bytesRead;
+ if (APR_STATUS_IS_EOF(rv) || (rv == APR_SUCCESS && bytesRead <
BUFSIZE)) {
+ //
+ // finished file
+ // transcode and exit
+ Transcoder::decode(contents, contentLength, output);
+//
+// TODO - assertion here when called from Compare
+//
+// rv = apr_file_close(f);
+// assert(rv == APR_SUCCESS);
+ return output;
+ } else if (rv == APR_SUCCESS) {
+ //
+ // file was larger than the buffer
+ // realloc a bigger buffer
+ char* newContents = p.palloc(contentLength + BUFSIZE);
+ buf = newContents + contentLength;
+ memcpy(newContents, contents, contentLength);
+ //
+ // we would free contents here if you did that sort of thing
+ //
+ contents = newContents;
+ }
+ } while(rv == APR_SUCCESS);
+
+ return output;
+}
diff -urN log4cxx-0.9.8.org/src/inputstream.cpp
log4cxx-0.9.8/src/inputstream.cpp
--- log4cxx-0.9.8.org/src/inputstream.cpp 1970-01-01 01:00:00.000000000
+0100
+++ log4cxx-0.9.8/src/inputstream.cpp 2005-09-27 22:13:17.000000000 +0200
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2003,2005 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+#include <log4cxx/helpers/inputstream.h>
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+
+IMPLEMENT_LOG4CXX_OBJECT(InputStream)
+
+InputStream::InputStream() {
+}
+
+InputStream::~InputStream() {
+}
diff -urN log4cxx-0.9.8.org/src/loader.cpp log4cxx-0.9.8/src/loader.cpp
--- log4cxx-0.9.8.org/src/loader.cpp 2005-06-01 21:11:13.000000000 +0200
+++ log4cxx-0.9.8/src/loader.cpp 2005-09-27 22:48:56.000000000 +0200
@@ -30,6 +30,7 @@
#include <sys/stat.h>
#include <fstream>
#include <log4cxx/helpers/transcoder.h>
+#include <log4cxx/helpers/fileinputstream.h>
using namespace log4cxx;
using namespace log4cxx::helpers;
@@ -80,29 +81,20 @@
}
#endif
-#if 0
-istream * Loader::getResourceAsStream(const LogString& name)
-{
- String path = getResource(name);
- if (path.empty())
- {
- return 0;
- }
-#ifdef LOG4CXX_UNICODE
- std::wifstream * stream = new std::wifstream();
-#else
- std::ifstream * stream = new std::ifstream();
+InputStreamPtr Loader::getResourceAsStream(const LogString& name) {
+#if 0
+ String path = getResource(name);
+ if (path.empty())
+ {
+ return 0;
+ }
#endif
- USES_CONVERSION;
- stream->open(T2A(name.c_str()));
- if (stream->fail())
- {
- delete stream;
- return 0;
- }
+ try {
+ return new FileInputStream(name);
+ } catch(const IOException& ioex) {
+ }
- return stream;
+ return 0;
}
-#endif
diff -urN log4cxx-0.9.8.org/src/logger.cpp log4cxx-0.9.8/src/logger.cpp
--- log4cxx-0.9.8.org/src/logger.cpp 2005-05-07 17:12:15.000000000 +0200
+++ log4cxx-0.9.8/src/logger.cpp 2005-09-27 23:44:52.000000000 +0200
@@ -206,8 +206,8 @@
return 0;
}
-#if 0
-String Logger::getResourceBundleString(const String& key) const
+
+LogString Logger::getResourceBundleString(const LogString& key) const
{
ResourceBundlePtr rb = getResourceBundle();
@@ -215,7 +215,7 @@
// to report errors from within log4j.
if (rb == 0)
{
- return String();
+ return LogString();
}
else
{
@@ -225,14 +225,14 @@
}
catch (MissingResourceException&)
{
- ((Logger *)this)->error(LOG4CXX_WSTR("No resource is
associated with key \"") +
- key + LOG4CXX_WSTR("\"."));
+ ((Logger *)this)->error(LOG4CXX_STR("No resource is
associated with key \"") +
+ key + LOG4CXX_STR("\"."));
- return String();
+ return LogString();
}
}
}
-#endif
+
const LoggerPtr& Logger::getParent() const
{
@@ -344,7 +344,7 @@
}*/
void Logger::l7dlog(const LevelPtr& level, const std::string& key,
- const LocationInfo& location, ...)
+ const LocationInfo& location, ...)
{
if (repository->isDisabled(level->toInt()))
{
@@ -353,24 +353,29 @@
if (level->isGreaterOrEqual(getEffectiveLevel()))
{
-#if 0
-// TODO
- String pattern = getResourceBundleString(key);
- String msg;
+ LogString lkey;
+ Transcoder::decode(key.c_str(), strlen(key.c_str()), lkey);
+
+ LogString pattern = getResourceBundleString(lkey);
+ LogString msg;
if (pattern.empty())
{
- msg = key;
+ msg = lkey;
}
else
{
+ msg = pattern;
+#if 0
+// TODO
va_list params;
va_start (params, line);
msg = StringHelper::format(pattern, params);
va_end (params);
- }
#endif
- forcedLog(level, key, location);
+ }
+
+ forcedLog(level, msg, location);
}
}
@@ -385,24 +390,27 @@
if (level->isGreaterOrEqual(getEffectiveLevel()))
{
-#if 0
-// TODO
- String pattern = getResourceBundleString(key);
- String msg;
+ LOG4CXX_DECODE_WCHAR(lkey, key);
+ LogString pattern = getResourceBundleString(lkey);
+ LogString msg;
if (pattern.empty())
{
- msg = key;
+ msg = lkey;
}
else
{
+ msg = pattern;
+#if 0
+// TODO
va_list params;
va_start (params, line);
msg = StringHelper::format(pattern, params);
va_end (params);
- }
#endif
- forcedLog(level, key, location);
+ }
+
+ forcedLog(level, msg, location);
}
}
#endif
diff -urN log4cxx-0.9.8.org/src/properties.cpp log4cxx-0.9.8/src/properties.cpp
--- log4cxx-0.9.8.org/src/properties.cpp 2005-02-16 00:56:01.000000000
+0100
+++ log4cxx-0.9.8/src/properties.cpp 2005-09-27 23:55:58.000000000 +0200
@@ -16,6 +16,7 @@
#include <log4cxx/helpers/properties.h>
#include <log4cxx/helpers/exception.h>
+#include <log4cxx/helpers/pool.h>
using namespace log4cxx;
using namespace log4cxx::helpers;
@@ -331,6 +332,13 @@
parser.parse(inStream, *this);
}
+
+void Properties::load(InputStreamPtr inStream) {
+ Pool pool;
+ LogString contents = inStream->read(pool);
+ load(contents);
+}
+
std::vector<LogString> Properties::propertyNames() const
{
std::vector<LogString> names;
diff -urN log4cxx-0.9.8.org/src/propertyconfigurator.cpp
log4cxx-0.9.8/src/propertyconfigurator.cpp
--- log4cxx-0.9.8.org/src/propertyconfigurator.cpp 2005-05-14
00:10:51.000000000 +0200
+++ log4cxx-0.9.8/src/propertyconfigurator.cpp 2005-09-27 23:11:15.000000000
+0200
@@ -35,6 +35,7 @@
#include <apr_file_info.h>
#include <apr_pools.h>
#include <log4cxx/helpers/transcoder.h>
+#include <log4cxx/helpers/fileinputstream.h>
using namespace log4cxx;
@@ -80,8 +81,11 @@
spi::LoggerRepositoryPtr& hierarchy)
{
hierarchy->setConfigured(true);
- Pool pool;
- LogString config(configFileName.read(pool));
+ Pool pool;
+
+ InputStreamPtr inputStream = new FileInputStream(configFileName);
+ LogString config = inputStream->read(pool);
+
if (config.length() == 0) {
LogLog::error(((LogString) LOG4CXX_STR("Could not read
configuration file ["))
+ configFileName.getName() + LOG4CXX_STR("]."));
diff -urN log4cxx-0.9.8.org/src/propertyresourcebundle.cpp
log4cxx-0.9.8/src/propertyresourcebundle.cpp
--- log4cxx-0.9.8.org/src/propertyresourcebundle.cpp 2005-05-07
17:12:15.000000000 +0200
+++ log4cxx-0.9.8/src/propertyresourcebundle.cpp 2005-09-27
22:27:28.000000000 +0200
@@ -23,6 +23,12 @@
IMPLEMENT_LOG4CXX_OBJECT(PropertyResourceBundle)
+
+PropertyResourceBundle::PropertyResourceBundle(InputStreamPtr inStream)
+{
+ properties.load(inStream);
+}
+
PropertyResourceBundle::PropertyResourceBundle(LogString& inStream)
{
properties.load(inStream);
diff -urN log4cxx-0.9.8.org/src/resourcebundle.cpp
log4cxx-0.9.8/src/resourcebundle.cpp
--- log4cxx-0.9.8.org/src/resourcebundle.cpp 2005-02-16 00:56:01.000000000
+0100
+++ log4cxx-0.9.8/src/resourcebundle.cpp 2005-09-27 23:50:09.000000000
+0200
@@ -21,6 +21,8 @@
#include <log4cxx/helpers/transcoder.h>
#include <log4cxx/helpers/locale.h>
+#include <apr_lib.h>
+
using namespace log4cxx;
using namespace log4cxx::helpers;
@@ -56,19 +58,16 @@
}
bundlesNames.push_back(baseName);
- Pool pool;
for (std::vector<LogString>::iterator it = bundlesNames.begin();
it != bundlesNames.end(); it++)
{
-#if 0
-// TODO
- LogString bundleStream;
bundleName = *it;
PropertyResourceBundlePtr current;
+ // Try loading a class which implements ResourceBundle
try
{
const Class& classObj = Loader::loadClass(bundleName);
@@ -79,29 +78,27 @@
current = 0;
}
+ // No class found, then try to create a PropertyResourceBundle from a
file
if (current == 0)
{
- apr_size_t bytes = 0;
- void* buf = Loader::getResourceAsStream(
- bundleName + LOG4CXX_STR(".properties"),
- &bytes, pool);
- if (bytes == 0 || buf == NULL) {
- continue;
- }
- log4cxx::helpers::Transcoder::decode(buf, bytes, pool,
bundleStream);
- }
-
- try
- {
- current = new PropertyResourceBundle(bundleStream);
- }
- catch(Exception&)
- {
- throw;
+ InputStreamPtr bundleStream =
+ Loader::getResourceAsStream(
+ bundleName + LOG4CXX_STR(".properties"));
+ if (bundleStream == 0) {
+ continue;
+ }
+
+ try
+ {
+ current = new PropertyResourceBundle(bundleStream);
+ }
+ catch(Exception&)
+ {
+ throw;
+ }
}
- bundleStream.erase(bundleStream.begin(), bundleStream.end());
-
+ // Add the new resource bundle to the hierarchy
if (resourceBundle == 0)
{
resourceBundle = current;
@@ -112,9 +109,9 @@
previous->setParent(current);
previous = current;
}
-#endif
}
+ // no resource bundle found at all, then throw exception
if (resourceBundle == 0)
{
throw MissingResourceException(
diff -urN log4cxx-0.9.8.org/tests/src/filetestcase.cpp
log4cxx-0.9.8/tests/src/filetestcase.cpp
--- log4cxx-0.9.8.org/tests/src/filetestcase.cpp 2005-03-11
07:34:49.000000000 +0100
+++ log4cxx-0.9.8/tests/src/filetestcase.cpp 2005-09-27 23:16:57.000000000
+0200
@@ -20,6 +20,7 @@
#include <log4cxx/helpers/pool.h>
#include <apr_errno.h>
#include <log4cxx/helpers/exception.h>
+#include <log4cxx/helpers/fileinputstream.h>
using namespace log4cxx;
using namespace log4cxx::helpers;
@@ -61,7 +62,8 @@
File defFile;
Pool pool;
try {
- LogString contents(defFile.read(pool));
+ FileInputStream defInput(defFile);
+ LogString contents(defInput.read(pool));
CPPUNIT_ASSERT(false);
} catch(IOException &ex) {
}
@@ -105,7 +107,8 @@
void propertyRead() {
File propFile("input/patternLayout1.properties");
Pool pool;
- LogString props(propFile.read(pool));
+ FileInputStream propStream(propFile);
+ LogString props(propStream.read(pool));
LogString line1(LOG4CXX_STR("log4j.rootCategory=DEBUG,
testAppender"));
CPPUNIT_ASSERT_EQUAL(line1, props.substr(0, line1.length()));
LogString tail(LOG4CXX_STR("%-5p - %m%n"));
@@ -127,7 +130,8 @@
apr_status_t stat = outFile.write(greeting, pool);
CPPUNIT_ASSERT_EQUAL(0, stat);
- LogString reply(outFile.read(pool));
+ FileInputStream outStream(outFile);
+ LogString reply(outStream.read(pool));
CPPUNIT_ASSERT_EQUAL(greeting, reply);
}
};
diff -urN log4cxx-0.9.8.org/tests/src/l7dtestcase.cpp
log4cxx-0.9.8/tests/src/l7dtestcase.cpp
--- log4cxx-0.9.8.org/tests/src/l7dtestcase.cpp 2005-03-04 22:21:43.000000000
+0100
+++ log4cxx-0.9.8/tests/src/l7dtestcase.cpp 2005-09-28 00:00:09.000000000
+0200
@@ -103,4 +102,4 @@
};
-//CPPUNIT_TEST_SUITE_REGISTRATION(L7dTestCase);
+CPPUNIT_TEST_SUITE_REGISTRATION(L7dTestCase);
diff -urN log4cxx-0.9.8.org/tests/src/util/compare.cpp
log4cxx-0.9.8/tests/src/util/compare.cpp
--- log4cxx-0.9.8.org/tests/src/util/compare.cpp 2005-06-01
21:11:14.000000000 +0200
+++ log4cxx-0.9.8/tests/src/util/compare.cpp 2005-09-27 23:14:33.000000000
+0200
@@ -21,6 +21,7 @@
#include <log4cxx/helpers/pool.h>
#include <log4cxx/file.h>
#include <log4cxx/helpers/stringhelper.h>
+#include <log4cxx/helpers/fileinputstream.h>
using namespace log4cxx;
using namespace log4cxx::helpers;
@@ -28,10 +29,12 @@
bool Compare::compare(const File& file1, const File& file2)
{
Pool pool;
+ FileInputStream fileIn1(file1);
+ LogString in1(fileIn1.read(pool));
- LogString in1(file1.read(pool));
Pool pool2;
- LogString in2(file2.read(pool2));
+ FileInputStream fileIn2(file2);
+ LogString in2(fileIn2.read(pool2));
LogString back1(in1);
LogString back2(in2);