Example #1
0
 /**
  * Opens a stream from a public and system ID.
  *
  * @param publicID the public ID, which may be null
  * @param systemID the system ID, which is never null
  * @throws java.net.MalformedURLException if the system ID does not contain a valid URL
  * @throws java.io.FileNotFoundException if the system ID refers to a local file which does not
  *     exist
  * @throws java.io.IOException if an error occurred opening the stream
  */
 public Reader openStream(final String publicID, final String systemID)
     throws MalformedURLException, FileNotFoundException, IOException {
   URL url = new URL(currentReader.systemId, systemID);
   if (url.getRef() != null) {
     final String ref = url.getRef();
     if (url.getFile().length() > 0) {
       url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile());
       url = new URL("jar:" + url + '!' + ref);
     } else {
       url = StdXMLReader.class.getResource(ref);
     }
   }
   currentReader.publicId = publicID;
   currentReader.systemId = url;
   final StringBuilder charsRead = new StringBuilder();
   final Reader reader = this.stream2reader(url.openStream(), charsRead);
   if (charsRead.length() == 0) {
     return reader;
   }
   final String charsReadStr = charsRead.toString();
   final PushbackReader pbreader = new PushbackReader(reader, charsReadStr.length());
   for (int i = charsReadStr.length() - 1; i >= 0; i--) {
     pbreader.unread(charsReadStr.charAt(i));
   }
   return pbreader;
 }
Example #2
0
 public SampleReportsEntry(
     String[] filePattern,
     String entryname,
     String fragmentPath,
     SampleReportsEntry parentEntry,
     boolean isFile) {
   // this( "BIRT Examples", "/samplereports", null, false );
   // //$NON-NLS-1$//$NON-NLS-2$
   this(entryname, fragmentPath, parentEntry, false);
   this.isRoot = true;
   this.displayName = "BIRT Examples"; // $NON-NLS-1$
   // samplesBundle = Platform.getBundle( SAMPLE_REPORTS_HOST );
   if (samplesBundle != null) {
     if (filePattern != null && filePattern.length > 0) {
       for (int i = 0; i < filePattern.length; i++) {
         String[] patterns = filePattern[i].split(";"); // $NON-NLS-1$
         for (int j = 0; j < patterns.length; j++) {
           Enumeration enumeration = samplesBundle.findEntries(fragmentPath, patterns[j], true);
           while (enumeration != null && enumeration.hasMoreElements()) {
             URL element = (URL) enumeration.nextElement();
             String path =
                 element.getPath()
                     + (element.getRef() != null
                         ? "#" //$NON-NLS-1$
                             + element.getRef()
                         : ""); //$NON-NLS-1$
             String[] pathtoken = path.split("/"); // $NON-NLS-1$
             SampleReportsEntry parent = this;
             for (int m = 0; m < pathtoken.length; m++) {
               if (pathtoken[m].equals("")
                   || pathtoken[m].equals(
                       fragmentPath.substring(fragmentPath.indexOf('/') + 1))) // $NON-NLS-1$
               continue;
               SampleReportsEntry child = parent.getChild(pathtoken[m]);
               if (child == null) {
                 child =
                     new SampleReportsEntry(
                         pathtoken[m],
                         (parent.path.equals("/")
                                 ? "" //$NON-NLS-1$//$NON-NLS-2$
                                 : parent.path)
                             + "/" //$NON-NLS-1$
                             + pathtoken[m],
                         parent,
                         m == pathtoken.length - 1);
               }
               parent = child;
             }
           }
         }
       }
     }
   }
 }
Example #3
0
  /**
   * Builds an URI from an URL (with a handle for URLs not compliant with RFC 2396).
   *
   * @param url an URL
   * @return an URI
   * @throws URISyntaxException if the URI is invalid and could not be repaired
   */
  public static URI urlToUri(URL url) throws URISyntaxException {

    URI uri;
    try {
      // Possible failing step.
      uri = url.toURI();

    } catch (Exception e) {
      // URL did not comply with RFC 2396 => illegal non-escaped characters.
      try {
        uri =
            new URI(
                url.getProtocol(),
                url.getUserInfo(),
                url.getHost(),
                url.getPort(),
                url.getPath(),
                url.getQuery(),
                url.getRef());

      } catch (Exception e1) {
        throw new URISyntaxException(String.valueOf(url), "Broken URL.");
      }
    }

    uri = uri.normalize();
    return uri;
  }
