private PropsUtil() {
    try {
      SystemProperties.set(PropsKeys.DEFAULT_LIFERAY_HOME, _getDefaultLiferayHome());

      _configuration = new ConfigurationImpl(PropsUtil.class.getClassLoader(), PropsFiles.PORTAL);

      String liferayHome = _get(PropsKeys.LIFERAY_HOME);

      if (_log.isDebugEnabled()) {
        _log.debug("Configured Liferay home " + liferayHome);
      }

      SystemProperties.set(PropsKeys.LIFERAY_HOME, liferayHome);

      SystemProperties.set("ehcache.disk.store.dir", liferayHome + "/data/ehcache");

      if (GetterUtil.getBoolean(SystemProperties.get("company-id-properties"))) {

        _configurations = new HashMap<Long, Configuration>();
      }
    } catch (Exception e) {
      if (_log.isErrorEnabled()) {
        _log.error("Unable to initialize PropsUtil", e);
      }
    }
  }
Esempio n. 2
0
  public Cache buildCache(String region, Properties properties) throws CacheException {

    int refreshPeriod =
        GetterUtil.get(
            SystemProperties.get(StringHelper.qualify(region, OSCACHE_REFRESH_PERIOD)),
            CacheEntry.INDEFINITE_EXPIRY);

    String cron = SystemProperties.get(StringHelper.qualify(region, OSCACHE_CRON));

    return new OSCache(refreshPeriod, cron, region);
  }
