Example #1
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;
    }
  }
Example #2
0
 /**
  * Extract a name from a Server URL by keeping the 1st part of the FQDN, between the protocol and
  * the first dot or the end of the URL. It is then capitalized. If an IP address is given instead,
  * it is used as-is. Examples:
  *
  * <ul>
  *   <li>http://int.exoplatform.com => Int
  *   <li>http://community.exoplatform.com => Community
  *   <li>https://mycompany.com => Mycompany
  *   <li>https://intranet.secure.mycompany.co.uk => Intranet
  *   <li>http://localhost => Localhost
  *   <li>http://192.168.1.15 => 192.168.1.15
  * </ul>
  *
  * @param url the Server URL
  * @param defaultName a default name in case it is impossible to extract
  * @return a name
  */
 public static String getAccountNameFromURL(String url, String defaultName) {
   String finalName = defaultName;
   if (url != null && !url.isEmpty()) {
     if (!url.startsWith("http")) url = ExoConnectionUtils.HTTP + url;
     try {
       URI theURL = new URI(url);
       finalName = theURL.getHost();
       if (!isCorrectIPAddress(finalName)) {
         int firstDot = finalName.indexOf('.');
         if (firstDot > 0) {
           finalName = finalName.substring(0, firstDot);
         }
         // else, no dot was found in the host,
         // return the hostname as is, e.g. localhost
       }
       // else, URL is an IP address, return it as is
     } catch (URISyntaxException e) {
       if (Log.LOGD)
         Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e));
       finalName = defaultName;
     } catch (IndexOutOfBoundsException e) {
       if (Log.LOGD)
         Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e));
       finalName = defaultName;
     }
   }
   return capitalize(finalName);
 }
Example #3
0
 public static boolean isDocumentUrlValid(String str) {
   try {
     URL url = new URL(str.replaceAll(" ", "%20"));
     url.toURI();
     return true;
   } catch (MalformedURLException e) {
     if (Log.LOGD)
       Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e));
     return false;
   } catch (URISyntaxException e) {
     if (Log.LOGD)
       Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e));
     return false;
   }
 }
Example #4
0
  private void deleteLocation(LocationInfo info) {
    if (NavigineApp.Navigation == null) return;

    if (info != null) {
      try {
        (new File(info.archiveFile)).delete();
        info.localVersion = -1;
        info.localModified = false;

        String locationDir = LocationLoader.getLocationDir(mContext, info.title);
        File dir = new File(locationDir);
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; ++i) files[i].delete();
        dir.delete();

        String mapFile = NavigineApp.Settings.getString("map_file", "");
        if (mapFile.equals(info.archiveFile)) {
          NavigineApp.Navigation.loadArchive(null);
          SharedPreferences.Editor editor = NavigineApp.Settings.edit();
          editor.putString("map_file", "");
          editor.commit();
        }

        mAdapter.updateList();
      } catch (Throwable e) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }
  }
Example #5
0
 private void parseMapsXml() {
   try {
     String fileName = LocationLoader.getLocationDir(NavigineApp.AppContext, null) + "/maps.xml";
     List<LocationInfo> infoList = Parser.parseMapsXml(NavigineApp.AppContext, fileName);
     mInfoList = new ArrayList<LocationInfo>();
     if (infoList != null) mInfoList = infoList;
     mAdapter.updateList();
     new File(fileName).delete();
   } catch (Throwable e) {
     Log.e(TAG, Log.getStackTraceString(e));
   }
 }