first commit
This commit is contained in:
commit
4d332ef662
27586 changed files with 3281783 additions and 0 deletions
|
|
@ -0,0 +1,76 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
|
||||
public class ActivationDataFlavor extends DataFlavor {
|
||||
private String mimeType = null;
|
||||
|
||||
private MimeType mimeObject = null;
|
||||
|
||||
private String humanPresentableName = null;
|
||||
|
||||
private Class representationClass = null;
|
||||
|
||||
public ActivationDataFlavor(Class paramClass, String paramString1, String paramString2) {
|
||||
super(paramString1, paramString2);
|
||||
this.mimeType = paramString1;
|
||||
this.humanPresentableName = paramString2;
|
||||
this.representationClass = paramClass;
|
||||
}
|
||||
|
||||
public ActivationDataFlavor(Class paramClass, String paramString) {
|
||||
super(paramClass, paramString);
|
||||
this.mimeType = super.getMimeType();
|
||||
this.representationClass = paramClass;
|
||||
this.humanPresentableName = paramString;
|
||||
}
|
||||
|
||||
public ActivationDataFlavor(String paramString1, String paramString2) {
|
||||
super(paramString1, paramString2);
|
||||
this.mimeType = paramString1;
|
||||
try {
|
||||
this.representationClass = Class.forName("java.io.InputStream");
|
||||
} catch (ClassNotFoundException e) {}
|
||||
this.humanPresentableName = paramString2;
|
||||
}
|
||||
|
||||
public String getMimeType() {
|
||||
return this.mimeType;
|
||||
}
|
||||
|
||||
public Class getRepresentationClass() {
|
||||
return this.representationClass;
|
||||
}
|
||||
|
||||
public String getHumanPresentableName() {
|
||||
return this.humanPresentableName;
|
||||
}
|
||||
|
||||
public void setHumanPresentableName(String paramString) {
|
||||
this.humanPresentableName = paramString;
|
||||
}
|
||||
|
||||
public boolean equals(DataFlavor paramDataFlavor) {
|
||||
return (isMimeTypeEqual(paramDataFlavor) && paramDataFlavor.getRepresentationClass() == this.representationClass);
|
||||
}
|
||||
|
||||
public boolean isMimeTypeEqual(String paramString) {
|
||||
MimeType mimeType = null;
|
||||
try {
|
||||
if (this.mimeObject == null)
|
||||
this.mimeObject = new MimeType(this.mimeType);
|
||||
mimeType = new MimeType(paramString);
|
||||
} catch (MimeTypeParseException e) {
|
||||
return this.mimeType.equalsIgnoreCase(paramString);
|
||||
}
|
||||
return this.mimeObject.match(mimeType);
|
||||
}
|
||||
|
||||
protected String normalizeMimeTypeParameter(String paramString1, String paramString2) {
|
||||
return paramString2;
|
||||
}
|
||||
|
||||
protected String normalizeMimeType(String paramString) {
|
||||
return paramString;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.beans.Beans;
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
|
||||
public class CommandInfo {
|
||||
private String verb;
|
||||
|
||||
private String className;
|
||||
|
||||
public CommandInfo(String paramString1, String paramString2) {
|
||||
this.verb = paramString1;
|
||||
this.className = paramString2;
|
||||
}
|
||||
|
||||
public String getCommandName() {
|
||||
return this.verb;
|
||||
}
|
||||
|
||||
public String getCommandClass() {
|
||||
return this.className;
|
||||
}
|
||||
|
||||
public Object getCommandObject(DataHandler paramDataHandler, ClassLoader paramClassLoader) throws IOException, ClassNotFoundException {
|
||||
Object object = null;
|
||||
object = Beans.instantiate(paramClassLoader, this.className);
|
||||
if (object != null)
|
||||
if (object instanceof CommandObject) {
|
||||
((CommandObject)object).setCommandContext(this.verb, paramDataHandler);
|
||||
} else if (object instanceof Externalizable &&
|
||||
paramDataHandler != null) {
|
||||
InputStream inputStream = paramDataHandler.getInputStream();
|
||||
if (inputStream != null)
|
||||
((Externalizable)object).readExternal(new ObjectInputStream(inputStream));
|
||||
}
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package javax.activation;
|
||||
|
||||
public abstract class CommandMap {
|
||||
private static CommandMap defaultCommandMap = null;
|
||||
|
||||
public static CommandMap getDefaultCommandMap() {
|
||||
if (defaultCommandMap == null)
|
||||
defaultCommandMap = new MailcapCommandMap();
|
||||
return defaultCommandMap;
|
||||
}
|
||||
|
||||
public static void setDefaultCommandMap(CommandMap paramCommandMap) {
|
||||
SecurityManager securityManager = System.getSecurityManager();
|
||||
if (securityManager != null)
|
||||
try {
|
||||
securityManager.checkSetFactory();
|
||||
} catch (SecurityException e) {
|
||||
if (CommandMap.class.getClassLoader() != paramCommandMap.getClass().getClassLoader())
|
||||
throw e;
|
||||
}
|
||||
defaultCommandMap = paramCommandMap;
|
||||
}
|
||||
|
||||
public CommandInfo[] getPreferredCommands(String paramString, DataSource paramDataSource) {
|
||||
return getPreferredCommands(paramString);
|
||||
}
|
||||
|
||||
public CommandInfo[] getAllCommands(String paramString, DataSource paramDataSource) {
|
||||
return getAllCommands(paramString);
|
||||
}
|
||||
|
||||
public CommandInfo getCommand(String paramString1, String paramString2, DataSource paramDataSource) {
|
||||
return getCommand(paramString1, paramString2);
|
||||
}
|
||||
|
||||
public DataContentHandler createDataContentHandler(String paramString, DataSource paramDataSource) {
|
||||
return createDataContentHandler(paramString);
|
||||
}
|
||||
|
||||
public String[] getMimeTypes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract CommandInfo[] getPreferredCommands(String paramString);
|
||||
|
||||
public abstract CommandInfo[] getAllCommands(String paramString);
|
||||
|
||||
public abstract CommandInfo getCommand(String paramString1, String paramString2);
|
||||
|
||||
public abstract DataContentHandler createDataContentHandler(String paramString);
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface CommandObject {
|
||||
void setCommandContext(String paramString, DataHandler paramDataHandler) throws IOException;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface DataContentHandler {
|
||||
DataFlavor[] getTransferDataFlavors();
|
||||
|
||||
Object getTransferData(DataFlavor paramDataFlavor, DataSource paramDataSource) throws UnsupportedFlavorException, IOException;
|
||||
|
||||
Object getContent(DataSource paramDataSource) throws IOException;
|
||||
|
||||
void writeTo(Object paramObject, String paramString, OutputStream paramOutputStream) throws IOException;
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package javax.activation;
|
||||
|
||||
public interface DataContentHandlerFactory {
|
||||
DataContentHandler createDataContentHandler(String paramString);
|
||||
}
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class DataHandler implements Transferable {
|
||||
private DataSource dataSource = null;
|
||||
|
||||
private DataSource objDataSource = null;
|
||||
|
||||
private Object object = null;
|
||||
|
||||
private String objectMimeType = null;
|
||||
|
||||
private CommandMap currentCommandMap = null;
|
||||
|
||||
private static final DataFlavor[] emptyFlavors = new DataFlavor[0];
|
||||
|
||||
private DataFlavor[] transferFlavors = emptyFlavors;
|
||||
|
||||
private DataContentHandler dataContentHandler = null;
|
||||
|
||||
private DataContentHandler factoryDCH = null;
|
||||
|
||||
private static DataContentHandlerFactory factory = null;
|
||||
|
||||
private DataContentHandlerFactory oldFactory = null;
|
||||
|
||||
private String shortType = null;
|
||||
|
||||
public DataHandler(DataSource paramDataSource) {
|
||||
this.dataSource = paramDataSource;
|
||||
this.oldFactory = factory;
|
||||
}
|
||||
|
||||
public DataHandler(Object paramObject, String paramString) {
|
||||
this.object = paramObject;
|
||||
this.objectMimeType = paramString;
|
||||
this.oldFactory = factory;
|
||||
}
|
||||
|
||||
public DataHandler(URL paramURL) {
|
||||
this.dataSource = new URLDataSource(paramURL);
|
||||
this.oldFactory = factory;
|
||||
}
|
||||
|
||||
private synchronized CommandMap getCommandMap() {
|
||||
if (this.currentCommandMap != null)
|
||||
return this.currentCommandMap;
|
||||
return CommandMap.getDefaultCommandMap();
|
||||
}
|
||||
|
||||
public DataSource getDataSource() {
|
||||
if (this.dataSource == null) {
|
||||
if (this.objDataSource == null)
|
||||
this.objDataSource = new DataHandlerDataSource(this);
|
||||
return this.objDataSource;
|
||||
}
|
||||
return this.dataSource;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (this.dataSource != null)
|
||||
return this.dataSource.getName();
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
if (this.dataSource != null)
|
||||
return this.dataSource.getContentType();
|
||||
return this.objectMimeType;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
InputStream inputStream = null;
|
||||
if (this.dataSource != null) {
|
||||
inputStream = this.dataSource.getInputStream();
|
||||
} else {
|
||||
DataContentHandler dataContentHandler1 = getDataContentHandler();
|
||||
if (dataContentHandler1 == null)
|
||||
throw new UnsupportedDataTypeException("no DCH for MIME type " + getBaseType());
|
||||
if (dataContentHandler1 instanceof ObjectDataContentHandler && (
|
||||
(ObjectDataContentHandler)dataContentHandler1).getDCH() == null)
|
||||
throw new UnsupportedDataTypeException("no object DCH for MIME type " + getBaseType());
|
||||
final DataContentHandler fdch = dataContentHandler1;
|
||||
final PipedOutputStream pos = new PipedOutputStream();
|
||||
PipedInputStream pipedInputStream = new PipedInputStream(pos);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
fdch.writeTo(DataHandler.this.object, DataHandler.this.objectMimeType, pos);
|
||||
} catch (IOException e) {
|
||||
|
||||
} finally {
|
||||
try {
|
||||
pos.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}, "DataHandler.getInputStream").start();
|
||||
inputStream = pipedInputStream;
|
||||
}
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
public void writeTo(OutputStream paramOutputStream) throws IOException {
|
||||
if (this.dataSource != null) {
|
||||
InputStream inputStream = null;
|
||||
byte[] arrayOfByte = new byte[8192];
|
||||
inputStream = this.dataSource.getInputStream();
|
||||
try {
|
||||
int i;
|
||||
while ((i = inputStream.read(arrayOfByte)) > 0)
|
||||
paramOutputStream.write(arrayOfByte, 0, i);
|
||||
} finally {
|
||||
inputStream.close();
|
||||
inputStream = null;
|
||||
}
|
||||
} else {
|
||||
DataContentHandler dataContentHandler = getDataContentHandler();
|
||||
dataContentHandler.writeTo(this.object, this.objectMimeType, paramOutputStream);
|
||||
}
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
if (this.dataSource != null)
|
||||
return this.dataSource.getOutputStream();
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized DataFlavor[] getTransferDataFlavors() {
|
||||
if (factory != this.oldFactory)
|
||||
this.transferFlavors = emptyFlavors;
|
||||
if (this.transferFlavors == emptyFlavors)
|
||||
this.transferFlavors = getDataContentHandler().getTransferDataFlavors();
|
||||
return this.transferFlavors;
|
||||
}
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor paramDataFlavor) {
|
||||
DataFlavor[] arrayOfDataFlavor = getTransferDataFlavors();
|
||||
for (int i = 0; i < arrayOfDataFlavor.length; i++) {
|
||||
if (arrayOfDataFlavor[i].equals(paramDataFlavor))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object getTransferData(DataFlavor paramDataFlavor) throws UnsupportedFlavorException, IOException {
|
||||
return getDataContentHandler().getTransferData(paramDataFlavor, this.dataSource);
|
||||
}
|
||||
|
||||
public synchronized void setCommandMap(CommandMap paramCommandMap) {
|
||||
if (paramCommandMap != this.currentCommandMap || paramCommandMap == null) {
|
||||
this.transferFlavors = emptyFlavors;
|
||||
this.dataContentHandler = null;
|
||||
this.currentCommandMap = paramCommandMap;
|
||||
}
|
||||
}
|
||||
|
||||
public CommandInfo[] getPreferredCommands() {
|
||||
if (this.dataSource != null)
|
||||
return getCommandMap().getPreferredCommands(getBaseType(), this.dataSource);
|
||||
return getCommandMap().getPreferredCommands(getBaseType());
|
||||
}
|
||||
|
||||
public CommandInfo[] getAllCommands() {
|
||||
if (this.dataSource != null)
|
||||
return getCommandMap().getAllCommands(getBaseType(), this.dataSource);
|
||||
return getCommandMap().getAllCommands(getBaseType());
|
||||
}
|
||||
|
||||
public CommandInfo getCommand(String paramString) {
|
||||
if (this.dataSource != null)
|
||||
return getCommandMap().getCommand(getBaseType(), paramString, this.dataSource);
|
||||
return getCommandMap().getCommand(getBaseType(), paramString);
|
||||
}
|
||||
|
||||
public Object getContent() throws IOException {
|
||||
if (this.object != null)
|
||||
return this.object;
|
||||
return getDataContentHandler().getContent(getDataSource());
|
||||
}
|
||||
|
||||
public Object getBean(CommandInfo paramCommandInfo) {
|
||||
Object object = null;
|
||||
try {
|
||||
ClassLoader classLoader = null;
|
||||
classLoader = SecuritySupport.getContextClassLoader();
|
||||
if (classLoader == null)
|
||||
classLoader = getClass().getClassLoader();
|
||||
object = paramCommandInfo.getCommandObject(this, classLoader);
|
||||
} catch (IOException e) {
|
||||
|
||||
} catch (ClassNotFoundException e) {}
|
||||
return object;
|
||||
}
|
||||
|
||||
private synchronized DataContentHandler getDataContentHandler() {
|
||||
if (factory != this.oldFactory) {
|
||||
this.oldFactory = factory;
|
||||
this.factoryDCH = null;
|
||||
this.dataContentHandler = null;
|
||||
this.transferFlavors = emptyFlavors;
|
||||
}
|
||||
if (this.dataContentHandler != null)
|
||||
return this.dataContentHandler;
|
||||
String str = getBaseType();
|
||||
if (this.factoryDCH == null && factory != null)
|
||||
this.factoryDCH = factory.createDataContentHandler(str);
|
||||
if (this.factoryDCH != null)
|
||||
this.dataContentHandler = this.factoryDCH;
|
||||
if (this.dataContentHandler == null)
|
||||
if (this.dataSource != null) {
|
||||
this.dataContentHandler = getCommandMap().createDataContentHandler(str, this.dataSource);
|
||||
} else {
|
||||
this.dataContentHandler = getCommandMap().createDataContentHandler(str);
|
||||
}
|
||||
if (this.dataSource != null) {
|
||||
this.dataContentHandler = new DataSourceDataContentHandler(this.dataContentHandler, this.dataSource);
|
||||
} else {
|
||||
this.dataContentHandler = new ObjectDataContentHandler(this.dataContentHandler, this.object, this.objectMimeType);
|
||||
}
|
||||
return this.dataContentHandler;
|
||||
}
|
||||
|
||||
private synchronized String getBaseType() {
|
||||
if (this.shortType == null) {
|
||||
String str = getContentType();
|
||||
try {
|
||||
MimeType mimeType = new MimeType(str);
|
||||
this.shortType = mimeType.getBaseType();
|
||||
} catch (MimeTypeParseException e) {
|
||||
this.shortType = str;
|
||||
}
|
||||
}
|
||||
return this.shortType;
|
||||
}
|
||||
|
||||
public static synchronized void setDataContentHandlerFactory(DataContentHandlerFactory paramDataContentHandlerFactory) {
|
||||
if (factory != null)
|
||||
throw new Error("DataContentHandlerFactory already defined");
|
||||
SecurityManager securityManager = System.getSecurityManager();
|
||||
if (securityManager != null)
|
||||
try {
|
||||
securityManager.checkSetFactory();
|
||||
} catch (SecurityException e) {
|
||||
if (DataHandler.class.getClassLoader() != paramDataContentHandlerFactory.getClass().getClassLoader())
|
||||
throw e;
|
||||
}
|
||||
factory = paramDataContentHandlerFactory;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
class DataHandlerDataSource implements DataSource {
|
||||
DataHandler dataHandler = null;
|
||||
|
||||
public DataHandlerDataSource(DataHandler paramDataHandler) {
|
||||
this.dataHandler = paramDataHandler;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return this.dataHandler.getInputStream();
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return this.dataHandler.getOutputStream();
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return this.dataHandler.getContentType();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.dataHandler.getName();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface DataSource {
|
||||
InputStream getInputStream() throws IOException;
|
||||
|
||||
OutputStream getOutputStream() throws IOException;
|
||||
|
||||
String getContentType();
|
||||
|
||||
String getName();
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
class DataSourceDataContentHandler implements DataContentHandler {
|
||||
private DataSource ds = null;
|
||||
|
||||
private DataFlavor[] transferFlavors = null;
|
||||
|
||||
private DataContentHandler dch = null;
|
||||
|
||||
public DataSourceDataContentHandler(DataContentHandler paramDataContentHandler, DataSource paramDataSource) {
|
||||
this.ds = paramDataSource;
|
||||
this.dch = paramDataContentHandler;
|
||||
}
|
||||
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
if (this.transferFlavors == null)
|
||||
if (this.dch != null) {
|
||||
this.transferFlavors = this.dch.getTransferDataFlavors();
|
||||
} else {
|
||||
this.transferFlavors = new DataFlavor[1];
|
||||
this.transferFlavors[0] = new ActivationDataFlavor(this.ds.getContentType(), this.ds.getContentType());
|
||||
}
|
||||
return this.transferFlavors;
|
||||
}
|
||||
|
||||
public Object getTransferData(DataFlavor paramDataFlavor, DataSource paramDataSource) throws UnsupportedFlavorException, IOException {
|
||||
if (this.dch != null)
|
||||
return this.dch.getTransferData(paramDataFlavor, paramDataSource);
|
||||
if (paramDataFlavor.equals(getTransferDataFlavors()[0]))
|
||||
return paramDataSource.getInputStream();
|
||||
throw new UnsupportedFlavorException(paramDataFlavor);
|
||||
}
|
||||
|
||||
public Object getContent(DataSource paramDataSource) throws IOException {
|
||||
if (this.dch != null)
|
||||
return this.dch.getContent(paramDataSource);
|
||||
return paramDataSource.getInputStream();
|
||||
}
|
||||
|
||||
public void writeTo(Object paramObject, String paramString, OutputStream paramOutputStream) throws IOException {
|
||||
if (this.dch != null) {
|
||||
this.dch.writeTo(paramObject, paramString, paramOutputStream);
|
||||
} else {
|
||||
throw new UnsupportedDataTypeException("no DCH for content type " + this.ds.getContentType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class FileDataSource implements DataSource {
|
||||
private File _file = null;
|
||||
|
||||
private FileTypeMap typeMap = null;
|
||||
|
||||
public FileDataSource(File paramFile) {
|
||||
this._file = paramFile;
|
||||
}
|
||||
|
||||
public FileDataSource(String paramString) {
|
||||
this(new File(paramString));
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new FileInputStream(this._file);
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return new FileOutputStream(this._file);
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
if (this.typeMap == null)
|
||||
return FileTypeMap.getDefaultFileTypeMap().getContentType(this._file);
|
||||
return this.typeMap.getContentType(this._file);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this._file.getName();
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return this._file;
|
||||
}
|
||||
|
||||
public void setFileTypeMap(FileTypeMap paramFileTypeMap) {
|
||||
this.typeMap = paramFileTypeMap;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class FileTypeMap {
|
||||
private static FileTypeMap defaultMap = null;
|
||||
|
||||
public static void setDefaultFileTypeMap(FileTypeMap paramFileTypeMap) {
|
||||
SecurityManager securityManager = System.getSecurityManager();
|
||||
if (securityManager != null)
|
||||
try {
|
||||
securityManager.checkSetFactory();
|
||||
} catch (SecurityException e) {
|
||||
if (FileTypeMap.class.getClassLoader() != paramFileTypeMap.getClass().getClassLoader())
|
||||
throw e;
|
||||
}
|
||||
defaultMap = paramFileTypeMap;
|
||||
}
|
||||
|
||||
public static FileTypeMap getDefaultFileTypeMap() {
|
||||
if (defaultMap == null)
|
||||
defaultMap = new MimetypesFileTypeMap();
|
||||
return defaultMap;
|
||||
}
|
||||
|
||||
public abstract String getContentType(File paramFile);
|
||||
|
||||
public abstract String getContentType(String paramString);
|
||||
}
|
||||
|
|
@ -0,0 +1,392 @@
|
|||
package javax.activation;
|
||||
|
||||
import com.sun.activation.registries.LogSupport;
|
||||
import com.sun.activation.registries.MailcapFile;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class MailcapCommandMap extends CommandMap {
|
||||
private static MailcapFile defDB = null;
|
||||
|
||||
private MailcapFile[] DB;
|
||||
|
||||
private static final int PROG = 0;
|
||||
|
||||
public MailcapCommandMap() {
|
||||
ArrayList arrayList = new ArrayList(5);
|
||||
MailcapFile mailcapFile = null;
|
||||
arrayList.add(null);
|
||||
LogSupport.log("MailcapCommandMap: load HOME");
|
||||
try {
|
||||
String str = System.getProperty("user.home");
|
||||
if (str != null) {
|
||||
String str1 = str + File.separator + ".mailcap";
|
||||
mailcapFile = loadFile(str1);
|
||||
if (mailcapFile != null)
|
||||
arrayList.add(mailcapFile);
|
||||
}
|
||||
} catch (SecurityException e) {}
|
||||
LogSupport.log("MailcapCommandMap: load SYS");
|
||||
try {
|
||||
String str = System.getProperty("java.home") + File.separator + "lib" + File.separator + "mailcap";
|
||||
mailcapFile = loadFile(str);
|
||||
if (mailcapFile != null)
|
||||
arrayList.add(mailcapFile);
|
||||
} catch (SecurityException e) {}
|
||||
LogSupport.log("MailcapCommandMap: load JAR");
|
||||
loadAllResources(arrayList, "META-INF/mailcap");
|
||||
LogSupport.log("MailcapCommandMap: load DEF");
|
||||
synchronized (MailcapCommandMap.class) {
|
||||
if (defDB == null)
|
||||
defDB = loadResource("/META-INF/mailcap.default");
|
||||
}
|
||||
if (defDB != null)
|
||||
arrayList.add(defDB);
|
||||
this.DB = new MailcapFile[arrayList.size()];
|
||||
this.DB = (MailcapFile[])arrayList.toArray(this.DB);
|
||||
}
|
||||
|
||||
private MailcapFile loadResource(String paramString) {
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = SecuritySupport.getResourceAsStream(getClass(), paramString);
|
||||
if (inputStream != null) {
|
||||
MailcapFile mailcapFile = new MailcapFile(inputStream);
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: successfully loaded mailcap file: " + paramString);
|
||||
return mailcapFile;
|
||||
}
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: not loading mailcap file: " + paramString);
|
||||
} catch (IOException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: can't load " + paramString, e);
|
||||
} catch (SecurityException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: can't load " + paramString, e);
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null)
|
||||
inputStream.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void loadAllResources(List paramList, String paramString) {
|
||||
boolean bool = false;
|
||||
try {
|
||||
URL[] arrayOfURL;
|
||||
ClassLoader classLoader = null;
|
||||
classLoader = SecuritySupport.getContextClassLoader();
|
||||
if (classLoader == null)
|
||||
classLoader = getClass().getClassLoader();
|
||||
if (classLoader != null) {
|
||||
arrayOfURL = SecuritySupport.getResources(classLoader, paramString);
|
||||
} else {
|
||||
arrayOfURL = SecuritySupport.getSystemResources(paramString);
|
||||
}
|
||||
if (arrayOfURL != null) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: getResources");
|
||||
for (int i = 0; i < arrayOfURL.length; i++) {
|
||||
URL uRL = arrayOfURL[i];
|
||||
InputStream inputStream = null;
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: URL " + uRL);
|
||||
try {
|
||||
inputStream = SecuritySupport.openStream(uRL);
|
||||
if (inputStream != null) {
|
||||
paramList.add(new MailcapFile(inputStream));
|
||||
bool = true;
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: successfully loaded mailcap file from URL: " + uRL);
|
||||
} else if (LogSupport.isLoggable()) {
|
||||
LogSupport.log("MailcapCommandMap: not loading mailcap file from URL: " + uRL);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: can't load " + uRL, e);
|
||||
} catch (SecurityException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: can't load " + uRL, e);
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null)
|
||||
inputStream.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: can't load " + paramString, e);
|
||||
}
|
||||
if (!bool) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: !anyLoaded");
|
||||
MailcapFile mailcapFile = loadResource("/" + paramString);
|
||||
if (mailcapFile != null)
|
||||
paramList.add(mailcapFile);
|
||||
}
|
||||
}
|
||||
|
||||
private MailcapFile loadFile(String paramString) {
|
||||
MailcapFile mailcapFile = null;
|
||||
try {
|
||||
mailcapFile = new MailcapFile(paramString);
|
||||
} catch (IOException e) {}
|
||||
return mailcapFile;
|
||||
}
|
||||
|
||||
public MailcapCommandMap(String paramString) throws IOException {
|
||||
this();
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: load PROG from " + paramString);
|
||||
if (this.DB[0] == null)
|
||||
this.DB[0] = new MailcapFile(paramString);
|
||||
}
|
||||
|
||||
public MailcapCommandMap(InputStream paramInputStream) {
|
||||
this();
|
||||
LogSupport.log("MailcapCommandMap: load PROG");
|
||||
if (this.DB[0] == null)
|
||||
try {
|
||||
this.DB[0] = new MailcapFile(paramInputStream);
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
public synchronized CommandInfo[] getPreferredCommands(String paramString) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
if (paramString != null)
|
||||
paramString = paramString.toLowerCase(Locale.ENGLISH);
|
||||
for (int j = 0; j < this.DB.length; j++) {
|
||||
if (this.DB[j] != null) {
|
||||
Map map = this.DB[j].getMailcapList(paramString);
|
||||
if (map != null)
|
||||
appendPrefCmdsToList(map, arrayList);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < this.DB.length; i++) {
|
||||
if (this.DB[i] != null) {
|
||||
Map map = this.DB[i].getMailcapFallbackList(paramString);
|
||||
if (map != null)
|
||||
appendPrefCmdsToList(map, arrayList);
|
||||
}
|
||||
}
|
||||
CommandInfo[] arrayOfCommandInfo = new CommandInfo[arrayList.size()];
|
||||
arrayOfCommandInfo = (CommandInfo[])arrayList.toArray(arrayOfCommandInfo);
|
||||
return arrayOfCommandInfo;
|
||||
}
|
||||
|
||||
private void appendPrefCmdsToList(Map paramMap, List paramList) {
|
||||
Iterator iterator = paramMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String str = (String)iterator.next();
|
||||
if (!checkForVerb(paramList, str)) {
|
||||
List list = (List)paramMap.get(str);
|
||||
String str1 = (String)list.get(0);
|
||||
paramList.add(new CommandInfo(str, str1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkForVerb(List paramList, String paramString) {
|
||||
Iterator iterator = paramList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String str = ((CommandInfo)iterator.next()).getCommandName();
|
||||
if (str.equals(paramString))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized CommandInfo[] getAllCommands(String paramString) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
if (paramString != null)
|
||||
paramString = paramString.toLowerCase(Locale.ENGLISH);
|
||||
for (int j = 0; j < this.DB.length; j++) {
|
||||
if (this.DB[j] != null) {
|
||||
Map map = this.DB[j].getMailcapList(paramString);
|
||||
if (map != null)
|
||||
appendCmdsToList(map, arrayList);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < this.DB.length; i++) {
|
||||
if (this.DB[i] != null) {
|
||||
Map map = this.DB[i].getMailcapFallbackList(paramString);
|
||||
if (map != null)
|
||||
appendCmdsToList(map, arrayList);
|
||||
}
|
||||
}
|
||||
CommandInfo[] arrayOfCommandInfo = new CommandInfo[arrayList.size()];
|
||||
arrayOfCommandInfo = (CommandInfo[])arrayList.toArray(arrayOfCommandInfo);
|
||||
return arrayOfCommandInfo;
|
||||
}
|
||||
|
||||
private void appendCmdsToList(Map paramMap, List paramList) {
|
||||
Iterator iterator = paramMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String str = (String)iterator.next();
|
||||
List list = (List)paramMap.get(str);
|
||||
Iterator iterator1 = list.iterator();
|
||||
while (iterator1.hasNext()) {
|
||||
String str1 = (String)iterator1.next();
|
||||
paramList.add(new CommandInfo(str, str1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized CommandInfo getCommand(String paramString1, String paramString2) {
|
||||
if (paramString1 != null)
|
||||
paramString1 = paramString1.toLowerCase(Locale.ENGLISH);
|
||||
for (int j = 0; j < this.DB.length; j++) {
|
||||
if (this.DB[j] != null) {
|
||||
Map map = this.DB[j].getMailcapList(paramString1);
|
||||
if (map != null) {
|
||||
List list = (List)map.get(paramString2);
|
||||
if (list != null) {
|
||||
String str = (String)list.get(0);
|
||||
if (str != null)
|
||||
return new CommandInfo(paramString2, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < this.DB.length; i++) {
|
||||
if (this.DB[i] != null) {
|
||||
Map map = this.DB[i].getMailcapFallbackList(paramString1);
|
||||
if (map != null) {
|
||||
List list = (List)map.get(paramString2);
|
||||
if (list != null) {
|
||||
String str = (String)list.get(0);
|
||||
if (str != null)
|
||||
return new CommandInfo(paramString2, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized void addMailcap(String paramString) {
|
||||
LogSupport.log("MailcapCommandMap: add to PROG");
|
||||
if (this.DB[0] == null)
|
||||
this.DB[0] = new MailcapFile();
|
||||
this.DB[0].appendToMailcap(paramString);
|
||||
}
|
||||
|
||||
public synchronized DataContentHandler createDataContentHandler(String paramString) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MailcapCommandMap: createDataContentHandler for " + paramString);
|
||||
if (paramString != null)
|
||||
paramString = paramString.toLowerCase(Locale.ENGLISH);
|
||||
for (int j = 0; j < this.DB.length; j++) {
|
||||
if (this.DB[j] != null) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log(" search DB #" + j);
|
||||
Map map = this.DB[j].getMailcapList(paramString);
|
||||
if (map != null) {
|
||||
List list = (List)map.get("content-handler");
|
||||
if (list != null) {
|
||||
String str = (String)list.get(0);
|
||||
DataContentHandler dataContentHandler = getDataContentHandler(str);
|
||||
if (dataContentHandler != null)
|
||||
return dataContentHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < this.DB.length; i++) {
|
||||
if (this.DB[i] != null) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log(" search fallback DB #" + i);
|
||||
Map map = this.DB[i].getMailcapFallbackList(paramString);
|
||||
if (map != null) {
|
||||
List list = (List)map.get("content-handler");
|
||||
if (list != null) {
|
||||
String str = (String)list.get(0);
|
||||
DataContentHandler dataContentHandler = getDataContentHandler(str);
|
||||
if (dataContentHandler != null)
|
||||
return dataContentHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private DataContentHandler getDataContentHandler(String paramString) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log(" got content-handler");
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log(" class " + paramString);
|
||||
try {
|
||||
ClassLoader classLoader = null;
|
||||
classLoader = SecuritySupport.getContextClassLoader();
|
||||
if (classLoader == null)
|
||||
classLoader = getClass().getClassLoader();
|
||||
Class clazz = null;
|
||||
try {
|
||||
clazz = classLoader.loadClass(paramString);
|
||||
} catch (Exception e) {
|
||||
clazz = Class.forName(paramString);
|
||||
}
|
||||
if (clazz != null)
|
||||
return (DataContentHandler)clazz.newInstance();
|
||||
} catch (IllegalAccessException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("Can't load DCH " + paramString, e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("Can't load DCH " + paramString, e);
|
||||
} catch (InstantiationException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("Can't load DCH " + paramString, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized String[] getMimeTypes() {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
for (int i = 0; i < this.DB.length; i++) {
|
||||
if (this.DB[i] != null) {
|
||||
String[] arrayOfString1 = this.DB[i].getMimeTypes();
|
||||
if (arrayOfString1 != null)
|
||||
for (int j = 0; j < arrayOfString1.length; j++) {
|
||||
if (!arrayList.contains(arrayOfString1[j]))
|
||||
arrayList.add(arrayOfString1[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] arrayOfString = new String[arrayList.size()];
|
||||
arrayOfString = (String[])arrayList.toArray(arrayOfString);
|
||||
return arrayOfString;
|
||||
}
|
||||
|
||||
public synchronized String[] getNativeCommands(String paramString) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
if (paramString != null)
|
||||
paramString = paramString.toLowerCase(Locale.ENGLISH);
|
||||
for (int i = 0; i < this.DB.length; i++) {
|
||||
if (this.DB[i] != null) {
|
||||
String[] arrayOfString1 = this.DB[i].getNativeCommands(paramString);
|
||||
if (arrayOfString1 != null)
|
||||
for (int j = 0; j < arrayOfString1.length; j++) {
|
||||
if (!arrayList.contains(arrayOfString1[j]))
|
||||
arrayList.add(arrayOfString1[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] arrayOfString = new String[arrayList.size()];
|
||||
arrayOfString = (String[])arrayList.toArray(arrayOfString);
|
||||
return arrayOfString;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.util.Locale;
|
||||
|
||||
public class MimeType implements Externalizable {
|
||||
private String primaryType;
|
||||
|
||||
private String subType;
|
||||
|
||||
private MimeTypeParameterList parameters;
|
||||
|
||||
private static final String TSPECIALS = "()<>@,;:/[]?=\\\"";
|
||||
|
||||
public MimeType() {
|
||||
this.primaryType = "application";
|
||||
this.subType = "*";
|
||||
this.parameters = new MimeTypeParameterList();
|
||||
}
|
||||
|
||||
public MimeType(String paramString) throws MimeTypeParseException {
|
||||
parse(paramString);
|
||||
}
|
||||
|
||||
public MimeType(String paramString1, String paramString2) throws MimeTypeParseException {
|
||||
if (isValidToken(paramString1)) {
|
||||
this.primaryType = paramString1.toLowerCase(Locale.ENGLISH);
|
||||
} else {
|
||||
throw new MimeTypeParseException("Primary type is invalid.");
|
||||
}
|
||||
if (isValidToken(paramString2)) {
|
||||
this.subType = paramString2.toLowerCase(Locale.ENGLISH);
|
||||
} else {
|
||||
throw new MimeTypeParseException("Sub type is invalid.");
|
||||
}
|
||||
this.parameters = new MimeTypeParameterList();
|
||||
}
|
||||
|
||||
private void parse(String paramString) throws MimeTypeParseException {
|
||||
int i = paramString.indexOf('/');
|
||||
int j = paramString.indexOf(';');
|
||||
if (i < 0 && j < 0)
|
||||
throw new MimeTypeParseException("Unable to find a sub type.");
|
||||
if (i < 0 && j >= 0)
|
||||
throw new MimeTypeParseException("Unable to find a sub type.");
|
||||
if (i >= 0 && j < 0) {
|
||||
this.primaryType = paramString.substring(0, i).trim().toLowerCase(Locale.ENGLISH);
|
||||
this.subType = paramString.substring(i + 1).trim().toLowerCase(Locale.ENGLISH);
|
||||
this.parameters = new MimeTypeParameterList();
|
||||
} else if (i < j) {
|
||||
this.primaryType = paramString.substring(0, i).trim().toLowerCase(Locale.ENGLISH);
|
||||
this.subType = paramString.substring(i + 1, j).trim().toLowerCase(Locale.ENGLISH);
|
||||
this.parameters = new MimeTypeParameterList(paramString.substring(j));
|
||||
} else {
|
||||
throw new MimeTypeParseException("Unable to find a sub type.");
|
||||
}
|
||||
if (!isValidToken(this.primaryType))
|
||||
throw new MimeTypeParseException("Primary type is invalid.");
|
||||
if (!isValidToken(this.subType))
|
||||
throw new MimeTypeParseException("Sub type is invalid.");
|
||||
}
|
||||
|
||||
public String getPrimaryType() {
|
||||
return this.primaryType;
|
||||
}
|
||||
|
||||
public void setPrimaryType(String paramString) throws MimeTypeParseException {
|
||||
if (!isValidToken(this.primaryType))
|
||||
throw new MimeTypeParseException("Primary type is invalid.");
|
||||
this.primaryType = paramString.toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public String getSubType() {
|
||||
return this.subType;
|
||||
}
|
||||
|
||||
public void setSubType(String paramString) throws MimeTypeParseException {
|
||||
if (!isValidToken(this.subType))
|
||||
throw new MimeTypeParseException("Sub type is invalid.");
|
||||
this.subType = paramString.toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public MimeTypeParameterList getParameters() {
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
public String getParameter(String paramString) {
|
||||
return this.parameters.get(paramString);
|
||||
}
|
||||
|
||||
public void setParameter(String paramString1, String paramString2) {
|
||||
this.parameters.set(paramString1, paramString2);
|
||||
}
|
||||
|
||||
public void removeParameter(String paramString) {
|
||||
this.parameters.remove(paramString);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getBaseType() + this.parameters.toString();
|
||||
}
|
||||
|
||||
public String getBaseType() {
|
||||
return this.primaryType + "/" + this.subType;
|
||||
}
|
||||
|
||||
public boolean match(MimeType paramMimeType) {
|
||||
return (this.primaryType.equals(paramMimeType.getPrimaryType()) && (this.subType.equals("*") || paramMimeType.getSubType().equals("*") || this.subType.equals(paramMimeType.getSubType())));
|
||||
}
|
||||
|
||||
public boolean match(String paramString) throws MimeTypeParseException {
|
||||
return match(new MimeType(paramString));
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput paramObjectOutput) throws IOException {
|
||||
paramObjectOutput.writeUTF(toString());
|
||||
paramObjectOutput.flush();
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput paramObjectInput) throws IOException, ClassNotFoundException {
|
||||
try {
|
||||
parse(paramObjectInput.readUTF());
|
||||
} catch (MimeTypeParseException e) {
|
||||
throw new IOException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isTokenChar(char paramChar) {
|
||||
return (paramChar > ' ' && paramChar < '\u007F' && "()<>@,;:/[]?=\\\"".indexOf(paramChar) < 0);
|
||||
}
|
||||
|
||||
private boolean isValidToken(String paramString) {
|
||||
int i = paramString.length();
|
||||
if (i > 0) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
char c = paramString.charAt(j);
|
||||
if (!isTokenChar(c))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
|
||||
public class MimeTypeParameterList {
|
||||
private Hashtable parameters;
|
||||
|
||||
private static final String TSPECIALS = "()<>@,;:/[]?=\\\"";
|
||||
|
||||
public MimeTypeParameterList() {
|
||||
this.parameters = new Hashtable();
|
||||
}
|
||||
|
||||
public MimeTypeParameterList(String paramString) throws MimeTypeParseException {
|
||||
this.parameters = new Hashtable();
|
||||
parse(paramString);
|
||||
}
|
||||
|
||||
protected void parse(String paramString) throws MimeTypeParseException {
|
||||
if (paramString == null)
|
||||
return;
|
||||
int i = paramString.length();
|
||||
if (i <= 0)
|
||||
return;
|
||||
int j = skipWhiteSpace(paramString, 0);
|
||||
char c;
|
||||
for (; j < i && (c = paramString.charAt(j)) == ';';
|
||||
j = skipWhiteSpace(paramString, j)) {
|
||||
String str2;
|
||||
j++;
|
||||
j = skipWhiteSpace(paramString, j);
|
||||
if (j >= i)
|
||||
return;
|
||||
int k = j;
|
||||
while (j < i && isTokenChar(paramString.charAt(j)))
|
||||
j++;
|
||||
String str1 = paramString.substring(k, j).toLowerCase(Locale.ENGLISH);
|
||||
j = skipWhiteSpace(paramString, j);
|
||||
if (j >= i || paramString.charAt(j) != '=')
|
||||
throw new MimeTypeParseException("Couldn't find the '=' that separates a parameter name from its value.");
|
||||
j++;
|
||||
j = skipWhiteSpace(paramString, j);
|
||||
if (j >= i)
|
||||
throw new MimeTypeParseException("Couldn't find a value for parameter named " + str1);
|
||||
c = paramString.charAt(j);
|
||||
if (c == '"') {
|
||||
j++;
|
||||
if (j >= i)
|
||||
throw new MimeTypeParseException("Encountered unterminated quoted parameter value.");
|
||||
k = j;
|
||||
while (j < i) {
|
||||
c = paramString.charAt(j);
|
||||
if (c == '"')
|
||||
break;
|
||||
if (c == '\\')
|
||||
j++;
|
||||
j++;
|
||||
}
|
||||
if (c != '"')
|
||||
throw new MimeTypeParseException("Encountered unterminated quoted parameter value.");
|
||||
str2 = unquote(paramString.substring(k, j));
|
||||
j++;
|
||||
} else if (isTokenChar(c)) {
|
||||
k = j;
|
||||
while (j < i && isTokenChar(paramString.charAt(j)))
|
||||
j++;
|
||||
str2 = paramString.substring(k, j);
|
||||
} else {
|
||||
throw new MimeTypeParseException("Unexpected character encountered at index " + j);
|
||||
}
|
||||
this.parameters.put(str1, str2);
|
||||
}
|
||||
if (j < i)
|
||||
throw new MimeTypeParseException("More characters encountered in input than expected.");
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.parameters.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.parameters.isEmpty();
|
||||
}
|
||||
|
||||
public String get(String paramString) {
|
||||
return (String)this.parameters.get(paramString.trim().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
public void set(String paramString1, String paramString2) {
|
||||
this.parameters.put(paramString1.trim().toLowerCase(Locale.ENGLISH), paramString2);
|
||||
}
|
||||
|
||||
public void remove(String paramString) {
|
||||
this.parameters.remove(paramString.trim().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
public Enumeration getNames() {
|
||||
return this.parameters.keys();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.ensureCapacity(this.parameters.size() * 16);
|
||||
Enumeration enumeration = this.parameters.keys();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
String str = (String)enumeration.nextElement();
|
||||
stringBuffer.append("; ");
|
||||
stringBuffer.append(str);
|
||||
stringBuffer.append('=');
|
||||
stringBuffer.append(quote((String)this.parameters.get(str)));
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
private static boolean isTokenChar(char paramChar) {
|
||||
return (paramChar > ' ' && paramChar < '\u007F' && "()<>@,;:/[]?=\\\"".indexOf(paramChar) < 0);
|
||||
}
|
||||
|
||||
private static int skipWhiteSpace(String paramString, int paramInt) {
|
||||
int i = paramString.length();
|
||||
while (paramInt < i && Character.isWhitespace(paramString.charAt(paramInt)))
|
||||
paramInt++;
|
||||
return paramInt;
|
||||
}
|
||||
|
||||
private static String quote(String paramString) {
|
||||
boolean bool = false;
|
||||
int i = paramString.length();
|
||||
for (int j = 0; j < i && !bool; j++)
|
||||
bool = !isTokenChar(paramString.charAt(j)) ? true : false;
|
||||
if (bool) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.ensureCapacity((int)((double)i * 1.5D));
|
||||
stringBuffer.append('"');
|
||||
for (int k = 0; k < i; k++) {
|
||||
char c = paramString.charAt(k);
|
||||
if (c == '\\' || c == '"')
|
||||
stringBuffer.append('\\');
|
||||
stringBuffer.append(c);
|
||||
}
|
||||
stringBuffer.append('"');
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
return paramString;
|
||||
}
|
||||
|
||||
private static String unquote(String paramString) {
|
||||
int i = paramString.length();
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.ensureCapacity(i);
|
||||
boolean bool = false;
|
||||
for (int j = 0; j < i; j++) {
|
||||
char c = paramString.charAt(j);
|
||||
if (!bool && c != '\\') {
|
||||
stringBuffer.append(c);
|
||||
} else if (bool) {
|
||||
stringBuffer.append(c);
|
||||
bool = false;
|
||||
} else {
|
||||
bool = true;
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package javax.activation;
|
||||
|
||||
public class MimeTypeParseException extends Exception {
|
||||
public MimeTypeParseException() {}
|
||||
|
||||
public MimeTypeParseException(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
package javax.activation;
|
||||
|
||||
import com.sun.activation.registries.LogSupport;
|
||||
import com.sun.activation.registries.MimeTypeFile;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Vector;
|
||||
|
||||
public class MimetypesFileTypeMap extends FileTypeMap {
|
||||
private static MimeTypeFile defDB = null;
|
||||
|
||||
private MimeTypeFile[] DB;
|
||||
|
||||
private static final int PROG = 0;
|
||||
|
||||
private static String defaultType = "application/octet-stream";
|
||||
|
||||
public MimetypesFileTypeMap() {
|
||||
Vector vector = new Vector(5);
|
||||
MimeTypeFile mimeTypeFile = null;
|
||||
vector.addElement(null);
|
||||
LogSupport.log("MimetypesFileTypeMap: load HOME");
|
||||
try {
|
||||
String str = System.getProperty("user.home");
|
||||
if (str != null) {
|
||||
String str1 = str + File.separator + ".mime.types";
|
||||
mimeTypeFile = loadFile(str1);
|
||||
if (mimeTypeFile != null)
|
||||
vector.addElement(mimeTypeFile);
|
||||
}
|
||||
} catch (SecurityException e) {}
|
||||
LogSupport.log("MimetypesFileTypeMap: load SYS");
|
||||
try {
|
||||
String str = System.getProperty("java.home") + File.separator + "lib" + File.separator + "mime.types";
|
||||
mimeTypeFile = loadFile(str);
|
||||
if (mimeTypeFile != null)
|
||||
vector.addElement(mimeTypeFile);
|
||||
} catch (SecurityException e) {}
|
||||
LogSupport.log("MimetypesFileTypeMap: load JAR");
|
||||
loadAllResources(vector, "META-INF/mime.types");
|
||||
LogSupport.log("MimetypesFileTypeMap: load DEF");
|
||||
synchronized (MimetypesFileTypeMap.class) {
|
||||
if (defDB == null)
|
||||
defDB = loadResource("/META-INF/mimetypes.default");
|
||||
}
|
||||
if (defDB != null)
|
||||
vector.addElement(defDB);
|
||||
this.DB = new MimeTypeFile[vector.size()];
|
||||
vector.copyInto(this.DB);
|
||||
}
|
||||
|
||||
private MimeTypeFile loadResource(String paramString) {
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = SecuritySupport.getResourceAsStream(getClass(), paramString);
|
||||
if (inputStream != null) {
|
||||
MimeTypeFile mimeTypeFile = new MimeTypeFile(inputStream);
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: successfully loaded mime types file: " + paramString);
|
||||
return mimeTypeFile;
|
||||
}
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: not loading mime types file: " + paramString);
|
||||
} catch (IOException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: can't load " + paramString, e);
|
||||
} catch (SecurityException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: can't load " + paramString, e);
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null)
|
||||
inputStream.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void loadAllResources(Vector paramVector, String paramString) {
|
||||
boolean bool = false;
|
||||
try {
|
||||
URL[] arrayOfURL;
|
||||
ClassLoader classLoader = null;
|
||||
classLoader = SecuritySupport.getContextClassLoader();
|
||||
if (classLoader == null)
|
||||
classLoader = getClass().getClassLoader();
|
||||
if (classLoader != null) {
|
||||
arrayOfURL = SecuritySupport.getResources(classLoader, paramString);
|
||||
} else {
|
||||
arrayOfURL = SecuritySupport.getSystemResources(paramString);
|
||||
}
|
||||
if (arrayOfURL != null) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: getResources");
|
||||
for (int i = 0; i < arrayOfURL.length; i++) {
|
||||
URL uRL = arrayOfURL[i];
|
||||
InputStream inputStream = null;
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: URL " + uRL);
|
||||
try {
|
||||
inputStream = SecuritySupport.openStream(uRL);
|
||||
if (inputStream != null) {
|
||||
paramVector.addElement(new MimeTypeFile(inputStream));
|
||||
bool = true;
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: successfully loaded mime types from URL: " + uRL);
|
||||
} else if (LogSupport.isLoggable()) {
|
||||
LogSupport.log("MimetypesFileTypeMap: not loading mime types from URL: " + uRL);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: can't load " + uRL, e);
|
||||
} catch (SecurityException e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: can't load " + uRL, e);
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null)
|
||||
inputStream.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (LogSupport.isLoggable())
|
||||
LogSupport.log("MimetypesFileTypeMap: can't load " + paramString, e);
|
||||
}
|
||||
if (!bool) {
|
||||
LogSupport.log("MimetypesFileTypeMap: !anyLoaded");
|
||||
MimeTypeFile mimeTypeFile = loadResource("/" + paramString);
|
||||
if (mimeTypeFile != null)
|
||||
paramVector.addElement(mimeTypeFile);
|
||||
}
|
||||
}
|
||||
|
||||
private MimeTypeFile loadFile(String paramString) {
|
||||
MimeTypeFile mimeTypeFile = null;
|
||||
try {
|
||||
mimeTypeFile = new MimeTypeFile(paramString);
|
||||
} catch (IOException e) {}
|
||||
return mimeTypeFile;
|
||||
}
|
||||
|
||||
public MimetypesFileTypeMap(String paramString) throws IOException {
|
||||
this();
|
||||
this.DB[0] = new MimeTypeFile(paramString);
|
||||
}
|
||||
|
||||
public MimetypesFileTypeMap(InputStream paramInputStream) {
|
||||
this();
|
||||
try {
|
||||
this.DB[0] = new MimeTypeFile(paramInputStream);
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
public synchronized void addMimeTypes(String paramString) {
|
||||
if (this.DB[0] == null)
|
||||
this.DB[0] = new MimeTypeFile();
|
||||
this.DB[0].appendToRegistry(paramString);
|
||||
}
|
||||
|
||||
public String getContentType(File paramFile) {
|
||||
return getContentType(paramFile.getName());
|
||||
}
|
||||
|
||||
public synchronized String getContentType(String paramString) {
|
||||
int i = paramString.lastIndexOf(".");
|
||||
if (i < 0)
|
||||
return defaultType;
|
||||
String str = paramString.substring(i + 1);
|
||||
if (str.length() == 0)
|
||||
return defaultType;
|
||||
for (int j = 0; j < this.DB.length; j++) {
|
||||
if (this.DB[j] != null) {
|
||||
String str1 = this.DB[j].getMIMETypeString(str);
|
||||
if (str1 != null)
|
||||
return str1;
|
||||
}
|
||||
}
|
||||
return defaultType;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
class ObjectDataContentHandler implements DataContentHandler {
|
||||
private DataFlavor[] transferFlavors = null;
|
||||
|
||||
private Object obj;
|
||||
|
||||
private String mimeType;
|
||||
|
||||
private DataContentHandler dch = null;
|
||||
|
||||
public ObjectDataContentHandler(DataContentHandler paramDataContentHandler, Object paramObject, String paramString) {
|
||||
this.obj = paramObject;
|
||||
this.mimeType = paramString;
|
||||
this.dch = paramDataContentHandler;
|
||||
}
|
||||
|
||||
public DataContentHandler getDCH() {
|
||||
return this.dch;
|
||||
}
|
||||
|
||||
public synchronized DataFlavor[] getTransferDataFlavors() {
|
||||
if (this.transferFlavors == null)
|
||||
if (this.dch != null) {
|
||||
this.transferFlavors = this.dch.getTransferDataFlavors();
|
||||
} else {
|
||||
this.transferFlavors = new DataFlavor[1];
|
||||
this.transferFlavors[0] = new ActivationDataFlavor(this.obj.getClass(), this.mimeType, this.mimeType);
|
||||
}
|
||||
return this.transferFlavors;
|
||||
}
|
||||
|
||||
public Object getTransferData(DataFlavor paramDataFlavor, DataSource paramDataSource) throws UnsupportedFlavorException, IOException {
|
||||
if (this.dch != null)
|
||||
return this.dch.getTransferData(paramDataFlavor, paramDataSource);
|
||||
if (paramDataFlavor.equals(getTransferDataFlavors()[0]))
|
||||
return this.obj;
|
||||
throw new UnsupportedFlavorException(paramDataFlavor);
|
||||
}
|
||||
|
||||
public Object getContent(DataSource paramDataSource) {
|
||||
return this.obj;
|
||||
}
|
||||
|
||||
public void writeTo(Object paramObject, String paramString, OutputStream paramOutputStream) throws IOException {
|
||||
if (this.dch != null) {
|
||||
this.dch.writeTo(paramObject, paramString, paramOutputStream);
|
||||
} else if (paramObject instanceof byte[]) {
|
||||
paramOutputStream.write((byte[])paramObject);
|
||||
} else if (paramObject instanceof String) {
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(paramOutputStream);
|
||||
outputStreamWriter.write((String)paramObject);
|
||||
outputStreamWriter.flush();
|
||||
} else {
|
||||
throw new UnsupportedDataTypeException("no object DCH for MIME type " + this.mimeType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
|
||||
class SecuritySupport {
|
||||
public static ClassLoader getContextClassLoader() {
|
||||
return (ClassLoader)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader classLoader = null;
|
||||
try {
|
||||
classLoader = Thread.currentThread().getContextClassLoader();
|
||||
} catch (SecurityException e) {}
|
||||
return classLoader;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static InputStream getResourceAsStream(final Class c, final String name) throws IOException {
|
||||
try {
|
||||
return (InputStream)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws IOException {
|
||||
return c.getResourceAsStream(name);
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (IOException)e.getException();
|
||||
}
|
||||
}
|
||||
|
||||
public static URL[] getResources(final ClassLoader cl, final String name) {
|
||||
return (URL[])AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
URL[] arrayOfURL = null;
|
||||
try {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
Enumeration enumeration = cl.getResources(name);
|
||||
while (enumeration != null && enumeration.hasMoreElements()) {
|
||||
URL uRL = (URL)enumeration.nextElement();
|
||||
if (uRL != null)
|
||||
arrayList.add(uRL);
|
||||
}
|
||||
if (arrayList.size() > 0) {
|
||||
arrayOfURL = new URL[arrayList.size()];
|
||||
arrayOfURL = (URL[])arrayList.toArray(arrayOfURL);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
} catch (SecurityException e) {}
|
||||
return arrayOfURL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static URL[] getSystemResources(final String name) {
|
||||
return (URL[])AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
URL[] arrayOfURL = null;
|
||||
try {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
Enumeration enumeration = ClassLoader.getSystemResources(name);
|
||||
while (enumeration != null && enumeration.hasMoreElements()) {
|
||||
URL uRL = (URL)enumeration.nextElement();
|
||||
if (uRL != null)
|
||||
arrayList.add(uRL);
|
||||
}
|
||||
if (arrayList.size() > 0) {
|
||||
arrayOfURL = new URL[arrayList.size()];
|
||||
arrayOfURL = (URL[])arrayList.toArray(arrayOfURL);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
} catch (SecurityException e) {}
|
||||
return arrayOfURL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static InputStream openStream(final URL url) throws IOException {
|
||||
try {
|
||||
return (InputStream)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws IOException {
|
||||
return url.openStream();
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (IOException)e.getException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class URLDataSource implements DataSource {
|
||||
private URL url = null;
|
||||
|
||||
private URLConnection url_conn = null;
|
||||
|
||||
public URLDataSource(URL paramURL) {
|
||||
this.url = paramURL;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
String str = null;
|
||||
try {
|
||||
if (this.url_conn == null)
|
||||
this.url_conn = this.url.openConnection();
|
||||
} catch (IOException e) {}
|
||||
if (this.url_conn != null)
|
||||
str = this.url_conn.getContentType();
|
||||
if (str == null)
|
||||
str = "application/octet-stream";
|
||||
return str;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.url.getFile();
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return this.url.openStream();
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
this.url_conn = this.url.openConnection();
|
||||
if (this.url_conn != null) {
|
||||
this.url_conn.setDoOutput(true);
|
||||
return this.url_conn.getOutputStream();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public URL getURL() {
|
||||
return this.url;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package javax.activation;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnsupportedDataTypeException extends IOException {
|
||||
public UnsupportedDataTypeException() {}
|
||||
|
||||
public UnsupportedDataTypeException(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue