@Override
  public void enumerateKnownFiles(ICollection collection, List<String> dsDefinitions)
      throws IOException {
    if (collection.exists()) {
      List<IResource> resources = collection.getResources();
      for (Iterator<IResource> iterator = resources.iterator(); iterator.hasNext(); ) {
        IResource resource = iterator.next();
        if (resource != null && resource.getName() != null) {
          if (resource.getName().endsWith(EXTENSION_TABLE)
              || resource.getName().endsWith(EXTENSION_VIEW)) {
            //						# 177
            //						String fullPath = collection.getPath().substring(
            //								this.location.length())
            //								+ IRepository.SEPARATOR + resource.getName();
            String fullPath = resource.getPath();
            dsDefinitions.add(fullPath);
          }
        }
      }

      List<ICollection> collections = collection.getCollections();
      for (Iterator<ICollection> iterator = collections.iterator(); iterator.hasNext(); ) {
        ICollection subCollection = iterator.next();
        enumerateKnownFiles(subCollection, dsDefinitions);
      }
    }
  }
 protected static final String readFile(IFile file) throws ContentProviderException {
   try {
     BufferedReader in = null;
     if (file.getClass()
         .getCanonicalName()
         .equals("org.eclipse.dirigible.ide.workspace.impl.File")) {
       in = new BufferedReader(new InputStreamReader(file.getContents()));
     } else {
       IResource resource = getFromRepository(file);
       in =
           new BufferedReader(
               new InputStreamReader(new ByteArrayInputStream(resource.getContent())));
     }
     StringBuilder builder = new StringBuilder();
     String line = null;
     while ((line = in.readLine()) != null) {
       builder.append(line);
       builder.append("\n"); // $NON-NLS-1$
     }
     return builder.toString();
   } catch (Exception ex) {
     LOGGER.error(CANNOT_READ_FILE_CONTENTS, ex);
     throw new ContentProviderException(CANNOT_READ_FILE_CONTENTS, ex);
   }
 }
  private JsonObject parseTable(String dsDefinition) throws IOException {
    // {
    // "tableName":"table_name",
    // "columns":
    // [
    // {
    // "name":"id",
    // "type":"INTEGER",
    // "length":"0",
    // "notNull":"true",
    // "primaryKey":"true"
    // },
    // {
    // "name":"text",
    // "type":"VARCHAR",
    // "length":"32",
    // "notNull":"false",
    // "primaryKey":"false"
    // },
    // ]
    // }
    IRepository repository = this.repository;
    //		# 177
    //		IResource resource = repository.getResource(this.location + dsDefinition);
    IResource resource = repository.getResource(dsDefinition);

    String content = new String(resource.getContent());
    JsonParser parser = new JsonParser();
    JsonObject dsDefinitionObject = (JsonObject) parser.parse(content);

    // TODO validate the parsed content has the right structure

    return dsDefinitionObject;
  }
 private byte[] getSettingsByRootAsBytes(String root, String path, String name)
     throws IOException {
   String normalizedPath = normalizePath(path);
   String resourcePath = root + normalizedPath + IRepository.SEPARATOR + name + PROPERTIES_EXT;
   if ((repository != null) && repository.hasResource(resourcePath)) {
     IResource resource = repository.getResource(resourcePath);
     return resource.getContent();
   }
   return new byte[] {};
 }
  public static InputStream getInputStreamByTemplateLocation(String location) throws IOException {
    InputStream in = null;
    IRepository repository = RepositoryFacade.getInstance().getRepository();
    org.eclipse.dirigible.repository.api.IResource resource = repository.getResource(location);
    if (resource != null) {
      in = new ByteArrayInputStream(resource.getContent());
    }

    return in;
  }
 private Properties getSettingsByRoot(String root, String path, String name) throws IOException {
   String normalizedPath = normalizePath(path);
   String resourcePath = root + normalizedPath + IRepository.SEPARATOR + name + PROPERTIES_EXT;
   if ((repository != null) && repository.hasResource(resourcePath)) {
     IResource resource = repository.getResource(resourcePath);
     Properties properties = new Properties();
     properties.load(new ByteArrayInputStream(resource.getContent()));
     return properties;
   }
   return new Properties();
 }
  private void setSettingsByRootAsBytes(String root, String path, String name, byte[] bytes)
      throws IOException {
    String normalizedPath = normalizePath(path);
    String resourcePath = root + normalizedPath + IRepository.SEPARATOR + name + PROPERTIES_EXT;
    IResource resource = null;
    if ((repository != null) && repository.hasResource(resourcePath)) {
      resource = repository.getResource(resourcePath);
    } else {
      resource = repository.createResource(resourcePath);
    }

    resource.setContent(bytes);
  }
  private JsonObject parseView(String dsDefinition) throws IOException {
    // {
    // "viewName":"view_name",
    // "query":"SELECT * FROM table_name"
    // }
    IRepository repository = this.repository;
    IResource resource = repository.getResource(this.location + dsDefinition);
    String content = new String(resource.getContent());
    JsonParser parser = new JsonParser();
    JsonObject dsDefinitionObject = (JsonObject) parser.parse(content);

    // TODO validate the parsed content has the right structure

    return dsDefinitionObject;
  }
  private void setSettingsByRoot(String root, String path, String name, Properties properties)
      throws IOException {
    String normalizedPath = normalizePath(path);
    String resourcePath = root + normalizedPath + IRepository.SEPARATOR + name + PROPERTIES_EXT;
    IResource resource = null;
    if ((repository != null) && repository.hasResource(resourcePath)) {
      resource = repository.getResource(resourcePath);
    } else {
      resource = repository.createResource(resourcePath);
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    properties.store(baos, resource.getPath());

    resource.setContent(baos.toByteArray());
  }
 protected static final void writeFile(IFile file, byte[] content)
     throws ContentProviderException {
   try {
     if (file.getClass()
         .getCanonicalName()
         .equals("org.eclipse.dirigible.ide.workspace.impl.File")) {
       file.setContents(new ByteArrayInputStream(content), false, false, null);
     } else {
       IResource resource = getFromRepository(file);
       resource.setContent(content);
     }
   } catch (CoreException ex) {
     LOGGER.error(CANNOT_SAVE_FILE_CONTENTS, ex);
     throw new ContentProviderException(CANNOT_SAVE_FILE_CONTENTS, ex);
   } catch (IOException e) {
     LOGGER.error(CANNOT_SAVE_FILE_CONTENTS, e);
     throw new ContentProviderException(CANNOT_SAVE_FILE_CONTENTS, e);
   }
 }
 protected byte[] readResourceData(IResource resource) throws IOException {
   return resource.getContent();
 }