Esempio n. 1
0
  /**
   * Returns the store specific/account specific path for the image. @see storeFileImagePath
   * and @see getSIP
   */
  private static String getSIP(
      String pPortal,
      String pFileName,
      String storePrefix,
      Locale locale,
      HashMap filePathHM,
      StoreData storeD,
      AccountData accountD,
      String webDir,
      String rootDir,
      boolean absolutePath) {
    if (pFileName == null) {
      return "";
    }
    pFileName = pFileName.trim();

    // guess at some values if not provided
    if (locale == null) {
      if (accountD != null && Utility.isSet(accountD.getBusEntity().getLocaleCd())) {
        locale = Utility.parseLocaleCode(accountD.getBusEntity().getLocaleCd());
      }
      if (storeD != null && Utility.isSet(storeD.getBusEntity().getLocaleCd())) {
        locale = Utility.parseLocaleCode(storeD.getBusEntity().getLocaleCd());
      }
    }
    if (filePathHM == null) {
      filePathHM = new HashMap();
    }
    if (rootDir == null) {
      rootDir = ClwCustomizerMyFax.getStoreDir();
    }
    if (!Utility.isSet(storePrefix)) {
      storePrefix = storeD.getPrefix().getValue();
    }
    if (!Utility.isSet(webDir)) {
      webDir = System.getProperty("webdeploy");
    }

    if (pPortal == null) pPortal = "store";
    // Make key

    int storeId = 0;
    int accountId = 0;
    String accountDir = "";

    if (storeD != null) {
      storeId = storeD.getBusEntity().getBusEntityId();
    }

    if (accountD != null) {
      accountId = accountD.getBusEntity().getBusEntityId();
      accountDir = accountD.getPropertyValue(RefCodeNames.PROPERTY_TYPE_CD.ACCOUNT_FOLDER);
    }

    String key =
        pPortal
            + "@"
            + locale
            + "@"
            + pFileName
            + "@"
            + storeId
            + "@"
            + accountId
            + "@"
            + absolutePath;
    String resultFilePath = (String) filePathHM.get(key);
    if (resultFilePath != null) {
      return resultFilePath;
    }

    if (storePrefix == null) storePrefix = "";

    // String webDir = System.getProperty("webdeploy");

    if (webDir == null) webDir = "";
    int ind = webDir.indexOf("deploy");
    if (ind < 0) {
      (new Exception("Invalid current directory: " + webDir)).printStackTrace();
      return "";
    }
    // trying to find file
    String storeAcctPrefix =
        (Utility.isSet(accountDir)) ? storePrefix + "/" + accountDir : storePrefix;
    StringTokenizer tok = new StringTokenizer(storeAcctPrefix, "/");
    String[] storeAcctPrefixA = new String[tok.countTokens() + 1];
    storeAcctPrefixA[0] = "";
    ind = 1;
    while (tok.hasMoreTokens()) {
      String nextToken = tok.nextToken();
      if (ind == 1) {
        storeAcctPrefixA[ind] = nextToken;
      } else {
        storeAcctPrefixA[ind] = storeAcctPrefixA[ind - 1] + "/" + nextToken;
      }
      ind++;
    }
    String absPath = "";
    String filePath = "";
    boolean foundFl = false;
    for (int ii = storeAcctPrefixA.length - 1; ii >= 0; ii--) {
      filePath =
          "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + locale + "/" + "images/" + pFileName;
      absPath = webDir + filePath;
      File tf = new File(absPath);
      if (tf.exists()) {
        foundFl = true;
        break;
      }

      filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + "images/" + pFileName;
      absPath = webDir + filePath;
      tf = new File(absPath);
      if (tf.exists()) {
        foundFl = true;
        break;
      }

      filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + "images/" + pFileName;
      absPath = webDir + filePath;
      tf = new File(absPath);
      if (tf.exists()) {
        foundFl = true;
        break;
      }

      /*
      filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] +
                 "/" + "images/"+ pFileName;
      absPath =  webDir + filePath;
      tf = new File(absPath);
      if(tf.exists()) {
          foundFl = true;
          break;
      }
      */
    }

    if (absolutePath) {
      filePath = absPath;
    } else {
      filePath = "/" + rootDir + filePath;
    }
    if (foundFl) {
      filePathHM.put(key, filePath);
    }
    return filePath;
  }
