Exemplo n.º 1
0
  /**
   * this will convert the IO file name of the resource bundle to java package name
   *
   * @param project
   * @param value - the io file name
   * @return - the java package name of the resource bundle
   */
  public static String convertIOToJavaFileName(IProject project, String value) {
    String rbIOFile = value.substring(value.lastIndexOf("/") + 1); // $NON-NLS-1$
    IFile resourceBundleFile = null;
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot wroot = workspace.getRoot();
    IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
    for (IClasspathEntry iClasspathEntry : cpEntries) {
      if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
        IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
        entryPath = entryPath.append(rbIOFile);
        resourceBundleFile = wroot.getFileForLocation(entryPath);
        // System.out.println( "ResourceBundleValidationService.validate():" + resourceBundleFile );
        if (resourceBundleFile != null && resourceBundleFile.exists()) {
          break;
        }
      }
    }

    String javaName = resourceBundleFile.getProjectRelativePath().toPortableString();
    if (javaName.indexOf('.') != -1) {
      // Strip the extension
      javaName = value.substring(0, value.lastIndexOf('.'));
      // Replace all "/" by "."
      javaName = javaName.replace('/', '.');
    }
    return javaName;
  }