Example usage for org.apache.commons.vfs2 FileObject getName

List of usage examples for org.apache.commons.vfs2 FileObject getName

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject getName.

Prototype

FileName getName();

Source Link

Document

Returns the name of this file.

Usage

From source file:org.luwrain.app.commander.PanelArea.java

Object[] getNativeObjectsToProcess() {
    final FileObject[] objs = getFileObjectsToProcess();
    final List res = new LinkedList();
    for (FileObject f : objs) {
        if (f instanceof org.apache.commons.vfs2.provider.local.LocalFile)
            res.add(new File(f.getName().getPath()));
        if (f instanceof org.apache.commons.vfs2.provider.ftp.FtpFileObject) {
            try {
                final org.apache.commons.vfs2.provider.ftp.FtpFileObject ftpFile = (org.apache.commons.vfs2.provider.ftp.FtpFileObject) f;
                final java.net.URL root = new java.net.URL(ftpFile.getFileSystem().getRootURI());
                res.add(new java.net.URL(root, f.getName().getPath()));
            } catch (MalformedURLException e) {
                //FIXME:
            }//from   w  w w.j  av a  2 s. co  m
        }
    }
    return res.toArray(new Object[res.size()]);
}

From source file:org.luwrain.app.commander.PanelArea.java

File getOpenedAsFile() {
    if (!isLocalDir())
        return null;
    final FileObject obj = opened();
    return obj != null ? new File(obj.getName().getPath()) : null;
}

From source file:org.luwrain.app.commander.PanelArea.java

static private Serializable fileObjectToJavaObject(FileObject obj) {
    NullCheck.notNull(obj, "obj");
    if (obj instanceof org.apache.commons.vfs2.provider.local.LocalFile)
        return new File(obj.getName().getPath());
    if (obj instanceof org.apache.commons.vfs2.provider.ftp.FtpFileObject) {
        try {//www .  j  a v a2s .co m
            final org.apache.commons.vfs2.provider.ftp.FtpFileObject ftpFile = (org.apache.commons.vfs2.provider.ftp.FtpFileObject) obj;
            final java.net.URL root = new java.net.URL(ftpFile.getFileSystem().getRootURI());
            return new java.net.URL(root, obj.getName().getPath());
        } catch (MalformedURLException e) {
            //FIXME:
        }
    }
    return null;
}

From source file:org.metaborg.intellij.idea.projects.ArtifactProjectService.java

/**
 * {@inheritDoc}/*from   w w w. j av a  2s . c o m*/
 */
@Nullable
@Override
public IProject get(final FileObject resource) {
    Preconditions.checkNotNull(resource);

    @Nullable
    final FileObject artifactRoot = getArtifactRoot(resource);
    if (artifactRoot == null)
        return null;

    final FileName artifactName = artifactRoot.getName();

    @Nullable
    ArtifactProject project = this.projects.get(artifactName);
    if (project == null) {
        project = this.artifactProjectFactory.create(artifactRoot, null);
        this.projects.put(artifactName, project);
    }
    return project;
}

From source file:org.metaborg.intellij.idea.projects.ArtifactProjectService.java

/**
 * Determines the language artifact root of the specified file.
 *
 * @param file The file.// w  ww . j  a v  a  2s .c  om
 * @return The language artifact root; or <code>null</code> when there is none.
 */
@Nullable
private FileObject getArtifactRoot(final FileObject file) {
    @Nullable
    FileObject current = getRoot(file);
    while (current != null && !isArtifactRoot(current.getName())) {
        current = getParentRoot(current);
    }
    return current;
}

From source file:org.metaborg.intellij.jps.builders.BuilderMessageFormatter.java

/**
 * Formats a compiler message.//from ww w  .j a  va 2s  . co  m
 *
 * @param builderName The name of the builder.
 * @param message     The message to format.
 * @return The formatted message.
 */
