/**
  * get the right enum value for this file extension, or null
  *
  * @param extension
  * @return
  */
 public static FileType getTypeFromExtension(String extension) {
   if (extension != null) {
     if (extension.equalsIgnoreCase(TML.getExtension())) {
       return TML;
     }
     if (extension.equalsIgnoreCase(JAVA.getExtension())) {
       return JAVA;
     }
     if (extension.equalsIgnoreCase(CLASS.getExtension())) {
       return CLASS;
     }
     if (extension.equalsIgnoreCase(PROPERTY.getExtension())) {
       return PROPERTY;
     }
   }
   return null;
 }
Example #2
0
  @Override
  protected void initCred(Map<PROPERTY, Object> config) {

    Object proxyTemp = null;
    if (config != null) {

      proxyTemp = config.get(PROPERTY.LocalPath);
    }
    if ((proxyTemp == null)
        || !(proxyTemp instanceof String)
        || StringUtils.isBlank((String) proxyTemp)) {
      proxyTemp = CoGProperties.getDefault().getProxyFile();
    }

    getProxyFile().set((String) proxyTemp);
    this.localPath = proxyFile.getValue();

    String mpFilePath = this.localPath + BaseCred.DEFAULT_MYPROXY_FILE_EXTENSION;
    File mpFile = new File(mpFilePath);
    if (mpFile.exists()) {
      myLogger.debug("Loading credential myproxy metadata from {}...", mpFilePath);

      try {

        Properties props = new Properties();
        FileInputStream in = new FileInputStream(mpFile);
        props.load(in);
        in.close();

        String username = null;
        String host = null;
        int port = -1;
        char[] password = null;
        for (Object o : props.keySet()) {

          String key = (String) o;

          PROPERTY p = PROPERTY.valueOf(key);
          String value = props.getProperty(key);

          switch (p) {
            case MyProxyHost:
              host = value;
              break;
            case MyProxyUsername:
              username = value;
              break;
            case MyProxyPort:
              port = Integer.parseInt(value);
              break;
            case MyProxyPassword:
              password = value.toCharArray();
              break;
            default:
              throw new CredentialException("Property " + p + " not supported.");
          }
        }

        if (StringUtils.isNotBlank(host)) {
          setMyProxyHost(host);
        }

        if (StringUtils.isNotBlank(username)) {
          setMyProxyUsername(username);
        }

        if (port > 0) {
          setMyProxyPort(port);
        }

        if (password != null) {
          setMyProxyPassword(password);
        }

        isUploaded = true;

      } catch (Exception e) {
        myLogger.error("Can't load myproxy metadata file", e);
      }

    } else {
      myLogger.debug("No myproxy metadata file found for cred.");
    }
  }