Esempio n. 3
0
  private ShoppingOrderPool() {
    _cacheable = ShoppingOrder.CACHEABLE;

    int maxSize = ShoppingOrder.MAX_SIZE;
    _cache = new GeneralCacheAdministrator(SystemProperties.getProperties());
    _cache.getCache().setCapacity(maxSize);
    GlobalPool.registerPool(ShoppingOrderPool.class.getName());
  }
  private String _getDefaultLiferayHome() {
    String defaultLiferayHome = null;

    if (ServerDetector.isGeronimo()) {
      defaultLiferayHome = SystemProperties.get("org.apache.geronimo.home.dir") + "/..";
    } else if (ServerDetector.isGlassfish()) {
      defaultLiferayHome = SystemProperties.get("com.sun.aas.installRoot") + "/..";
    } else if (ServerDetector.isJBoss()) {
      defaultLiferayHome = SystemProperties.get("jboss.home.dir") + "/..";
    } else if (ServerDetector.isJOnAS()) {
      defaultLiferayHome = SystemProperties.get("jonas.base") + "/..";
    } else if (ServerDetector.isWebLogic()) {
      defaultLiferayHome = SystemProperties.get("env.DOMAIN_HOME") + "/..";
    } else if (ServerDetector.isJetty()) {
      defaultLiferayHome = SystemProperties.get("jetty.home") + "/..";
    } else if (ServerDetector.isResin()) {
      defaultLiferayHome = SystemProperties.get("resin.home") + "/..";
    } else if (ServerDetector.isTomcat()) {
      defaultLiferayHome = SystemProperties.get("catalina.base") + "/..";
    } else {
      defaultLiferayHome = SystemProperties.get("user.dir") + "/liferay";
    }

    defaultLiferayHome =
        StringUtil.replace(defaultLiferayHome, CharPool.BACK_SLASH, CharPool.SLASH);

    defaultLiferayHome =
        StringUtil.replace(defaultLiferayHome, StringPool.DOUBLE_SLASH, StringPool.SLASH);

    if (defaultLiferayHome.endsWith("/..")) {
      int pos = defaultLiferayHome.lastIndexOf(CharPool.SLASH, defaultLiferayHome.length() - 4);

      if (pos != -1) {
        defaultLiferayHome = defaultLiferayHome.substring(0, pos);
      }
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Default Liferay home " + defaultLiferayHome);
    }

    return defaultLiferayHome;
  }
  protected void doAddBookItems(long userId, long groupId, long categoryId, String[] isbns)
      throws IOException, PortalException, SystemException {

    String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);

    for (int i = 0; (i < isbns.length) && (i < 50); i++) {
      String isbn = isbns[i];

      AmazonRankings amazonRankings = AmazonRankingsUtil.getAmazonRankings(isbn);

      if (amazonRankings == null) {
        continue;
      }

      String name = amazonRankings.getProductName();
      String description = StringPool.BLANK;
      String properties = getBookProperties(amazonRankings);

      int minQuantity = 0;
      int maxQuantity = 0;
      double price = amazonRankings.getListPrice();
      double discount = 1 - amazonRankings.getOurPrice() / price;
      boolean taxable = true;
      double shipping = 0.0;
      boolean useShippingFormula = true;

      ShoppingItemPrice itemPrice = shoppingItemPricePersistence.create(0);

      itemPrice.setMinQuantity(minQuantity);
      itemPrice.setMaxQuantity(maxQuantity);
      itemPrice.setPrice(price);
      itemPrice.setDiscount(discount);
      itemPrice.setTaxable(taxable);
      itemPrice.setShipping(shipping);
      itemPrice.setUseShippingFormula(useShippingFormula);
      itemPrice.setStatus(ShoppingItemPriceConstants.STATUS_ACTIVE_DEFAULT);

      boolean requiresShipping = true;
      int stockQuantity = 0;
      boolean featured = false;
      Boolean sale = null;

      // Small image

      boolean smallImage = true;
      String smallImageURL = StringPool.BLANK;
      File smallFile =
          new File(
              tmpDir
                  + File.separatorChar
                  + PwdGenerator.getPassword(PwdGenerator.KEY1 + PwdGenerator.KEY2, 12)
                  + ".jpg");

      byte[] smallBytes = HttpUtil.URLtoByteArray(amazonRankings.getSmallImageURL());

      if (smallBytes.length < 1024) {
        smallImage = false;
      } else {
        OutputStream os = new FileOutputStream(smallFile);

        os.write(smallBytes);

        os.close();
      }

      // Medium image

      boolean mediumImage = true;
      String mediumImageURL = StringPool.BLANK;
      File mediumFile =
          new File(
              tmpDir
                  + File.separatorChar
                  + PwdGenerator.getPassword(PwdGenerator.KEY1 + PwdGenerator.KEY2, 12)
                  + ".jpg");

      byte[] mediumBytes = HttpUtil.URLtoByteArray(amazonRankings.getMediumImageURL());

      if (mediumBytes.length < 1024) {
        mediumImage = false;
      } else {
        OutputStream os = new FileOutputStream(mediumFile);

        os.write(mediumBytes);

        os.close();
      }

      // Large image

      boolean largeImage = true;
      String largeImageURL = StringPool.BLANK;
      File largeFile =
          new File(
              tmpDir
                  + File.separatorChar
                  + PwdGenerator.getPassword(PwdGenerator.KEY1 + PwdGenerator.KEY2, 12)
                  + ".jpg");

      byte[] largeBytes = HttpUtil.URLtoByteArray(amazonRankings.getLargeImageURL());

      if (largeBytes.length < 1024) {
        largeImage = false;
      } else {
        OutputStream os = new FileOutputStream(largeFile);

        os.write(largeBytes);

        os.close();
      }

      List<ShoppingItemField> itemFields = new ArrayList<ShoppingItemField>();

      List<ShoppingItemPrice> itemPrices = new ArrayList<ShoppingItemPrice>();

      itemPrices.add(itemPrice);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);

      addItem(
          userId,
          groupId,
          categoryId,
          isbn,
          name,
          description,
          properties,
          StringPool.BLANK,
          requiresShipping,
          stockQuantity,
          featured,
          sale,
          smallImage,
          smallImageURL,
          smallFile,
          mediumImage,
          mediumImageURL,
          mediumFile,
          largeImage,
          largeImageURL,
          largeFile,
          itemFields,
          itemPrices,
          serviceContext);

      smallFile.delete();
      mediumFile.delete();
      largeFile.delete();
    }
  }