public CompilerMessage formatMessage(final String builderName, final IMessage message) {
    final BuildMessage.Kind kind;
    switch (message.severity()) {
    case NOTE:
        kind = BuildMessage.Kind.INFO;
        break;
    case WARNING:
        kind = BuildMessage.Kind.WARNING;
        break;
    case ERROR:
        kind = BuildMessage.Kind.ERROR;
        break;
    default:
        throw new UnsupportedOperationException();
    }

    String msgString = message.message();
    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
    @Nullable
    Throwable exception = message.exception();
    while (exception != null) {
        msgString += "\n" + exception.getMessage();
        if (exception instanceof StrategoErrorExit) {
            final StrategoErrorExit strategoException = (StrategoErrorExit) exception;
            IStrategoList trace = strategoException.getTrace();
            while (!trace.isEmpty()) {
                msgString += "\n\t" + trace.head();
                trace = trace.tail();
            }
        }
        exception = exception.getCause();
    }

    final FileObject source = message.source();
    final String sourcePath;
    if (source != null) {
        sourcePath = source.getName().getPath();
    } else {
        sourcePath = null;
    }
    long problemBeginOffset = -1L;
    long problemEndOffset = -1L;
    long problemLocationOffset = -1L;
    long locationLine = -1L;
    long locationColumn = -1L;

    @Nullable
    final ISourceRegion region = message.region();
    if (!isEmptyRegion(region)) {
        problemBeginOffset = region.startOffset();
        problemEndOffset = region.endOffset();
        problemLocationOffset = region.startOffset();
        locationLine = region.startRow() + 1;
        locationColumn = region.startColumn() + 1;
    }

    return new CompilerMessage(builderName, kind, msgString, sourcePath, problemBeginOffset, problemEndOffset,
            problemLocationOffset, locationLine, locationColumn);
}

From source file:org.metaborg.intellij.jps.projects.JpsProjectService.java

/**
 * Determines whether the specified file is equal to or a descendant of the specified path.
 *
 * @param ancestor   The path.//w  w  w .  ja  v a 2s  .  co m
 * @param descendant The descendant.
 * @return <code>true</code> when the file is equal to or a descendant of the path;
 * otherwise, <code>false</code>.
 */
private boolean isEqualOrDescendant(final String ancestor, final FileObject descendant) {
    final FileObject contentRoot = this.resourceService.resolve(ancestor);
    final FileName lhs = contentRoot.getName();
    final FileName rhs = descendant.getName();
    return lhs.equals(rhs) || lhs.isDescendent(rhs);
}

From source file:org.metaborg.intellij.resources.DefaultIntelliJResourceService.java

/**
 * {@inheritDoc}/*ww  w. j ava  2 s  . c  o  m*/
 */
@Override
public final VirtualFile unresolve(final FileObject resource) {
    if (resource instanceof IntelliJFileObject) {
        final IntelliJFileObject intellijResource = (IntelliJFileObject) resource;
        try {
            return intellijResource.asVirtualFile();
        } catch (final FileSystemException e) {
            throw LoggerUtils2.exception(this.logger, UnhandledException.class,
                    "Unexpected exception while resolving file: {}", e, resource);
        }
    }

    final URI uri = toUri(resource.getName().getURI());
    @Nullable
    final VirtualFileSystem fileSystem = getFileSystem(uri);
    @Nullable
    final String path = getPath(uri);
    if (fileSystem == null || path == null) {
        throw LoggerUtils2.exception(this.logger, IllegalStateException.class, "Can't unresolve this URI: {}",
                uri);
    }
    return fileSystem.refreshAndFindFileByPath(path);
}

From source file:org.metaborg.intellij.vfs.IntelliJFileObject.java

/**
 * {@inheritDoc}/*from  w w  w .  j  av a2s  .  c o m*/
 */
@Override
protected void doRename(final FileObject newFile) throws Exception {
    assert isAttached();

    if (this.file == null)
        throw new RuntimeException("File not found.");

    ApplicationManager.getApplication().runWriteAction(() -> {
        try {
            this.file.rename(null, newFile.getName().getBaseName());
        } catch (final IOException e) {
            throw new UnhandledException(e);
        }
    });
}

From source file:org.mycore.common.content.MCRVFSContent.java

public MCRVFSContent(FileObject fo) throws IOException {
    this.fo = fo;
    setName(fo.getName().getBaseName());
    setSystemId(fo.getURL().toString());
}