public LoadedDeclarations parse(XModelObject o, IPath source, IKbProject sp) { if (o == null) return null; if (o.getParent() instanceof FolderImpl) { IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(source); if (f != null && f.exists()) { try { ((FolderImpl) o.getParent()).updateChildFile(o, f.getLocation().toFile()); } catch (XModelException e) { ModelPlugin.getPluginLog().logError(e); } if (o.getParent() == null) { boolean b = isLikelyComponentSource(f); if (!b) return null; o = EclipseResourceUtil.getObjectByResource(o.getModel(), f); if (o == null) return null; } } } LoadedDeclarations ds = new LoadedDeclarations(); if (LibraryScanner.isTLDFile(o)) { parseTLD(o, source, ds); } else if (LibraryScanner.isFaceletTaglibFile(o)) { parseFaceletTaglib(o, source, ds); } else if (LibraryScanner.isFacesConfigFile(o)) { parseFacesConfig(o, source, ds); } return ds; }
public boolean isFileChanged() { XModelObject o = getXModelObject(); IFile f1 = super.getFile(); if (o == null || o.getPath() == null) return false; IFile f2 = getFileByObject(o); return !f1.equals(f2); }
public void synchronize() { XModelObject o = getXModelObject(); IFile f1 = super.getFile(); if (o == null || o.getPath() == null) return; IFile f2 = getFileByObject(o); if (!f1.equals(f2) && f2 != null) hackSetFile(f2); }
public void load(XModelObject object) { if (EclipseResourceUtil.isProjectFragment(object.getModel())) return; IAutoLoad auto = (IAutoLoad) object.getModel().getProperties().get(XModelConstants.AUTOLOAD); if (auto != null) { auto.load(object.getModel()); updateLibs(object); _updateSrcs(object); ((FileSystemsImpl) object).updateOverlapped(); return; } String f = getEclipseFileName(object, true); if (f == null) super.load(object); else util().load(new File(f), object); XModelObject[] os = object.getChildren(); for (int i = 0; i < os.length; i++) { String s = os[i].getAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION); if (s == null || !s.startsWith(XModelConstants.WORKSPACE_OLD_REF)) continue; s = XModelConstants.WORKSPACE_REF + s.substring(XModelConstants.WORKSPACE_OLD_REF.length()); os[i].setAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION, s); } removeMissingJarSystems(object); }
public void update() { if (!object.isActive()) { if (file == null) return; else file = null; } else if (file == null) { XModelObject f = object; while (f != null && f.getFileType() != XModelObject.FILE) f = f.getParent(); if (f instanceof FileAnyImpl) file = (FileAnyImpl) f; } if (file == null) { fileTimeStamp = -1; start = -1; end = -1; line = -1; return; } long ts = (file == null) ? -1 : file.getTimeStamp(); if (ts == fileTimeStamp) return; fileTimeStamp = ts; String text = file.getAsText(); PositionSearcher searcher = new PositionSearcher(); searcher.init(text, object, attribute); searcher.execute(); start = searcher.getStartPosition(); end = searcher.getEndPosition(); line = computeLine(text, start); }
public void updateSrcs(XModelObject object) { IAutoLoad auto = (IAutoLoad) object.getModel().getProperties().get(XModelConstants.AUTOLOAD); if (auto == null && WatcherLoader.isLocked(object.getModel())) { return; } _updateSrcs(object); }
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; }
protected String getAddActionPath() { XModelObject o = helper.getModelObject(); XActionList l = (XActionList) o.getModelEntity().getActionList().getItem("CreateActions"); // $NON-NLS-1$ XActionItem[] is = l.getActionItems(); if (is.length != 1 || !(is[0] instanceof XAction)) return null; return "CreateActions" + "." + is[0].getName(); // $NON-NLS-1$ //$NON-NLS-2$ }
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(); }
private static String getNextSrcName(XModelObject object) { if (object.getChildByPath("src") == null) return "src"; // $NON-NLS-1$ //$NON-NLS-2$ int i = 1; while (true) { String s = "src-" + i; // $NON-NLS-1$ if (object.getChildByPath(s) == null) return s; i++; } }
void printPaths(XModelObject o) { if (o == null) { System.out.println("null"); return; } System.out.println(o.getPath()); XModelObject[] cs = o.getChildren(); for (int i = 0; i < cs.length; i++) printPaths(cs[i]); }
void removeMissingJarSystems(XModelObject object) { XModelObject[] os = object.getChildren("FileSystemJar"); // $NON-NLS-1$ for (int i = 0; i < os.length; i++) { JarSystemImpl jar = (JarSystemImpl) os[i]; String location = jar.getLocation(); if (location != null && !new File(location).isFile()) { jar.removeFromParent(); object.setModified(true); } } }
protected void edit() { XModelObject o = helper.getModelObject(xtable.getSelectionIndex()); if (o == null) return; XActionList l = (XActionList) o.getModelEntity().getActionList(); if (l.getAction("Edit") != null) { // $NON-NLS-1$ callAction(o, "Edit"); // $NON-NLS-1$ } else if (l.getAction("EditActions.Edit") != null) { // $NON-NLS-1$ callAction(o, "EditActions.Edit"); // $NON-NLS-1$ } else { callAction(o, "Properties.Properties"); // $NON-NLS-1$ } }
public static PositionHolder getPosition(XModelObject object, String attribute) { String id = (attribute == null) ? POSITION_HOLDER_ID : POSITION_HOLDER_ID + "." + attribute; // $NON-NLS-1$ PositionHolder h = (PositionHolder) object.getObject(id); if (h == null) { h = new PositionHolder(object, attribute); object.setObject(id, h); } return h; }
protected void setOtherProperties(XModelObject object, Properties p) { String fvi = p.getProperty("from-view-id"); // $NON-NLS-1$ XModelObject parent = object.getParent(); while (parent != null && !(parent instanceof JSFNavigationModel)) { parent = parent.getParent(); } if (parent != null) { JSFNavigationModel m = (JSFNavigationModel) parent; int i = m.getRuleCount(fvi); p.setProperty("index", "" + i); // $NON-NLS-1$ //$NON-NLS-2$ } }
private void setSelectedProperties(String[] s) { XModelObject[] cs = propertyListObject.getChildren(); for (int i = 0; i < cs.length; i++) cs[i].removeFromParent(); for (int i = 0; i < s.length; i++) { XModelObject c = propertyListObject .getModel() .createModelObject("JSFDataTableProperty", null); // $NON-NLS-1$ c.setAttributeValue("name", s[i]); // $NON-NLS-1$ propertyListObject.addChild(c); } propertyListEditor.update(); }
public static IEditorInput checkInput(IEditorInput input) { if (input instanceof IModelObjectEditorInput) return input; if (input instanceof ILocationProvider) return convertExternalInput((ILocationProvider) input); if (input instanceof IFileEditorInput) return convertFileInput((IFileEditorInput) input); if (input instanceof IStorageEditorInput) return convertStorageEditorInput((IStorageEditorInput) input); if (input instanceof IURIEditorInput) { URI uri = ((IURIEditorInput) input).getURI(); String f = uri.getPath(); XModelObject o = EclipseResourceUtil.createObjectForLocation(f); return (o == null || o.getFileType() != XModelObject.FILE) ? (IEditorInput) input : new ModelObjectLocationEditorInput(getMainObject(o), new Path(f)); } return input; }
private String getEclipseFileName(XModelObject object, boolean load) { String project = object.getModel().getProperties().getProperty(IModelNature.ECLIPSE_PROJECT); if (project == null) return null; String fn = project + XModelObjectConstants.SEPARATOR + IModelNature.PROJECT_FILE; if (!load || new File(fn).exists()) return fn; return null; }
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); } } }
public boolean update(XModelObject object) throws XModelException { boolean b = true; IAutoLoad auto = (IAutoLoad) object.getModel().getProperties().get(XModelConstants.AUTOLOAD); if (auto != null) { auto.update(object.getModel()); } XModelObject[] cs = object.getChildren(); for (int i = 0; i < cs.length; i++) { XObjectLoader loader = XModelObjectLoaderUtil.getObjectLoader(cs[i]); if (loader != null) b &= loader.update(cs[i]); } updateClassPath(object); ((FileSystemsImpl) object).updateOverlapped(); return b; }
public boolean save(XModelObject object) { if (!fsutil.isModified(object)) return true; if (object.getModel().getProperties().get(XModelConstants.AUTOLOAD) != null) { return true; } String s = getEclipseFileName(object, false); boolean b = (s == null) ? super.save(object.copy(1)) : saveEclipse(object.copy(1)); if (((FileSystemsImpl) object).requestSave()) return true; XModelObject[] cs = object.getChildren(); for (int i = 0; i < cs.length; i++) { XObjectLoader loader = XModelObjectLoaderUtil.getObjectLoader(cs[i]); if (loader != null) b &= loader.save(cs[i]); } return b; }
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); }
public String[] getSelectedProperties() { support.store(); XModelObject[] cs = propertyListObject.getChildren(); String[] s = new String[cs.length]; for (int i = 0; i < cs.length; i++) { s[i] = cs[i].getAttributeValue("name"); // $NON-NLS-1$ } return s; }
private static IEditorInput convertFileInput(IFileEditorInput input) { IFileEditorInput fi = (IFileEditorInput) input; IFile f = fi.getFile(); if (f != null && !f.isSynchronized(IResource.DEPTH_INFINITE)) { try { f.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { // ignore } } XModelObject o = EclipseResourceUtil.getObjectByResource(f); if (o == null) { o = EclipseResourceUtil.createObjectForResource(f); } return (o == null || o.getFileType() != XModelObject.FILE) ? input : new XModelObjectEditorInput(getMainObject(o)); }
private void saveWorkspaceHomeAttr(Element element, XModelObject o) { Properties p = o.getModel().getProperties(); String project = p.getProperty(IModelNature.ECLIPSE_PROJECT); String workspace = p.getProperty(XModelConstants.WORKSPACE); if (project == null) return; String relative = workspace.startsWith(project + XModelObjectConstants.SEPARATOR) ? "." + workspace.substring(project.length()) : workspace; //$NON-NLS-1$ element.setAttribute("workspace-home", relative); // $NON-NLS-1$ }
public boolean saveChildren(Element element, XModelObject o) { if ("FileSystemJar".equals(o.getModelEntity().getName())) { // $NON-NLS-1$ return true; } boolean b = super.saveChildren(element, o); if (b && isFileSystems(element.getNodeName())) { saveWorkspaceHomeAttr(element, o); XModelObject w = getWeb(o); if (w != null) save(element, w); } return b; }
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 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); }
private void updateLibs(XModelObject object) { if (WatcherLoader.isLocked(object.getModel())) { return; } IProject project = EclipseResourceUtil.getProject(object); if (project == null) return; XModelObject lib = validateLib(object); // if(lib == null) { // return; // } Libs libs = FileSystemsHelper.getLibs(object); if (libs != null) libs.update(); }
private String[] getAvailableProperties(String value) { if (value == null || value.length() == 0) { return new String[0]; } JSFPromptingProvider provider = new JSFPromptingProvider(); XModel xModel = getXModel(); if (xModel == null) { // lets create fake model, which can build properties for the value. IFile file = (IFile) properties.get("file"); // $NON-NLS-1$ if (file != null) { XModelObject f = EclipseResourceUtil.createObjectForResource(file); if (f != null) { xModel = f.getModel(); } } } if (xModel == null) { return new String[0]; } return (String[]) provider.buildBeanProperties(xModel, value, null).toArray(new String[0]); }