first commit
This commit is contained in:
commit
4d332ef662
27586 changed files with 3281783 additions and 0 deletions
|
|
@ -0,0 +1,85 @@
|
|||
package com.sun.activation.registries;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Vector;
|
||||
|
||||
class LineTokenizer {
|
||||
private int currentPosition;
|
||||
|
||||
private int maxPosition;
|
||||
|
||||
private String str;
|
||||
|
||||
private Vector stack = new Vector();
|
||||
|
||||
private static final String singles = "=";
|
||||
|
||||
public LineTokenizer(String paramString) {
|
||||
this.currentPosition = 0;
|
||||
this.str = paramString;
|
||||
this.maxPosition = paramString.length();
|
||||
}
|
||||
|
||||
private void skipWhiteSpace() {
|
||||
while (this.currentPosition < this.maxPosition && Character.isWhitespace(this.str.charAt(this.currentPosition)))
|
||||
this.currentPosition++;
|
||||
}
|
||||
|
||||
public boolean hasMoreTokens() {
|
||||
if (this.stack.size() > 0)
|
||||
return true;
|
||||
skipWhiteSpace();
|
||||
return (this.currentPosition < this.maxPosition);
|
||||
}
|
||||
|
||||
public String nextToken() {
|
||||
int i = this.stack.size();
|
||||
if (i > 0) {
|
||||
String str = (String)this.stack.elementAt(i - 1);
|
||||
this.stack.removeElementAt(i - 1);
|
||||
return str;
|
||||
}
|
||||
skipWhiteSpace();
|
||||
if (this.currentPosition >= this.maxPosition)
|
||||
throw new NoSuchElementException();
|
||||
int j = this.currentPosition;
|
||||
char c = this.str.charAt(j);
|
||||
if (c == '"') {
|
||||
this.currentPosition++;
|
||||
boolean bool = false;
|
||||
while (this.currentPosition < this.maxPosition) {
|
||||
c = this.str.charAt(this.currentPosition++);
|
||||
if (c == '\\') {
|
||||
this.currentPosition++;
|
||||
bool = true;
|
||||
continue;
|
||||
}
|
||||
if (c == '"') {
|
||||
String str;
|
||||
if (bool) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int k = j + 1; k < this.currentPosition - 1; k++) {
|
||||
c = this.str.charAt(k);
|
||||
if (c != '\\')
|
||||
stringBuffer.append(c);
|
||||
}
|
||||
str = stringBuffer.toString();
|
||||
} else {
|
||||
str = this.str.substring(j + 1, this.currentPosition - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
} else if ("=".indexOf(c) >= 0) {
|
||||
this.currentPosition++;
|
||||
} else {
|
||||
while (this.currentPosition < this.maxPosition && "=".indexOf(this.str.charAt(this.currentPosition)) < 0 && !Character.isWhitespace(this.str.charAt(this.currentPosition)))
|
||||
this.currentPosition++;
|
||||
}
|
||||
return this.str.substring(j, this.currentPosition);
|
||||
}
|
||||
|
||||
public void pushToken(String paramString) {
|
||||
this.stack.addElement(paramString);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.sun.activation.registries;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class LogSupport {
|
||||
private static boolean debug = false;
|
||||
|
||||
private static final Level level = Level.FINE;
|
||||
|
||||
static {
|
||||
try {
|
||||
debug = Boolean.getBoolean("javax.activation.debug");
|
||||
} catch (Throwable e) {}
|
||||
}
|
||||
|
||||
private static Logger logger = Logger.getLogger("javax.activation");
|
||||
|
||||
public static void log(String paramString) {
|
||||
if (debug)
|
||||
System.out.println(paramString);
|
||||
logger.log(level, paramString);
|
||||
}
|
||||
|
||||
public static void log(String paramString, Throwable paramThrowable) {
|
||||
if (debug)
|
||||
System.out.println(paramString + "; Exception: " + paramThrowable);
|
||||
logger.log(level, paramString, paramThrowable);
|
||||
}
|
||||
|
||||
public static boolean isLoggable() {
|
||||
return (debug || logger.isLoggable(level));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,310 @@
|
|||
package com.sun.activation.registries;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class MailcapFile {
|
||||
private Map type_hash = new HashMap();
|
||||
|
||||
private Map fallback_hash = new HashMap();
|
||||
|
||||
private Map native_commands = new HashMap();
|
||||
|
||||
private static boolean addReverse = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
addReverse = Boolean.getBoolean("javax.activation.addreverse");
|
||||
} catch (Throwable e) {}
|
||||
}
|
||||
|
||||
public MailcapFile(String paramString) throws IOException {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("new MailcapFile: file " + paramString);
|
||||
FileReader fileReader = null;
|
||||
try {
|
||||
fileReader = new FileReader(paramString);
|
||||
parse(new BufferedReader(fileReader));
|
||||
} finally {
|
||||
if (fileReader != null)
|
||||
try {
|
||||
fileReader.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public MailcapFile(InputStream paramInputStream) throws IOException {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("new MailcapFile: InputStream");
|
||||
parse(new BufferedReader(new InputStreamReader(paramInputStream, "iso-8859-1")));
|
||||
}
|
||||
|
||||
public MailcapFile() {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("new MailcapFile: default");
|
||||
}
|
||||
|
||||
public Map getMailcapList(String paramString) {
|
||||
Map map1 = null;
|
||||
Map map2 = null;
|
||||
map1 = (Map)this.type_hash.get(paramString);
|
||||
int i = paramString.indexOf('/');
|
||||
String str = paramString.substring(i + 1);
|
||||
if (!str.equals("*")) {
|
||||
String str1 = paramString.substring(0, i + 1) + "*";
|
||||
map2 = (Map)this.type_hash.get(str1);
|
||||
if (map2 != null)
|
||||
if (map1 != null) {
|
||||
map1 = mergeResults(map1, map2);
|
||||
} else {
|
||||
map1 = map2;
|
||||
}
|
||||
}
|
||||
return map1;
|
||||
}
|
||||
|
||||
public Map getMailcapFallbackList(String paramString) {
|
||||
Map map1 = null;
|
||||
Map map2 = null;
|
||||
map1 = (Map)this.fallback_hash.get(paramString);
|
||||
int i = paramString.indexOf('/');
|
||||
String str = paramString.substring(i + 1);
|
||||
if (!str.equals("*")) {
|
||||
String str1 = paramString.substring(0, i + 1) + "*";
|
||||
map2 = (Map)this.fallback_hash.get(str1);
|
||||
if (map2 != null)
|
||||
if (map1 != null) {
|
||||
map1 = mergeResults(map1, map2);
|
||||
} else {
|
||||
map1 = map2;
|
||||
}
|
||||
}
|
||||
return map1;
|
||||
}
|
||||
|
||||
public String[] getMimeTypes() {
|
||||
HashSet hashSet = new HashSet(this.type_hash.keySet());
|
||||
hashSet.addAll(this.fallback_hash.keySet());
|
||||
hashSet.addAll(this.native_commands.keySet());
|
||||
String[] arrayOfString = new String[hashSet.size()];
|
||||
arrayOfString = (String[])hashSet.toArray(arrayOfString);
|
||||
return arrayOfString;
|
||||
}
|
||||
|
||||
public String[] getNativeCommands(String paramString) {
|
||||
String[] arrayOfString = null;
|
||||
List list = (List)this.native_commands.get(paramString.toLowerCase(Locale.ENGLISH));
|
||||
if (list != null) {
|
||||
arrayOfString = new String[list.size()];
|
||||
arrayOfString = (String[])list.toArray(arrayOfString);
|
||||
}
|
||||
return arrayOfString;
|
||||
}
|
||||
|
||||
private Map mergeResults(Map paramMap1, Map paramMap2) {
|
||||
Iterator iterator = paramMap2.keySet().iterator();
|
||||
HashMap hashMap = new HashMap(paramMap1);
|
||||
while (iterator.hasNext()) {
|
||||
String str = (String)iterator.next();
|
||||
List list1 = (List)hashMap.get(str);
|
||||
if (list1 == null) {
|
||||
hashMap.put(str, paramMap2.get(str));
|
||||
continue;
|
||||
}
|
||||
List list2 = (List)paramMap2.get(str);
|
||||
list1 = new ArrayList(list1);
|
||||
list1.addAll(list2);
|
||||
hashMap.put(str, list1);
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
public void appendToMailcap(String paramString) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("appendToMailcap: " + paramString);
|
||||
try {
|
||||
parse(new StringReader(paramString));
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
private void parse(Reader paramReader) throws IOException {
|
||||
BufferedReader bufferedReader = new BufferedReader(paramReader);
|
||||
String str1 = null;
|
||||
String str2 = null;
|
||||
while ((str1 = bufferedReader.readLine()) != null) {
|
||||
str1 = str1.trim();
|
||||
try {
|
||||
if (str1.charAt(0) == '#')
|
||||
continue;
|
||||
if (str1.charAt(str1.length() - 1) == '\\') {
|
||||
if (str2 != null) {
|
||||
str2 = str2 + str1.substring(0, str1.length() - 1);
|
||||
continue;
|
||||
}
|
||||
str2 = str1.substring(0, str1.length() - 1);
|
||||
continue;
|
||||
}
|
||||
if (str2 != null) {
|
||||
str2 = str2 + str1;
|
||||
try {
|
||||
parseLine(str2);
|
||||
} catch (MailcapParseException e) {}
|
||||
str2 = null;
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
parseLine(str1);
|
||||
} catch (MailcapParseException e) {}
|
||||
} catch (StringIndexOutOfBoundsException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
protected void parseLine(String paramString) throws MailcapParseException, IOException {
|
||||
MailcapTokenizer mailcapTokenizer = new MailcapTokenizer(paramString);
|
||||
mailcapTokenizer.setIsAutoquoting(false);
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("parse: " + paramString);
|
||||
int i = mailcapTokenizer.nextToken();
|
||||
if (i != 2)
|
||||
reportParseError(2, i, mailcapTokenizer.getCurrentTokenValue());
|
||||
String str1 = mailcapTokenizer.getCurrentTokenValue().toLowerCase(Locale.ENGLISH);
|
||||
String str2 = "*";
|
||||
i = mailcapTokenizer.nextToken();
|
||||
if (i != 47 && i != 59)
|
||||
reportParseError(47, 59, i, mailcapTokenizer.getCurrentTokenValue());
|
||||
if (i == 47) {
|
||||
i = mailcapTokenizer.nextToken();
|
||||
if (i != 2)
|
||||
reportParseError(2, i, mailcapTokenizer.getCurrentTokenValue());
|
||||
str2 = mailcapTokenizer.getCurrentTokenValue().toLowerCase(Locale.ENGLISH);
|
||||
i = mailcapTokenizer.nextToken();
|
||||
}
|
||||
String str3 = str1 + "/" + str2;
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log(" Type: " + str3);
|
||||
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
||||
if (i != 59)
|
||||
reportParseError(59, i, mailcapTokenizer.getCurrentTokenValue());
|
||||
mailcapTokenizer.setIsAutoquoting(true);
|
||||
i = mailcapTokenizer.nextToken();
|
||||
mailcapTokenizer.setIsAutoquoting(false);
|
||||
if (i != 2 && i != 59)
|
||||
reportParseError(2, 59, i, mailcapTokenizer.getCurrentTokenValue());
|
||||
if (i == 2) {
|
||||
List list = (List)this.native_commands.get(str3);
|
||||
if (list == null) {
|
||||
list = new ArrayList();
|
||||
list.add(paramString);
|
||||
this.native_commands.put(str3, list);
|
||||
} else {
|
||||
list.add(paramString);
|
||||
}
|
||||
}
|
||||
if (i != 59)
|
||||
i = mailcapTokenizer.nextToken();
|
||||
if (i == 59) {
|
||||
boolean bool = false;
|
||||
do {
|
||||
i = mailcapTokenizer.nextToken();
|
||||
if (i != 2)
|
||||
reportParseError(2, i, mailcapTokenizer.getCurrentTokenValue());
|
||||
String str4 = mailcapTokenizer.getCurrentTokenValue().toLowerCase(Locale.ENGLISH);
|
||||
i = mailcapTokenizer.nextToken();
|
||||
if (i != 61 && i != 59 && i != 5)
|
||||
reportParseError(61, 59, 5, i, mailcapTokenizer.getCurrentTokenValue());
|
||||
if (i != 61)
|
||||
continue;
|
||||
mailcapTokenizer.setIsAutoquoting(true);
|
||||
i = mailcapTokenizer.nextToken();
|
||||
mailcapTokenizer.setIsAutoquoting(false);
|
||||
if (i != 2)
|
||||
reportParseError(2, i, mailcapTokenizer.getCurrentTokenValue());
|
||||
String str5 = mailcapTokenizer.getCurrentTokenValue();
|
||||
if (str4.startsWith("x-java-")) {
|
||||
String str = str4.substring(7);
|
||||
if (str.equals("fallback-entry") && str5.equalsIgnoreCase("true")) {
|
||||
bool = true;
|
||||
} else {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log(" Command: " + str + ", Class: " + str5);
|
||||
List list = (List)linkedHashMap.get(str);
|
||||
if (list == null) {
|
||||
list = new ArrayList();
|
||||
linkedHashMap.put(str, list);
|
||||
}
|
||||
if (addReverse) {
|
||||
list.add(0, str5);
|
||||
} else {
|
||||
list.add(str5);
|
||||
}
|
||||
}
|
||||
}
|
||||
i = mailcapTokenizer.nextToken();
|
||||
} while (i == 59);
|
||||
Map map1 = bool ? this.fallback_hash : this.type_hash;
|
||||
Map map2 = (Map)map1.get(str3);
|
||||
if (map2 == null) {
|
||||
map1.put(str3, linkedHashMap);
|
||||
} else {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("Merging commands for type " + str3);
|
||||
Iterator iterator = map2.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String str = (String)iterator.next();
|
||||
List list1 = (List)map2.get(str);
|
||||
List list2 = (List)linkedHashMap.get(str);
|
||||
if (list2 == null)
|
||||
continue;
|
||||
Iterator iterator1 = list2.iterator();
|
||||
while (iterator1.hasNext()) {
|
||||
String str4 = (String)iterator1.next();
|
||||
if (!list1.contains(str4)) {
|
||||
if (addReverse) {
|
||||
list1.add(0, str4);
|
||||
continue;
|
||||
}
|
||||
list1.add(str4);
|
||||
}
|
||||
}
|
||||
}
|
||||
iterator = linkedHashMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String str = (String)iterator.next();
|
||||
if (map2.containsKey(str))
|
||||
continue;
|
||||
List list = (List)linkedHashMap.get(str);
|
||||
map2.put(str, list);
|
||||
}
|
||||
}
|
||||
} else if (i != 5) {
|
||||
reportParseError(5, 59, i, mailcapTokenizer.getCurrentTokenValue());
|
||||
}
|
||||
}
|
||||
|
||||
protected static void reportParseError(int paramInt1, int paramInt2, String paramString) throws MailcapParseException {
|
||||
throw new MailcapParseException("Encountered a " + MailcapTokenizer.nameForToken(paramInt2) + " token (" + paramString + ") while expecting a " + MailcapTokenizer.nameForToken(paramInt1) + " token.");
|
||||
}
|
||||
|
||||
protected static void reportParseError(int paramInt1, int paramInt2, int paramInt3, String paramString) throws MailcapParseException {
|
||||
throw new MailcapParseException("Encountered a " + MailcapTokenizer.nameForToken(paramInt3) + " token (" + paramString + ") while expecting a " + MailcapTokenizer.nameForToken(paramInt1) + " or a " + MailcapTokenizer.nameForToken(paramInt2) + " token.");
|
||||
}
|
||||
|
||||
protected static void reportParseError(int paramInt1, int paramInt2, int paramInt3, int paramInt4, String paramString) throws MailcapParseException {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("PARSE ERROR: Encountered a " + MailcapTokenizer.nameForToken(paramInt4) + " token (" + paramString + ") while expecting a " + MailcapTokenizer.nameForToken(paramInt1) + ", a " + MailcapTokenizer.nameForToken(paramInt2) + ", or a " + MailcapTokenizer.nameForToken(paramInt3) + " token.");
|
||||
throw new MailcapParseException("Encountered a " + MailcapTokenizer.nameForToken(paramInt4) + " token (" + paramString + ") while expecting a " + MailcapTokenizer.nameForToken(paramInt1) + ", a " + MailcapTokenizer.nameForToken(paramInt2) + ", or a " + MailcapTokenizer.nameForToken(paramInt3) + " token.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.sun.activation.registries;
|
||||
|
||||
public class MailcapParseException extends Exception {
|
||||
public MailcapParseException() {}
|
||||
|
||||
public MailcapParseException(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
package com.sun.activation.registries;
|
||||
|
||||
public class MailcapTokenizer {
|
||||
public static final int UNKNOWN_TOKEN = 0;
|
||||
|
||||
public static final int START_TOKEN = 1;
|
||||
|
||||
public static final int STRING_TOKEN = 2;
|
||||
|
||||
public static final int EOI_TOKEN = 5;
|
||||
|
||||
public static final int SLASH_TOKEN = 47;
|
||||
|
||||
public static final int SEMICOLON_TOKEN = 59;
|
||||
|
||||
public static final int EQUALS_TOKEN = 61;
|
||||
|
||||
private String data;
|
||||
|
||||
private int dataIndex;
|
||||
|
||||
private int dataLength;
|
||||
|
||||
private int currentToken;
|
||||
|
||||
private String currentTokenValue;
|
||||
|
||||
private boolean isAutoquoting;
|
||||
|
||||
private char autoquoteChar;
|
||||
|
||||
public MailcapTokenizer(String paramString) {
|
||||
this.data = paramString;
|
||||
this.dataIndex = 0;
|
||||
this.dataLength = paramString.length();
|
||||
this.currentToken = 1;
|
||||
this.currentTokenValue = "";
|
||||
this.isAutoquoting = false;
|
||||
this.autoquoteChar = ';';
|
||||
}
|
||||
|
||||
public void setIsAutoquoting(boolean paramBoolean) {
|
||||
this.isAutoquoting = paramBoolean;
|
||||
}
|
||||
|
||||
public int getCurrentToken() {
|
||||
return this.currentToken;
|
||||
}
|
||||
|
||||
public static String nameForToken(int paramInt) {
|
||||
String str = "really unknown";
|
||||
switch (paramInt) {
|
||||
case 0:
|
||||
str = "unknown";
|
||||
break;
|
||||
case 1:
|
||||
str = "start";
|
||||
break;
|
||||
case 2:
|
||||
str = "string";
|
||||
break;
|
||||
case 5:
|
||||
str = "EOI";
|
||||
break;
|
||||
case 47:
|
||||
str = "'/'";
|
||||
break;
|
||||
case 59:
|
||||
str = "';'";
|
||||
break;
|
||||
case 61:
|
||||
str = "'='";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public String getCurrentTokenValue() {
|
||||
return this.currentTokenValue;
|
||||
}
|
||||
|
||||
public int nextToken() {
|
||||
if (this.dataIndex < this.dataLength) {
|
||||
while (this.dataIndex < this.dataLength && isWhiteSpaceChar(this.data.charAt(this.dataIndex)))
|
||||
this.dataIndex++;
|
||||
if (this.dataIndex < this.dataLength) {
|
||||
char c = this.data.charAt(this.dataIndex);
|
||||
if (this.isAutoquoting) {
|
||||
if (c == ';' || c == '=') {
|
||||
this.currentToken = c;
|
||||
this.currentTokenValue = new Character(c).toString();
|
||||
this.dataIndex++;
|
||||
} else {
|
||||
processAutoquoteToken();
|
||||
}
|
||||
} else if (isStringTokenChar(c)) {
|
||||
processStringToken();
|
||||
} else if (c == '/' || c == ';' || c == '=') {
|
||||
this.currentToken = c;
|
||||
this.currentTokenValue = new Character(c).toString();
|
||||
this.dataIndex++;
|
||||
} else {
|
||||
this.currentToken = 0;
|
||||
this.currentTokenValue = new Character(c).toString();
|
||||
this.dataIndex++;
|
||||
}
|
||||
} else {
|
||||
this.currentToken = 5;
|
||||
this.currentTokenValue = null;
|
||||
}
|
||||
} else {
|
||||
this.currentToken = 5;
|
||||
this.currentTokenValue = null;
|
||||
}
|
||||
return this.currentToken;
|
||||
}
|
||||
|
||||
private void processStringToken() {
|
||||
int i = this.dataIndex;
|
||||
while (this.dataIndex < this.dataLength && isStringTokenChar(this.data.charAt(this.dataIndex)))
|
||||
this.dataIndex++;
|
||||
this.currentToken = 2;
|
||||
this.currentTokenValue = this.data.substring(i, this.dataIndex);
|
||||
}
|
||||
|
||||
private void processAutoquoteToken() {
|
||||
int i = this.dataIndex;
|
||||
boolean bool = false;
|
||||
while (this.dataIndex < this.dataLength && !bool) {
|
||||
char c = this.data.charAt(this.dataIndex);
|
||||
if (c != this.autoquoteChar) {
|
||||
this.dataIndex++;
|
||||
continue;
|
||||
}
|
||||
bool = true;
|
||||
}
|
||||
this.currentToken = 2;
|
||||
this.currentTokenValue = fixEscapeSequences(this.data.substring(i, this.dataIndex));
|
||||
}
|
||||
|
||||
private static boolean isSpecialChar(char paramChar) {
|
||||
boolean bool = false;
|
||||
switch (paramChar) {
|
||||
case '"':
|
||||
case '(':
|
||||
case ')':
|
||||
case ',':
|
||||
case '/':
|
||||
case ':':
|
||||
case ';':
|
||||
case '<':
|
||||
case '=':
|
||||
case '>':
|
||||
case '?':
|
||||
case '@':
|
||||
case '[':
|
||||
case '\\':
|
||||
case ']':
|
||||
bool = true;
|
||||
break;
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
|
||||
private static boolean isControlChar(char paramChar) {
|
||||
return Character.isISOControl(paramChar);
|
||||
}
|
||||
|
||||
private static boolean isWhiteSpaceChar(char paramChar) {
|
||||
return Character.isWhitespace(paramChar);
|
||||
}
|
||||
|
||||
private static boolean isStringTokenChar(char paramChar) {
|
||||
return (!isSpecialChar(paramChar) && !isControlChar(paramChar) && !isWhiteSpaceChar(paramChar));
|
||||
}
|
||||
|
||||
private static String fixEscapeSequences(String paramString) {
|
||||
int i = paramString.length();
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.ensureCapacity(i);
|
||||
for (int j = 0; j < i; j++) {
|
||||
char c = paramString.charAt(j);
|
||||
if (c != '\\') {
|
||||
stringBuffer.append(c);
|
||||
} else if (j < i - 1) {
|
||||
char c1 = paramString.charAt(j + 1);
|
||||
stringBuffer.append(c1);
|
||||
j++;
|
||||
} else {
|
||||
stringBuffer.append(c);
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.sun.activation.registries;
|
||||
|
||||
public class MimeTypeEntry {
|
||||
private String type;
|
||||
|
||||
private String extension;
|
||||
|
||||
public MimeTypeEntry(String paramString1, String paramString2) {
|
||||
this.type = paramString1;
|
||||
this.extension = paramString2;
|
||||
}
|
||||
|
||||
public String getMIMEType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String getFileExtension() {
|
||||
return this.extension;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "MIMETypeEntry: " + this.type + ", " + this.extension;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
package com.sun.activation.registries;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Hashtable;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class MimeTypeFile {
|
||||
private String fname = null;
|
||||
|
||||
private Hashtable type_hash = new Hashtable();
|
||||
|
||||
public MimeTypeFile(String paramString) throws IOException {
|
||||
File file = null;
|
||||
FileReader fileReader = null;
|
||||
this.fname = paramString;
|
||||
file = new File(this.fname);
|
||||
fileReader = new FileReader(file);
|
||||
try {
|
||||
parse(new BufferedReader(fileReader));
|
||||
} finally {
|
||||
try {
|
||||
fileReader.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
public MimeTypeFile(InputStream paramInputStream) throws IOException {
|
||||
parse(new BufferedReader(new InputStreamReader(paramInputStream, "iso-8859-1")));
|
||||
}
|
||||
|
||||
public MimeTypeFile() {}
|
||||
|
||||
public MimeTypeEntry getMimeTypeEntry(String paramString) {
|
||||
return (MimeTypeEntry)this.type_hash.get(paramString);
|
||||
}
|
||||
|
||||
public String getMIMETypeString(String paramString) {
|
||||
MimeTypeEntry mimeTypeEntry = getMimeTypeEntry(paramString);
|
||||
if (mimeTypeEntry != null)
|
||||
return mimeTypeEntry.getMIMEType();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void appendToRegistry(String paramString) {
|
||||
try {
|
||||
parse(new BufferedReader(new StringReader(paramString)));
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
private void parse(BufferedReader paramBufferedReader) throws IOException {
|
||||
String str1 = null, str2 = null;
|
||||
while ((str1 = paramBufferedReader.readLine()) != null) {
|
||||
if (str2 == null) {
|
||||
str2 = str1;
|
||||
} else {
|
||||
str2 = str2 + str1;
|
||||
}
|
||||
int i = str2.length();
|
||||
if (str2.length() > 0 && str2.charAt(i - 1) == '\\') {
|
||||
str2 = str2.substring(0, i - 1);
|
||||
continue;
|
||||
}
|
||||
parseEntry(str2);
|
||||
str2 = null;
|
||||
}
|
||||
if (str2 != null)
|
||||
parseEntry(str2);
|
||||
}
|
||||
|
||||
private void parseEntry(String paramString) {
|
||||
String str1 = null;
|
||||
String str2 = null;
|
||||
paramString = paramString.trim();
|
||||
if (paramString.length() == 0)
|
||||
return;
|
||||
if (paramString.charAt(0) == '#')
|
||||
return;
|
||||
if (paramString.indexOf('=') > 0) {
|
||||
LineTokenizer lineTokenizer = new LineTokenizer(paramString);
|
||||
while (lineTokenizer.hasMoreTokens()) {
|
||||
String str3 = lineTokenizer.nextToken();
|
||||
String str4 = null;
|
||||
if (lineTokenizer.hasMoreTokens() && lineTokenizer.nextToken().equals("=") && lineTokenizer.hasMoreTokens())
|
||||
str4 = lineTokenizer.nextToken();
|
||||
if (str4 == null) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("Bad .mime.types entry: " + paramString);
|
||||
return;
|
||||
}
|
||||
if (str3.equals("type")) {
|
||||
str1 = str4;
|
||||
continue;
|
||||
}
|
||||
if (str3.equals("exts")) {
|
||||
StringTokenizer stringTokenizer = new StringTokenizer(str4, ",");
|
||||
while (stringTokenizer.hasMoreTokens()) {
|
||||
str2 = stringTokenizer.nextToken();
|
||||
MimeTypeEntry mimeTypeEntry = new MimeTypeEntry(str1, str2);
|
||||
this.type_hash.put(str2, mimeTypeEntry);
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("Added: " + mimeTypeEntry.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
StringTokenizer stringTokenizer = new StringTokenizer(paramString);
|
||||
int i = stringTokenizer.countTokens();
|
||||
if (i == 0)
|
||||
return;
|
||||
str1 = stringTokenizer.nextToken();
|
||||
while (stringTokenizer.hasMoreTokens()) {
|
||||
MimeTypeEntry mimeTypeEntry = null;
|
||||
str2 = stringTokenizer.nextToken();
|
||||
mimeTypeEntry = new MimeTypeEntry(str1, str2);
|
||||
this.type_hash.put(str2, mimeTypeEntry);
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("Added: " + mimeTypeEntry.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.sun.activation.viewers;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Image;
|
||||
import java.awt.MediaTracker;
|
||||
import java.awt.Panel;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.activation.CommandObject;
|
||||
import javax.activation.DataHandler;
|
||||
|
||||
public class ImageViewer extends Panel implements CommandObject {
|
||||
private ImageViewerCanvas canvas = null;
|
||||
|
||||
private Image image = null;
|
||||
|
||||
private DataHandler _dh = null;
|
||||
|
||||
private boolean DEBUG = false;
|
||||
|
||||
public ImageViewer() {
|
||||
this.canvas = new ImageViewerCanvas();
|
||||
add(this.canvas);
|
||||
}
|
||||
|
||||
public void setCommandContext(String paramString, DataHandler paramDataHandler) throws IOException {
|
||||
this._dh = paramDataHandler;
|
||||
setInputStream(this._dh.getInputStream());
|
||||
}
|
||||
|
||||
private void setInputStream(InputStream paramInputStream) throws IOException {
|
||||
MediaTracker mediaTracker = new MediaTracker(this);
|
||||
int i = 0;
|
||||
byte[] arrayOfByte = new byte[1024];
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
while ((i = paramInputStream.read(arrayOfByte)) > 0)
|
||||
byteArrayOutputStream.write(arrayOfByte, 0, i);
|
||||
paramInputStream.close();
|
||||
this.image = getToolkit().createImage(byteArrayOutputStream.toByteArray());
|
||||
mediaTracker.addImage(this.image, 0);
|
||||
try {
|
||||
mediaTracker.waitForID(0);
|
||||
mediaTracker.waitForAll();
|
||||
if (mediaTracker.statusID(0, true) != 8)
|
||||
System.out.println("Error occured in image loading = " + mediaTracker.getErrorsID(0));
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException("Error reading image data");
|
||||
}
|
||||
this.canvas.setImage(this.image);
|
||||
if (this.DEBUG)
|
||||
System.out.println("calling invalidate");
|
||||
}
|
||||
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
invalidate();
|
||||
validate();
|
||||
doLayout();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return this.canvas.getPreferredSize();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.sun.activation.viewers;
|
||||
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
|
||||
public class ImageViewerCanvas extends Canvas {
|
||||
private Image canvas_image = null;
|
||||
|
||||
public void setImage(Image paramImage) {
|
||||
this.canvas_image = paramImage;
|
||||
invalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension dimension = null;
|
||||
if (this.canvas_image == null) {
|
||||
dimension = new Dimension(200, 200);
|
||||
} else {
|
||||
dimension = new Dimension(this.canvas_image.getWidth(this), this.canvas_image.getHeight(this));
|
||||
}
|
||||
return dimension;
|
||||
}
|
||||
|
||||
public void paint(Graphics paramGraphics) {
|
||||
if (this.canvas_image != null)
|
||||
paramGraphics.drawImage(this.canvas_image, 0, 0, this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
package com.sun.activation.viewers;
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Panel;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.activation.CommandObject;
|
||||
import javax.activation.DataHandler;
|
||||
|
||||
public class TextEditor extends Panel implements CommandObject, ActionListener {
|
||||
private TextArea text_area = null;
|
||||
|
||||
private GridBagLayout panel_gb = null;
|
||||
|
||||
private Panel button_panel = null;
|
||||
|
||||
private Button save_button = null;
|
||||
|
||||
private File text_file = null;
|
||||
|
||||
private String text_buffer = null;
|
||||
|
||||
private InputStream data_ins = null;
|
||||
|
||||
private FileInputStream fis = null;
|
||||
|
||||
private DataHandler _dh = null;
|
||||
|
||||
private boolean DEBUG = false;
|
||||
|
||||
public TextEditor() {
|
||||
this.panel_gb = new GridBagLayout();
|
||||
setLayout(this.panel_gb);
|
||||
this.button_panel = new Panel();
|
||||
this.button_panel.setLayout(new FlowLayout());
|
||||
this.save_button = new Button("SAVE");
|
||||
this.button_panel.add(this.save_button);
|
||||
addGridComponent(this, this.button_panel, this.panel_gb, 0, 0, 1, 1, 1, 0);
|
||||
this.text_area = new TextArea("This is text", 24, 80, 1);
|
||||
this.text_area.setEditable(true);
|
||||
addGridComponent(this, this.text_area, this.panel_gb, 0, 1, 1, 2, 1, 1);
|
||||
this.save_button.addActionListener(this);
|
||||
}
|
||||
|
||||
private void addGridComponent(Container paramContainer, Component paramComponent, GridBagLayout paramGridBagLayout, int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6) {
|
||||
GridBagConstraints gridBagConstraints = new GridBagConstraints();
|
||||
gridBagConstraints.gridx = paramInt1;
|
||||
gridBagConstraints.gridy = paramInt2;
|
||||
gridBagConstraints.gridwidth = paramInt3;
|
||||
gridBagConstraints.gridheight = paramInt4;
|
||||
gridBagConstraints.fill = 1;
|
||||
gridBagConstraints.weighty = (double)paramInt6;
|
||||
gridBagConstraints.weightx = (double)paramInt5;
|
||||
gridBagConstraints.anchor = 10;
|
||||
paramGridBagLayout.setConstraints(paramComponent, gridBagConstraints);
|
||||
paramContainer.add(paramComponent);
|
||||
}
|
||||
|
||||
public void setCommandContext(String paramString, DataHandler paramDataHandler) throws IOException {
|
||||
this._dh = paramDataHandler;
|
||||
setInputStream(this._dh.getInputStream());
|
||||
}
|
||||
|
||||
public void setInputStream(InputStream paramInputStream) throws IOException {
|
||||
byte[] arrayOfByte = new byte[1024];
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
int i = 0;
|
||||
while ((i = paramInputStream.read(arrayOfByte)) > 0)
|
||||
byteArrayOutputStream.write(arrayOfByte, 0, i);
|
||||
paramInputStream.close();
|
||||
this.text_buffer = byteArrayOutputStream.toString();
|
||||
this.text_area.setText(this.text_buffer);
|
||||
}
|
||||
|
||||
private void performSaveOperation() {
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
outputStream = this._dh.getOutputStream();
|
||||
} catch (Exception e) {}
|
||||
String str = this.text_area.getText();
|
||||
if (outputStream == null) {
|
||||
System.out.println("Invalid outputstream in TextEditor!");
|
||||
System.out.println("not saving!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
outputStream.write(str.getBytes());
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("TextEditor Save Operation failed with: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return this.text_area.getMinimumSize(24, 80);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent paramActionEvent) {
|
||||
if (paramActionEvent.getSource() == this.save_button)
|
||||
performSaveOperation();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.sun.activation.viewers;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Panel;
|
||||
import java.awt.TextArea;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.activation.CommandObject;
|
||||
import javax.activation.DataHandler;
|
||||
|
||||
public class TextViewer extends Panel implements CommandObject {
|
||||
private TextArea text_area = null;
|
||||
|
||||
private File text_file = null;
|
||||
|
||||
private String text_buffer = null;
|
||||
|
||||
private DataHandler _dh = null;
|
||||
|
||||
private boolean DEBUG = false;
|
||||
|
||||
public TextViewer() {
|
||||
setLayout(new GridLayout(1, 1));
|
||||
this.text_area = new TextArea("", 24, 80, 1);
|
||||
this.text_area.setEditable(false);
|
||||
add(this.text_area);
|
||||
}
|
||||
|
||||
public void setCommandContext(String paramString, DataHandler paramDataHandler) throws IOException {
|
||||
this._dh = paramDataHandler;
|
||||
setInputStream(this._dh.getInputStream());
|
||||
}
|
||||
|
||||
public void setInputStream(InputStream paramInputStream) throws IOException {
|
||||
int i = 0;
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
byte[] arrayOfByte = new byte[1024];
|
||||
while ((i = paramInputStream.read(arrayOfByte)) > 0)
|
||||
byteArrayOutputStream.write(arrayOfByte, 0, i);
|
||||
paramInputStream.close();
|
||||
this.text_buffer = byteArrayOutputStream.toString();
|
||||
this.text_area.setText(this.text_buffer);
|
||||
}
|
||||
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return this.text_area.getMinimumSize(24, 80);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue