org-netbeans-modules-editor-mimelookup

16:39:55.363 INFO  jd.cli.Main - Decompiling org-netbeans-modules-editor-mimelookup.jar
package org.netbeans.api.editor.mimelookup;

import org.netbeans.modules.editor.mimelookup.MimePathLookup;
import org.openide.util.Lookup;
import org.openide.util.Lookup.Result;
import org.openide.util.Lookup.Template;

public final class MimeLookup
  extends Lookup
{
  private MimePathLookup mimePathLookup;
  
  public static Lookup getLookup(MimePath paramMimePath)
  {
    if (paramMimePath == null) {
      throw new NullPointerException("The mimePath parameter must not be null.");
    }
    return paramMimePath.getLookup();
  }
  
  public static Lookup getLookup(String paramString)
  {
    return getLookup(MimePath.parse(paramString));
  }
  
  /**
   * @deprecated
   */
  public static MimeLookup getMimeLookup(String paramString)
  {
    if (paramString == null) {
      throw new NullPointerException("The mimeType parameter must not be null.");
    }
    return new MimeLookup(MimePath.get(paramString).getLookup());
  }
  
  private MimeLookup(MimePathLookup paramMimePathLookup)
  {
    mimePathLookup = paramMimePathLookup;
  }
  
  /**
   * @deprecated
   */
  public MimeLookup childLookup(String paramString)
  {
    if (paramString == null) {
      throw new NullPointerException("The mimeType parameter must not be null.");
    }
    MimePath localMimePath = MimePath.get(mimePathLookup.getMimePath(), paramString);
    return new MimeLookup(localMimePath.getLookup());
  }
  
  /**
   * @deprecated
   */
  public <T> T lookup(Class<T> paramClass)
  {
    return (T)mimePathLookup.lookup(paramClass);
  }
  
  /**
   * @deprecated
   */
  public <T> Lookup.Result<T> lookup(Lookup.Template<T> paramTemplate)
  {
    return mimePathLookup.lookup(paramTemplate);
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.editor.mimelookup.MimeLookup
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.api.editor.mimelookup;

import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.netbeans.modules.editor.mimelookup.MimePathLookup;

public final class MimePath
{
  public static final MimePath EMPTY = new MimePath();
  private static final Object LOCK = new Object();
  private static final ArrayList<MimePath> LRU = new ArrayList();
  static final int MAX_LRU_SIZE = 3;
  private static final Pattern REG_NAME_PATTERN = Pattern.compile("^[[\\p{Alnum}][!#$&.+\\-^_]]{1,127}$");
  private static final Set<String> WELL_KNOWN_TYPES = new HashSet(Arrays.asList(new String[] { "application", "audio", "content", "image", "message", "model", "multipart", "text", "video" }));
  private static final Map<String, Reference<MimePath>> string2mimePath = new HashMap();
  private final MimePath[] mimePaths;
  private final String path;
  private final String mimeType;
  private Map<String, SoftReference<MimePath>> mimeType2mimePathRef;
  private MimePathLookup lookup;
  
  public static MimePath get(String paramString)
  {
    if ((paramString == null) || (paramString.length() == 0)) {
      return EMPTY;
    }
    return get(EMPTY, paramString);
  }
  
  public static MimePath get(MimePath paramMimePath, String paramString)
  {
    if (!validate(paramString)) {
      throw new IllegalArgumentException("Invalid mimeType=\"" + paramString + "\"");
    }
    return paramMimePath.getEmbedded(paramString);
  }
  
  public static MimePath parse(String paramString)
  {
    assert (paramString != null) : "path cannot be null";
    MimePath localMimePath;
    synchronized (string2mimePath)
    {
      Reference localReference = (Reference)string2mimePath.get(paramString);
      localMimePath = localReference != null ? (MimePath)localReference.get() : null;
      if (localMimePath != null) {
        return localMimePath;
      }
    }
    ??? = parseImpl(paramString, false);
    if (!(??? instanceof MimePath)) {
      throw new IllegalArgumentException((String)???);
    }
    synchronized (string2mimePath)
    {
      localMimePath = (MimePath)???;
      
      string2mimePath.put(paramString.intern(), new WeakReference(localMimePath));
      
      return localMimePath;
    }
  }
  
  public static boolean validate(CharSequence paramCharSequence1, CharSequence paramCharSequence2)
  {
    if (paramCharSequence1 != null)
    {
      if (startsWith(paramCharSequence1, "test")) {
        for (int i = 4; i < paramCharSequence1.length(); i++) {
          if (paramCharSequence1.charAt(i) == '_')
          {
            paramCharSequence1 = paramCharSequence1.subSequence(i + 1, paramCharSequence1.length());
            break;
          }
        }
      }
      if (!WELL_KNOWN_TYPES.contains(paramCharSequence1.toString())) {
        return false;
      }
    }
    if ((paramCharSequence2 != null) && 
      (!REG_NAME_PATTERN.matcher(paramCharSequence2).matches())) {
      return false;
    }
    return true;
  }
  
  public static boolean validate(CharSequence paramCharSequence)
  {
    return !(parseImpl(paramCharSequence, true) instanceof String);
  }
  
  private final String LOOKUP_LOCK = new String("MimePath.LOOKUP_LOCK");
  
  private MimePath(MimePath paramMimePath, String paramString)
  {
    int i = paramMimePath.size();
    mimePaths = new MimePath[i + 1];
    System.arraycopy(mimePaths, 0, mimePaths, 0, i);
    mimePaths[i] = this;
    String str = path;
    path = ((str != null) && (str.length() > 0) ? (str + '/' + paramString).intern() : paramString.intern());
    
    mimeType = paramString;
  }
  
  private MimePath()
  {
    mimePaths = new MimePath[0];
    path = "";
    mimeType = "";
  }
  
  public String getPath()
  {
    return path;
  }
  
  public int size()
  {
    return mimePaths.length;
  }
  
  public String getMimeType(int paramInt)
  {
    return mimePaths[paramInt].mimeType;
  }
  
  public MimePath getPrefix(int paramInt)
  {
    return paramInt == 0 ? EMPTY : mimePaths[(paramInt - 1)];
  }
  
  private MimePath getEmbedded(String paramString)
  {
    synchronized (LOCK)
    {
      if (mimeType2mimePathRef == null) {
        mimeType2mimePathRef = new HashMap();
      }
      Reference localReference = (Reference)mimeType2mimePathRef.get(paramString);
      MimePath localMimePath;
      if ((localReference == null) || ((localMimePath = (MimePath)localReference.get()) == null))
      {
        localMimePath = new MimePath(this, paramString);
        mimeType2mimePathRef.put(paramString, new SoftReference(localMimePath));
        
        LRU.add(0, localMimePath);
        if (LRU.size() > 3) {
          LRU.remove(LRU.size() - 1);
        }
      }
      return localMimePath;
    }
  }
  
  private static Object parseImpl(CharSequence paramCharSequence, boolean paramBoolean)
  {
    MimePath localMimePath = EMPTY;
    int i = paramCharSequence.length();
    int j = 0;
    for (;;)
    {
      int k = j;
      int m = -1;
      while (k < i)
      {
        if (paramCharSequence.charAt(k) == '/')
        {
          m = k;
          break;
        }
        k++;
      }
      if (m == -1)
      {
        if (k == j) {
          break;
        }
        return "mimeType '" + paramCharSequence.subSequence(j, paramCharSequence.length()) + "' does not contain '/'.";
      }
      k++;
      while (k < i)
      {
        if (paramCharSequence.charAt(k) == '/')
        {
          if (k != m + 1) {
            break;
          }
          return "Two successive slashes in '" + paramCharSequence.subSequence(j, paramCharSequence.length()) + "'";
        }
        k++;
      }
      if (k == m + 1) {
        return "Empty string after '/' in '" + paramCharSequence.subSequence(j, paramCharSequence.length()) + "'";
      }
      if (!validate(paramCharSequence.subSequence(j, m), paramCharSequence.subSequence(m + 1, k))) {
        return "Invalid mimeType=\"" + paramCharSequence.subSequence(j, k) + "\"";
      }
      if (!paramBoolean)
      {
        String str = paramCharSequence.subSequence(j, k).toString();
        localMimePath = localMimePath.getEmbedded(str);
      }
      j = k + 1;
    }
    return localMimePath;
  }
  
  MimePathLookup getLookup()
  {
    synchronized (LOOKUP_LOCK)
    {
      if (lookup == null) {
        lookup = new MimePathLookup(this);
      }
      return lookup;
    }
  }
  
  public String toString()
  {
    return "MimePath[" + path + "]";
  }
  
  private static boolean startsWith(CharSequence paramCharSequence1, CharSequence paramCharSequence2)
  {
    if (paramCharSequence1.length() < paramCharSequence2.length()) {
      return false;
    }
    for (int i = 0; i < paramCharSequence2.length(); i++) {
      if (paramCharSequence1.charAt(i) != paramCharSequence2.charAt(i)) {
        return false;
      }
    }
    return true;
  }
  
  List<String> getInheritedPaths(String paramString1, String paramString2)
  {
    synchronized (LOCK)
    {
      ArrayList localArrayList1 = new ArrayList(size());
      String[] arrayOfString = split(this);
      Object localObject2;
      Object localObject3;
      for (int i = 0; i <= arrayOfString.length; i++)
      {
        localObject1 = new String[arrayOfString.length - i];
        for (int j = 0; j < localObject1.length; j++) {
          localObject1[j] = arrayOfString[(i + j)];
        }
        localArrayList1.add(localObject1);
        if (localObject1.length > 0)
        {
          localObject2 = getGenericPartOfCompoundMimeType(localObject1[0]);
          if (localObject2 != null)
          {
            localObject3 = new String[localObject1.length];
            System.arraycopy(localObject1, 0, localObject3, 0, localObject1.length);
            localObject3[0] = localObject2;
            
            localArrayList1.add(localObject3);
          }
        }
      }
      ArrayList localArrayList2 = new ArrayList(localArrayList1.size());
      for (Object localObject1 = localArrayList1.iterator(); ((Iterator)localObject1).hasNext();)
      {
        localObject2 = (String[])((Iterator)localObject1).next();
        localObject3 = new StringBuffer(10 * localObject2.length + 20);
        if ((paramString1 != null) && (paramString1.length() > 0)) {
          ((StringBuffer)localObject3).append(paramString1);
        }
        for (int k = 0; k < localObject2.length; k++) {
          if (localObject2[k].length() > 0)
          {
            if (((StringBuffer)localObject3).length() > 0) {
              ((StringBuffer)localObject3).append('/');
            }
            ((StringBuffer)localObject3).append(localObject2[k]);
          }
        }
        if ((paramString2 != null) && (paramString2.length() > 0))
        {
          if (((StringBuffer)localObject3).length() > 0) {
            ((StringBuffer)localObject3).append('/');
          }
          ((StringBuffer)localObject3).append(paramString2);
        }
        localArrayList2.add(((StringBuffer)localObject3).toString());
      }
      return localArrayList2;
    }
  }
  
  static String getGenericPartOfCompoundMimeType(String paramString)
  {
    int i = paramString.lastIndexOf('+');
    if ((i != -1) && (i < paramString.length() - 1))
    {
      int j = paramString.indexOf('/');
      String str1 = paramString.substring(0, j + 1);
      String str2 = paramString.substring(i + 1);
      if (str2.equals("xml")) {
        str1 = "text/";
      }
      return str1 + str2;
    }
    return null;
  }
  
  private static String[] split(MimePath paramMimePath)
  {
    String[] arrayOfString = new String[paramMimePath.size()];
    for (int i = 0; i < paramMimePath.size(); i++) {
      arrayOfString[i] = paramMimePath.getMimeType(i);
    }
    return arrayOfString;
  }
}

/* Location:
 * Qualified Name:     org.netbeans.api.editor.mimelookup.MimePath
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.modules.editor.mimelookup;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.editor.mimelookup.MimePath;
import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
import org.netbeans.spi.editor.mimelookup.MimeLookupInitializer;
import org.openide.util.Lookup;
import org.openide.util.Lookup.Result;
import org.openide.util.Lookup.Template;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.WeakListeners;
import org.openide.util.lookup.ProxyLookup;

public final class MimePathLookup
  extends ProxyLookup
  implements LookupListener
{
  private static final Logger LOG = Logger.getLogger(MimePathLookup.class.getName());
  private final MimePath mimePath;
  private final boolean mimePathBanned;
  private final Lookup.Result<MimeDataProvider> dataProviders;
  private final Lookup.Result<MimeLookupInitializer> mimeInitializers;
  private boolean initialized = false;
  
  public MimePathLookup(MimePath paramMimePath)
  {
    if (paramMimePath == null) {
      throw new NullPointerException("Mime path can't be null.");
    }
    mimePath = paramMimePath;
    mimePathBanned = ((paramMimePath.size() > 0) && (paramMimePath.getMimeType(0).contains("text/base")));
    
    dataProviders = Lookup.getDefault().lookup(new Lookup.Template(MimeDataProvider.class));
    dataProviders.addLookupListener((LookupListener)WeakListeners.create(LookupListener.class, this, dataProviders));
    
    mimeInitializers = Lookup.getDefault().lookup(new Lookup.Template(MimeLookupInitializer.class));
    mimeInitializers.addLookupListener((LookupListener)WeakListeners.create(LookupListener.class, this, mimeInitializers));
  }
  
  protected void beforeLookup(Lookup.Template<?> paramTemplate)
  {
    synchronized (this)
    {
      if (!initialized)
      {
        initialized = true;
        rebuild();
      }
    }
  }
  
  public MimePath getMimePath()
  {
    return mimePath;
  }
  
  private void rebuild()
  {
    ArrayList localArrayList = new ArrayList();
    for (Object localObject1 = dataProviders.allInstances().iterator(); ((Iterator)localObject1).hasNext();)
    {
      localObject2 = (MimeDataProvider)((Iterator)localObject1).next();
      if ((!mimePathBanned) || (isDefaultProvider((MimeDataProvider)localObject2)))
      {
        localObject3 = ((MimeDataProvider)localObject2).getLookup(mimePath);
        if (localObject3 != null) {
          localArrayList.add(localObject3);
        }
      }
    }
    Object localObject3;
    try
    {
      Object localObject2 = MimePath.class.getDeclaredMethod("getInheritedPaths", new Class[] { String.class, String.class });
      ((Method)localObject2).setAccessible(true);
      
      localObject3 = (List)((Method)localObject2).invoke(mimePath, new Object[] { null, null });
      localObject1 = localObject3;
    }
    catch (Exception localException)
    {
      LOG.log(Level.WARNING, "Can't call org.netbeans.api.editor.mimelookup.MimePath.getInheritedPaths method.", localException);
      localObject1 = Collections.singletonList(mimePath.getPath());
    }
    for (Iterator localIterator1 = ((List)localObject1).iterator(); localIterator1.hasNext();)
    {
      localObject3 = (String)localIterator1.next();
      MimePath localMimePath = MimePath.parse((String)localObject3);
      Object localObject4 = mimeInitializers.allInstances();
      for (int i = 0; i < localMimePath.size(); i++)
      {
        localObject5 = new ArrayList(((Collection)localObject4).size());
        for (localObject6 = ((Collection)localObject4).iterator(); ((Iterator)localObject6).hasNext();)
        {
          MimeLookupInitializer localMimeLookupInitializer = (MimeLookupInitializer)((Iterator)localObject6).next();
          ((Collection)localObject5).addAll(localMimeLookupInitializer.child(localMimePath.getMimeType(i)).allInstances());
        }
        localObject4 = localObject5;
      }
      for (localIterator2 = ((Collection)localObject4).iterator(); localIterator2.hasNext();)
      {
        localObject5 = (MimeLookupInitializer)localIterator2.next();
        localObject6 = ((MimeLookupInitializer)localObject5).lookup();
        if (localObject6 != null) {
          localArrayList.add(localObject6);
        }
      }
    }
    Object localObject5;
    Object localObject6;
    Iterator localIterator2;
    setLookups((Lookup[])localArrayList.toArray(new Lookup[localArrayList.size()]));
  }
  
  private boolean isDefaultProvider(MimeDataProvider paramMimeDataProvider)
  {
    return paramMimeDataProvider.getClass().getName().equals("org.netbeans.modules.editor.mimelookup.impl.DefaultMimeDataProvider");
  }
  
  public void resultChanged(LookupEvent paramLookupEvent)
  {
    rebuild();
  }
}

/* Location:
 * Qualified Name:     org.netbeans.modules.editor.mimelookup.MimePathLookup
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.spi.editor.mimelookup;

public abstract interface Class2LayerFolder<T>
{
  public abstract Class<T> getClazz();
  
  public abstract String getLayerFolderName();
  
  public abstract InstanceProvider<T> getInstanceProvider();
}

/* Location:
 * Qualified Name:     org.netbeans.spi.editor.mimelookup.Class2LayerFolder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.spi.editor.mimelookup;

import java.util.List;
import org.openide.filesystems.FileObject;

public abstract interface InstanceProvider<T>
{
  public abstract T createInstance(List<FileObject> paramList);
}

/* Location:
 * Qualified Name:     org.netbeans.spi.editor.mimelookup.InstanceProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.spi.editor.mimelookup;

import org.netbeans.api.editor.mimelookup.MimePath;
import org.openide.util.Lookup;

public abstract interface MimeDataProvider
{
  public abstract Lookup getLookup(MimePath paramMimePath);
}

/* Location:
 * Qualified Name:     org.netbeans.spi.editor.mimelookup.MimeDataProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.netbeans.spi.editor.mimelookup;

import org.openide.util.Lookup;
import org.openide.util.Lookup.Result;

@Deprecated
public abstract interface MimeLookupInitializer
{
  public abstract Lookup lookup();
  
  public abstract Lookup.Result<MimeLookupInitializer> child(String paramString);
}

/* Location:
 * Qualified Name:     org.netbeans.spi.editor.mimelookup.MimeLookupInitializer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
1

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