Esempio n. 1
0
 /**
  * Guess url.
  *
  * @param baseURL the base url
  * @param spec the spec
  * @return the url
  * @throws MalformedURLException the malformed url exception
  */
 public static URL guessURL(URL baseURL, String spec) throws MalformedURLException {
   URL finalURL = null;
   try {
     if (baseURL != null) {
       int colonIdx = spec.indexOf(':');
       String newProtocol = colonIdx == -1 ? null : spec.substring(0, colonIdx);
       if ((newProtocol != null) && !newProtocol.equalsIgnoreCase(baseURL.getProtocol())) {
         baseURL = null;
       }
     }
     finalURL = createURL(baseURL, spec);
   } catch (MalformedURLException | UnsupportedEncodingException mfu) {
     spec = spec.trim();
     int idx = spec.indexOf(':');
     if (idx == -1) {
       int slashIdx = spec.indexOf('/');
       if (slashIdx == 0) {
         // A file, absolute
         finalURL = new URL("file:" + spec);
       } else {
         if (slashIdx == -1) {
           // No slash, no colon, must be host.
           finalURL = new URL(baseURL, "http://" + spec);
         } else {
           String possibleHost = spec.substring(0, slashIdx).toLowerCase();
           if (Domains.isLikelyHostName(possibleHost)) {
             finalURL = new URL(baseURL, "http://" + spec);
           } else {
             finalURL = new URL(baseURL, "file:" + spec);
           }
         }
       }
     } else {
       if (idx == 1) {
         // Likely a drive
         finalURL = new URL(baseURL, "file:" + spec);
       } else {
         try {
           throw mfu;
         } catch (IOException e) {
           // TODO Auto-generated catch block
           logger.severe(e.getMessage());
         }
       }
     }
   }
   if (!"".equals(finalURL.getHost()) && (finalURL.toExternalForm().indexOf(' ') != -1)) {
     throw new MalformedURLException("There are blanks in the URL: " + finalURL.toExternalForm());
   }
   return finalURL;
 }
Esempio n. 2
0
 public void addDomain(Domains domain) {
   domains.put(domain.getId(), domain);
 }
Esempio n. 3
0
 private void doCleanDomains() throws IOException {
   Domains.cleanDomains(coordinator.getDomains());
 }