javax.activation_1.1.0.v201108011116

16:37:05.644 INFO  jd.cli.Main - Decompiling javax.activation_1.1.0.v201108011116.jar
package javax.activation;

import java.awt.datatransfer.DataFlavor;
import java.io.InputStream;

public class ActivationDataFlavor
  extends DataFlavor
{
  private final Class representationClass;
  private final String mimeType;
  private String humanPresentableName;
  
  public ActivationDataFlavor(Class representationClass, String mimeType, String humanPresentableName)
  {
    this.representationClass = representationClass;
    this.mimeType = mimeType;
    this.humanPresentableName = humanPresentableName;
  }
  
  public ActivationDataFlavor(Class representationClass, String humanPresentableName)
  {
    this.representationClass = representationClass;
    mimeType = "application/x-java-serialized-object";
    this.humanPresentableName = humanPresentableName;
  }
  
  public ActivationDataFlavor(String mimeType, String humanPresentableName)
  {
    this.mimeType = mimeType;
    representationClass = InputStream.class;
    this.humanPresentableName = humanPresentableName;
  }
  
  public String getMimeType()
  {
    return mimeType;
  }
  
  public Class getRepresentationClass()
  {
    return representationClass;
  }
  
  public String getHumanPresentableName()
  {
    return humanPresentableName;
  }
  
  public void setHumanPresentableName(String humanPresentableName)
  {
    this.humanPresentableName = humanPresentableName;
  }
  
  public boolean equals(DataFlavor dataFlavor)
  {
    return (isMimeTypeEqual(dataFlavor.getMimeType())) && (representationClass == dataFlavor.getRepresentationClass());
  }
  
  public boolean isMimeTypeEqual(String mimeType)
  {
    try
    {
      MimeType thisType = new MimeType(this.mimeType);
      MimeType thatType = new MimeType(mimeType);
      return thisType.match(thatType);
    }
    catch (MimeTypeParseException e) {}
    return false;
  }
  
  protected String normalizeMimeTypeParameter(String parameterName, String parameterValue)
  {
    return parameterName + "=" + parameterValue;
  }
  
  protected String normalizeMimeType(String mimeType)
  {
    return mimeType;
  }
}

