Java 类com.intellij.util.UriUtil 实例源码

项目:consulo-javaee    文件:WebUtil.java   
public static VirtualFile findSourceFile(@NotNull String relative, @NotNull CommonModel commonModel, @NotNull Function<DeploymentModel, String> fun)
{
    Pair<DeploymentModel, String> deploymentModel = findDeploymentModel(UriUtil.trimTrailingSlashes(relative), commonModel, fun);
    if(deploymentModel == null)
    {
        return null;
    }

    Artifact artifact = deploymentModel.getFirst().getArtifact();
    if(artifact == null)
    {
        return null;
    }

    for(JavaWebModuleExtension facet : JavaeeArtifactUtil.getInstance().getFacetsIncludedInArtifact(commonModel.getProject(), artifact, JavaWebModuleExtension.class))
    {
        VirtualFile file = getWebUtil().createWebDirectoryElement(facet, deploymentModel.getSecond(), false).getOriginalVirtualFile();
        if(file != null)
        {
            return file;
        }
    }
    return null;
}
项目:consulo-javaee    文件:WebUtil.java   
@Nullable
private static Pair<DeploymentModel, String> findDeploymentModel(String relative, CommonModel commonModel, Function<DeploymentModel, String> fun)
{
    DeploymentModel defaultModel = null;
    for(DeploymentModel deploymentModel : commonModel.getDeploymentModels())
    {
        String contextPath = fun.fun(deploymentModel);
        if(contextPath == null)
        {
            continue;
        }

        contextPath = com.intellij.javaee.UriUtil.trimSlashFrom(contextPath);
        if(contextPath.isEmpty())
        {
            defaultModel = deploymentModel;
        }
        else if(relative.startsWith(contextPath))
        {
            return Pair.create(deploymentModel, relative.substring(contextPath.length()));
        }
    }
    return defaultModel != null ? Pair.create(defaultModel, relative) : null;
}
项目:consulo    文件:FileTemplatesLoader.java   
protected FileTemplatesLoader(@Nonnull FileTypeManagerEx typeManager, @Nullable Project project) {
  myTypeManager = typeManager;
  File configDir = project == null || project.isDefault()
                   ? new File(PathManager.getConfigPath(), TEMPLATES_DIR)
                   : new File(UriUtil.trimTrailingSlashes(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR));
  myDefaultTemplatesManager = new FTManager(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, configDir);
  myInternalTemplatesManager = new FTManager(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, new File(configDir, INTERNAL_DIR), true);
  myPatternsManager = new FTManager(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY, new File(configDir, INCLUDES_DIR));
  myCodeTemplatesManager = new FTManager(FileTemplateManager.CODE_TEMPLATES_CATEGORY, new File(configDir, CODE_TEMPLATES_DIR));
  myJ2eeTemplatesManager = new FTManager(FileTemplateManager.J2EE_TEMPLATES_CATEGORY, new File(configDir, J2EE_TEMPLATES_DIR));
  myAllManagers = new FTManager[]{myDefaultTemplatesManager, myInternalTemplatesManager, myPatternsManager, myCodeTemplatesManager, myJ2eeTemplatesManager};

  myDirToManagerMap.put("", myDefaultTemplatesManager);
  myDirToManagerMap.put(INTERNAL_DIR + "/", myInternalTemplatesManager);
  myDirToManagerMap.put(INCLUDES_DIR + "/", myPatternsManager);
  myDirToManagerMap.put(CODE_TEMPLATES_DIR + "/", myCodeTemplatesManager);
  myDirToManagerMap.put(J2EE_TEMPLATES_DIR + "/", myJ2eeTemplatesManager);

  loadDefaultTemplates();
  for (FTManager manager : myAllManagers) {
    manager.loadCustomizedContent();
  }
}
项目:intellij-ce-playground    文件:VcsDirectoryConfigurationPanel.java   
@Override
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
  if (value instanceof MapInfo) {
    MapInfo info = (MapInfo)value;

    if (!selected && (info == MapInfo.SEPARATOR || info.type == MapInfo.Type.UNREGISTERED)) {
      setBackground(getUnregisteredRootBackground());
    }

    if (info == MapInfo.SEPARATOR) {
      append("Unregistered roots:", getAttributes(info));
      return;
    }

    if (info.mapping.isDefaultMapping()) {
      append(VcsDirectoryMapping.PROJECT_CONSTANT, getAttributes(info));
      return;
    }

    String directory = info.mapping.getDirectory();
    VirtualFile baseDir = myProject.getBaseDir();
    if (baseDir != null) {
      final File directoryFile = new File(StringUtil.trimEnd(UriUtil.trimTrailingSlashes(directory), "\\") + "/");
      File ioBase = new File(baseDir.getPath());
      if (directoryFile.isAbsolute() && !FileUtil.isAncestor(ioBase, directoryFile, false)) {
        append(new File(directory).getPath(), getAttributes(info));
        return;
      }
      String relativePath = FileUtil.getRelativePath(ioBase, directoryFile);
      if (".".equals(relativePath) || relativePath == null) {
        append(ioBase.getPath(), getAttributes(info));
      }
      else {
        append(relativePath, getAttributes(info));
        append(" (" + ioBase + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
      }
    }
  }
}
项目:intellij-ce-playground    文件:GitHttpGuiAuthenticator.java   
@NotNull
private String findPresetHttpUrl() {
  return ObjectUtils.chooseNotNull(ContainerUtil.find(myUrlsFromCommand, new Condition<String>() {
    @Override
    public boolean value(String url) {
      String scheme = UriUtil.splitScheme(url).getFirst();
      return scheme.startsWith("http");
    }
  }), ContainerUtil.getFirstItem(myUrlsFromCommand));
}
项目:intellij-ce-playground    文件:RootUrlInfo.java   
public RootUrlInfo(@NotNull final Node node,
                   @NotNull final WorkingCopyFormat format,
                   @NotNull final VirtualFile root,
                   @Nullable final NestedCopyType type) {
  myNode = node;
  myFormat = format;
  myRoot = root;
  myRepositoryUrl = UriUtil.trimTrailingSlashes(node.getRepositoryRootUrl().toString());
  myType = type;
}
项目:intellij-ce-playground    文件:SvnChangeList.java   
public SvnChangeList(SvnVcs vcs, @NotNull final SvnRepositoryLocation location, final LogEntry logEntry, String repositoryRoot) {
  myVcs = vcs;
  myLocation = location;
  setRevision(logEntry.getRevision());
  myAuthor = StringUtil.notNullize(logEntry.getAuthor());
  myDate = logEntry.getDate();
  myMessage = StringUtil.notNullize(logEntry.getMessage());
  myRepositoryRoot = UriUtil.trimTrailingSlashes(repositoryRoot);

  myCommonPathSearcher = new CommonPathSearcher();

  myKnownAsDirectories = new HashSet<String>(0);
  for(LogEntryPath entry : logEntry.getChangedPaths().values()) {
    final String path = entry.getPath();

    if (entry.isDirectory()) {
      myKnownAsDirectories.add(path);
    }

    myCommonPathSearcher.next(path);

    if (entry.getType() == 'A') {
      if (entry.getCopyPath() != null) {
        myCopiedAddedPaths.put(path, entry.getCopyPath());
      }
      myAddedPaths.add(path);
    }
    else if (entry.getType() == 'D') {
      myDeletedPaths.add(path);
    }
    else {
      if (entry.getType() == 'R') {
        myReplacedPaths.add(path);
      }
      myChangedPaths.add(path);
    }
  }
}
项目:consulo    文件:VcsDirectoryConfigurationPanel.java   
@Override
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
  if (value instanceof MapInfo) {
    MapInfo info = (MapInfo)value;

    if (!selected && (info == MapInfo.SEPARATOR || info.type == MapInfo.Type.UNREGISTERED)) {
      setBackground(getUnregisteredRootBackground());
    }

    if (info == MapInfo.SEPARATOR) {
      append("Unregistered roots:", getAttributes(info));
      return;
    }

    if (info.mapping.isDefaultMapping()) {
      append(VcsDirectoryMapping.PROJECT_CONSTANT, getAttributes(info));
      return;
    }

    String directory = info.mapping.getDirectory();
    VirtualFile baseDir = myProject.getBaseDir();
    if (baseDir != null) {
      final File directoryFile = new File(StringUtil.trimEnd(UriUtil.trimTrailingSlashes(directory), "\\") + "/");
      File ioBase = new File(baseDir.getPath());
      if (directoryFile.isAbsolute() && !FileUtil.isAncestor(ioBase, directoryFile, false)) {
        append(new File(directory).getPath(), getAttributes(info));
        return;
      }
      String relativePath = FileUtil.getRelativePath(ioBase, directoryFile);
      if (".".equals(relativePath) || relativePath == null) {
        append(ioBase.getPath(), getAttributes(info));
      }
      else {
        append(relativePath, getAttributes(info));
        append(" (" + ioBase + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
      }
    }
  }
}
项目:intellij-ce-playground    文件:VirtualDirectoryImpl.java   
@Nullable // null if there can't be a child with this name, NULL_VIRTUAL_FILE if cached as absent, the file if found
private VirtualFileSystemEntry doFindChild(@NotNull String name,
                                           boolean ensureCanonicalName,
                                           @NotNull NewVirtualFileSystem delegate,
                                           boolean ignoreCase) {
  if (name.isEmpty()) {
    return null;
  }

  VirtualFileSystemEntry found = doFindChildInArray(name, ignoreCase);
  if (found != null) return found;

  if (allChildrenLoaded()) {
    return NULL_VIRTUAL_FILE;
  }

  if (ensureCanonicalName) {
    name = UriUtil.trimTrailingSlashes(UriUtil.trimLeadingSlashes(FileUtilRt.toSystemIndependentName(name)));
    if (name.indexOf('/') != -1) return null; // name must not contain slashes in the middle
    VirtualFile fake = new FakeVirtualFile(this, name);
    name = delegate.getCanonicallyCasedName(fake);
    if (name.isEmpty()) return null;
  }

  VirtualFileSystemEntry child;
  synchronized (myData) {
    // maybe another doFindChild() sneaked in the middle
    if (myData.isAdoptedName(name)) return NULL_VIRTUAL_FILE;

    int[] array = myData.myChildrenIds;
    int indexInReal = findIndex(array, name, ignoreCase);
    // double check
    if (indexInReal >= 0) {
      return VfsData.getFileById(array[indexInReal], this);
    }
    if (allChildrenLoaded()) {
      return null;
    }

    // do not extract getId outside the synchronized block since it will cause a concurrency problem.
    int id = ourPersistence.getId(this, name, delegate);
    if (id <= 0) {
      myData.addAdoptedName(name, !ignoreCase);
      return null;
    }
    child = createChild(FileNameCache.storeName(name), id, delegate);

    int[] after = myData.myChildrenIds;
    if (after != array)  {
      // in tests when we call assertAccessInTests it can load a huge number of files which lead to children modification
      // so fall back to slow path
      addChild(child);
    }
    else {
      insertChildAt(child, indexInReal);
      assertConsistency(!delegate.isCaseSensitive(), name);
    }
  }

  if (!child.isDirectory()) {
    // access check should only be called when child is actually added to the parent, otherwise it may break VirtualFilePointers validity
    //noinspection TestOnlyProblems
    VfsRootAccess.assertAccessInTests(child, getFileSystem());
  }

  return child;
}
项目:vso-intellij    文件:TfsUtil.java   
public static String appendPath(URI serverUri, String path) {
  path = StringUtil.trimStart(path, "/");
  return UriUtil.trimTrailingSlashes(serverUri.toString()) + "/" + path.replace(" ", "%20");
}
项目:consulo    文件:VirtualDirectoryImpl.java   
@Nullable // null if there can't be a child with this name, NULL_VIRTUAL_FILE if cached as absent, the file if found
private VirtualFileSystemEntry doFindChild(@Nonnull String name,
                                           boolean ensureCanonicalName,
                                           @Nonnull NewVirtualFileSystem delegate,
                                           boolean ignoreCase) {
  if (name.isEmpty()) {
    return null;
  }
  if (!isValid()) {
    throw new InvalidVirtualFileAccessException(this);
  }

  VirtualFileSystemEntry found = doFindChildInArray(name, ignoreCase);
  if (found != null) return found;

  if (allChildrenLoaded()) {
    return NULL_VIRTUAL_FILE;
  }

  if (ensureCanonicalName) {
    name = UriUtil.trimTrailingSlashes(UriUtil.trimLeadingSlashes(FileUtilRt.toSystemIndependentName(name)));
    if (name.indexOf('/') != -1) return null; // name must not contain slashes in the middle
    VirtualFile fake = new FakeVirtualFile(this, name);
    name = delegate.getCanonicallyCasedName(fake);
    if (name.isEmpty()) return null;
  }

  VirtualFileSystemEntry child;
  synchronized (myData) {
    // maybe another doFindChild() sneaked in the middle
    if (myData.isAdoptedName(name)) return NULL_VIRTUAL_FILE;

    int[] array = myData.myChildrenIds;
    int indexInReal = findIndex(array, name, ignoreCase);
    // double check
    if (indexInReal >= 0) {
      return VfsData.getFileById(array[indexInReal], this);
    }
    if (allChildrenLoaded()) {
      return null;
    }

    // do not extract getId outside the synchronized block since it will cause a concurrency problem.
    int id = ourPersistence.getId(this, name, delegate);
    if (id <= 0) {
      myData.addAdoptedName(name, !ignoreCase);
      return null;
    }
    child = createChild(FileNameCache.storeName(name), id, delegate);

    int[] after = myData.myChildrenIds;
    if (after != array)  {
      // in tests when we call assertAccessInTests it can load a huge number of files which lead to children modification
      // so fall back to slow path
      addChild(child);
    }
    else {
      insertChildAt(child, indexInReal);
      assertConsistency(!delegate.isCaseSensitive(), name);
    }
  }

  if (!child.isDirectory()) {
    // access check should only be called when child is actually added to the parent, otherwise it may break VirtualFilePointers validity
    //noinspection TestOnlyProblems
    VfsRootAccess.assertAccessInTests(child, getFileSystem());
  }

  return child;
}