Example #4
0
  public static URL getURL(double latitude, double longitude, String output)
      throws MalformedURLException, IOException {
    StringBuilder stringBuilder = new StringBuilder(URL_PREFIX);
    stringBuilder.append("?");
    stringBuilder.append("output=" + output + "&");
    stringBuilder.append("location=" + latitude + "," + longitude + "&");
    stringBuilder.append("key=" + PRIVATE_KEY);

    URL url = new URL(stringBuilder.toString());

    System.out.println(String.format("getProtocol %s", url.getProtocol()));
    System.out.println(String.format("getHost %s", url.getHost()));
    System.out.println(String.format("getPath %s", url.getPath()));
    System.out.println(String.format("getPort %s", url.getPort()));
    System.out.println(String.format("getDefaultPort %s", url.getDefaultPort()));
    System.out.println(String.format("getQuery %s", url.getQuery()));
    System.out.println(String.format("getAuthority %s", url.getAuthority()));
    System.out.println(String.format("getRef %s", url.getRef()));
    System.out.println(String.format("getUserInfo %s", url.getUserInfo()));
    System.out.println(String.format("getFile %s", url.getFile()));
    System.out.println(String.format("getContent %s", url.getContent()));
    System.out.println(String.format("toExternalForm %s", url.toExternalForm()));
    System.out.println("---------------");

    return url;
  }
  @Override
  public boolean isValidAuthority(URL authorizationEndpoint) {
    // For comparison purposes, convert to lowercase Locale.US
    // getProtocol returns scheme and it is available if it is absolute url
    // Authority is in the form of https://Instance/tenant/somepath
    if (authorizationEndpoint != null
        && !StringExtensions.IsNullOrBlank(authorizationEndpoint.getHost())
        && authorizationEndpoint.getProtocol().equals("https")
        && StringExtensions.IsNullOrBlank(authorizationEndpoint.getQuery())
        && StringExtensions.IsNullOrBlank(authorizationEndpoint.getRef())
        && !StringExtensions.IsNullOrBlank(authorizationEndpoint.getPath())) {

      if (UrlExtensions.isADFSAuthority(authorizationEndpoint)) {
        throw new AuthenticationException(ADALError.DISCOVERY_NOT_SUPPORTED);
      } else if (sValidHosts.contains(authorizationEndpoint.getHost().toLowerCase(Locale.US))) {
        // host can be the instance or inside the validated list.
        // Valid hosts will help to skip validation if validated before
        // call Callback and skip the look up
        return true;
      } else {
        // Only query from Prod instance for now, not all of the
        // instances in the list
        return queryInstance(authorizationEndpoint);
      }
    }

    return false;
  }
Example #6
0
  public static String removeprincipal(String u) {
    // Must be a simpler way
    String newurl = null;
    try {
      int index;
      URL url = new URL(u);
      String protocol = url.getProtocol() + "://";
      String host = url.getHost();
      int port = url.getPort();
      String path = url.getPath();
      String query = url.getQuery();
      String ref = url.getRef();

      String sport = (port <= 0 ? "" : (":" + port));
      path = (path == null ? "" : path);
      query = (query == null ? "" : "?" + query);
      ref = (ref == null ? "" : "#" + ref);

      // rebuild the url
      // (and leaving encoding in place)
      newurl = protocol + host + sport + path + query + ref;

    } catch (MalformedURLException use) {
      newurl = u;
    }
    return newurl;
  }
Example #7
0
  @Override
  protected URLConnection openConnection(URL u) throws IOException {
    String path = u.getPath().substring(1);
    String refr = u.getRef();

    StringBuilder test = new StringBuilder(path);
    if (refr != null && refr.length() > 0) {
      test.append(".part.");
      for (int i = 0; i < refr.length() - 1; i++) {
        test.append("0");
      }
      test.append("1");
    }

    URL local = Thread.currentThread().getContextClassLoader().getResource(test.toString());
    String base = local.toExternalForm();
    int end = base.length() - test.length();
    base = base.substring(0, end);

    if ("file".equals(local.getProtocol())) {
      return new XcfFileConnection(new URL(base), u);
    } else if ("jar".equals(local.getProtocol())) {
      return new XcfJarConnection(new URL(base), u);
    } else {
      throw new IOException("base protocol[" + local.getProtocol() + "] isn't supported");
    }
  }
Example #8
0
 /**
  * The URL-safe version of a string is obtained by an URL encoding to a string value.
  *
  * @throws R2RMLDataError
  * @throws MalformedURLException
  */
 public static String getURLSafeVersion(String value) throws R2RMLDataError {
   if (value == null) return null;
   URL url = null;
   try {
     url = new URL(value);
   } catch (MalformedURLException mue) {
     // This template should be not a url : no encoding
     return value;
   }
   // No exception raised, this template is a valid url : perform
   // percent-encoding
   try {
     java.net.URI uri =
         new java.net.URI(
             url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), url.getRef());
     String result = uri.toURL().toString();
     // Percent encoding : complete with no supported char in this
     // treatment
     result = result.replaceAll("\\,", "%2C");
     return result;
   } catch (URISyntaxException e) {
     throw new R2RMLDataError(
         "[R2RMLToolkit:getIRISafeVersion] This value "
             + value
             + " can not be percent-encoded because "
             + e.getMessage());
   } catch (MalformedURLException e) {
     throw new R2RMLDataError(
         "[R2RMLToolkit:getIRISafeVersion] This value "
             + value
             + " can not be percent-encoded because "
             + e.getMessage());
   }
 }
Example #9
0
  /**
   * Construct a URL from its basic parts.
   *
   * @param base The base URL.
   * @param url The URL that was found on the base URL's page.
   * @param stripRef True if the URL's reference should be stripped.
   * @return The new URL, built upon the base URL.
   * @throws IOException Thrown if any IO error occurs.
   */
  public static URL constructURL(final URL base, final String url, final boolean stripRef)
      throws IOException {
    URL result = new URL(base, url);
    String file = result.getFile();
    final String protocol = result.getProtocol();
    final String host = result.getHost();
    final int port = result.getPort();
    final String ref = result.getRef();
    final StringBuilder sb = new StringBuilder(file);
    int index = sb.indexOf(" ");
    while (index != -1) {
      if (index != -1) {
        sb.replace(index, index + 1, "%20");
      }
      index = sb.indexOf(" ");
    }

    file = sb.toString();
    if ((ref != null) && !stripRef) {
      result = new URL(protocol, host, port, file + "#" + ref);
    } else {
      result = new URL(protocol, host, port, file);
    }
    return result;
  }
Example #10
0
 /**
  * Encodes illegal characters in the specified URL's path, query string and anchor according to
  * the URL encoding rules observed in real browsers.
  *
  * <p>For example, this method changes <tt>"http://first/?a=b c"</tt> to
  * <tt>"http://first/?a=b%20c"</tt>.
  *
  * @param url the URL to encode
  * @param minimalQueryEncoding whether or not to perform minimal query encoding, like IE does
  * @param charset the charset
  * @return the encoded URL
  */
 public static URL encodeUrl(
     final URL url, final boolean minimalQueryEncoding, final String charset) {
   final String p = url.getProtocol();
   if ("javascript".equalsIgnoreCase(p)
       || "about".equalsIgnoreCase(p)
       || "data".equalsIgnoreCase(p)) {
     // Special exception.
     return url;
   }
   try {
     String path = url.getPath();
     if (path != null) {
       path = encode(path, PATH_ALLOWED_CHARS, "UTF-8");
     }
     String query = url.getQuery();
     if (query != null) {
       if (minimalQueryEncoding) {
         query = org.apache.commons.lang3.StringUtils.replace(query, " ", "%20");
       } else {
         query = encode(query, QUERY_ALLOWED_CHARS, charset);
       }
     }
     String anchor = url.getRef();
     if (anchor != null) {
       anchor = encode(anchor, ANCHOR_ALLOWED_CHARS, "UTF-8");
     }
     return createNewUrl(url.getProtocol(), url.getHost(), url.getPort(), path, anchor, query);
   } catch (final MalformedURLException e) {
     // Impossible... I think.
     throw new RuntimeException(e);
   }
 }
Example #11
0
  private static void setValues(
      URL url,
      HttpResponse<InputStream> jsonResponse,
      AbstractMap<String, String> localHeaders,
      Long responseTime) {
    generalInfo = new HashMap<>();

    int responseCode = jsonResponse.getStatus();

    generalInfo.put("Protocol", url.getProtocol());
    generalInfo.put("Authority", url.getAuthority());
    generalInfo.put("Host", url.getHost());
    generalInfo.put("Default Port", Integer.toString(url.getDefaultPort()));
    generalInfo.put("Port ", Integer.toString(url.getPort()));
    generalInfo.put("Path", url.getPath());
    generalInfo.put("Query", url.getQuery());
    generalInfo.put("Filename", url.getFile());
    generalInfo.put("Ref", url.getRef());

    responseValues.resetProperties();
    responseValues.setRequestHeaders(localHeaders);
    responseValues.setResponseHeaders(jsonResponse.getHeaders());
    responseValues.setGeneralInfo(generalInfo);
    responseValues.setResponseTime(responseTime);
    responseValues.setResponseCode(
        Integer.toString(responseCode) + " " + jsonResponse.getStatusText());
  }
Example #12
0
  public static String encodeDocumentUrl(String urlString) {
    try {

      URL url = new URL(urlString);
      URI uri =
          new URI(
              url.getProtocol(),
              url.getUserInfo(),
              url.getHost(),
              url.getPort(),
              url.getPath(),
              url.getQuery(),
              url.getRef());

      return uri.toASCIIString();

    } catch (MalformedURLException e) {
      if (Log.LOGD)
        Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e));
      return null;
    } catch (URISyntaxException e) {
      if (Log.LOGD)
        Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e));
      return null;
    }
  }
  @Override
  public void runner() throws Exception {
    try {
      initDriver();
      String sUrl;
      if (credentialItem != null) {
        sUrl =
            new URI(
                    url.getProtocol(),
                    credentialItem.getURLUserInfo(),
                    url.getHost(),
                    url.getPort(),
                    url.getPath(),
                    url.getQuery(),
                    url.getRef())
                .toString();
      } else sUrl = url.toExternalForm();
      browserDriver.get(sUrl);
      if (waitSec > 0) sleepSec(waitSec);
      BufferedImage image = browserDriver.getScreenshot();
      if (visiblePartOnly)
        image = ImageUtils.getSubimage(image, 0, 0, capture.width, capture.height);

      if (resize != null) image = ImageUtils.reduceImage(image, resize.width, resize.height);
      if (reductionPercent < 100) image = ImageUtils.reduceImage(image, reductionPercent);
      if (screenshotManager != null) screenshotManager.store(url, image);
      finalImage = image;
    } finally {
      release();
    }
  }
  public String evaluate(String urlStr, String partToExtract) {
    if (urlStr == null || partToExtract == null) {
      return null;
    }

    if (lastUrlStr == null || !urlStr.equals(lastUrlStr)) {
      try {
        url = new URL(urlStr);
      } catch (Exception e) {
        return null;
      }
    }
    lastUrlStr = urlStr;

    if (partToExtract.equals("HOST")) return url.getHost();
    if (partToExtract.equals("PATH")) return url.getPath();
    if (partToExtract.equals("QUERY")) return url.getQuery();
    if (partToExtract.equals("REF")) return url.getRef();
    if (partToExtract.equals("PROTOCOL")) return url.getProtocol();
    if (partToExtract.equals("FILE")) return url.getFile();
    if (partToExtract.equals("AUTHORITY")) return url.getAuthority();
    if (partToExtract.equals("USERINFO")) return url.getUserInfo();

    return null;
  }