/* Location:
 * Qualified Name:     javax.activation.ActivationDataFlavor
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.beans.Beans;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInputStream;

public class CommandInfo
{
  private final String commandName;
  private final String commandClass;
  
  public CommandInfo(String commandName, String commandClass)
  {
    this.commandName = commandName;
    this.commandClass = commandClass;
  }
  
  public String getCommandName()
  {
    return commandName;
  }
  
  public String getCommandClass()
  {
    return commandClass;
  }
  
  public Object getCommandObject(DataHandler dh, ClassLoader loader)
    throws IOException, ClassNotFoundException
  {
    Object bean = Beans.instantiate(loader, commandClass);
    if ((bean instanceof CommandObject)) {
      ((CommandObject)bean).setCommandContext(commandName, dh);
    } else if (((bean instanceof Externalizable)) && (dh != null)) {
      ((Externalizable)bean).readExternal(new ObjectInputStream(dh.getInputStream()));
    }
    return bean;
  }
}

/* Location:
 * Qualified Name:     javax.activation.CommandInfo
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

public abstract class CommandMap
{
  private static CommandMap defaultCommandMap = new MailcapCommandMap();
  
  public static CommandMap getDefaultCommandMap()
  {
    return defaultCommandMap;
  }
  
  public static void setDefaultCommandMap(CommandMap commandMap)
  {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
      sm.checkSetFactory();
    }
    defaultCommandMap = commandMap == null ? new MailcapCommandMap() : commandMap;
  }
  
  public CommandInfo[] getPreferredCommands(String mimeType, DataSource ds)
  {
    return getPreferredCommands(mimeType);
  }
  
  public abstract CommandInfo[] getPreferredCommands(String paramString);
  
  public CommandInfo[] getAllCommands(String mimeType, DataSource ds)
  {
    return getAllCommands(mimeType);
  }
  
  public abstract CommandInfo[] getAllCommands(String paramString);
  
  public CommandInfo getCommand(String mimeType, String cmdName, DataSource ds)
  {
    return getCommand(mimeType, cmdName);
  }
  
  public abstract CommandInfo getCommand(String paramString1, String paramString2);
  
  public DataContentHandler createDataContentHandler(String mimeType, DataSource ds)
  {
    return createDataContentHandler(mimeType);
  }
  
  public abstract DataContentHandler createDataContentHandler(String paramString);
  
  public String[] getMimeTypes()
  {
    return null;
  }
}

/* Location:
 * Qualified Name:     javax.activation.CommandMap
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.io.IOException;

public abstract interface CommandObject
{
  public abstract void setCommandContext(String paramString, DataHandler paramDataHandler)
    throws IOException;
}

/* Location:
 * Qualified Name:     javax.activation.CommandObject
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.io.OutputStream;

public abstract interface DataContentHandler
{
  public abstract DataFlavor[] getTransferDataFlavors();
  
  public abstract Object getTransferData(DataFlavor paramDataFlavor, DataSource paramDataSource)
    throws UnsupportedFlavorException, IOException;
  
  public abstract Object getContent(DataSource paramDataSource)
    throws IOException;
  
  public abstract void writeTo(Object paramObject, String paramString, OutputStream paramOutputStream)
    throws IOException;
}

/* Location:
 * Qualified Name:     javax.activation.DataContentHandler
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

public abstract interface DataContentHandlerFactory
{
  public abstract DataContentHandler createDataContentHandler(String paramString);
}

/* Location:
 * Qualified Name:     javax.activation.DataContentHandlerFactory
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.io.IOException;
import java.io.PipedOutputStream;

class DataHandler$ObjectDataSource$1
  extends Thread
{
  private final DataHandler.ObjectDataSource this$1;
  
  DataHandler$ObjectDataSource$1(DataHandler.ObjectDataSource paramObjectDataSource, String x0, DataContentHandler paramDataContentHandler, PipedOutputStream paramPipedOutputStream)
  {
    super(x0);
  }
  
  public void run()
  {
    try
    {
      try
      {
        val$dch.writeTo(DataHandler.ObjectDataSource.access$100(this$1), DataHandler.ObjectDataSource.access$000(this$1), val$os);
      }
      finally
      {
        val$os.close();
      }
    }
    catch (IOException e) {}
  }
}

/* Location:
 * Qualified Name:     javax.activation.DataHandler.ObjectDataSource.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

class DataHandler$ObjectDataSource
  implements DataSource
{
  private final Object data;
  private final String mimeType;
  private final DataHandler this$0;
  
  public DataHandler$ObjectDataSource(DataHandler paramDataHandler, Object data, String mimeType)
  {
    this.data = data;
    this.mimeType = mimeType;
  }
  
  public String getName()
  {
    return null;
  }
  
  public String getContentType()
  {
    return mimeType;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    final DataContentHandler dch = DataHandler.access$200(this$0);
    if (dch == null) {
      throw new UnsupportedDataTypeException(mimeType);
    }
    PipedInputStream is = new PipedInputStream();
    final PipedOutputStream os = new PipedOutputStream(is);
    Thread thread = new Thread("DataHandler Pipe Pump")
    {
      public void run()
      {
        try
        {
          try
          {
            dch.writeTo(data, mimeType, os);
          }
          finally
          {
            os.close();
          }
        }
        catch (IOException e) {}
      }
    };
    thread.start();
    return is;
  }
  
  public OutputStream getOutputStream()
    throws IOException
  {
    return null;
  }
}

/* Location:
 * Qualified Name:     javax.activation.DataHandler.ObjectDataSource
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
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 final DataSource ds;
  private final DataFlavor flavor;
  private CommandMap commandMap;
  private DataContentHandler dch;
  private DataContentHandlerFactory originalFactory;
  private static DataContentHandlerFactory factory;
  
  public DataHandler(DataSource ds)
  {
    synchronized (DataHandler.class)
    {
      originalFactory = factory;
    }
    this.ds = ds;
    flavor = new ActivationDataFlavor(ds.getContentType(), null);
  }
  
  public DataHandler(Object data, String type)
  {
    synchronized (DataHandler.class)
    {
      originalFactory = factory;
    }
    ds = new ObjectDataSource(data, type);
    flavor = new ActivationDataFlavor(data.getClass(), null);
  }
  
  public DataHandler(URL url)
  {
    synchronized (DataHandler.class)
    {
      originalFactory = factory;
    }
    ds = new URLDataSource(url);
    flavor = new ActivationDataFlavor(ds.getContentType(), null);
  }
  
  public DataSource getDataSource()
  {
    return ds;
  }
  
  public String getName()
  {
    return ds.getName();
  }
  
  public String getContentType()
  {
    return ds.getContentType();
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return ds.getInputStream();
  }
  
  public void writeTo(OutputStream os)
    throws IOException
  {
    if ((ds instanceof ObjectDataSource))
    {
      ObjectDataSource ods = (ObjectDataSource)ds;
      DataContentHandler dch = getDataContentHandler();
      if (dch == null) {
        throw new UnsupportedDataTypeException(mimeType);
      }
      dch.writeTo(data, mimeType, os);
    }
    else
    {
      byte[] buffer = new byte['?'];
      InputStream is = getInputStream();
      try
      {
        int count;
        while ((count = is.read(buffer)) != -1) {
          os.write(buffer, 0, count);
        }
      }
      finally
      {
        is.close();
      }
    }
  }
  
  public OutputStream getOutputStream()
    throws IOException
  {
    return ds.getOutputStream();
  }
  
  public synchronized DataFlavor[] getTransferDataFlavors()
  {
    return getDataContentHandler().getTransferDataFlavors();
  }
  
  public boolean isDataFlavorSupported(DataFlavor flavor)
  {
    DataFlavor[] flavors = getTransferDataFlavors();
    for (int i = 0; i < flavors.length; i++)
    {
      DataFlavor dataFlavor = flavors[i];
      if (dataFlavor.equals(flavor)) {
        return true;
      }
    }
    return false;
  }
  
  public Object getTransferData(DataFlavor flavor)
    throws UnsupportedFlavorException, IOException
  {
    DataContentHandler dch = getDataContentHandler();
    if (dch != null) {
      return dch.getTransferData(flavor, ds);
    }
    if (this.flavor.match(flavor))
    {
      if ((ds instanceof ObjectDataSource)) {
        return ds).data;
      }
      return ds.getInputStream();
    }
    throw new UnsupportedFlavorException(flavor);
  }
  
  public CommandInfo[] getPreferredCommands()
  {
    return getCommandMap().getPreferredCommands(ds.getContentType());
  }
  
  public CommandInfo[] getAllCommands()
  {
    return getCommandMap().getAllCommands(ds.getContentType());
  }
  
  public CommandInfo getCommand(String cmdName)
  {
    return getCommandMap().getCommand(ds.getContentType(), cmdName);
  }
  
  public Object getContent()
    throws IOException
  {
    if ((ds instanceof ObjectDataSource)) {
      return ds).data;
    }
    DataContentHandler dch = getDataContentHandler();
    if (dch != null) {
      return dch.getContent(ds);
    }
    return ds.getInputStream();
  }
  
  public Object getBean(CommandInfo cmdinfo)
  {
    try
    {
      return cmdinfo.getCommandObject(this, getClass().getClassLoader());
    }
    catch (IOException e)
    {
      return null;
    }
    catch (ClassNotFoundException e) {}
    return null;
  }
  
  private class ObjectDataSource
    implements DataSource
  {
    private final Object data;
    private final String mimeType;
    
    public ObjectDataSource(Object data, String mimeType)
    {
      this.data = data;
      this.mimeType = mimeType;
    }
    
    public String getName()
    {
      return null;
    }
    
    public String getContentType()
    {
      return mimeType;
    }
    
    public InputStream getInputStream()
      throws IOException
    {
      final DataContentHandler dch = DataHandler.this.getDataContentHandler();
      if (dch == null) {
        throw new UnsupportedDataTypeException(mimeType);
      }
      PipedInputStream is = new PipedInputStream();
      final PipedOutputStream os = new PipedOutputStream(is);
      Thread thread = new Thread("DataHandler Pipe Pump")
      {
        public void run()
        {
          try
          {
            try
            {
              dch.writeTo(data, mimeType, os);
            }
            finally
            {
              os.close();
            }
          }
          catch (IOException e) {}
        }
      };
      thread.start();
      return is;
    }
    
    public OutputStream getOutputStream()
      throws IOException
    {
      return null;
    }
  }
  
  public synchronized void setCommandMap(CommandMap commandMap)
  {
    this.commandMap = commandMap;
    dch = null;
  }
  
  private synchronized CommandMap getCommandMap()
  {
    return commandMap != null ? commandMap : CommandMap.getDefaultCommandMap();
  }
  
  private synchronized DataContentHandler getDataContentHandler()
  {
    DataContentHandlerFactory localFactory;
    synchronized (DataHandler.class)
    {
      if (factory != originalFactory)
      {
        dch = null;
        originalFactory = factory;
      }
      localFactory = originalFactory;
    }
    if (dch == null)
    {
      String mimeType = getMimeType(ds.getContentType());
      if (localFactory != null) {
        dch = localFactory.createDataContentHandler(mimeType);
      }
      if (dch == null) {
        if (commandMap != null) {
          dch = commandMap.createDataContentHandler(mimeType);
        } else {
          dch = CommandMap.getDefaultCommandMap().createDataContentHandler(mimeType);
        }
      }
    }
    return dch;
  }
  
  private String getMimeType(String contentType)
  {
    try
    {
      MimeType mimeType = new MimeType(contentType);
      return mimeType.getBaseType();
    }
    catch (MimeTypeParseException e) {}
    return contentType;
  }
  
  public static synchronized void setDataContentHandlerFactory(DataContentHandlerFactory newFactory)
  {
    if (factory != null) {
      throw new Error("javax.activation.DataHandler.setDataContentHandlerFactory has already been defined");
    }
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
      sm.checkSetFactory();
    }
    factory = newFactory;
  }
}

/* Location:
 * Qualified Name:     javax.activation.DataHandler
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public abstract interface DataSource
{
  public abstract InputStream getInputStream()
    throws IOException;
  
  public abstract OutputStream getOutputStream()
    throws IOException;
  
  public abstract String getContentType();
  
  public abstract String getName();
}

/* Location:
 * Qualified Name:     javax.activation.DataSource
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
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 final File file;
  private FileTypeMap fileTypeMap;
  
  public FileDataSource(File file)
  {
    this.file = file;
  }
  
  public FileDataSource(String name)
  {
    this(new File(name));
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return new FileInputStream(file);
  }
  
  public OutputStream getOutputStream()
    throws IOException
  {
    return new FileOutputStream(file);
  }
  
  public String getContentType()
  {
    if (fileTypeMap == null) {
      return FileTypeMap.getDefaultFileTypeMap().getContentType(file);
    }
    return fileTypeMap.getContentType(file);
  }
  
  public String getName()
  {
    return file.getName();
  }
  
  public File getFile()
  {
    return file;
  }
  
  public void setFileTypeMap(FileTypeMap map)
  {
    fileTypeMap = map;
  }
}

/* Location:
 * Qualified Name:     javax.activation.FileDataSource
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.io.File;

public abstract class FileTypeMap
{
  private static FileTypeMap defaultFileTypeMap = null;
  
  public static void setDefaultFileTypeMap(FileTypeMap fileMap)
  {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
      sm.checkSetFactory();
    }
    defaultFileTypeMap = fileMap;
  }
  
  public static synchronized FileTypeMap getDefaultFileTypeMap()
  {
    if (defaultFileTypeMap == null) {
      defaultFileTypeMap = new MimetypesFileTypeMap();
    }
    return defaultFileTypeMap;
  }
  
  public abstract String getContentType(File paramFile);
  
  public abstract String getContentType(String paramString);
}

/* Location:
 * Qualified Name:     javax.activation.FileTypeMap
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MailcapCommandMap
  extends CommandMap
{
  private final Map mimeTypes = new HashMap();
  private final Map preferredCommands = new HashMap();
  private final Map allCommands = new HashMap();
  private final Map nativeCommands = new HashMap();
  private final Map fallbackCommands = new HashMap();
  private URL url;
  
  public MailcapCommandMap()
  {
    ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
    try
    {
      InputStream is = MailcapCommandMap.class.getResourceAsStream("/META-INF/mailcap.default");
      if (is != null) {
        try
        {
          parseMailcap(is);
        }
        finally
        {
          is.close();
        }
      }
    }
    catch (IOException e) {}
    try
    {
      Enumeration e = contextLoader.getResources("META-INF/mailcap");
      while (e.hasMoreElements())
      {
        url = ((URL)e.nextElement());
        try
        {
          InputStream is = url.openStream();
          try
          {
            parseMailcap(is);
          }
          finally
          {
            is.close();
          }
        }
        catch (IOException e1) {}
      }
    }
    catch (SecurityException e) {}catch (IOException e) {}
    try
    {
      File file = new File(System.getProperty("java.home"), "lib/mailcap");
      Object is = new FileInputStream(file);
      try
      {
        parseMailcap((InputStream)is);
      }
      finally
      {
        ((InputStream)is).close();
      }
    }
    catch (SecurityException e) {}catch (IOException e) {}
    try
    {
      File file = new File(System.getProperty("user.home"), ".mailcap");
      Object is = new FileInputStream(file);
      try
      {
        parseMailcap((InputStream)is);
      }
      finally
      {
        ((InputStream)is).close();
      }
    }
    catch (SecurityException e) {}catch (IOException e) {}
  }
  
  public MailcapCommandMap(String fileName)
    throws IOException
  {
    this();
    FileReader reader = new FileReader(fileName);
    try
    {
      parseMailcap(reader);
    }
    finally
    {
      reader.close();
    }
  }
  
  public MailcapCommandMap(InputStream is)
  {
    this();
    parseMailcap(is);
  }
  
  private void parseMailcap(InputStream is)
  {
    try
    {
      parseMailcap(new InputStreamReader(is));
    }
    catch (IOException e) {}
  }
  
  void parseMailcap(Reader reader)
    throws IOException
  {
    BufferedReader br = new BufferedReader(reader);
    String line;
    while ((line = br.readLine()) != null) {
      addMailcap(line);
    }
  }
  
  public synchronized void addMailcap(String mail_cap)
  {
    int index = 0;
    
    index = skipSpace(mail_cap, index);
    if ((index == mail_cap.length()) || (mail_cap.charAt(index) == '#')) {
      return;
    }
    int start = index;
    index = getToken(mail_cap, index);
    if (start == index) {
      return;
    }
    String mimeType = mail_cap.substring(start, index);
    
    index = skipSpace(mail_cap, index);
    if ((index == mail_cap.length()) || (mail_cap.charAt(index) == '#')) {
      return;
    }
    if (mail_cap.charAt(index) == '/')
    {
      index = skipSpace(mail_cap, ++index);
      start = index;
      index = getToken(mail_cap, index);
      mimeType = mimeType + '/' + mail_cap.substring(start, index);
    }
    else
    {
      mimeType = mimeType + "/*";
    }
    mimeType = mimeType.toLowerCase();
    
    index = skipSpace(mail_cap, index);
    if ((index == mail_cap.length()) || (mail_cap.charAt(index) != ';')) {
      return;
    }
    index = skipSpace(mail_cap, index + 1);
    if ((index == mail_cap.length()) || (mail_cap.charAt(index) != ';'))
    {
      ArrayList nativeCommandList = (ArrayList)nativeCommands.get(mimeType);
      if (nativeCommandList == null)
      {
        nativeCommandList = new ArrayList();
        nativeCommands.put(mimeType, nativeCommandList);
      }
      nativeCommandList.add(mail_cap);
      
      index = getMText(mail_cap, index);
    }
    List commandList = new ArrayList();
    
    boolean fallback = false;
    
    int fieldNumber = 0;
    while ((index < mail_cap.length()) && (mail_cap.charAt(index) == ';'))
    {
      index = skipSpace(mail_cap, index + 1);
      start = index;
      index = getToken(mail_cap, index);
      String fieldName = mail_cap.substring(start, index).toLowerCase();
      index = skipSpace(mail_cap, index);
      if ((index < mail_cap.length()) && (mail_cap.charAt(index) == '='))
      {
        index = skipSpace(mail_cap, index + 1);
        start = index;
        index = getMText(mail_cap, index);
        String value = mail_cap.substring(start, index);
        index = skipSpace(mail_cap, index);
        if ((fieldName.startsWith("x-java-")) && (fieldName.length() > 7))
        {
          String command = fieldName.substring(7);
          value = value.trim();
          if (command.equals("fallback-entry"))
          {
            if (value.equals("true")) {
              fallback = true;
            }
          }
          else
          {
            CommandInfo info = new CommandInfo(command, value);
            commandList.add(info);
          }
        }
      }
    }
    addCommands(mimeType, commandList, fallback);
  }
  
  private void addCommands(String mimeType, List commands, boolean fallback)
  {
    mimeTypes.put(mimeType, mimeType);
    
    Map target = fallback ? fallbackCommands : preferredCommands;
    for (Iterator i = commands.iterator(); i.hasNext();)
    {
      CommandInfo info = (CommandInfo)i.next();
      addCommand(target, mimeType, info);
      if (!fallback)
      {
        List cmdList = (List)allCommands.get(mimeType);
        if (cmdList == null)
        {
          cmdList = new ArrayList();
          allCommands.put(mimeType, cmdList);
        }
        cmdList.add(info);
      }
    }
  }
  
  private void addCommand(Map commandList, String mimeType, CommandInfo command)
  {
    Map commands = (Map)commandList.get(mimeType);
    if (commands == null)
    {
      commands = new HashMap();
      commandList.put(mimeType, commands);
    }
    commands.put(command.getCommandName(), command);
  }
  
  private int skipSpace(String s, int index)
  {
    while ((index < s.length()) && (Character.isWhitespace(s.charAt(index)))) {
      index++;
    }
    return index;
  }
  
  private int getToken(String s, int index)
  {
    while ((index < s.length()) && (s.charAt(index) != '#') && (!MimeType.isSpecial(s.charAt(index)))) {
      index++;
    }
    return index;
  }
  
  private int getMText(String s, int index)
  {
    while (index < s.length())
    {
      char c = s.charAt(index);
      if ((c == '#') || (c == ';') || (Character.isISOControl(c))) {
        return index;
      }
      if (c == '\\')
      {
        index++;
        if (index == s.length()) {
          return index;
        }
      }
      index++;
    }
    return index;
  }
  
  public synchronized CommandInfo[] getPreferredCommands(String mimeType)
  {
    mimeType = mimeType.toLowerCase();
    
    Map commands = (Map)preferredCommands.get(mimeType);
    if (commands == null) {
      commands = (Map)preferredCommands.get(getWildcardMimeType(mimeType));
    }
    Map fallbackCommands = getFallbackCommands(mimeType);
    if (fallbackCommands != null) {
      if (commands == null) {
        commands = fallbackCommands;
      } else {
        commands = mergeCommandMaps(commands, fallbackCommands);
      }
    }
    if (commands == null) {
      return new CommandInfo[0];
    }
    return (CommandInfo[])commands.values().toArray(new CommandInfo[commands.size()]);
  }
  
  private Map getFallbackCommands(String mimeType)
  {
    Map commands = (Map)fallbackCommands.get(mimeType);
    
    Map wildcardCommands = (Map)fallbackCommands.get(getWildcardMimeType(mimeType));
    if (wildcardCommands == null) {
      return commands;
    }
    return mergeCommandMaps(commands, wildcardCommands);
  }
  
  private Map mergeCommandMaps(Map main, Map fallback)
  {
    Map result = new HashMap(fallback);
    result.putAll(main);
    
    return result;
  }
  
  public synchronized CommandInfo[] getAllCommands(String mimeType)
  {
    mimeType = mimeType.toLowerCase();
    List exactCommands = (List)allCommands.get(mimeType);
    if (exactCommands == null) {
      exactCommands = Collections.EMPTY_LIST;
    }
    List wildCommands = (List)allCommands.get(getWildcardMimeType(mimeType));
    if (wildCommands == null) {
      wildCommands = Collections.EMPTY_LIST;
    }
    Map fallbackCommands = getFallbackCommands(mimeType);
    if (fallbackCommands == null) {
      fallbackCommands = Collections.EMPTY_MAP;
    }
    CommandInfo[] result = new CommandInfo[exactCommands.size() + wildCommands.size() + fallbackCommands.size()];
    int j = 0;
    for (int i = 0; i < exactCommands.size(); i++) {
      result[(j++)] = ((CommandInfo)exactCommands.get(i));
    }
    for (int i = 0; i < wildCommands.size(); i++) {
      result[(j++)] = ((CommandInfo)wildCommands.get(i));
    }
    for (Iterator i = fallbackCommands.keySet().iterator(); i.hasNext();) {
      result[(j++)] = ((CommandInfo)fallbackCommands.get((String)i.next()));
    }
    return result;
  }
  
  public synchronized CommandInfo getCommand(String mimeType, String cmdName)
  {
    mimeType = mimeType.toLowerCase();
    
    int i = mimeType.indexOf(';');
    if (i != -1) {
      mimeType = mimeType.substring(0, i).trim();
    }
    Map commands = (Map)preferredCommands.get(mimeType);
    if (commands == null)
    {
      commands = (Map)preferredCommands.get(getWildcardMimeType(mimeType));
      if (commands == null)
      {
        commands = (Map)fallbackCommands.get(mimeType);
        if (commands == null) {
          commands = (Map)fallbackCommands.get(getWildcardMimeType(mimeType));
        }
        if (commands == null) {
          return null;
        }
      }
    }
    return (CommandInfo)commands.get(cmdName.toLowerCase());
  }
  
  private String getWildcardMimeType(String mimeType)
  {
    int i = mimeType.indexOf('/');
    if (i == -1) {
      return mimeType + "/*";
    }
    return mimeType.substring(0, i + 1) + "*";
  }
  
  public synchronized DataContentHandler createDataContentHandler(String mimeType)
  {
    CommandInfo info = getCommand(mimeType, "content-handler");
    if (info == null) {
      return null;
    }
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (cl == null) {
      cl = getClass().getClassLoader();
    }
    try
    {
      return (DataContentHandler)cl.loadClass(info.getCommandClass()).newInstance();
    }
    catch (ClassNotFoundException e)
    {
      return null;
    }
    catch (IllegalAccessException e)
    {
      return null;
    }
    catch (InstantiationException e) {}
    return null;
  }
  
  public synchronized String[] getMimeTypes()
  {
    ArrayList types = new ArrayList(mimeTypes.values());
    return (String[])types.toArray(new String[types.size()]);
  }
  
  public synchronized String[] getNativeCommands(String mimeType)
  {
    ArrayList commands = (ArrayList)nativeCommands.get(mimeType.toLowerCase());
    if (commands == null) {
      return new String[0];
    }
    return (String[])commands.toArray(new String[commands.size()]);
  }
}

/* Location:
 * Qualified Name:     javax.activation.MailcapCommandMap
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

public class MimeType
  implements Externalizable
{
  private static final String SPECIALS = "()<>@,;:\\\"/[]?=";
  
  static boolean isSpecial(char c)
  {
    return (Character.isWhitespace(c)) || (Character.isISOControl(c)) || ("()<>@,;:\\\"/[]?=".indexOf(c) != -1);
  }
  
  private String primaryType = "application";
  private String subType = "*";
  private final MimeTypeParameterList parameterList = new MimeTypeParameterList();
  
  public MimeType() {}
  
  public MimeType(String rawdata)
    throws MimeTypeParseException
  {
    parseMimeType(rawdata);
  }
  
  public MimeType(String primary, String sub)
    throws MimeTypeParseException
  {
    setPrimaryType(primary);
    setSubType(sub);
  }
  
  public String getPrimaryType()
  {
    return primaryType;
  }
  
  public void setPrimaryType(String primary)
    throws MimeTypeParseException
  {
    primaryType = parseToken(primary);
  }
  
  public String getSubType()
  {
    return subType;
  }
  
  public void setSubType(String sub)
    throws MimeTypeParseException
  {
    subType = parseToken(sub);
  }
  
  public MimeTypeParameterList getParameters()
  {
    return parameterList;
  }
  
  public String getParameter(String name)
  {
    return parameterList.get(name);
  }
  
  public void setParameter(String name, String value)
  {
    parameterList.set(name, value);
  }
  
  public void removeParameter(String name)
  {
    parameterList.remove(name);
  }
  
  public String toString()
  {
    return getBaseType() + parameterList.toString();
  }
  
  public String getBaseType()
  {
    return getPrimaryType() + '/' + getSubType();
  }
  
  public boolean match(MimeType type)
  {
    if (!primaryType.equals(primaryType)) {
      return false;
    }
    if ("*".equals(subType)) {
      return true;
    }
    if ("*".equals(subType)) {
      return true;
    }
    return subType.equals(subType);
  }
  
  public boolean match(String rawdata)
    throws MimeTypeParseException
  {
    return match(new MimeType(rawdata));
  }
  
  public void writeExternal(ObjectOutput out)
    throws IOException
  {
    out.writeUTF(toString());
    out.flush();
  }
  
  public void readExternal(ObjectInput in)
    throws IOException, ClassNotFoundException
  {
    try
    {
      parseMimeType(in.readUTF());
    }
    catch (MimeTypeParseException mtpex)
    {
      throw new IOException(mtpex.getMessage());
    }
  }
  
  private void parseMimeType(String rawData)
    throws MimeTypeParseException
  {
    int index = rawData.indexOf('/');
    if (index == -1) {
      throw new MimeTypeParseException("Expected '/'");
    }
    setPrimaryType(rawData.substring(0, index));
    int index2 = rawData.indexOf(';', index + 1);
    if (index2 == -1)
    {
      setSubType(rawData.substring(index + 1));
    }
    else
    {
      setSubType(rawData.substring(index + 1, index2));
      parameterList.parse(rawData.substring(index2));
    }
  }
  
  private static String parseToken(String tokenString)
    throws MimeTypeParseException
  {
    tokenString = tokenString.trim();
    for (int i = 0; i < tokenString.length(); i++)
    {
      char c = tokenString.charAt(i);
      if (isSpecial(c)) {
        throw new MimeTypeParseException("Special '" + c + "' not allowed in token");
      }
    }
    return tokenString;
  }
}

/* Location:
 * Qualified Name:     javax.activation.MimeType
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

class MimeTypeParameterList$1 {}

/* Location:
 * Qualified Name:     javax.activation.MimeTypeParameterList.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

class MimeTypeParameterList$RFC2045Parser
{
  private final String text;
  
  MimeTypeParameterList$RFC2045Parser(String x0, MimeTypeParameterList.1 x1)
  {
    this(x0);
  }
  
  private int index = 0;
  
  private MimeTypeParameterList$RFC2045Parser(String text)
  {
    this.text = text;
  }
  
  private boolean hasMoreParams()
    throws MimeTypeParseException
  {
    char c;
    do
    {
      if (index == text.length()) {
        return false;
      }
      c = text.charAt(index++);
    } while (Character.isWhitespace(c));
    if (c != ';') {
      throw new MimeTypeParseException("Expected \";\" at " + (index - 1) + " in " + text);
    }
    return true;
  }
  
  private String expectAttribute()
    throws MimeTypeParseException
  {
    char c;
    do
    {
      if (index == text.length()) {
        throw new MimeTypeParseException("Expected attribute at " + (index - 1) + " in " + text);
      }
      c = text.charAt(index++);
    } while (Character.isWhitespace(c));
    int start = index - 1;
    while ((index != text.length()) && (!MimeType.isSpecial(text.charAt(index)))) {
      index += 1;
    }
    return text.substring(start, index);
  }
  
  private void expectEquals()
    throws MimeTypeParseException
  {
    char c;
    do
    {
      if (index == text.length()) {
        throw new MimeTypeParseException("Expected \"=\" at " + (index - 1) + " in " + text);
      }
      c = text.charAt(index++);
    } while (Character.isWhitespace(c));
    if (c != '=') {
      throw new MimeTypeParseException("Expected \"=\" at " + (index - 1) + " in " + text);
    }
  }
  
  private String expectValue()
    throws MimeTypeParseException
  {
    char c;
    do
    {
      if (index == text.length()) {
        throw new MimeTypeParseException("Expected value at " + (index - 1) + " in " + text);
      }
      c = text.charAt(index++);
    } while (Character.isWhitespace(c));
    if (c == '"')
    {
      StringBuffer buf = new StringBuffer();
      for (;;)
      {
        if (index == text.length()) {
          throw new MimeTypeParseException("Expected closing quote at " + (index - 1) + " in " + text);
        }
        c = text.charAt(index++);
        if (c == '"') {
          break;
        }
        if (c == '\\')
        {
          if (index == text.length()) {
            throw new MimeTypeParseException("Expected escaped char at " + (index - 1) + " in " + text);
          }
          c = text.charAt(index++);
        }
        buf.append(c);
      }
      return buf.toString();
    }
    int start = index - 1;
    while ((index != text.length()) && (!MimeType.isSpecial(text.charAt(index)))) {
      index += 1;
    }
    return text.substring(start, index);
  }
}

/* Location:
 * Qualified Name:     javax.activation.MimeTypeParameterList.RFC2045Parser
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package javax.activation;

import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class MimeTypeParameterList
{
  private final Map params = new HashMap();
  
  public MimeTypeParameterList() {}
  
  public MimeTypeParameterList(String parameterList)
    throws MimeTypeParseException
  {
    parse(parameterList);
  }
  
  protected void parse(String parameterList)
    throws MimeTypeParseException
  {
    if (parameterList == null) {
      throw new MimeTypeParseException("parameterList is null");
    }
    RFC2045Parser parser = new RFC2045Parser(parameterList, null);
    while (parser.hasMoreParams())
    {
      String attribute = parser.expectAttribute();
      parser.expectEquals();
      String value = parser.expectValue();
      params.put(attribute.toLowerCase(), value);
    }
  }
  
  public int size()
  {
    return params.size();
  }
  
  public boolean isEmpty()
  {
    return params.isEmpty();
  }
  
  public String get(String name)
  {
    return (String)params.get(name.toLowerCase());
  }
  
  public void set(String name, String value)
  {
    params.put(name.toLowerCase(), value);
  }
  
  public void remove(String name)
  {
    params.remove(name.toLowerCase());
  }
  
  public Enumeration getNames()
  {
    return Collections.enumeration(params.keySet());
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer(params.size() << 4);
    for (Iterator i = params.entrySet().iterator(); i.hasNext();)
    {
      Map.Entry entry = (Map.Entry)i.next();
      buf.append("; ").append(entry.getKey()).append('=');
      quote(buf, (String)entry.getValue());
    }
    return buf.toString();
  }
  
  private void quote(StringBuffer buf, String value)
  {
    int length = value.length();
    boolean quote = false;
    for (int i = 0; i < length; i++) {
      if (MimeType.isSpecial(value.charAt(i)))
      {
        quote = true;
        break;
      }
    }
    if (quote)
    {
      buf.append('"');
      for (int i = 0; i < length; i++)
      {
        char c = value.charAt(i);
        if ((c == '\\') || (c == '"')) {
          buf.append('\\');
        }
        buf.append(c);
      }
      buf.append('"');
    }
    else
    {
      buf.append(value);
    }
  }
  
  private static class RFC2045Parser
  {
    private final String text;
    
    RFC2045Parser(String x0, MimeTypeParameterList.1 x1)
    {
      this(x0);
    }
    
    private int index = 0;
    
    private RFC2045Parser(String text)
    {
      this.text = text;
    }
    
    private boolean hasMoreParams()
      throws MimeT
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd