Search in sources :

Example 1 with HttpFileSystem

use of com.intellij.openapi.vfs.ex.http.HttpFileSystem in project intellij-community by JetBrains.

the class HtmlFileImpl method resolveFileReference.

@Nullable
@Override
public PsiFileSystemItem resolveFileReference(@NotNull FileReference reference, @NotNull String name) {
    VirtualFile file = getVirtualFile();
    if (!(file instanceof HttpVirtualFile)) {
        return null;
    }
    VirtualFile parent = file;
    if (!parent.isDirectory()) {
        parent = parent.getParent();
        if (parent == null) {
            parent = file;
        }
    }
    VirtualFile childFile = parent.findChild(name);
    HttpFileSystem fileSystem = (HttpFileSystem) parent.getFileSystem();
    if (childFile == null) {
        childFile = fileSystem.createChild(parent, name, !reference.isLast());
    }
    if (childFile.isDirectory()) {
        // pre create children
        VirtualFile childParent = childFile;
        FileReference[] references = reference.getFileReferenceSet().getAllReferences();
        for (int i = reference.getIndex() + 1, n = references.length; i < n; i++) {
            FileReference childReference = references[i];
            childParent = fileSystem.createChild(childParent, childReference.decode(childReference.getText()), i != (n - 1));
        }
        return getManager().findDirectory(childFile);
    } else {
        return getManager().findFile(childFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HttpVirtualFile(com.intellij.openapi.vfs.impl.http.HttpVirtualFile) HttpVirtualFile(com.intellij.openapi.vfs.impl.http.HttpVirtualFile) HttpFileSystem(com.intellij.openapi.vfs.ex.http.HttpFileSystem) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with HttpFileSystem

use of com.intellij.openapi.vfs.ex.http.HttpFileSystem in project intellij-community by JetBrains.

the class XmlResourceResolver method getBaseFile.

private PsiFile getBaseFile(String baseSystemId) {
    PsiFile baseFile = resolve(null, baseSystemId);
    if (baseFile != null)
        return baseFile;
    // Find relative to myFile
    File workingFile = new File("");
    String workingDir = workingFile.getAbsoluteFile().getAbsolutePath().replace(File.separatorChar, '/');
    String id = StringUtil.replace(baseSystemId, workingDir, myFile.getVirtualFile().getParent().getPath());
    VirtualFile vFile = UriUtil.findRelative(id, myFile);
    if (vFile == null) {
        vFile = UriUtil.findRelative(baseSystemId, myFile);
    }
    if (vFile == null) {
        try {
            vFile = VirtualFileManager.getInstance().findFileByUrl(VfsUtilCore.convertFromUrl(new URL(baseSystemId)));
        } catch (MalformedURLException ignore) {
        }
    }
    if (vFile != null && !vFile.isDirectory() && !(vFile.getFileSystem() instanceof HttpFileSystem)) {
        baseFile = PsiManager.getInstance(myProject).findFile(vFile);
    }
    return baseFile;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MalformedURLException(java.net.MalformedURLException) PsiFile(com.intellij.psi.PsiFile) HttpFileSystem(com.intellij.openapi.vfs.ex.http.HttpFileSystem) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) URL(java.net.URL)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 HttpFileSystem (com.intellij.openapi.vfs.ex.http.HttpFileSystem)2 HttpVirtualFile (com.intellij.openapi.vfs.impl.http.HttpVirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 FileReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference)1 XmlFile (com.intellij.psi.xml.XmlFile)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Nullable (org.jetbrains.annotations.Nullable)1