public static org.eclipse.jface.text.Document getTextDocument(File bundleLocation, String path) { ZipFile jarFile = null; InputStream stream = null; try { String extension = new Path(bundleLocation.getName()).getFileExtension(); if ("jar".equals(extension) && bundleLocation.isFile()) { //$NON-NLS-1$ jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ); ZipEntry manifestEntry = jarFile.getEntry(path); if (manifestEntry != null) { stream = jarFile.getInputStream(manifestEntry); } } else { File file = new File(bundleLocation, path); if (file.exists()) stream = new FileInputStream(file); } return getTextDocument(stream); } catch (IOException e) { } finally { try { if (jarFile != null) jarFile.close(); } catch (IOException e) { } } return null; }
stream = new FileInputStream(file); return getTextDocument(stream); } catch (IOException e) { PDECore.logException(e);
private static IBundle getTextBundle(IPluginModelBase model) { if (model != null) { if (!fileExists(model.getInstallLocation(), ICoreConstants.BUNDLE_FILENAME_DESCRIPTOR)) return null; IDocument doc = CoreUtility.getTextDocument(new File(model.getInstallLocation()), ICoreConstants.BUNDLE_FILENAME_DESCRIPTOR); IBundleModel bundleModel = new BundleModel(doc, false); try { bundleModel.load(); } catch (CoreException e) { } if (bundleModel.isLoaded()) return bundleModel.getBundle(); } return null; }
private static IPluginModelBase getTextModel(IPluginModelBase model, boolean fragment) { if (model instanceof PluginModel || model instanceof FragmentModel) return model; if (model != null) { if (!fileExists(model.getInstallLocation(), fragment ? ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR : ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR)) return null; IDocument doc = CoreUtility.getTextDocument(new File(model.getInstallLocation()), fragment ? ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR : ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR); IPluginModelBase returnModel; if (fragment) returnModel = new FragmentModel(doc, false); else returnModel = new PluginModel(doc, false); try { returnModel.load(); } catch (CoreException e) { } if (returnModel.isLoaded()) return returnModel; } return null; }
public void validateContent(IProgressMonitor monitor) { try { Document textDocument = CoreUtility.getTextDocument(fFile .getContents()); IDSModel model = new DSModel(textDocument, false); model.load(); IDSComponent component = model.getDSComponent(); validateComponentElement(component); validateImplementationElement(component.getImplementation()); validateServiceElement(component.getService()); validatePropertyElements(component.getPropertyElements()); validatePropertiesElements(component.getPropertiesElements()); validateReferenceElements(component.getReferences()); } catch (CoreException e) { Activator.log(e); } }