Example #15
0
 public static Map<String, String> parseRef(URL url) {
   try {
     return parseRef(url.getRef());
   } catch (MalformedURLException e) {
     e.printStackTrace();
     throw new RuntimeException(e.getMessage());
   }
 }
Example #16
0
 /**
  * Gets a file from a path relative to this AssetManager's root. Will be from a local file if the
  * root is a local file, will be from a URL if the root is a URL. This method does not return a
  * file for if it was from a jar file.
  *
  * @param loc the relative location
  * @return the file at that location
  */
 private File getFile(String loc) {
   if (localRoot != null) {
     return new File(localRoot.getAbsolutePath() + System.getProperty("file.separator") + loc);
   } else if (urlRoot != null) {
     return new File(urlRoot.getRef() + "/" + loc);
   } else {
     return null;
   }
 }
Example #17
0
 public static Bundle parseUrl(String url) {
   try {
     URL u = new URL(url);
     Bundle b = decodeUrl(u.getQuery());
     b.putAll(decodeUrl(u.getRef()));
     return b;
   } catch (MalformedURLException e) {
     return new Bundle();
   }
 }
 private String getURLString(URL url) {
   String location = url.toExternalForm();
   if (url.getRef() != null) {
     int anchorIdx = location.lastIndexOf('#');
     if (anchorIdx != -1) {
       return location.substring(0, anchorIdx)
           + "?noframes=true"
           + location.substring(anchorIdx); // $NON-NLS-1$
     }
   }
   return location + "?noframes=true"; // $NON-NLS-1$
 }
Example #19
0
 /**
  * Parse a URL query and fragment parameters into a key-value bundle.
  *
  * @param url the URL to parse
  * @return a dictionary bundle of keys and values
  */
 public static Bundle parseUrl(String url) {
   // hack to prevent MalformedURLException
   url = url.replace("fbconnect", "http");
   try {
     URL u = new URL(url);
     Bundle b = decodeUrl(u.getQuery());
     b.putAll(decodeUrl(u.getRef()));
     return b;
   } catch (MalformedURLException e) {
     return new Bundle();
   }
 }
Example #20
0
  public void setPage(final URL page) throws IOException {
    if (page == null) {
      throw new IOException(Messages.getString("swing.03", "Page")); // $NON-NLS-1$ //$NON-NLS-2$
    }

    String url = page.toString();
    String baseUrl = getBaseURL(url);
    Document oldDoc = getDocument();
    if (baseUrl != null
        && oldDoc != null
        && baseUrl.equals(oldDoc.getProperty(Document.StreamDescriptionProperty))) {

      scrollToReference(page.getRef());
      return;
    }
    InputStream stream = getStream(page);
    if (stream == null) {
      return;
    }
    Document newDoc = editorKit.createDefaultDocument();
    // Perhaps, it is reasonable only for HTMLDocument...
    if (newDoc instanceof HTMLDocument) {
      newDoc.putProperty(Document.StreamDescriptionProperty, baseUrl);
      newDoc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE, new Boolean(false));
      try {
        ((HTMLDocument) newDoc).setBase(new URL(baseUrl));
      } catch (IOException e) {
      }
    }
    // TODO Asynch loading doesn't work with completely.
    // Also page property change event is written incorrectly now
    // (at the asynchrounous loading), because loading may not be
    // completed.
    // int asynchronousLoadPriority = getAsynchronousLoadPriority(newDoc);
    int asynchronousLoadPriority = -1;
    if (asynchronousLoadPriority >= 0) {
      setDocument(newDoc);
      AsynchLoad newThread = new AsynchLoad(asynchronousLoadPriority, stream, page);
      newThread.start();
      if (newThread.successfulLoading) {
        changePage(page);
      }
    } else {
      try {
        documentLoading(stream, newDoc, page);
        stream.close();
        setDocument(newDoc);
        changePage(page);
      } catch (IOException e) {
      }
    }
  }
  private static URL _encode(URL url) throws Exception {
    URI uri =
        new URI(
            url.getProtocol(),
            url.getUserInfo(),
            url.getHost(),
            url.getPort(),
            url.getPath(),
            url.getQuery(),
            url.getRef());

    return new URL(uri.toASCIIString());
  }
Example #22
0
 public static void main(String[] args) throws IOException {
   URL url = new URL("http://www.javajeff.com/articles/articles/html");
   System.out.println("Authority = " + url.getAuthority());
   System.out.println("Default port = " + url.getDefaultPort());
   System.out.println("File = " + url.getFile());
   System.out.println("Host = " + url.getHost());
   System.out.println("Path = " + url.getPath());
   System.out.println("Port = " + url.getPort());
   System.out.println("Protocol = " + url.getProtocol());
   System.out.println("Query = " + url.getQuery());
   System.out.println("Ref = " + url.getRef());
   System.out.println("User Info = " + url.getUserInfo());
 }
 private void _log(@Nonnull final URL aURL) throws URISyntaxException {
   s_aLogger.info("Next URL");
   s_aLogger.info("  protocol = " + aURL.getProtocol());
   s_aLogger.info("  authority = " + aURL.getAuthority());
   s_aLogger.info("  host = " + aURL.getHost());
   s_aLogger.info("  port = " + aURL.getPort());
   s_aLogger.info("  defaultPort = " + aURL.getDefaultPort());
   s_aLogger.info("  path = " + aURL.getPath());
   s_aLogger.info("  query = " + aURL.getQuery());
   s_aLogger.info("  file = " + aURL.getFile());
   s_aLogger.info("  ref = " + aURL.getRef());
   s_aLogger.info("  externalForm = " + aURL.toExternalForm());
   s_aLogger.info("  URI          = " + aURL.toURI().toString());
 }
Example #24
0
  /** Build from an existing URL. */
  public ParsedURLData(URL url) {
    protocol = url.getProtocol();
    if ((protocol != null) && (protocol.length() == 0)) protocol = null;

    host = url.getHost();
    if ((host != null) && (host.length() == 0)) host = null;

    port = url.getPort();

    path = url.getFile();
    if ((path != null) && (path.length() == 0)) path = null;

    ref = url.getRef();
    if ((ref != null) && (ref.length() == 0)) ref = null;
  }
Example #25
0
 /**
  * Encodes passed URL
  *
  * @param url Prepared URL
  */
 protected String encodeUrl(URL url) {
   try {
     URI uri =
         new URI(
             url.getProtocol(),
             url.getUserInfo(),
             url.getHost(),
             url.getPort(),
             url.getPath(),
             url.getQuery(),
             url.getRef());
     return uri.toASCIIString();
   } catch (URISyntaxException e) {
     return url.toString();
   }
 }
Example #26
0
  @Test
  public void test_javaNetUrl() throws Exception {
    java.net.URL url =
        new java.net.URL(
            "http://*****:*****@10.20.130.230:20880/context/path?version=1.0.0&application=morgan#anchor1");

    assertEquals("http", url.getProtocol());
    assertEquals("admin:hello1234", url.getUserInfo());
    assertEquals("10.20.130.230", url.getHost());
    assertEquals(20880, url.getPort());
    assertEquals("/context/path", url.getPath());
    assertEquals("version=1.0.0&application=morgan", url.getQuery());
    assertEquals("anchor1", url.getRef());

    assertEquals("admin:[email protected]:20880", url.getAuthority());
    assertEquals("/context/path?version=1.0.0&application=morgan", url.getFile());
  }
Example #27
0
  public static int[] getCodigoETipo(URL url) {

    if (url == null) return null;

    String ref = url.getRef();

    int pos_tip = ref.indexOf(TIP);

    int pos_end = ref.indexOf(END, pos_tip + 1);

    if (pos_tip > 0) {

      int x[] = null;

      try {

        String cod = ref.substring(0, pos_tip);

        String tip = ref.substring(pos_tip + 1, ref.length());

        /*

                          String tip;

                          if( pos_end > 0 )

                              tip = ref.substring(pos_tip+1,pos_end);

                          else

                              tip = ref.substring(pos_tip+1,ref.length());

        */

        x = new int[] {Integer.valueOf(cod).intValue(), Integer.valueOf(tip).intValue()};

      } catch (Exception exc) {

        x = null;
      }

      return x;
    }

    return null;
  }
