mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@752 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
42ce70e744
commit
1a08b36a78
5 changed files with 189 additions and 0 deletions
82
src/org/fbreader/encoding/ZLEncodingCollection.java
Normal file
82
src/org/fbreader/encoding/ZLEncodingCollection.java
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package org.fbreader.encoding;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.zlibrary.core.config.ZLConfigManager;
|
||||||
|
import org.zlibrary.core.library.ZLibrary;
|
||||||
|
import org.zlibrary.core.options.ZLBooleanOption;
|
||||||
|
import org.zlibrary.core.options.ZLOption;
|
||||||
|
|
||||||
|
public class ZLEncodingCollection {
|
||||||
|
private static ZLEncodingCollection ourInstance;
|
||||||
|
private static ZLBooleanOption ourUseWindows1252HackOption;
|
||||||
|
|
||||||
|
public static ZLEncodingCollection instance() {
|
||||||
|
if (ourInstance == null) {
|
||||||
|
ourInstance = new ZLEncodingCollection();
|
||||||
|
}
|
||||||
|
return ourInstance;
|
||||||
|
}
|
||||||
|
public static String encodingDescriptionPath() {
|
||||||
|
return ZLibrary.JAR_DATA_PREFIX + "zlibrary" + File.separator + "encodings";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ZLBooleanOption useWindows1252HackOption() {
|
||||||
|
if (ourUseWindows1252HackOption == null) {
|
||||||
|
ourUseWindows1252HackOption =
|
||||||
|
new ZLBooleanOption(ZLOption.CONFIG_CATEGORY, "Encoding", "UseWindows1252Hack", true);
|
||||||
|
}
|
||||||
|
return ourUseWindows1252HackOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean useWindows1252Hack() {
|
||||||
|
return ZLConfigManager.getInstance() != null/*.isInitialised()*/ && useWindows1252HackOption().getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ArrayList<ZLEncodingSet> sets() {
|
||||||
|
init();
|
||||||
|
return mySets;
|
||||||
|
}
|
||||||
|
public ZLEncodingConverterInfo info(String name) {
|
||||||
|
init();
|
||||||
|
String lowerCaseName = name.toLowerCase();
|
||||||
|
if (useWindows1252Hack() && (lowerCaseName == "iso-8859-1")) {
|
||||||
|
lowerCaseName = "windows-1252";
|
||||||
|
}
|
||||||
|
return (ZLEncodingConverterInfo)myInfosByName.get(lowerCaseName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZLEncodingConverterInfo info(int code) {
|
||||||
|
String name = "" + code;
|
||||||
|
return info(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZLEncodingConverter defaultConverter() {
|
||||||
|
return null;//DummyEncodingConverterProvider().createConverter();
|
||||||
|
}
|
||||||
|
public void registerProvider(ZLEncodingConverterProvider provider) {
|
||||||
|
myProviders.add(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addInfo(ZLEncodingConverterInfo info) {
|
||||||
|
|
||||||
|
}
|
||||||
|
ArrayList/*<ZLEncodingConverterProvider>*/ providers() {
|
||||||
|
return myProviders;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList/*<ZLEncodingSet>*/ mySets;
|
||||||
|
private HashMap/*<String,ZLEncodingConverterInfo>*/ myInfosByName;
|
||||||
|
private ArrayList/*<ZLEncodingConverterProvider>*/ myProviders;
|
||||||
|
|
||||||
|
//private ZLEncodingCollection();
|
||||||
|
private void init() {
|
||||||
|
if (mySets.isEmpty()) {
|
||||||
|
String prefix = encodingDescriptionPath() + File.separator;
|
||||||
|
//new ZLEncodingCollectionReader(this).readDocument(prefix + "Encodings.xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
src/org/fbreader/encoding/ZLEncodingConverter.java
Normal file
15
src/org/fbreader/encoding/ZLEncodingConverter.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package org.fbreader.encoding;
|
||||||
|
|
||||||
|
public abstract class ZLEncodingConverter {
|
||||||
|
protected ZLEncodingConverter() {}
|
||||||
|
|
||||||
|
//abstract public void convert(String dst, const char *srcStart, const char *srcEnd);
|
||||||
|
public void convert(String dst, String src) {
|
||||||
|
//convert(dst, src.toCharArray(), src.data() + src.length());
|
||||||
|
}
|
||||||
|
public abstract void reset();
|
||||||
|
public abstract boolean fillTable(int[] map);
|
||||||
|
|
||||||
|
//private ZLEncodingConverter(ZLEncodingConverter zl);
|
||||||
|
//private ZLEncodingConverter &operator=(ZLEncodingConverter zl);
|
||||||
|
}
|
60
src/org/fbreader/encoding/ZLEncodingConverterInfo.java
Normal file
60
src/org/fbreader/encoding/ZLEncodingConverterInfo.java
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package org.fbreader.encoding;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public class ZLEncodingConverterInfo {
|
||||||
|
public ZLEncodingConverterInfo(String name, String region) {
|
||||||
|
myName = name;
|
||||||
|
myVisibleName = region + " (" + name + ")";
|
||||||
|
addAlias(myName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAlias(String alias) {
|
||||||
|
myAliases.add(alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return myName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String visibleName() {
|
||||||
|
return myVisibleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZLEncodingConverter createConverter() {
|
||||||
|
ZLEncodingCollection collection = ZLEncodingCollection.instance();
|
||||||
|
ArrayList<ZLEncodingConverterProvider> providers = collection.providers();
|
||||||
|
for (Iterator it = providers.iterator(); it.hasNext(); ) {
|
||||||
|
for (Iterator jt = myAliases.iterator(); jt.hasNext(); ) {
|
||||||
|
ZLEncodingConverterProvider itp = (ZLEncodingConverterProvider)it.next();
|
||||||
|
String str = (String)jt.next();
|
||||||
|
if (itp.providesConverter(str)) {
|
||||||
|
return itp.createConverter(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ZLEncodingCollection.instance().defaultConverter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canCreateConverter() {
|
||||||
|
ZLEncodingCollection collection = ZLEncodingCollection.instance();
|
||||||
|
ArrayList<ZLEncodingConverterProvider> providers = collection.providers();
|
||||||
|
for (Iterator it = providers.iterator(); it.hasNext();) {
|
||||||
|
for (Iterator jt = myAliases.iterator(); jt.hasNext(); ) {
|
||||||
|
if (((ZLEncodingConverterProvider)it.next()).providesConverter((String)jt.next())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String myName = "";
|
||||||
|
private String myVisibleName = "";
|
||||||
|
private ArrayList<String> myAliases = new ArrayList();
|
||||||
|
|
||||||
|
//private ZLEncodingConverterInfo(const ZLEncodingConverterInfo&);
|
||||||
|
//private ZLEncodingConverterInfo &operator=(const ZLEncodingConverterInfo&);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.fbreader.encoding;
|
||||||
|
|
||||||
|
public abstract class ZLEncodingConverterProvider {
|
||||||
|
protected ZLEncodingConverterProvider() {}
|
||||||
|
|
||||||
|
public abstract boolean providesConverter(String encoding);
|
||||||
|
public abstract ZLEncodingConverter createConverter(String encoding);
|
||||||
|
|
||||||
|
}
|
23
src/org/fbreader/encoding/ZLEncodingSet.java
Normal file
23
src/org/fbreader/encoding/ZLEncodingSet.java
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package org.fbreader.encoding;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ZLEncodingSet {
|
||||||
|
public ZLEncodingSet(String name) {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void addInfo(ZLEncodingConverterInfo info) {
|
||||||
|
myInfos.add(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return myName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList/*<ZLEncodingConverterInfo>*/ infos() {
|
||||||
|
return myInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String myName = "";
|
||||||
|
private ArrayList/*<ZLEncodingConverterInfo>*/ myInfos = new ArrayList();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue