Exemplo n.º 1
0
  @Test
  public void getPortの引数にftpスキームのURIを渡した場合_マイナス1が返されること() {

    // Setup
    URI uri = URIUtil.toURI("ftp://www.ambrosoli.jp/"); // $NON-NLS-1$

    // Exercise
    int actual = URIUtil.getPort(uri);

    // Verify
    assertThat(actual, is(-1));
  }
Exemplo n.º 2
0
  @Test
  public void getPortの引数にポート番号を指定しないhttpsスキームのURIを渡した場合_443が返されること() {

    // Setup
    URI uri = URIUtil.toURI("https://www.ambrosoli.jp/"); // $NON-NLS-1$

    // Exercise
    int actual = URIUtil.getPort(uri);

    // Verify
    assertThat(actual, is(443));
  }
Exemplo n.º 3
0
  @Test
  public void getPortの引数にポート番号8080を指定したhttpスキームのURIを渡した場合_8080が返されること() {

    // Setup
    URI uri = URIUtil.toURI("http://www.ambrosoli.jp:8080/"); // $NON-NLS-1$

    // Exercise
    int actual = URIUtil.getPort(uri);

    // Verify
    assertThat(actual, is(8080));
  }
Exemplo n.º 4
0
  @Test
  public void addQueryStringの引数にURIと空文字を渡すと_クエリストリングが追加されないこと() {

    // Setup
    URI uri = URIUtil.toURI("http://www.ambrosoli.jp/"); // $NON-NLS-1$
    String queryString = ""; // $NON-NLS-1$

    // Exercise
    URI actual = URIUtil.addQueryString(uri, queryString);

    // Verify
    assertThat(actual.toString(), is(equalTo("http://www.ambrosoli.jp/"))); // $NON-NLS-1$
  }
  private void mkParentDir(URI uri) throws IOException {
    URI parentURI = URIUtil.getParentURI(uri);

    if (parentURI != null && !exists(parentURI)) {
      mkDirectory(parentURI);
    }
  }
Exemplo n.º 6
0
 private void handleOpenArticle(
     Request request, HttpServletResponse httpServletResponse, String target) throws Exception {
   try {
     int k1 = target.indexOf('/', 1);
     int k2 = target.indexOf('/', k1 + 1);
     String feedId = target.substring(k1 + 1, k2);
     String strSeq = target.substring(k2 + 1);
     int seq = Integer.parseInt(strSeq);
     Article article = articleDb.get(feedId, seq);
     LoginInfo loginInfo = userHelpers.getLoginInfo(request);
     // ttt2 using the link from a non-authenticated browser causes a NPE; maybe do something
     // better, e.g. sign up
     ReadArticlesColl readArticlesColl = readArticlesCollDb.get(loginInfo.userId, feedId);
     if (readArticlesColl == null) {
       readArticlesColl = new ReadArticlesColl(loginInfo.userId, feedId);
     }
     if (!readArticlesColl.isRead(seq)) {
       readArticlesColl.markRead(seq, Config.getConfig().maxSizeForReadArticles);
       readArticlesCollDb.add(readArticlesColl);
     }
     String s =
         URIUtil.encodePath(article.url)
             .replace("%3F", "?")
             .replace("%23", "#"); // ttt2 see how to do this right
     httpServletResponse.sendRedirect(s);
   } catch (Exception e) {
     WebUtils.showResult(
         String.format("Failed to get article for path %s. %s", target, e),
         "/",
         request,
         httpServletResponse);
   }
 }
  /**
   * Returns paths constructed by rewriting pathInfo using rules from the hosted site's mappings.
   * Paths are ordered from most to least specific match.
   *
   * @param site The hosted site.
   * @param pathInfo Path to be rewritten.
   * @param queryString
   * @return The rewritten path. May be either:
   *     <ul>
   *       <li>A path to a file in the Orion workspace, eg. <code>/ProjectA/foo/bar.txt</code>
   *       <li>An absolute URL pointing to another site, eg. <code>http://foo.com/bar.txt</code>
   *     </ul>
   *
   * @return The rewritten paths.
   * @throws URISyntaxException
   */
  private URI[] getMapped(IHostedSite site, IPath pathInfo, String queryString)
      throws URISyntaxException {
    final Map<String, List<String>> map = site.getMappings();
    final IPath originalPath = pathInfo;
    IPath path = originalPath.removeTrailingSeparator();

    List<URI> uris = new ArrayList<URI>();
    String rest = null;
    final int count = path.segmentCount();
    for (int i = 0; i <= count; i++) {
      List<String> base = map.get(path.toString());
      if (base != null) {
        rest = originalPath.removeFirstSegments(count - i).toString();
        for (int j = 0; j < base.size(); j++) {
          URI uri =
              rest.equals("") ? new URI(base.get(j)) : URIUtil.append(new URI(base.get(j)), rest);
          uris.add(
              new URI(
                  uri.getScheme(),
                  uri.getUserInfo(),
                  uri.getHost(),
                  uri.getPort(),
                  uri.getPath(),
                  queryString,
                  uri.getFragment()));
        }
      }
      path = path.removeLastSegments(1);
    }
    if (uris.size() == 0)
      // No mapping for /
      return null;
    else return uris.toArray(new URI[uris.size()]);
  }
Exemplo n.º 8
0
  private ServerStatus getSpaces(List<Space> spaces, JSONObject orgJSON) throws Exception {
    URI targetURI = URIUtil.toURI(target.getUrl());
    URI spaceURI = targetURI.resolve(orgJSON.getJSONObject("entity").getString("spaces_url"));

    GetMethod getDomainsMethod = new GetMethod(spaceURI.toString());
    HttpUtil.configureHttpMethod(getDomainsMethod, target);
    getDomainsMethod.setQueryString("inline-relations-depth=1"); // $NON-NLS-1$

    ServerStatus status = HttpUtil.executeMethod(getDomainsMethod);
    if (!status.isOK()) return status;

    /* extract available spaces */
    JSONObject orgs = status.getJsonData();

    if (orgs.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) {
      return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
    }

    /* look if the domain is available */
    int resources = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).length();
    for (int k = 0; k < resources; ++k) {
      JSONObject spaceJSON =
          orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).getJSONObject(k);
      spaces.add(new Space().setCFJSON(spaceJSON));
    }

    return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK);
  }
 /**
  * Returns the file path where the given resolved bundle can be found. Used to group bundles by
  * file path in the tree.
  *
  * @param bundle bundle to lookup parent path for
  * @return path of parent directory, if unknown it will be a path object containing "Unknown"
  */
 private IPath getParentPath(IResolvedBundle bundle) {
   URI location = bundle.getBundleInfo().getLocation();
   if (location == null) {
     return new Path(Messages.TargetContentsGroup_8);
   }
   IPath path = new Path(URIUtil.toUnencodedString(location));
   path = path.removeLastSegments(1);
   return path;
 }
Exemplo n.º 10
0
  public static IFileArtifactRepository getAggregatedBundleRepository(
      IProvisioningAgent agent, IProfile profile, int repoFilter) {
    List<IFileArtifactRepository> bundleRepositories = new ArrayList<IFileArtifactRepository>();

    // we check for a shared bundle pool first as it should be preferred over the user bundle pool
    // in a shared install
    IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent);
    if ((repoFilter & AGGREGATE_SHARED_CACHE) != 0) {
      String sharedCache = profile.getProperty(IProfile.PROP_SHARED_CACHE);
      if (sharedCache != null) {
        try {
          URI repoLocation = new File(sharedCache).toURI();
          IArtifactRepository repository = manager.loadRepository(repoLocation, null);
          if (repository != null
              && repository instanceof IFileArtifactRepository
              && !bundleRepositories.contains(repository))
            bundleRepositories.add((IFileArtifactRepository) repository);
        } catch (ProvisionException e) {
          // skip repository if it could not be read
        }
      }
    }

    if ((repoFilter & AGGREGATE_CACHE) != 0) {
      IFileArtifactRepository bundlePool = Util.getBundlePoolRepository(agent, profile);
      if (bundlePool != null) bundleRepositories.add(bundlePool);
    }

    if ((repoFilter & AGGREGATE_CACHE_EXTENSIONS) != 0) {
      List<String> repos = getListProfileProperty(profile, CACHE_EXTENSIONS);
      for (String repo : repos) {
        try {
          URI repoLocation;
          try {
            repoLocation = new URI(repo);
          } catch (URISyntaxException e) {
            // in 1.0 we wrote unencoded URL strings, so try as an unencoded string
            repoLocation = URIUtil.fromString(repo);
          }
          IArtifactRepository repository = manager.loadRepository(repoLocation, null);
          if (repository != null
              && repository instanceof IFileArtifactRepository
              && !bundleRepositories.contains(repository))
            bundleRepositories.add((IFileArtifactRepository) repository);
        } catch (ProvisionException e) {
          // skip repositories that could not be read
        } catch (URISyntaxException e) {
          // unexpected, URLs should be pre-checked
          LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e));
        }
      }
    }
    return new AggregatedBundleRepository(agent, bundleRepositories);
  }
Exemplo n.º 11
0
  @Test
  public void isSSLの引数にftpスキームのURI文字列を渡した場合_falseが返されること() {

    // Setup
    String uri = null;

    // Exercise
    boolean actual = URIUtil.isSSL(uri);
    // Verify
    assertThat(actual, is(false));
  }
Exemplo n.º 12
0
  @Test
  public void isSSLの引数にftpスキームのURIを渡した場合_falseが返されること() {

    // Setup
    URI uri = URI.create("ftp://www.ambrosoli.jp/"); // $NON-NLS-1$

    // Exercise
    boolean actual = URIUtil.isSSL(uri);

    // Verify
    assertThat(actual, is(false));
  }
Exemplo n.º 13
0
  @Test
  public void isPlainの引数に文字列型のnullを渡した場合_falseが返されること() {

    // Setup
    String uri = "willard379"; // $NON-NLS-1$

    // Exercise
    boolean actual = URIUtil.isPlain(uri);

    // Verify
    assertThat(actual, is(false));
  }
Exemplo n.º 14
0
  @Test
  public void isPlainの引数にURIでない文字列を渡した場合_falseが返されること() {

    // Setup
    String uri = "ftp://www.ambrosoli.jp/"; // $NON-NLS-1$

    // Exercise
    boolean actual = URIUtil.isPlain(uri);

    // Verify
    assertThat(actual, is(false));
  }
Exemplo n.º 15
0
  @Test
  public void toURIの引数に空文字を渡した場合_nullが返されること() {

    // Setup
    String uri = ""; // $NON-NLS-1$

    // Exercise
    URI actual = URIUtil.toURI(uri);

    // Verify
    assertThat(actual, is(nullValue()));
  }
Exemplo n.º 16
0
  @Test
  public void toURIの引数にhttpsスキームのURI文字列を渡した場合_URIが生成されること() {

    // Setup
    String uri = "https://www.ambrosoli.jp/"; // $NON-NLS-1$

    // Exercise
    URI actual = URIUtil.toURI(uri);

    // Verify
    assertThat(actual.toString(), is(equalTo(uri)));
  }
Exemplo n.º 17
0
  @Test
  public void isSSLの引数にhttpスキームのURI文字列を渡した場合_falseが返されること() {

    // Setup
    String uri = "http://www.ambrosoli.jp/"; // $NON-NLS-1$

    // Exercise
    boolean actual = URIUtil.isSSL(uri);

    // Verify
    assertThat(actual, is(false));
  }
Exemplo n.º 18
0
  @Test
  public void getPortの引数にnullを渡した場合_マイナス1が返されること() {

    // Setup
    URI uri = null;

    // Exercise
    int actual = URIUtil.getPort(uri);

    // Verify
    assertThat(actual, is(-1));
  }
Exemplo n.º 19
0
  @Test
  public void isSSLの引数にURI型のnullを渡した場合_falseが返されること() {

    // Setup
    URI uri = null;

    // Exercise
    boolean actual = URIUtil.isSSL(uri);

    // Verify
    assertThat(actual, is(false));
  }
Exemplo n.º 20
0
  @Test
  public void isSSLの引数にデタラメなURIを渡した場合_falseが返されること() {

    // Setup
    URI uri = URI.create("willard379"); // $NON-NLS-1$

    // Exercise
    boolean actual = URIUtil.isSSL(uri);

    // Verify
    assertThat(actual, is(false));
  }
Exemplo n.º 21
0
  @Test
  public void isPlainの引数にhttpスキームのURIを渡した場合_trueが返されること() {

    // Setup
    URI uri = URI.create("http://www.ambrosoli.jp/"); // $NON-NLS-1$

    // Exercise
    boolean actual = URIUtil.isPlain(uri);

    // Verify
    assertThat(actual, is(true));
  }
  public void testVirtualFolderInLinkedFolder() {
    // setup handles
    IFolder topFolder = existingProject.getFolder("topFolder");
    IFolder linkedFolder = topFolder.getFolder("linkedFolder");
    IFolder subFolder = linkedFolder.getFolder("subFolder");
    IFolder virtualFolder = subFolder.getFolder("virtualFolder");

    IPath linkedFolderLocation = getRandomLocation();
    IPath subFolderLocation = linkedFolderLocation.append(subFolder.getName());

    try {
      try {
        // create the structure on disk
        linkedFolderLocation.toFile().mkdir();
        subFolderLocation.toFile().mkdir();

        // create the structure in the workspace
        ensureExistsInWorkspace(topFolder, true);
        linkedFolder.createLink(linkedFolderLocation, IResource.NONE, getMonitor());
        virtualFolder.create(IResource.VIRTUAL, true, getMonitor());
      } catch (CoreException e) {
        fail("1.0", e);
      }

      // assert locations
      assertEquals("2.0", linkedFolderLocation, linkedFolder.getLocation());
      assertEquals(
          "3.0", linkedFolderLocation.append(subFolder.getName()), subFolder.getLocation());
      assertTrue("4.0", virtualFolder.isVirtual());
      assertTrue("5.0", virtualFolder.getLocation() == null);

      // assert URIs
      assertEquals("6.0", URIUtil.toURI(linkedFolderLocation), linkedFolder.getLocationURI());
      assertEquals("7.0", URIUtil.toURI(subFolderLocation), subFolder.getLocationURI());
      // assertTrue("8.0", virtualFolder.getLocationURI() == null);
    } finally {
      Workspace.clear(subFolderLocation.toFile());
      Workspace.clear(linkedFolderLocation.toFile());
    }
  }
Exemplo n.º 23
0
  @Test
  public void addQueryStringの引数がどちらもnullの場合_nullが返されること() {

    // Setup
    URI uri = null;
    String queryString = null;

    // Exercise
    URI actual = URIUtil.addQueryString(uri, queryString);

    // Verify
    assertThat(actual, is(nullValue()));
  }
Exemplo n.º 24
0
  @Test
  public void addQueryStringの引数にnullとクエリストリングを渡すと_nullが返されること() {

    // Setup
    URI uri = null;
    String queryString = "?a=A"; // $NON-NLS-1$

    // Exercise
    URI actual = URIUtil.addQueryString(uri, queryString);

    // Verify
    assertThat(actual, is(nullValue()));
  }
Exemplo n.º 25
0
 @Override
 protected IStatus performJob() {
   IStatus result = doClone();
   if (result.isOK()) {
     return result;
   } else {
     try {
       if (project != null) GitCloneHandlerV1.removeProject(user, project);
       else FileUtils.delete(URIUtil.toFile(clone.getContentLocation()), FileUtils.RECURSIVE);
     } catch (IOException e) {
       String msg = "An error occured when cleaning up after a clone failure";
       result =
           new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
     }
     return result;
   }
 }
