Ejemplo n.º 1
0
  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;
  }
 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);
   }
 }
Ejemplo n.º 3
0
 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[] {};
 }
Ejemplo n.º 4
0
  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;
  }
Ejemplo n.º 5
0
 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();
 }
Ejemplo n.º 6
0
  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;
  }
Ejemplo n.º 7
0
 protected byte[] readResourceData(IResource resource) throws IOException {
   return resource.getContent();
 }