@CheckForNull public static BasicSourceFileObject create ( @NonNull final FileObject file, @NonNull final FileObject root) { try { return new BasicSourceFileObject ( new Handle(file, root), null, null, false); } catch (IOException ioe) { if (LOG.isLoggable(Level.SEVERE)) LOG.log(Level.SEVERE, ioe.getMessage(), ioe); return null; } }
@Override public boolean equals(Object obj) { if (file != null) { return super.equals(obj); } else if (obj instanceof AbstractSourceFileObject.Handle) { try { return getURL().equals(((AbstractSourceFileObject.Handle) obj).getURL()); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } return false; }
@Override public String getExt() { String ext = super.getExt(); if (ext == null) { ext = FileObjects.getExtension(path.getPath()); } return ext; }
@Override public final boolean delete() { if (isDirty() != null) { //If the file is modified in editor do not delete it return false; } else { final FileObject file = handle.resolveFileObject(false); if (file == null) { return false; } try { FileLock lock = file.lock(); try { file.delete (lock); return true; } finally { lock.releaseLock(); } } catch (IOException e) { return false; } } }
/** * Creates {@link JavaFileObject} for a NetBeans {@link FileObject} * Any client which needs to create {@link JavaFileObject} for java * source file should use this factory method. * @param {@link FileObject} for which the {@link JavaFileObject} should be created * @param {@link FileObject} root owning the file * @param renderNow if true the snap shot of the file is taken immediately * @return {@link JavaFileObject}, never returns null * @exception {@link IOException} may be thrown */ public static AbstractSourceFileObject sourceFileObject (final FileObject file, final FileObject root, final JavaFileFilterImplementation filter, final CharSequence content) throws IOException { assert file != null; if (!file.isValid() || file.isVirtual()) { throw new InvalidFileException (file); } return AbstractSourceFileObject.getFactory().createJavaFileObject( new AbstractSourceFileObject.Handle(file, root), filter, content, true); }
/** * Creates {@link JavaFileObject} for a NetBeans {@link FileObject} * Any client which needs to create {@link JavaFileObject} for java * source file should use this factory method. * @param {@link FileObject} for which the {@link JavaFileObject} should be created * @param {@link FileObject} root owning the file * @param renderNow if true the snap shot of the file is taken immediately * @return {@link JavaFileObject}, never returns null * @exception {@link IOException} may be thrown */ public static AbstractSourceFileObject sourceFileObject (final FileObject file, final FileObject root, JavaFileFilterImplementation filter, boolean renderNow) throws IOException { assert file != null; if (!file.isValid() || file.isVirtual()) { throw new InvalidFileException (file); } return AbstractSourceFileObject.getFactory().createJavaFileObject( new AbstractSourceFileObject.Handle(file, root), filter, null, renderNow); }
@Override public FileObject resolveFileObject(boolean write) { FileObject res = super.resolveFileObject(write); if (res == null) { try { if (write) { //Create the file file = FileUtil.createData(root,getRelativePath()); } else { //Resolve file file = URLMapper.findFileObject(path); } res = file; } catch (IOException e) { //pass, return null } } return res; }
@Override @NonNull protected final CharSequence createContent() throws IOException { final FileObject file = getHandle().resolveFileObject(false); if (file == null) { throw new FileNotFoundException("Cannot open file: " + toString()); } final Source source = Source.create(file); if (source == null) { throw new IOException("No source for: " + FileUtil.getFileDisplayName(file)); //NOI18N } CharSequence content = source.createSnapshot().getText(); if (hasFilter && source.getDocument(false) == null) { content = filter(content); } return content; }
@Override protected final Long isDirty() { final FileObject file = getHandle().resolveFileObject(false); if (file == null) { return null; } final Source source = Source.create(file); if (source != null) { Document doc = source.getDocument(false); if (doc != null) { return DocumentUtilities.getDocumentTimestamp(doc); } } return null; }
@Override public void run () { try { doc.remove(0,doc.getLength()); doc.insertString(0,new String( data, 0, pos, FileEncodingQuery.getEncoding(getHandle().resolveFileObject(false))), null); } catch (BadLocationException e) { if (LOG.isLoggable(Level.SEVERE)) LOG.log(Level.SEVERE, e.getMessage(), e); } } });
public final void update (CharSequence content) throws IOException { if (content == null) { update(); } else { if (filter != null) { final FileObject file = handle.resolveFileObject(false); if (file != null) { final Source source = Source.create(file); if (source != null && source.getDocument(false) == null) { content = filter.filterCharSequence(content); } } } this.text = toString(content); } this.tokens = null; }
@Override public final URI toUri () { if (this.uri == null) { try { this.uri = URI.create(this.handle.getURL().toExternalForm()); } catch (IOException e) { LOG.log( Level.SEVERE, e.getMessage(), e); } } return this.uri; }
@Override @NonNull public final OutputStream openOutputStream() throws IOException { final FileObject file = handle.resolveFileObject(true); if (file == null) { throw new IOException("Cannot create file: " + toString()); //NOI18N } OutputStream res = createOutputStream(); if (res == null) { res = new LckStream (file); } return res; }
@Override @CheckForNull protected final OutputStream createOutputStream() throws IOException { final FileObject file = getHandle().resolveFileObject(true); if (file == null) { throw new IOException("Cannot create file: " + toString()); //NOI18N } final StyledDocument doc = getDocument(); if (doc != null) { return new DocumentStream (doc); } return null; }
@NonNull public final String getNameWithoutExtension() { return this.handle.getName(false); }
@Override public final int hashCode () { return this.handle.hashCode(); }
@Override public String getName(boolean includeExtension) { String name = super.getName(includeExtension); if (name == null) { name = FileObjects.getBaseName(path.getPath(),NBFS_SEPARATOR_CHAR); if (!includeExtension) { name = FileObjects.stripExtension(name); } } return name; }
private boolean isModifiedByWorkingCopy() { final FileObject file = handle.resolveFileObject(false); if (file == null) { return false; } return SourceFileManager.getModifiedFiles().isModified(file.toURI()); }
@Override @NonNull public final String getName() { return this.handle.getName(true); }
@Override public String getRelativePath() { String relativePath = super.getRelativePath(); if (relativePath == null) { try { relativePath = FileObjects.getRelativePath(root.toURL(), path); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } } return relativePath; }