From 4b833c39d897eb1dba546b13b39a52eab9320ea7 Mon Sep 17 00:00:00 2001 From: MarinaSokol Date: Sun, 11 Nov 2007 21:12:04 +0000 Subject: [PATCH] git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@106 6a642e6f-84f6-412e-ac94-c4a38d5a04b0 --- .../zlibrary/core/resources/ZLResource.java | 43 +++++++++++ .../core/resources/ZLResourceKey.java | 11 +++ .../core/resources/ZLTreeResource.java | 74 +++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 src/org/zlibrary/core/resources/ZLResource.java create mode 100644 src/org/zlibrary/core/resources/ZLResourceKey.java create mode 100644 src/org/zlibrary/core/resources/ZLTreeResource.java diff --git a/src/org/zlibrary/core/resources/ZLResource.java b/src/org/zlibrary/core/resources/ZLResource.java new file mode 100644 index 000000000..23c1dd7b6 --- /dev/null +++ b/src/org/zlibrary/core/resources/ZLResource.java @@ -0,0 +1,43 @@ +package org.zlibrary.core.resources; + +abstract public class ZLResource { + private String myName; + + public static ZLResource resource(String key) { + return null;//todo + } + + public static ZLResource resource(ZLResourceKey key) { + return resource(key.Name); + } + + protected ZLResource(String name) { + this.myName = name; + } + + public String name() { + return myName; + } + abstract public boolean hasValue(); + + abstract public String value(); + + public ZLResource getResource(ZLResourceKey key) { + return getResource(key.Name); + } + + abstract public ZLResource getResource(String key); +} +/*const ZLResource &ZLResource::operator [] (const ZLResourceKey &key) const { + return (*this)[key.Name]; +} + +const ZLResource &ZLResource::resource(const std::string &key) { + ZLTreeResource::buildTree(); + if (ZLTreeResource::ourRoot.isNull()) { + return ZLMissingResource::instance(); + } + return (*ZLTreeResource::ourRoot)[key]; +} + +*/ diff --git a/src/org/zlibrary/core/resources/ZLResourceKey.java b/src/org/zlibrary/core/resources/ZLResourceKey.java new file mode 100644 index 000000000..926ebf041 --- /dev/null +++ b/src/org/zlibrary/core/resources/ZLResourceKey.java @@ -0,0 +1,11 @@ +package org.zlibrary.core.resources; + +public class ZLResourceKey { + public String Name; + + public ZLResourceKey() {} + + public ZLResourceKey(String name) { + Name = name; + } +} diff --git a/src/org/zlibrary/core/resources/ZLTreeResource.java b/src/org/zlibrary/core/resources/ZLTreeResource.java new file mode 100644 index 000000000..40541fa34 --- /dev/null +++ b/src/org/zlibrary/core/resources/ZLTreeResource.java @@ -0,0 +1,74 @@ +package org.zlibrary.core.resources; + +import java.util.Map; + +public class ZLTreeResource { + public static ZLTreeResource ourRoot; + + /*public static void buildTree() { + + } + public static void loadData(String language) { + String filePath = ZLibrary.FileNameDelimiter + "resources" + ZLibrary.FileNameDelimiter + language + ".xml"; + new ZLResourceTreeReader(ourRoot).readDocument(ZLApplication.ZLibraryDirectory() + filePath); + new ZLResourceTreeReader(ourRoot).readDocument(ZLApplication.ApplicationDirectory() + filePath); + + } + + private ZLTreeResource(String name); + private ZLTreeResource(String name, String value); + private void setValue(String value); + private boolean hasValue(); + private String value(); + + public ZLResource &operator [] (String key); + + private boolean myHasValue; + private String myValue; + private Map myChildren;*/ +} + +/*void ZLTreeResource::loadData(const std::string &language) { + std::string filePath = ZLibrary::FileNameDelimiter + "resources" + ZLibrary::FileNameDelimiter + language + ".xml"; + ZLResourceTreeReader(ourRoot).readDocument(ZLApplication::ZLibraryDirectory() + filePath); + ZLResourceTreeReader(ourRoot).readDocument(ZLApplication::ApplicationDirectory() + filePath); +} + +void ZLTreeResource::buildTree() { + if (ourRoot.isNull()) { + ourRoot = new ZLTreeResource(std::string()); + loadData("en"); + const std::string language = ZLibrary::Language(); + if (language != "en") { + loadData(language); + } + } +} + +ZLTreeResource::ZLTreeResource(const std::string &name) : ZLResource(name), myHasValue(false) { +} + +ZLTreeResource::ZLTreeResource(const std::string &name, const std::string &value) : ZLResource(name), myHasValue(true), myValue(value) { +} + +void ZLTreeResource::setValue(const std::string &value) { + myHasValue = true; + myValue = value; +} + +bool ZLTreeResource::hasValue() const { + return myHasValue; +} + +const std::string &ZLTreeResource::value() const { + return myHasValue ? myValue : ZLMissingResource::ourValue; +} + +const ZLResource &ZLTreeResource::operator [] (const std::string &key) const { + std::map >::const_iterator it = myChildren.find(key); + if (it != myChildren.end()) { + return *it->second; + } else { + return ZLMissingResource::instance(); + } +}*/