Exemplo n.º 26
0
  @Override
  protected ServerStatus _doIt() {
    try {
      /* get available orgs */
      URI targetURI = URIUtil.toURI(target.getUrl());
      URI orgsURI = targetURI.resolve("/v2/organizations");

      GetMethod getDomainsMethod = new GetMethod(orgsURI.toString());
      HttpUtil.configureHttpMethod(getDomainsMethod, target);
      getDomainsMethod.setQueryString("inline-relations-depth=1"); // $NON-NLS-1$

      ServerStatus status = HttpUtil.executeMethod(getDomainsMethod);
      if (!status.isOK()) return status;

      /* extract available orgs */
      JSONObject orgs = status.getJsonData();

      if (orgs.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) {
        return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null);
      }

      /* look if the domain is available */
      JSONObject result = new JSONObject();
      int resources = orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).length();
      for (int k = 0; k < resources; ++k) {
        JSONObject orgJSON =
            orgs.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES).getJSONObject(k);
        List<Space> spaces = new ArrayList<Space>();
        status = getSpaces(spaces, orgJSON);
        if (!status.isOK()) return status;
        OrgWithSpaces orgWithSpaces = new OrgWithSpaces();
        orgWithSpaces.setCFJSON(orgJSON);
        orgWithSpaces.setSpaces(spaces);
        result.append("Orgs", orgWithSpaces.toJSON());
      }

      return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result);
    } catch (Exception e) {
      String msg =
          NLS.bind("An error occured when performing operation {0}", commandName); // $NON-NLS-1$
      logger.error(msg, e);
      return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
    }
  }
  /**
   * Creates a URL describing the location of a included schema. First looks up the plug-in in the
   * schema registry, then tries additional source locations, then looks for a co-located plug-in,
   * then looks in the additional search path locations.
   *
   * @param pluginID ID of the plug-in owning the schema
   * @param path the path to the schema inside the plug-in
   * @param parentURL url of the parent schema file
   * @param additionalSearchPath list of additional locations to search; only used with the <code>
   *     pde.convertSchemaToHTML</code> Ant task
   * @return a url location of the included schema or <code>null</code>
   */
  private static URL getPluginRelativePath(
      String pluginID, IPath path, URL parentURL, List<IPath> additionalSearchPath) {
    // Start by looking in the schema registry
    URL url = SchemaRegistry.getSchemaURL(pluginID, path.toString());

    // Next search source locations
    if (url == null) {
      IPluginModelBase model = PluginRegistry.findModel(pluginID);
      if (model != null)
        url = SchemaRegistry.getSchemaFromSourceExtension(model.getPluginBase(), path);
    }

    File parentFile = null;
    if (url == null && parentURL != null) {
      try {
        parentFile = URIUtil.toFile(URIUtil.toURI(parentURL));
      } catch (URISyntaxException e) {
      }
    }

    // If we are running the ant task, see if another project co-located with the parent contains
    // the schema file
    // The project folder must have the plug-in ID as its file name
    if (url == null && parentFile != null) {
      try {
        // assuming schemas are located in: pluginId/schema/schemaFile.exsd (need to go up to parent
        // of plug-in directory)
        File pluginFile = new File(parentFile + "/../../../" + pluginID); // $NON-NLS-1$
        if (pluginFile.isDirectory()) {
          File schemaFile = new File(pluginFile, path.toOSString());
          if (schemaFile.exists()) {
            url = schemaFile.toURL();
          }
          // This is how we would extract the schema from a jar, but in practice this will never be
          // the case
          // because when a bundle is built, the schema files are moved to the source bundle, not
          // the bundle we are checking
          //					} else if (CoreUtility.jarContainsResource(pluginFile, path.toPortableString(),
          // false)) {
          //						url = new URL("jar:file:" + pluginFile.getAbsolutePath() + "!/" + path);
          // //$NON-NLS-1$ //$NON-NLS-2$
        }
      } catch (MalformedURLException e) {
      }
    }

    // If we are running the ant task, additional search locations may be provided
    // The project folder must have the plug-in ID as its file name
    if (url == null && additionalSearchPath != null) {
      for (IPath searchPath : additionalSearchPath) {
        File pluginFile = null;
        if (searchPath.isAbsolute()) {
          // Append plug-in id directly to absolute paths
          pluginFile = new File(searchPath.toFile(), pluginID);
        } else if (parentFile != null) {
          // Append relative path to parent file location
          File file = new File(parentFile, searchPath.toOSString());
          pluginFile = new File(file, pluginID);
        }

        if (pluginFile != null && pluginFile.isDirectory()) {
          try {
            File schemaFile = new File(pluginFile, path.toOSString());
            if (schemaFile.exists()) {
              url = schemaFile.toURL();
              break;
            }
          } catch (MalformedURLException e) {
          }
        }
      }
    }
    return url;
  }