public VResult[] check(VObject object) {
    XModelObject o = ((VObjectImpl) object).getModelObject();
    String paramName = o.getAttributeValue("param-name");
    if (paramName == null) return null;
    XModelObject parent = o.getParent();
    if (parent == null || !"WebAppServlet".equals(parent.getModelEntity().getName())) {
      return null;
    }
    if (!paramName.equals("config") && !paramName.startsWith("config/")) return null;

    String value = o.getAttributeValue("param-value");
    if (value == null || value.length() == 0) return null;
    XModel model = getXModel(object);
    XModelObject webRoot = model == null ? null : model.getByPath("FileSystems/WEB-ROOT");
    if (webRoot == null) return null;
    StringTokenizer st = new StringTokenizer(value, ",");
    while (st.hasMoreTokens()) {
      String path = st.nextToken().trim();
      if (path.length() == 0) continue;
      XModelObject fc = XModelImpl.getByRelativePath(model, path);
      if (fc == null) {
        return fire(object, "config.exists", "param-value", path);
      }
      String path2 = path.startsWith("/") ? path.substring(1) : path;
      XModelObject fc2 = webRoot.getChildByPath(path2);
      if (fc2 == null) {
        return fire(object, "config.exists", "param-value", path);
      }
      if (!fc2.getModelEntity().getName().startsWith("StrutsConfig")) {
        return fire(object, "config.valid", "param-value", path);
      }
    }
    return null;
  }
Esempio n. 2
0
  private void parseTLD(XModelObject o, IPath source, LoadedDeclarations ds) {
    TLDLibrary library = new TLDLibrary();
    library.setId(o);
    library.setURI(new XMLValueInfo(o, AbstractTagLib.URI));
    library.setDisplayName(new XMLValueInfo(o, TLDLibrary.DISPLAY_NAME));
    library.setShortName(new XMLValueInfo(o, ATTR_SHORTNAME));
    String version = o.getAttributeValue(TLDLibrary.VERSION);
    if (version == null) {
      if ("FileTLD_1_2".equals(o.getModelEntity().getName())) { // $NON-NLS-1$
        version = "1.2"; // $NON-NLS-1$
      } else {
        version = "1.1"; // $NON-NLS-1$
      }
      library.setVersion(version);
    } else {
      library.setVersion(new XMLValueInfo(o, TLDLibrary.VERSION));
    }

    ds.getLibraries().add(library);

    XModelObject[] ts = o.getChildren();
    for (XModelObject t : ts) {
      if (t.getModelEntity().getName().startsWith("TLDTag")) { // $NON-NLS-1$
        AbstractComponent tag = new TLDTag();
        tag.setId(t);

        tag.setName(new XMLValueInfo(t, XMLStoreConstants.ATTR_NAME));
        tag.setDescription(new XMLValueInfo(t, AbstractComponent.DESCRIPTION));
        tag.setComponentClass(new XMLValueInfo(t, ATTR_TAGCLASS));
        tag.setCanHaveBody(new XMLValueInfo(t, ATTR_BODY_CONTENT));

        XModelObject[] as = t.getChildren();
        for (XModelObject a : as) {
          if (a.getModelEntity().getName().startsWith("TLDAttribute")) { // $NON-NLS-1$
            AbstractAttribute attr = new TLDAttribute();
            attr.setId(a);
            attr.setName(new XMLValueInfo(a, XMLStoreConstants.ATTR_NAME));
            attr.setDescription(new XMLValueInfo(a, AbstractComponent.DESCRIPTION));
            attr.setRequired(new XMLValueInfo(a, AbstractAttribute.REQUIRED));

            tag.addAttribute(attr);
          }
        }

        library.addComponent(tag);
      }
    }
    XModelObject functions = o.getChildByPath("Functions"); // $NON-NLS-1$
    if (functions != null) {
      ts = functions.getChildren();
      for (XModelObject t : ts) {
        ELFunction f = new ELFunction();
        f.setId(t);
        f.setName(new XMLValueInfo(t, XModelObjectConstants.ATTR_NAME));
        f.setSignature(new XMLValueInfo(t, ATTR_FUNC_SIGN));
        f.setFunctionClass(new XMLValueInfo(t, ELFunction.FUNCTION_CLASS));
        library.addFunction(f);
      }
    }
  }
 public void saveTo(File f, XModelObject object) {
   XModelObject o = object.copy(1);
   XModelObject[] cs = o.getChildren();
   for (XModelObject c : cs) {
     if (c.getModelEntity().getName().equals("FileSystemJar")) { // $NON-NLS-1$
       o.removeChild(c);
     }
     if (!c.getAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION)
         .startsWith("%")) { // $NON-NLS-1$
       o.removeChild(c);
     }
   }
   util().save(f, o);
 }
