示例#1
0
 @Override
 public Map<String, ?> getAttributes(URI uri, Map<?, ?> options) {
   Map<String, Object> result = new HashMap<String, Object>();
   String filePath = uri.toFileString();
   File file = new File(filePath);
   if (file.exists()) {
     Set<String> requestedAttributes = getRequestedAttributes(options);
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_TIME_STAMP)) {
       result.put(IURIConverter.ATTRIBUTE_TIME_STAMP, file.lastModified());
     }
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_LENGTH)) {
       result.put(IURIConverter.ATTRIBUTE_LENGTH, file.length());
     }
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_READ_ONLY)) {
       result.put(IURIConverter.ATTRIBUTE_READ_ONLY, !file.canWrite());
     }
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_HIDDEN)) {
       result.put(IURIConverter.ATTRIBUTE_HIDDEN, file.isHidden());
     }
     if (requestedAttributes == null
         || requestedAttributes.contains(IURIConverter.ATTRIBUTE_DIRECTORY)) {
       result.put(IURIConverter.ATTRIBUTE_DIRECTORY, file.isDirectory());
     }
   }
   return result;
 }
示例#2
0
  @Override
  public int compare(Viewer viewer, Object e1, Object e2) {
    int cat1 = category(e1);
    int cat2 = category(e2);

    if (cat1 != cat2) {
      return cat1 - cat2;
    }

    if (!(e1 instanceof IProperty)) {
      return 1;
    }
    if (!(e2 instanceof IProperty)) {
      return -1;
    }

    URI u1 = ((IProperty) e1).getURI();
    URI u2 = ((IProperty) e2).getURI();

    if (u1.equals(u2)) {
      return 0;
    }

    int cmpVal = getComparator().compare(u1.namespace().toString(), u2.namespace().toString());

    if (0 == cmpVal) {
      cmpVal = getComparator().compare(u1.localPart(), u2.localPart());
    }

    return cmpVal;
  }
示例#3
0
 /**
  * Creates an input stream for the file path and returns it.
  *
  * <p>This implementation allocates a {@link FileInputStream}.
  *
  * @return an open input stream.
  * @exception IOException if there is a problem obtaining an open input stream.
  */
 @Override
 public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException {
   String filePath = uri.toFileString();
   File file = new File(filePath);
   InputStream inputStream = new FileInputStream(file);
   Map<Object, Object> response = getResponse(options);
   if (response != null) {
     response.put(IURIConverter.RESPONSE_TIME_STAMP_PROPERTY, file.lastModified());
   }
   return inputStream;
 }
示例#4
0
 @Override
 public void setAttributes(URI uri, Map<String, ?> attributes, Map<?, ?> options)
     throws IOException {
   String filePath = uri.toFileString();
   File file = new File(filePath);
   if (file.exists()) {
     Long timeStamp = (Long) attributes.get(IURIConverter.ATTRIBUTE_TIME_STAMP);
     if (timeStamp != null && !file.setLastModified(timeStamp)) {
       throw new IOException("Could not set the timestamp for the file '" + file + "'");
     }
     Boolean isReadOnly = (Boolean) attributes.get(IURIConverter.ATTRIBUTE_READ_ONLY);
     if (Boolean.TRUE.equals(isReadOnly) && !file.setReadOnly()) {
       throw new IOException("Could not set the file '" + file + "' to be read only");
     }
   } else {
     throw new FileNotFoundException("The file '" + file + "' does not exist");
   }
 }
示例#5
0
 /**
  * Creates an output stream for the file path and returns it.
  *
  * <p>This implementation allocates a {@link FileOutputStream} and creates subdirectories as
  * necessary.
  *
  * @return an open output stream.
  * @exception IOException if there is a problem obtaining an open output stream.
  */
 @Override
 public OutputStream createOutputStream(URI uri, Map<?, ?> options) throws IOException {
   String filePath = uri.toFileString();
   final File file = new File(filePath);
   String parent = file.getParent();
   if (parent != null) {
     new File(parent).mkdirs();
   }
   final Map<Object, Object> response = getResponse(options);
   OutputStream outputStream =
       new FileOutputStream(file) {
         @Override
         public void close() throws IOException {
           try {
             super.close();
           } finally {
             if (response != null) {
               response.put(IURIConverter.RESPONSE_TIME_STAMP_PROPERTY, file.lastModified());
             }
           }
         }
       };
   return outputStream;
 }
示例#6
0
 @Override
 public boolean exists(URI uri, Map<?, ?> options) {
   String filePath = uri.toFileString();
   File file = new File(filePath);
   return file.exists();
 }
示例#7
0
 @Override
 public void delete(URI uri, Map<?, ?> options) throws IOException {
   String filePath = uri.toFileString();
   File file = new File(filePath);
   file.delete();
 }
示例#8
0
 @Override
 public boolean canHandle(URI uri) {
   return uri.isFile();
 }
示例#9
0
  protected void addBasicKnowledge(Repository repository) throws RepositoryException {
    String[] bundles = {"net.enilink.vocab.owl", "net.enilink.vocab.rdfs"};

    if (AbstractKommaPlugin.IS_ECLIPSE_RUNNING) {
      RepositoryConnection conn = null;
      try {
        conn = repository.getConnection();
        URI defaultGraph = getDefaultGraph();
        Resource[] contexts =
            defaultGraph == null
                ? new Resource[0]
                : new Resource[] {repository.getValueFactory().createURI(defaultGraph.toString())};
        if (!conn.hasStatement(null, null, null, false, contexts)) {
          for (String name : bundles) {
            URL url = Platform.getBundle(name).getResource("META-INF/org.openrdf.ontologies");
            if (url != null) {
              URL resolvedUrl = FileLocator.resolve(url);

              Properties properties = new Properties();
              InputStream in = resolvedUrl.openStream();
              properties.load(in);
              in.close();

              URI baseUri = URIs.createURI(url.toString()).trimSegments(1);
              for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                String file = entry.getKey().toString();
                if (file.contains("rdfs") && skipRdfsOnImport()) {
                  // skip RDF and RDFS schema
                  continue;
                }

                URI fileUri = URIs.createFileURI(file);
                fileUri = fileUri.resolve(baseUri);

                resolvedUrl = FileLocator.resolve(new URL(fileUri.toString()));
                if (resolvedUrl != null) {
                  in = resolvedUrl.openStream();
                  if (in != null && in.available() > 0) {
                    conn.add(in, "", RDFFormat.RDFXML, contexts);
                  }
                  if (in != null) {
                    in.close();
                  }
                }
              }
            }
          }
        }
      } catch (IOException e) {
        throw new KommaException("Cannot access RDF data", e);
      } catch (RepositoryException e) {
        throw new KommaException("Loading RDF failed", e);
      } catch (RDFParseException e) {
        throw new KommaException("Invalid RDF data", e);
      } finally {
        if (conn != null) {
          try {
            conn.close();
          } catch (RepositoryException e) {
            ModelPlugin.log(e);
          }
        }
      }
    }
  }