/**
  * @see
  *     com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
  *     com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
  */
 public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
   StructuredModelWrapper smw = new StructuredModelWrapper();
   smw.init(document);
   try {
     IFile documentFile = smw.getFile();
     if (documentFile == null) {
       return false;
     }
     IProject project = documentFile.getProject();
     if (project == null) {
       return false;
     }
     if (EclipseResourceUtil.getModelNature(project) != null) {
       for (int i = 0; i < JSF_PROJECT_NATURES.length; i++) {
         if (project.getNature(JSF_PROJECT_NATURES[i]) != null) return true;
       }
       return false;
     }
     return true;
   } catch (CoreException x) {
     JSFExtensionsPlugin.log("", x); // $NON-NLS-1$
     return false;
   } finally {
     smw.dispose();
   }
 }
Ejemplo n.º 2
0
 public void testWebApp() {
   String testName = "WebAppModelTest:testPaths:attribute";
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   doAttributeTest(n.getModel(), testName);
   XModelObject o = n.getModel().getByPath("/web30.xml");
   printPaths(o);
 }
Ejemplo n.º 3
0
  public void testPaths() {
    IModelNature n = EclipseResourceUtil.getModelNature(project);
    String testName = "JSFModelTest:testPaths";
    IFile f = project.getFile(new Path("/testCases.xml"));
    ArrayList<TestDescription> tests = new TestDescriptionFactory(f).getTestDescriptions(testName);
    System.out.println(testName + " " + (tests == null ? -1 : tests.size()));
    StringBuilder sb = new StringBuilder();
    int errorCount = 0;

    if (tests != null)
      for (int i = 0; i < tests.size(); i++) {
        TestDescription t = tests.get(i);
        String path = t.getProperty("path");
        XModelObject o = n.getModel().getByPath(path);
        if (o == null) {
          sb.append(path).append("\n");
          errorCount++;
        }
      }
    assertTrue(
        "Cannot find objects at " + errorCount + " paths\n" + sb.toString(), errorCount == 0);

    testName = "JSFModelTest:testPaths:attribute";
    doAttributeTest(n.getModel(), testName);
  }
 public static XModelObject getJarEntryObject(IProject p, String jarFile, String entry) {
   if (p == null) {
     IFile f = EclipseResourceUtil.getFile(jarFile);
     if (f == null) return null;
     p = f.getProject();
   }
   if (p == null) return null;
   IModelNature n = EclipseResourceUtil.getModelNature(p);
   XModel model = null;
   if (n != null) {
     model = n.getModel();
   } else {
     XModelObject o = EclipseResourceUtil.createObjectForResource(p);
     if (o != null) model = o.getModel();
   }
   if (model == null) return null;
   XModelObject[] fs = FileSystemsHelper.getFileSystems(model).getChildren();
   for (XModelObject s : fs) {
     String loc =
         Paths.expand(s.get(XModelObjectConstants.ATTR_NAME_LOCATION), model.getProperties());
     if (new File(loc).equals(new File(jarFile))) {
       XModelObject result = s.getChildByPath(entry);
       if (result == null && entry != null) {
         int q = entry.indexOf('/');
         int d = entry.indexOf('.');
         if (q > d && d >= 0) {
           String entry1 = entry.substring(0, q).replace('.', '/') + entry.substring(q);
           result = s.getChildByPath(entry1);
         }
       }
       if (result != null) return result;
     }
   }
   return (n == null) ? null : n.getModel().getByPath("/" + entry); // $NON-NLS-1$
 }
 public static XModel getXModel(IFile file) {
   if (file == null) return null;
   XModelObject fs = EclipseResourceUtil.getObjectByResource(file);
   if (fs != null) return fs.getModel();
   IProject project = file.getProject();
   IModelNature nature = EclipseResourceUtil.getModelNature(project);
   return (nature == null) ? null : nature.getModel();
 }
Ejemplo n.º 6
0
 public void testJSFProjectStructure() {
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   JSFProjectsRoot root = JSFProjectsTree.getProjectsRoot(n.getModel());
   assertTrue("Cannot find root object.", root != null);
   XModelObject[] cs = root.getTreeChildren();
   for (int i = 0; i < cs.length; i++) {
     System.out.println(cs[i].getPath());
   }
 }
 XFilteredTree createTree(String name, XModel model) {
   if (model == null || name == null) return null;
   String classname =
       model.getMetaData().getMapping("FilteredTrees").getValue(name); // $NON-NLS-1$
   XFilteredTree result = null;
   try {
     result = (XFilteredTree) ModelFeatureFactory.getInstance().createFeatureInstance(classname);
   } catch (ClassCastException e) {
     ModelUIPlugin.getPluginLog().logError(e);
     return null;
   }
   result.setModel(model);
   if (result.getRoot() == null) {
     result = null;
     IProject p = EclipseResourceUtil.getProject(model.getRoot());
     IModelNature nature = EclipseResourceUtil.getModelNature(p);
     if (nature != null) {
       ModelUIPlugin.getPluginLog()
           .logInfo(
               "Red Hat Project " + p.getName() + " is corrupted."); // $NON-NLS-1$ //$NON-NLS-2$
     }
   }
   return result;
 }
Ejemplo n.º 8
0
 public void testWebAppLoader() {
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   XModelObject o = n.getModel().getByPath("/web30.xml");
   String error = ((AbstractXMLFileImpl) o).getLoaderError();
   assertNull("Loader reported an error.", error);
 }
Ejemplo n.º 9
0
 public void testModelExists() {
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   assertTrue("Test project " + project.getName() + " has no model nature.", n != null);
   assertTrue("XModel for project " + project.getName() + " is not loaded.", n.getModel() != null);
 }
Ejemplo n.º 10
0
 public void testRecognizer() {
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   EntityRecognizer recognizer = n.getModel().getEntityRecognizer();
   String entity = recognizer.getEntityName(new EntityRecognizerContext("tld", TLD_FILE));
   assertEquals("FileTLD_1_2", entity);
 }