Esempio n. 2
0
  public static Object getJavaObject(HttpServletRequest pRequest, String pFullClassName)
      throws Exception {
    HttpSession session = pRequest.getSession();
    CleanwiseUser appUser = (CleanwiseUser) session.getAttribute(Constants.APP_USER);
    StoreData storeD = appUser.getUserStore();
    AccountData accountD = appUser.getUserAccount();
    int storeId = 0;
    int accountId = 0;
    if (storeD != null) storeId = storeD.getBusEntity().getBusEntityId();
    if (accountD != null) accountId = accountD.getBusEntity().getBusEntityId();
    String key = storeId + "@" + accountId + "@" + pFullClassName;
    Object javaObj = session.getAttribute(key);
    if (javaObj == null) {
      ArrayList prefAL = new ArrayList();
      String path = "";
      PropertyData storePrefixPD = storeD.getPrefix();
      if (storePrefixPD != null) {
        path = Utility.strNN(storePrefixPD.getValue());
      }
      String accountDir = accountD.getPropertyValue(RefCodeNames.PROPERTY_TYPE_CD.ACCOUNT_FOLDER);
      if (Utility.isSet(accountDir)) {
        path += "/" + accountDir;
      }
      path = path.replace('\\', '/').toLowerCase();
      String[] pathDirA = Utility.parseStringToArray(path, "/");
      String pathInc = null;
      for (int ii = 0; ii < pathDirA.length; ii++) {
        String ss = pathDirA[ii];
        if (Utility.isSet(ss)) {
          if (pathInc == null) {
            pathInc = "." + ss;
          } else {
            pathInc += "." + ss;
          }
          pathDirA[ii] = pathInc;
        } else {
          pathDirA[ii] = null;
        }
      }

      int ll = pFullClassName.lastIndexOf(".");
      String defaultPath = pFullClassName.substring(0, ll);
      String className = pFullClassName.substring(ll);
      Class clazz = null;
      for (int ii = pathDirA.length - 1; ii >= 0; ii--) {
        if (pathDirA[ii] != null) {
          String fullClassNameTest = defaultPath + pathDirA[ii] + className;
          try {
            clazz = Class.forName(fullClassNameTest);
            if (clazz != null) {
              break;
            }
          } catch (Exception exc) {
          }
        }
      }
      if (clazz == null) {
        clazz = Class.forName(pFullClassName);
      }
      if (clazz != null) {
        javaObj = clazz.newInstance();
        session.setAttribute(key, javaObj);
      }
    }
    return javaObj;
  }
Esempio n. 3
0
  public static String getStoreFilePath(
      HttpServletRequest pRequest, String pPortal, String pFileName) {
    if (pFileName == null) {
      return "";
    }
    pFileName = pFileName.trim();
    HttpSession session = pRequest.getSession();
    HashMap filePathHM = (HashMap) session.getAttribute("store.files");
    if (filePathHM == null) {
      filePathHM = new HashMap();
      session.setAttribute("store.files", filePathHM);
    }
    if (pPortal == null) pPortal = "store";
    // Make key
    int storeId = 0;
    int accountId = 0;
    CleanwiseUser user = (CleanwiseUser) session.getAttribute(Constants.APP_USER);
    String accountDir = "";
    if (user != null) {
      StoreData storeD = user.getUserStore();
      if (storeD != null) {
        storeId = storeD.getBusEntity().getBusEntityId();
      }
      AccountData accountD = user.getUserAccount();
      if (accountD != null) {
        accountId = accountD.getBusEntity().getBusEntityId();
        accountDir = accountD.getPropertyValue(RefCodeNames.PROPERTY_TYPE_CD.ACCOUNT_FOLDER);
      }
    }
    Locale locale = ClwI18nUtil.getUserLocale(pRequest);

    String key = pPortal + "@" + locale + "@" + pFileName + "@" + storeId + "@" + accountId;
    String resultFilePath = (String) filePathHM.get(key);
    if (resultFilePath != null) {
      return resultFilePath;
    }

    String storeDir = (String) session.getAttribute("store.dir") + ".clw";
    String storePrefix = (String) session.getAttribute("pages.store.prefix");
    if (storePrefix == null) storePrefix = "";

    // String webDir = System.getProperty("webdeploy");

    String webDir = (String) session.getAttribute("webdeploy");

    if (webDir == null) webDir = "";
    int ind = webDir.indexOf("deploy");
    if (ind < 0) {
      (new Exception("Invalid current directory: " + webDir)).printStackTrace();
      return "";
    }
    // trying to find file
    String storeAcctPrefix =
        (Utility.isSet(accountDir)) ? storePrefix + "/" + accountDir : storePrefix;
    StringTokenizer tok = new StringTokenizer(storeAcctPrefix, "/");
    String[] storeAcctPrefixA = new String[tok.countTokens() + 1];
    storeAcctPrefixA[0] = "";
    ind = 1;
    while (tok.hasMoreTokens()) {
      String nextToken = tok.nextToken();
      if (ind == 1) {
        storeAcctPrefixA[ind] = nextToken;
      } else {
        storeAcctPrefixA[ind] = storeAcctPrefixA[ind - 1] + "/" + nextToken;
      }
      ind++;
    }
    String absPath = "";
    String filePath = "";
    boolean foundFl = false;
    for (int ii = storeAcctPrefixA.length - 1; ii >= 0; ii--) {
      filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + locale + "/" + pFileName;

      absPath = webDir + filePath;
      File tf = new File(absPath);
      if (tf.exists()) {
        foundFl = true;
        break;
      }

      if (Utility.isSet(locale.getLanguage())) {
        filePath =
            "/"
                + pPortal
                + "/"
                + storeAcctPrefixA[ii]
                + "/"
                + locale.getLanguage()
                + "/"
                + pFileName;
        absPath = webDir + filePath;
        tf = new File(absPath);
        if (tf.exists()) {
          foundFl = true;
          break;
        }
      }

      filePath = "/" + pPortal + "/" + storeAcctPrefixA[ii] + "/" + pFileName;
      absPath = webDir + filePath;
      tf = new File(absPath);
      if (tf.exists()) {
        foundFl = true;
        break;
      }

      /*
      filePath = "/" + pPortal  + "/" + storeAcctPrefixA[ii] +  "/" + pFileName;
      absPath =  webDir + filePath;
      tf = new File(absPath);
      if(tf.exists()) {
          foundFl = true;
          break;
      }
      */
    }

    if (foundFl) {
      filePathHM.put(key, filePath);
    }
    return filePath;
  }