Example #28
0
  /** 设置现成的uri。 */
  public final URIBroker setServerURI(String uriString) {
    URL uri;

    try {
      uri = new URL(assertNotNull(trimToNull(uriString), "serverURI"));
    } catch (MalformedURLException e) {
      throw new IllegalArgumentException(e.getMessage());
    }

    String serverScheme = uri.getProtocol();
    String[] userInfo = StringUtil.split(uri.getUserInfo(), ":");
    String serverName = uri.getHost();
    int serverPort = uri.getPort();

    if (serverScheme != null) {
      setServerScheme(serverScheme);
    }

    if (!isEmptyArray(userInfo)) {
      if (userInfo.length > 0) {
        setLoginUser(userInfo[0]);
      }

      if (userInfo.length > 1) {
        setLoginPassword(userInfo[1]);
      }
    }

    if (serverName != null) {
      setServerName(serverName);
    }

    if (serverPort > 0) {
      setServerPort(serverPort);
    }

    setServerURI(uri);

    new URIBrokerQueryStringParser().parse(uri.getQuery());

    setReference(uri.getRef());

    return this;
  }
Example #29
0
  /**
   * Copies the gold folder to the runtime workspace CONTRACT: folder exists in the devspace,
   * goldFolder has been set In this implementation, the gold folder is copied from
   * bin/test/GoldFolder
   */
  public static void copyGoldFolder() {
    /* goldFolder (location where goldfolder should go in runspace) must not be null */
    Assert.assertTrue(goldFolder != null);

    Bundle model2testsBundle = EclipsePlugin.getDefault().getBundle();
    /* this is the source for our goldfolder in the devspace that we're copying to the runspace */
    URL gfURL = model2testsBundle.getEntry("/");

    /* devspace GoldFolder must exist */
    // Assert.assertTrue(goldFolder.exists());
    // Assert.assertTrue(gf.exists());
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot workspaceRoot = workspace.getRoot();
    IPath rootPath = workspaceRoot.getLocation();
    try {
      gfURL = Platform.asLocalURL(gfURL);
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.out.println("URL path: " + gfURL.getPath());
    System.out.println("URL file: " + gfURL.getFile());
    System.out.println("URL ref: " + gfURL.getRef());
    File srcDir = new File(gfURL.getPath(), "GoldFolder");
    Path p = new Path(gfURL.getPath());
    IResource igf = ((Workspace) workspace).newResource(p, IResource.FOLDER);
    IPath gfpath = goldFolder.getFullPath();
    File destDir = new File(gfpath.toOSString());
    /* Make sure both of these directories exist */
    System.out.println("Source directory exists: " + srcDir.exists());
    /* destination directory shouldn't exist because we're going to create it */
    // System.out.println ("Dest directory exists: " + destDir.exists());
    /* Since assert isn't working for the moment... */
    if (!srcDir.exists()) {
      System.out.println("GoldFolder not found");
      Log.log("GoldFolder not found");
      Assert.fail("GoldFolder not found");
    }
    //		Assert.assertTrue("Source goldfolder does not exist", srcDir.exists());
    //		Assert.assertTrue("Destination goldfolder does not exist", destDir.exists());
    copyFolder(srcDir, destDir);
  }
Example #30
0
 private String createPublicUrl(String baseUrl, String path) {
   if (!ObjectUtils.isBlank(baseUrl)) {
     path = StringUtils.ensureEnd(baseUrl, "/") + path;
     try {
       URL url = new URL(path);
       path =
           new URI(
                   url.getProtocol(),
                   url.getAuthority(),
                   url.getPath(),
                   url.getQuery(),
                   url.getRef())
               .toASCIIString();
     } catch (MalformedURLException error) {
       // Return the path as is if the given path is malformed.
     } catch (URISyntaxException error) {
       // Return the path as is if the resolved path is malformed.
     }
   }
   return path;
 }