org.eclipse.jst.jsf.common.ui_1.2.100.v201104061711

    if (result == null)
    {
      IPath path = new Path(typeContainerName.replace('.', '/'));
      result = jproject.findElement(path);
      if (!(result instanceof IPackageFragment)) {
        result = null;
      }
    }
    return result;
  }
  
  public static IType findTypeInCompilationUnit(ICompilationUnit cu, String typeQualifiedName)
    throws JavaModelException
  {
    IType[] types = cu.getAllTypes();
    for (int i = 0; i < types.length; i++)
    {
      String currName = getTypeQualifiedName(types[i]);
      if (typeQualifiedName.equals(currName)) {
        return types[i];
      }
    }
    return null;
  }
  
  public static IMember findMemberInCompilationUnit(ICompilationUnit cu, IMember member)
  {
    IJavaElement[] elements = cu.findElements(member);
    if ((elements != null) && (elements.length > 0)) {
      return (IMember)elements[0];
    }
    return null;
  }
  
  public static IJavaElement findInCompilationUnit(ICompilationUnit cu, IJavaElement element)
  {
    IJavaElement[] elements = cu.findElements(element);
    if ((elements != null) && (elements.length > 0)) {
      return elements[0];
    }
    return null;
  }
  
  public static String getTypeQualifiedName(IType type)
  {
    return type.getTypeQualifiedName('.');
  }
  
  public static String getFullyQualifiedName(IType type)
  {
    return type.getFullyQualifiedName('.');
  }
  
  public static String getTypeContainerName(IType type)
  {
    IType outerType = type.getDeclaringType();
    if (outerType != null) {
      return outerType.getFullyQualifiedName('.');
    }
    return type.getPackageFragment().getElementName();
  }
  
  public static String concatenateName(String name1, String name2)
  {
    StringBuffer buf = new StringBuffer();
    if ((name1 != null) && (name1.length() > 0)) {
      buf.append(name1);
    }
    if ((name2 != null) && (name2.length() > 0))
    {
      if (buf.length() > 0) {
        buf.append('.');
      }
      buf.append(name2);
    }
    return buf.toString();
  }
  
  public static String concatenateName(char[] name1, char[] name2)
  {
    StringBuffer buf = new StringBuffer();
    if ((name1 != null) && (name1.length > 0)) {
      buf.append(name1);
    }
    if ((name2 != null) && (name2.length > 0))
    {
      if (buf.length() > 0) {
        buf.append('.');
      }
      buf.append(name2);
    }
    return buf.toString();
  }
  
  public static boolean isVisible(IMember member, IPackageFragment pack)
    throws JavaModelException
  {
    int type = member.getElementType();
    if ((type == 10) || (
      (type == 9) && 
      (member.getElementName().startsWith("<")))) {
      return false;
    }
    int otherflags = member.getFlags();
    IType declaringType = member.getDeclaringType();
    if ((Flags.isPublic(otherflags)) || (
      (declaringType != null) && (declaringType.isInterface()))) {
      return true;
    }
    if (Flags.isPrivate(otherflags)) {
      return false;
    }
    IPackageFragment otherpack = (IPackageFragment)findParentOfKind(
      member, 4);
    return (pack != null) && (otherpack != null) && (isSamePackage(pack, 
      otherpack));
  }
  
  public static boolean isVisibleInHierarchy(IMember member, IPackageFragment pack)
    throws JavaModelException
  {
    int type = member.getElementType();
    if ((type == 10) || (
      (type == 9) && 
      (member.getElementName().startsWith("<")))) {
      return false;
    }
    int otherflags = member.getFlags();
    
    IType declaringType = member.getDeclaringType();
    if ((Flags.isPublic(otherflags)) || (Flags.isProtected(otherflags)) || (
      (declaringType != null) && (declaringType.isInterface()))) {
      return true;
    }
    if (Flags.isPrivate(otherflags)) {
      return false;
    }
    IPackageFragment otherpack = (IPackageFragment)findParentOfKind(
      member, 4);
    return (pack != null) && (pack.equals(otherpack));
  }
  
  public static IPackageFragmentRoot getPackageFragmentRoot(IJavaElement element)
  {
    return (IPackageFragmentRoot)element
      .getAncestor(3);
  }
  
  /**
   * @deprecated
   */
  private static IJavaElement findParentOfKind(IJavaElement element, int kind)
  {
    if ((element != null) && (element.getParent() != null)) {
      return element.getParent().getAncestor(kind);
    }
    return null;
  }
  
  public static IMethod findMethod(String name, String[] paramTypes, boolean isConstructor, IType type)
    throws JavaModelException
  {
    return findMethod(name, paramTypes, isConstructor, type.getMethods());
  }
  
  public static IMethod findMethod(String name, String[] paramTypes, boolean isConstructor, IMethod[] methods)
    throws JavaModelException
  {
    for (int i = methods.length - 1; i >= 0; i--) {
      if (isSameMethodSignature(name, paramTypes, isConstructor, 
        methods[i])) {
        return methods[i];
      }
    }
    return null;
  }
  
  public static IMethod findMethodDeclarationInHierarchy(ITypeHierarchy hierarchy, IType type, String name, String[] paramTypes, boolean isConstructor)
    throws JavaModelException
  {
    IType[] superTypes = hierarchy.getAllSupertypes(type);
    for (int i = superTypes.length - 1; i >= 0; i--)
    {
      IMethod first = findMethod(name, paramTypes, isConstructor, 
        superTypes[i]);
      if ((first != null) && (!Flags.isPrivate(first.getFlags())))
      {
        IMethod res = findMethodDeclarationInHierarchy(hierarchy, first
          .getDeclaringType(), name, paramTypes, isConstructor);
        if (res != null) {
          return res;
        }
        return first;
      }
    }
    return null;
  }
  
  public static IMethod findMethodImplementationInHierarchy(ITypeHierarchy hierarchy, IType type, String name, String[] paramTypes, boolean isConstructor)
    throws JavaModelException
  {
    IType[] superTypes = hierarchy.getAllSuperclasses(type);
    for (int i = 0; i < superTypes.length; i++)
    {
      IMethod found = findMethod(name, paramTypes, isConstructor, 
        superTypes[i]);
      if (found != null)
      {
        if (Flags.isAbstract(found.getFlags())) {
          return null;
        }
        return found;
      }
    }
    return null;
  }
  
  private static IMethod findMethodInHierarchy(ITypeHierarchy hierarchy, IType type, String name, String[] paramTypes, boolean isConstructor)
    throws JavaModelException
  {
    IMethod method = findMethod(name, paramTypes, isConstructor, type);
    if (method != null) {
      return method;
    }
    IType superClass = hierarchy.getSuperclass(type);
    if (superClass != null)
    {
      IMethod res = findMethodInHierarchy(hierarchy, superClass, name, 
        paramTypes, isConstructor);
      if (res != null) {
        return res;
      }
    }
    if (!isConstructor)
    {
      IType[] superInterfaces = hierarchy.getSuperInterfaces(type);
      for (int i = 0; i < superInterfaces.length; i++)
      {
        IMethod res = findMethodInHierarchy(hierarchy, 
          superInterfaces[i], name, paramTypes, false);
        if (res != null) {
          return res;
        }
      }
    }
    return method;
  }
  
  public static IMethod findMethodDefininition(ITypeHierarchy typeHierarchy, IType type, String methodName, String[] paramTypes, boolean isConstructor, boolean testVisibility)
    throws JavaModelException
  {
    IType superClass = typeHierarchy.getSuperclass(type);
    if (superClass != null)
    {
      IMethod res = findMethodInHierarchy(typeHierarchy, superClass, 
        methodName, paramTypes, isConstructor);
      if ((res != null) && (!Flags.isPrivate(res.getFlags())) && (
        (!testVisibility) || 
        (isVisibleInHierarchy(res, type.getPackageFragment())))) {
        return res;
      }
    }
    if (!isConstructor)
    {
      IType[] interfaces = typeHierarchy.getSuperInterfaces(type);
      for (int i = 0; i < interfaces.length; i++)
      {
        IMethod res = findMethodInHierarchy(typeHierarchy, 
          interfaces[i], methodName, paramTypes, false);
        if (res != null) {
          return res;
        }
      }
    }
    return null;
  }
  
  public static boolean isSameMethodSignature(String name, String[] paramTypes, boolean isConstructor, IMethod curr)
    throws JavaModelException
  {
    if (((isConstructor) || (name.equals(curr.getElementName()))) && 
      (isConstructor == curr.isConstructor()))
    {
      String[] currParamTypes = curr.getParameterTypes();
      if (paramTypes.length == currParamTypes.length)
      {
        for (int i = 0; i < paramTypes.length; i++)
        {
          String t1 = Signature.getSimpleName(
            Signature.toString(paramTypes[i]));
          String t2 = Signature.getSimpleName(
            Signature.toString(currParamTypes[i]));
          if (!t1.equals(t2)) {
            return false;
          }
        }
        return true;
      }
    }
    return false;
  }
  
  public static boolean isSamePackage(IPackageFragment pack1, IPackageFragment pack2)
  {
    return pack1.getElementName().equals(pack2.getElementName());
  }
  
  public static boolean hasMainMethod(IType type)
    throws JavaModelException
  {
    IMethod[] methods = type.getMethods();
    for (int i = 0; i < methods.length; i++) {
      if (methods[i].isMainMethod()) {
        return true;
      }
    }
    return false;
  }
  
  public static boolean isBoolean(IField field)
    throws JavaModelException
  {
    return field.getTypeSignature().equals("Z");
  }
  
  public static boolean isOnClasspath(IJavaElement element)
  {
    IJavaProject project = element.getJavaProject();
    if (!project.exists()) {
      return false;
    }
    return project.isOnClasspath(element);
  }
  
  public static String getResolvedTypeName(String refTypeSig, IType declaringType)
    throws JavaModelException
  {
    int arrayCount = Signature.getArrayCount(refTypeSig);
    char type = refTypeSig.charAt(arrayCount);
    if (type == 'Q')
    {
      int semi = refTypeSig
        .indexOf(';', arrayCount + 1);
      if (semi == -1) {
        throw new IllegalArgumentException();
      }
      String name = refTypeSig.substring(arrayCount + 1, semi);
      
      String[][] resolvedNames = declaringType.resolveType(name);
      if ((resolvedNames != null) && (resolvedNames.length > 0)) {
        return concatenateName(resolvedNames[0][0], 
          resolvedNames[0][1]);
      }
      return null;
    }
    return Signature.toString(refTypeSig.substring(arrayCount));
  }
  
  public static boolean isEditable(ICompilationUnit cu)
  {
    IResource resource = toOriginal(cu).getResource();
    
    return (resource.exists()) && (!resource.getResourceAttributes().isReadOnly());
  }
  
  public static IImportDeclaration findImport(ICompilationUnit cu, String simpleName)
    throws JavaModelException
  {
    IImportDeclaration[] existing = cu.getImports();
    for (int i = 0; i < existing.length; i++)
    {
      String curr = existing[i].getElementName();
      if (curr.endsWith(simpleName))
      {
        int dotPos = curr.length() - simpleName.length() - 1;
        if ((dotPos == -1) || (
          (dotPos > 0) && (curr.charAt(dotPos) == '.'))) {
          return existing[i];
        }
      }
    }
    return null;
  }
  
  public static IMember toOriginal(IMember member)
  {
    if ((member instanceof IMethod)) {
      return toOriginalMethod((IMethod)member);
    }
    return (IMember)member.getPrimaryElement();
  }
  
  private static IMethod toOriginalMethod(IMethod method)
  {
    ICompilationUnit cu = method.getCompilationUnit();
    if ((cu == null) || (isPrimary(cu))) {
      return method;
    }
    try
    {
      if (!method.getElementName().equals(
        method.getDeclaringType().getElementName())) {
        return (IMethod)method.getPrimaryElement();
      }
      IType originalType = (IType)toOriginal(method.getDeclaringType());
      IMethod[] methods = originalType.findMethods(method);
      boolean isConstructor = method.isConstructor();
      for (int i = 0; i < methods.length; i++) {
        if (methods[i].isConstructor() == isConstructor) {
          return methods[i];
        }
      }
      return null;
    }
    catch (JavaModelException localJavaModelException) {}
    return null;
  }
  
  public static ICompilationUnit toOriginal(ICompilationUnit cu)
  {
    if (cu == null) {
      return cu;
    }
    return cu.getPrimary();
  }
  
  public static IJavaElement toOriginal(IJavaElement element)
  {
    return element.getPrimaryElement();
  }
  
  public static boolean isPrimary(ICompilationUnit cu)
  {
    return cu.getOwner() == null;
  }
  
  public static boolean filterNotPresentException(CoreException exception)
  {
    if (!(exception instanceof JavaModelException)) {
      return true;
    }
    JavaModelException je = (JavaModelException)exception;
    if (!je.isDoesNotExist()) {
      return true;
    }
    IJavaElement[] elements = je.getJavaModelStatus().getElements();
    for (int i = 0; i < elements.length; i++)
    {
      IJavaElement element = elements[i];
      ICompilationUnit unit = (ICompilationUnit)element
        .getAncestor(5);
      if (unit == null) {
        return true;
      }
      if (!unit.isWorkingCopy()) {
        return true;
      }
    }
    return false;
  }
  
  public static IType[] getAllSuperTypes(IType type, IProgressMonitor pm)
    throws JavaModelException
  {
    Set types = new HashSet(Arrays.asList(type.newSupertypeHierarchy(pm)
      .getAllSupertypes(type)));
    IType objekt = type.getJavaProject().findType("java.lang.Object");
    if (objekt != null) {
      types.add(objekt);
    }
    return (IType[])types.toArray(new IType[types.size()]);
  }
  
  public static boolean isExcludedPath(IPath resourcePath, IPath[] exclusionPatterns)
  {
    char[] path = resourcePath.toString().toCharArray();
    int i = 0;
    for (int length = exclusionPatterns.length; i < length; i++)
    {
      char[] pattern = exclusionPatterns[i].toString().toCharArray();
      if (CharOperation.pathMatch(pattern, path, true, '/')) {
        return true;
      }
    }
    return false;
  }
  
  public static boolean isExcluded(IPath resourcePath, char[][] exclusionPatterns)
  {
    if (exclusionPatterns == null) {
      return false;
    }
    char[] path = resourcePath.toString().toCharArray();
    int i = 0;
    for (int length = exclusionPatterns.length; i < length; i++) {
      if (CharOperation.pathMatch(exclusionPatterns[i], path, true, '/')) {
        return true;
      }
    }
    return false;
  }
  
  private static Boolean fgIsJDTCore_1_5 = null;
  
  public static boolean isJDTCore_1_5()
  {
    if (fgIsJDTCore_1_5 == null) {
      fgIsJDTCore_1_5 = 
      
        JavaCore.getDefaultOptions().containsKey(
        "org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation") ? Boolean.TRUE : 
        Boolean.FALSE;
    }
    return fgIsJDTCore_1_5.booleanValue();
  }
  
  public static IClasspathEntry getClasspathEntryToEdit(IJavaProject jproject, IPath containerPath, IPath libPath)
    throws JavaModelException
  {
    IClasspathContainer container = JavaCore.getClasspathContainer(
      containerPath, jproject);
    ClasspathContainerInitializer initializer = 
      JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if ((container != null) && 
      (initializer != null) && 
      (initializer.canUpdateClasspathContainer(containerPath, 
      jproject)))
    {
      IClasspathEntry[] entries = container.getClasspathEntries();
      for (int i = 0; i < entries.length; i++)
      {
        IClasspathEntry curr = entries[i];
        IClasspathEntry resolved = 
          JavaCore.getResolvedClasspathEntry(curr);
        if ((resolved != null) && (libPath.equals(resolved.getPath()))) {
          return curr;
        }
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.JavaModelUtil
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import java.io.File;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJarEntryResource;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

public final class PathUtil
{
  private static final String FORWARD_SLASH = "/";
  private static final String RELATIVE_PATH_SIGNAL = "../";
  
  public static String adjustPath(String path)
  {
    int i = 0;
    while ((i = path.indexOf("../")) > 0)
    {
      String part1 = path.substring(0, i - 1);
      String part2 = path
        .substring(i + "../".length() - 1);
      
      int j = part1.lastIndexOf("/");
      if (j == -1) {
        return "";
      }
      part1 = part1.substring(0, j);
      path = part1 + part2;
    }
    return path;
  }
  
  public static String appendTrailingURLSlash(String input)
  {
    if (!input.endsWith("/")) {
      input = input + "/";
    }
    return input;
  }
  
  public static String convertToRelativePath(String input, String base)
  {
    StringTokenizer inputTokenizer = new StringTokenizer(input, 
      "/");
    StringTokenizer baseTokenizer = new StringTokenizer(base, "/");
    String token1 = "";String token2 = "";
    do
    {
      if ((!inputTokenizer.hasMoreTokens()) || 
        (!baseTokenizer.hasMoreTokens())) {
        break;
      }
      token1 = baseTokenizer.nextToken();
      token2 = inputTokenizer.nextToken();
    } while (token1.equals(token2));
    String output = "";
    while (baseTokenizer.hasMoreTokens())
    {
      baseTokenizer.nextToken();
      output = output + "../";
    }
    output = output + token2;
    while (inputTokenizer.hasMoreTokens()) {
      output = output + "/" + inputTokenizer.nextToken();
    }
    return output;
  }
  
  public static String convertToWebPath(String projectName, String path)
  {
    String name = "";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
      projectName);
    String webrootName = WebrootUtil.getWebContentContainer(project).getName();
    if (path.indexOf(webrootName) != -1) {
      name = 
        projectName + "/" + webrootName;
    } else {
      name = projectName;
    }
    int index = path.indexOf(projectName);
    
    return path.substring(index + name.length());
  }
  
  public static String convertToAbsolutePath(String uri, IFile curFile)
  {
    if ((uri == null) || (uri.trim().equals(""))) {
      return uri;
    }
    String webroot = "";
    IFile jsp = curFile;
    try
    {
      if (jsp == null) {
        jsp = 
          ((IFileEditorInput)getActivePage().getActiveEditor().getEditorInput()).getFile();
      }
      if (jsp != null)
      {
        String webrootName = WebrootUtil.getWebContentContainer(
          jsp.getProject()).getName();
        webroot = jsp.getProject().getFolder(webrootName).getLocation()
          .toString();
      }
    }
    catch (NullPointerException localNullPointerException)
    {
      return uri;
    }
    if (uri.startsWith("/")) {
      return webroot + uri;
    }
    if (jsp != null)
    {
      IContainer con = jsp.getParent();
      if (con != null)
      {
        IPath path = con.getLocation();
        if (path != null)
        {
          String aPath = path.toString() + File.separator + uri;
          aPath = aPath.replace('/', File.separatorChar);
          aPath = aPath.replace('\\', File.separatorChar);
          if (aPath.endsWith(File.separator)) {
            aPath = aPath + "/";
          }
          File file = new File(aPath);
          if ((file.exists()) && (file.isFile())) {
            return file.getAbsolutePath();
          }
          return uri;
        }
      }
    }
    return uri;
  }
  
  private static IWorkbenchWindow getActiveWorkbenchWindow()
  {
    if (PlatformUI.getWorkbench() == null) {
      return null;
    }
    return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  }
  
  private static IWorkbenchPage getActivePage()
  {
    IWorkbenchWindow window = getActiveWorkbenchWindow();
    if (window == null) {
      return null;
    }
    return window.getActivePage();
  }
  
  public static IPath getPathOnClasspath(IJavaProject javaProject, Object parent)
  {
    IPath result = null;
    if ((javaProject == null) || (parent == null)) {
      return new Path("");
    }
    IClasspathEntry[] entries = javaProject.readRawClasspath();
    IPath classPath = null;
    if ((parent instanceof IResource))
    {
      if ((javaProject != null) && 
        (!javaProject.isOnClasspath((IResource)parent))) {
        return new Path("");
      }
      if ((parent instanceof IFile))
      {
        IPath elementPath = ((IFile)parent).getFullPath();
        if (((IFile)parent).getFileExtension().equalsIgnoreCase(
          "properties"))
        {
          int machings = 0;
          try
          {
            for (int i = 0; i < entries.length; i++)
            {
              int n = entries[i].getPath().matchingFirstSegments(
                elementPath);
              if (n > machings)
              {
                machings = n;
                classPath = elementPath.removeFirstSegments(
                  machings).removeLastSegments(1);
              }
            }
            if (classPath == null) {
              return null;
            }
            if (classPath.segmentCount() > 0)
            {
              IJavaElement element = javaProject
                .findElement(classPath);
              if (element != null)
              {
                IPath path = element.getPath();
                if (path != null)
                {
                  IPath path1 = path
                    .removeFirstSegments(machings);
                  
                  String fileName = ((IFile)parent)
                    .getName();
                  if (fileName != null) {
                    result = path1.append(fileName);
                  }
                }
              }
            }
            else
            {
              result = 
                ((IFile)parent).getFullPath().removeFirstSegments(machings);
            }
          }
          catch (Exception localException)
          {
            return null;
          }
        }
      }
    }
    else if ((parent instanceof IJarEntryResource))
    {
      IPath elementPath = ((IJarEntryResource)parent).getFullPath();
      if (elementPath.getFileExtension().equalsIgnoreCase(
        "properties")) {
        result = elementPath;
      }
    }
    if (result != null) {
      return result;
    }
    return new Path("");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.PathUtil
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Control;

public class PixelConverter
{
  private final FontMetrics fFontMetrics;
  
  public PixelConverter(Control control)
  {
    this(control.getFont());
  }
  
  public PixelConverter(Font font)
  {
    GC gc = new GC(font.getDevice());
    gc.setFont(font);
    fFontMetrics = gc.getFontMetrics();
    gc.dispose();
  }
  
  public int convertHeightInCharsToPixels(int chars)
  {
    return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
  }
  
  public int convertHorizontalDLUsToPixels(int dlus)
  {
    return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
  }
  
  public int convertVerticalDLUsToPixels(int dlus)
  {
    return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
  }
  
  public int convertWidthInCharsToPixels(int chars)
  {
    return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.PixelConverter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import java.util.HashMap;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

public class PluginImageHelper
{
  private static PluginImageHelper _instance = null;
  
  public static synchronized PluginImageHelper getInstance()
  {
    if (_instance == null) {
      _instance = new PluginImageHelper();
    }
    return _instance;
  }
  
  private HashMap _imageDescRegistry = null;
  private final String PLUGIN_SEPARATOR = "^";
  
  private Image createImage(String resource, String pluginId)
  {
    ImageDescriptor desc = getImageDescriptor(resource, pluginId);
    Image image = null;
    if (desc != null)
    {
      image = desc.createImage();
      if (!desc.equals(ImageDescriptor.getMissingImageDescriptor()))
      {
        String thePluginId = pluginId;
        if (thePluginId == null) {
          return null;
        }
        String key = thePluginId + "^" + resource;
        getImageRegistry().put(key, image);
      }
    }
    return image;
  }
  
  private ImageDescriptor createImageDescriptor(String imageFilePath, String pluginId)
  {
    String thePluginId = pluginId;
    if (thePluginId == null) {
      return null;
    }
    ImageDescriptor imageDescriptor = 
      AbstractUIPlugin.imageDescriptorFromPlugin(thePluginId, imageFilePath);
    if (imageDescriptor != null)
    {
      String key = thePluginId + "^" + imageFilePath;
      getImageDescriptorRegistry().put(key, imageDescriptor);
    }
    else
    {
      imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
    }
    return imageDescriptor;
  }
  
  public Image getImage(String resource)
  {
    return getImage(resource, null);
  }
  
  public Image getImage(String resource, String pluginId)
  {
    String thePluginId = pluginId;
    if (thePluginId == null) {
      return null;
    }
    String key = thePluginId + "^" + resource;
    
    Image image = getImageRegistry().get(key);
    if (image == null) {
      image = createImage(resource, pluginId);
    }
    return image;
  }
  
  public ImageDescriptor getImageDescriptor(String resource)
  {
    return getImageDescriptor(resource, null);
  }
  
  public ImageDescriptor getImageDescriptor(String resource, String pluginId)
  {
    ImageDescriptor imageDescriptor = null;
    String thePluginId = pluginId;
    if (thePluginId == null) {
      return null;
    }
    String key = thePluginId + "^" + resource;
    Object o = getImageDescriptorRegistry().get(key);
    if (o == null) {
      imageDescriptor = createImageDescriptor(resource, pluginId);
    } else {
      imageDescriptor = (ImageDescriptor)o;
    }
    return imageDescriptor;
  }
  
  private HashMap getImageDescriptorRegistry()
  {
    if (_imageDescRegistry == null) {
      _imageDescRegistry = new HashMap();
    }
    return _imageDescRegistry;
  }
  
  private ImageRegistry getImageRegistry()
  {
    return JFaceResources.getImageRegistry();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.PluginImageHelper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import org.eclipse.jst.jsf.common.ui.JSFUICommonPlugin;
import org.eclipse.jst.jsf.common.ui.internal.logging.Logger;

public final class PropertyUtils
{
  private static final String ENCODED_CHAR_PERCENT = "%25";
  private static final String ENCODED_CHAR_CARRIAGE_RETURN = "%0d";
  private static final String ENCODED_CHAR_TAB = "%09";
  private static final String ENCODED_CHAR_NEWLINE = "%0a";
  private static final String ENCODED_CHAR_SPACE = "%20";
  private static final String ENCODED_CHAR_COLON = "%3a";
  private static final String ENCODED_CHAR_EQUALS = "%3d";
  private static final String NAME_PROPERTIES = ".props";
  private static final String STR_BOUNDS_END = ".bounds";
  private static final int INSET = 40;
  
  public static String getProperty(Properties props, String key, String theDefault)
  {
    try
    {
      String value = props.getProperty(key, theDefault);
      if ((value != null) && (value.length() == 0)) {
        value = null;
      }
      if (value == null) {}
      return theDefault;
    }
    catch (Exception localException) {}
    return theDefault;
  }
  
  public static String getProperty(Properties props, String key)
  {
    try
    {
      String value = props.getProperty(key);
      if ((value != null) && (value.length() == 0)) {}
      return null;
    }
    catch (Exception localException) {}
    return null;
  }
  
  public static int getPropertyValue(Properties props, String key, int defaultValue, int minimumValue)
  {
    int theValue = getPropertyValue(props, key, defaultValue);
    if (theValue < minimumValue) {
      theValue = minimumValue;
    }
    return theValue;
  }
  
  public static int getPropertyValue(Properties props, String key, int defaultValue)
  {
    String stringValue = getProperty(props, key);
    if (stringValue != null) {
      try
      {
        return Integer.parseInt(stringValue);
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
    return defaultValue;
  }
  
  public static long getPropertyLongValue(Properties props, String key, long defaultValue)
  {
    String stringValue = getProperty(props, key);
    if (stringValue != null) {
      try
      {
        return Long.parseLong(stringValue);
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
    return defaultValue;
  }
  
  public static boolean isProperty(Properties props, String key, boolean bDefault)
  {
    return getProperty(props, key, bDefault).equals("true");
  }
  
  public static String[] getPropertyStrings(Properties props, String key)
  {
    String tokenString = getProperty(props, key);
    if (tokenString == null) {
      return new String[0];
    }
    StringTokenizer tokenizer = new StringTokenizer(tokenString, ",");
    String[] pNames = new String[tokenizer.countTokens()];
    for (int ii = 0; ii < pNames.length; ii++) {
      pNames[ii] = ((String)tokenizer.nextElement()).trim();
    }
    return pNames;
  }
  
  public static String getResourceProperty(ResourceBundle bundle, String key, String theDefault)
  {
    try
    {
      String value = bundle.getString(key);
      if ((value == null) || (value.length() == 0)) {}
      return theDefault;
    }
    catch (NullPointerException localNullPointerException)
    {
      return theDefault;
    }
    catch (MissingResourceException localMissingResourceException)
    {
      return theDefault;
    }
    catch (ClassCastException localClassCastException) {}
    return theDefault;
  }
  
  public static String getResourceProperty(ResourceBundle bundle, String key)
  {
    try
    {
      String value = bundle.getString(key);
      if ((value != null) && (value.length() == 0)) {}
      return null;
    }
    catch (NullPointerException localNullPointerException)
    {
      return null;
    }
    catch (MissingResourceException localMissingResourceException)
    {
      return null;
    }
    catch (ClassCastException localClassCastException) {}
    return null;
  }
  
  public static int getResourcePropertyValue(ResourceBundle bundle, String key, int defaultValue, int minimumValue)
  {
    int theValue = getResourcePropertyValue(bundle, key, defaultValue);
    if (theValue < minimumValue) {
      theValue = minimumValue;
    }
    return theValue;
  }
  
  public static int getResourcePropertyValue(ResourceBundle bundle, String key, int defaultValue)
  {
    String stringValue = getResourceProperty(bundle, key);
    if (stringValue != null) {
      try
      {
        return Integer.parseInt(stringValue);
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
    return defaultValue;
  }
  
  public static long getResourcePropertyLongValue(ResourceBundle bundle, String key, long defaultValue)
  {
    String stringValue = getResourceProperty(bundle, key);
    if (stringValue != null) {
      try
      {
        return Long.parseLong(stringValue);
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
    return defaultValue;
  }
  
  public static boolean isResourceProperty(ResourceBundle bundle, String key, boolean bDefault)
  {
    return 
      getResourceProperty(bundle, key, bDefault).equals("true");
  }
  
  public static String encodeName(String theName)
  {
    int theSize = theName.length();
    StringBuffer encoded = new StringBuffer(theSize);
    for (int ii = 0; ii < theSize; ii++)
    {
      char ch = theName.charAt(ii);
      switch (ch)
      {
      case '=': 
        encoded.append("%3d");
        break;
      case ':': 
        encoded.append("%3a");
        break;
      case ' ': 
        encoded.append("%20");
        break;
      case '\n': 
        encoded.append("%0a");
        break;
      case '\t': 
        encoded.append("%09");
        break;
      case '\r': 
        encoded.append("%0d");
        break;
      case '%': 
        encoded.append("%25");
        break;
      default: 
        encoded.append(ch);
      }
    }
    return encoded.toString();
  }
  
  public static String decodeName(String theName)
  {
    int theSize = theName.length();
    
    StringBuffer decoded = new StringBuffer(theSize);
    for (int ii = 0; ii < theSize; ii++)
    {
      char ch = theName.charAt(ii);
      if (ch == '%')
      {
        ch = theName.charAt(++ii);
        int kk = Character.digit(ch, 16);
        kk *= 16;
        ch = theName.charAt(++ii);
        kk += Character.digit(ch, 16);
        decoded.append((char)kk);
      }
      else
      {
        decoded.append(ch);
      }
    }
    return decoded.toString();
  }
  
  public static Properties openProperties(String propName)
    throws IOException, FileNotFoundException
  {
    return openProperties(propName, null, true);
  }
  
  public static Properties openProperties(String propName, Properties propDefaults)
    throws IOException, FileNotFoundException
  {
    return openProperties(propName, propDefaults, true);
  }
  
  public static Properties openProperties(String propName, Properties propDefaults, boolean bCreatePropertiesPathname)
    throws IOException, FileNotFoundException
  {
    Properties theProperties = new Properties(propDefaults);
    try
    {
      String propertiesFilename = bCreatePropertiesPathname ? getPropertiesPathname(propName) : 
        propName;
      InputStream theStream = new FileInputStream(propertiesFilename);
      theProperties.load(theStream);
      theStream.close();
    }
    catch (FileNotFoundException ee)
    {
      if (propDefaults == null) {
        throw ee;
      }
    }
    catch (IOException ee)
    {
      if (propDefaults == null) {
        throw ee;
      }
    }
    return theProperties;
  }
  
  public static Properties combineProperties(Properties localProperties, Properties defaultProperties)
    throws IOException
  {
    Properties theNewProperties = new Properties();
    
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    defaultProperties.store(os, "");
    localProperties.store(os, "");
    byte[] theData = os.toByteArray();
    ByteArrayInputStream is = new ByteArrayInputStream(theData);
    theNewProperties.load(is);
    
    return theNewProperties;
  }
  
  public static String encodeFilename(String theFilename)
  {
    String theSeparator = System.getProperty("file.separator");
    for (int ii = 0; ii < theSeparator.length(); ii++)
    {
      char theChar = theSeparator.charAt(ii);
      theFilename = theFilename.replace(theChar, ' ');
    }
    return theFilename;
  }
  
  public static String getPropertiesPathname(String baseName)
  {
    if (baseName.endsWith(".props")) {
      return 
      
        System.getProperty("user.dir") + System.getProperty("file.separator") + encodeFilename(baseName);
    }
    return 
    
      System.getProperty("user.dir") + System.getProperty("file.separator") + encodeFilename(baseName) + ".props";
  }
  
  public static void setComponentBounds(Properties props, Component theComponent, String[] names, String defaultValue)
  {
    setComponentBounds(props, theComponent, names, defaultValue, false);
  }
  
  public static void setComponentBounds(Properties props, Component theComponent, String[] names, String defaultValue, boolean bEnsureDesktopVisibility)
  {
    String tmpString = getComponentPropertyName(names, ".bounds");
    setComponentBounds(props, theComponent, tmpString, defaultValue, 
      bEnsureDesktopVisibility);
  }
  
  public static void setComponentBounds(Properties props, Component theComponent, String thePropertyName, String defaultValue)
  {
    setComponentBounds(props, theComponent, thePropertyName, defaultValue, 
      false);
  }
  
  public static void setComponentBounds(Properties props, Component theComponent, String thePropertyName, String defaultValue, boolean bEnsureDesktopVisibility)
  {
    String tmpString = props.getProperty(thePropertyName, defaultValue);
    Rectangle theValue = decodeBounds(tmpString);
    theComponent.setBounds(theValue);
    if (bEnsureDesktopVisibility)
    {
      Point theLoc = theComponent.getLocation();
      
      Dimension portSize = new Dimension(Toolkit.getDefaultToolkit()
        .getScreenSize());
      if (x > width) {
        x = 40;
      }
      if (y > height) {
        y = 40;
      }
      theComponent.setLocation(theLoc);
    }
  }
  
  public static void saveComponentBounds(Properties props, Component theComponent, String[] names)
  {
    String tmpString = getComponentPropertyName(names, ".bounds");
    saveComponentBounds(props, theComponent, tmpString);
  }
  
  public static void saveComponentBounds(Properties props, Component theComponent, String thePropertyName)
  {
    Rectangle theBounds = theComponent.getBounds();
    String theValue = encodeBounds(theBounds);
    props.put(thePropertyName, theValue);
  }
  
  public static String getComponentPropertyName(String[] names, String subsystemName)
  {
    String tmpString = "";
    for (int ii = 0; ii < names.length; ii++) {
      tmpString = 
        tmpString + (ii > 0 ? "." : "") + encodeName(names[ii]);
    }
    if (!subsystemName.startsWith(".")) {
      tmpString = tmpString + ".";
    }
    tmpString = tmpString + subsystemName;
    return tmpString;
  }
  
  public static Rectangle decodeBounds(String sBounds)
  {
    int[] theValue = new int[4];
    
    String restString = sBounds;
    for (int ii = 0; ii < 4; ii++) {
      theValue[ii] = 0;
    }
    try
    {
      for (ii = 0; ii < 4; ii++)
     
1 2 3 4 5 6 7 8 9 10 11

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