Esempio n. 4
0
  private void parseFaceletTaglib(XModelObject o, IPath source, LoadedDeclarations ds) {
    FaceletTagLibrary library = new FaceletTagLibrary();
    library.setId(o);
    library.setURI(new XMLValueInfo(o, AbstractTagLib.URI));

    ds.getLibraries().add(library);

    XModelObject[] os = o.getChildren();
    for (XModelObject t : os) {
      String entity = t.getModelEntity().getName();
      if (entity.startsWith("FaceletTaglibTag")) { // $NON-NLS-1$
        FaceletTag tag = new FaceletTag();
        tag.setId(t);
        tag.setName(new XMLValueInfo(t, ATTR_TAG_NAME));
        tag.setDescription(new XMLValueInfo(t, AbstractComponent.DESCRIPTION));
        XModelObject d = t.getChildByPath("declaration"); // $NON-NLS-1$
        if (d != null
            && d.getModelEntity().getName().startsWith("FaceletTaglibComponent")) { // $NON-NLS-1$
          String componentType = d.getAttributeValue(ATTR_COMPONENT_TYPE); // $NON-NLS-1$
          if (componentType != null && componentType.length() > 0) {
            tag.setComponentType(new XMLValueInfo(d, ATTR_COMPONENT_TYPE)); // $NON-NLS-1$
          }
        }
        XModelObject[] as = t.getChildren();
        for (XModelObject a : as) {
          String entity2 = a.getModelEntity().getName();
          if (entity2.startsWith("FaceletTaglibAttribute")) { // $NON-NLS-1$
            FaceletAttribute attr = new FaceletAttribute();
            attr.setId(a);
            attr.setName(new XMLValueInfo(a, XMLStoreConstants.ATTR_NAME));
            attr.setDescription(new XMLValueInfo(a, AbstractComponent.DESCRIPTION));
            attr.setRequired(new XMLValueInfo(a, AbstractAttribute.REQUIRED));

            tag.addAttribute(attr);
          }
        }
        library.addComponent(tag);
      } else if (entity.startsWith("FaceletTaglibFunction")) { // $NON-NLS-1$
        ELFunction f = new ELFunction();
        f.setId(t);
        f.setName(new XMLValueInfo(t, ATTR_FUNC_NAME));
        f.setSignature(new XMLValueInfo(t, ATTR_FUNC_SIGN));
        f.setFunctionClass(new XMLValueInfo(t, ELFunction.FUNCTION_CLASS));
        library.addFunction(f);
      }
    }
  }
 private XModelObject validateLib(XModelObject object) {
   XModelObject lib = object.getChildByPath("lib"); // $NON-NLS-1$
   if (lib == null) {
     XModelObject wi = object.getChildByPath("WEB-INF"); // $NON-NLS-1$
     if (wi == null) return null;
     XModelObject lb = wi.getChildByPath("lib"); // $NON-NLS-1$
     if (lb == null) return null;
     lib = wi.getModel().createModelObject(XModelObjectConstants.ENT_FILE_SYSTEM_FOLDER, null);
     lib.setAttributeValue(XModelObjectConstants.ATTR_NAME, "lib"); // $NON-NLS-1$
     lib.setAttributeValue(
         XModelObjectConstants.ATTR_NAME_LOCATION,
         wi.getAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION) + "/lib"); // $NON-NLS-1$
     object.addChild(lib);
     object.setModified(true);
   }
   return lib;
 }
 void doAttributeTest(XModel model, String testName) {
   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 = model.getByPath(path);
       if (o == null) {
         sb.append("Cannot find object at " + path).append("\n");
         errorCount++;
         continue;
       }
       String attribute = t.getProperty("attributeName");
       if (attribute == null) {
         sb.append("Attribute name is required for this test " + path).append("\n");
         errorCount++;
         continue;
       }
       if (o.getModelEntity().getAttribute(attribute) == null) {
         sb.append("Attribute " + attribute + " is not found in object " + path).append("\n");
         errorCount++;
         continue;
       }
       String testValue = t.getProperty("attributeValue");
       String realValue = o.getAttributeValue(attribute);
       if (realValue == null || !realValue.equals(testValue)) {
         sb.append(
                 "Attribute "
                     + attribute
                     + " in object "
                     + path
                     + " has unexpected value '"
                     + realValue
                     + "'")
             .append("\n");
         errorCount++;
         continue;
       }
     }
   assertTrue(sb.toString(), errorCount == 0);
 }