public abstract class BaseDroplet extends DynamoServlet {

  private static ParameterName IP_PAGE_NAME = ParameterName.getParameterName("pageName");
  private static ParameterName IP_CURRENCY = ParameterName.getParameterName("currency");
  private static ParameterName IP_LANGUAGE = ParameterName.getParameterName("language");

  protected String getPageName(final DynamoHttpServletRequest req) {
    return req.getParameter(IP_PAGE_NAME);
  }

  protected String getCurrency(final DynamoHttpServletRequest req) {
    return req.getParameter(IP_CURRENCY);
  }

  protected String getLanguage(final DynamoHttpServletRequest req) {
    return req.getParameter(IP_LANGUAGE);
  }

  protected void serviceScript(CharSequence script, DynamoHttpServletResponse resp)
      throws IOException {
    vlogDebug("Generated script: {0}", script);
    resp.getOutputStream().print(script.toString());
  }

  private DataConverter converter;

  /* Get/Set */
  public DataConverter getConverter() {
    return converter;
  }

  public void setConverter(DataConverter converter) {
    this.converter = converter;
  }
}
Exemplo n.º 2
0
 public static String createQueryStringWithoutEmptyParams(
     DynamoHttpServletRequest pRequest, Set<ParameterName> params) {
   Iterator<ParameterName> it = params.iterator();
   StringBuilder sb = new StringBuilder();
   while (it.hasNext()) {
     ParameterName paramName = it.next();
     Object paramValue = pRequest.getLocalParameter(paramName);
     String sParamValue = paramValue != null ? paramValue.toString() : null;
     if (!StringUtils.isEmpty(sParamValue)) {
       sb.append(paramName.toString());
       sb.append('=');
       sb.append(sParamValue);
       sb.append('&');
     }
   }
   if (null != sb && sb.length() > 0) {
     sb.delete(sb.length() - 1, sb.length());
     sb.insert(0, '?');
   }
   return sb.toString();
 }
Exemplo n.º 3
0
 /** Called to execute this droplet */
 @Override
 public void service(
     final DynamoHttpServletRequest request, final DynamoHttpServletResponse response)
     throws ServletException, IOException {
   logInfo("Starting: " + this.getClass().getName());
   request.serviceLocalParameter(ParameterName.getParameterName("output"), request, response);
   request.setParameter("entry", "The Value");
   response.getOutputStream().write("Some content from the simple droplet".getBytes());
   mUsername = request.getParameter(USERNAME);
   // try to read data from the client if it is available
   if ("POST".equals(request.getMethod())) {
     ServletInputStream s = request.getInputStream();
     Properties p = new Properties();
     p.load(s);
     mUsernameFromInputStream = p.getProperty(USERNAME);
   }
 }
Exemplo n.º 4
0
/**
 * This droplet builds a complete URL string for the Endeca-produced action object. The action can
 * be represented either by NavigationAction, RecordAction or UrlAction.
 *
 * <p>For the NavigationAction type of Action the URL is built of request's context path, action's
 * <code>contentPath</code> and <code>navigationState</code>.
 *
 * <p>For the RecordAction type of Action the URL is built of request's context path, action's
 * <code>contentPath</code> and <code>recordState</code>.
 *
 * <p>For the UrlAction type of Action the URL is built of request's context path (only in the case
 * of relative URL) and action's URL.
 *
 * <p>Input parameters:
 *
 * <ul>
 *   <li>action - An <code>action</code> object to produce URL for.
 * </ul>
 *
 * <p>Output parameters:
 *
 * <ul>
 *   <li>actionURL - An URL for the passed in action Object.
 * </ul>
 *
 * <p>Open parameters rendered by the droplet:
 *
 * <ul>
 *   <li>output - The <code>output</code> oparam is rendered when the not empty URL is represented
 *       by the Action object. *
 *   <li>empty - The <code>empty</code> oparam is rendered in the case of empty URL.
 * </ul>
 *
 * <p>Here is the example of droplet's usage:
 *
 * <p>&lt;dsp:droplet name="ActionURLDroplet"&gt; &lt;dsp:param name="action"
 * value="${contentItem.link}"/&gt; &lt;dsp:oparam name="output"&gt; &lt;dsp:getvalueof
 * var="actionURL" param="actionURL"/&gt; &lt;c:set var="url"
 * value="${originatingRequest.contextPath}${actionURL}"/&gt; &lt;/dsp:oparam&gt; &lt;dsp:oparam
 * name="empty"&gt; &lt;c:set var="url" value="#"/&gt; &lt;/dsp:oparam&gt; &lt;/dsp:droplet&gt;
 *
 * @author Natallia Paulouskaya
 * @version $Id:
 *     //hosting-blueprint/B2CBlueprint/version/10.2.1/Endeca/Assembler/src/atg/projects/store/droplet/ActionURLDroplet.java#1
 *     $$Change: 796860 $
 * @updated $DateTime: 2013/03/14 09:30:30 $$Author: npaulous $
 */
public class ActionURLDroplet extends DynamoServlet {

  // ----------------------------------------
  /** Class version string */
  public static final String CLASS_VERSION =
      "$Id: //hosting-blueprint/B2CBlueprint/version/10.2.1/Endeca/Assembler/src/atg/projects/store/droplet/ActionURLDroplet.java#1 $$Change: 796860 $";

  /** Action object input parameter name */
  public static final ParameterName ACTION = ParameterName.getParameterName("action");

  /** The URL for the action output parameter name */
  public static final String ACTION_URL = "actionURL";

  /** Output parameter name. */
  public static final String OUTPUT = "output";

  /** Empty parameter name. */
  public static final String EMPTY = "empty";

  /** URL separator */
  public static final String URL_SEPARATOR = "/";

  /**
   * Builds the complete URL string for the Endeca-produced action object. The action can be
   * represented either by NavigationAction, RecordAction or UrlAction.
   */
  @Override
  public void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
      throws ServletException, IOException {

    // Take Action object from the request
    Action action = (Action) pRequest.getObjectParameter(ACTION);

    StringBuilder actionURL = new StringBuilder();

    if (action != null) {

      // Check the type of the action
      if (action instanceof NavigationAction) {

        // NavigationAction case
        actionURL.append(pRequest.getContextPath());
        actionURL.append(action.getContentPath());
        String navigationState = ((NavigationAction) action).getNavigationState();
        if (navigationState != null) {
          actionURL.append(navigationState);
        }
      } else {
        if (action instanceof RecordAction) {

          // RecordAction case
          actionURL.append(pRequest.getContextPath());
          actionURL.append(action.getContentPath());
          String recordState = ((RecordAction) action).getRecordState();
          if (recordState != null) {
            actionURL.append(recordState);
          }
        } else {
          if (action instanceof UrlAction) {

            // UrlAction case
            String url = ((UrlAction) action).getUrl();
            if (url.startsWith(URL_SEPARATOR)) {
              actionURL.append(pRequest.getContextPath());
            }
            actionURL.append(((UrlAction) action).getUrl());
          }
        }
      }

      // If action's URL is not empty pass it through output parameter
      if (actionURL.length() > 0) {
        pRequest.setParameter(ACTION_URL, actionURL.toString());
        pRequest.serviceLocalParameter(OUTPUT, pRequest, pResponse);
        return;
      }
    }

    // Action's URL is empty, render empty oparam
    pRequest.serviceLocalParameter(EMPTY, pRequest, pResponse);
  }
}
Exemplo n.º 5
0
/**
 * Calculate percent and discount of the product.
 *
 * @author Alena_Karpenkava
 */
public class CastPriceDroplet extends DynamoServlet {

  /** */
  private static final String ENABLED_CAST_CART = "enabledCastCart";

  private static final String STORE_IS_LOCAL = "storeIsLocal";
  /** */
  private static final String SHOW_CAST_CARD_PRICE = "showCastCardPrice";

  static final String LIST_PRICE = "listPrice";
  static final String SALE_PRICE = "salePrice";
  static final String CARD_PRICE = "cardPrice";

  /** Output parameters */
  static final ParameterName OUTPUT = ParameterName.getParameterName("output");

  private CastoDropletsPricingTools mDropletsPricingTools;

  /**
   * Calculate percent and discount of the product.
   *
   * @param pRequest - dynamo http request
   * @param pResponse - dynamo http response
   * @throws IOException - exception
   * @throws ServletException - exception
   */
  public void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
      throws ServletException, IOException {
    BigDecimal listPrice = null;
    BigDecimal salePrice = null;
    BigDecimal cardPrice = null;
    try {
      listPrice = new BigDecimal("" + pRequest.getObjectParameter(LIST_PRICE));
    } catch (NumberFormatException ex) {
      if (isLoggingError())
        logError(
            "NumberFormatException: Please check list_price param: "
                + pRequest.getObjectParameter(LIST_PRICE));
    }
    try {
      salePrice = new BigDecimal("" + pRequest.getObjectParameter(SALE_PRICE));
    } catch (NumberFormatException ex) {
      if (isLoggingError())
        logError(
            "NumberFormatException: Please check sale_price param: "
                + pRequest.getObjectParameter(SALE_PRICE));
    }
    Object showCardPriceObj = pRequest.getObjectParameter(SHOW_CAST_CARD_PRICE);
    Object enabledCastCartObj = pRequest.getObjectParameter(ENABLED_CAST_CART);
    Object storeIsLocalObj = pRequest.getObjectParameter(STORE_IS_LOCAL);
    Object reqPrice = pRequest.getObjectParameter(CARD_PRICE);
    cardPrice = (reqPrice != null) ? new BigDecimal(reqPrice.toString()) : null;
    Boolean showCardPrice = (showCardPriceObj != null) ? (Boolean) showCardPriceObj : false;
    Boolean enabledCastCart = (enabledCastCartObj != null) ? (Boolean) enabledCastCartObj : false;
    Boolean storeIsLocal = (storeIsLocalObj != null) ? (Boolean) storeIsLocalObj : false;

    Map<String, Object> outputParams =
        getDropletsPricingTools()
            .calculateForCastPriceDroplet(
                listPrice, salePrice, cardPrice, showCardPrice, enabledCastCart, storeIsLocal);
    getDropletsPricingTools().putParamsToRequest(pRequest, outputParams);
    pRequest.serviceLocalParameter(OUTPUT, pRequest, pResponse);
  }

  /** @return the dropletsPricingTools */
  public CastoDropletsPricingTools getDropletsPricingTools() {
    return mDropletsPricingTools;
  }

  /** @param dropletsPricingTools the dropletsPricingTools to set */
  public void setDropletsPricingTools(CastoDropletsPricingTools dropletsPricingTools) {
    this.mDropletsPricingTools = dropletsPricingTools;
  }
}
Exemplo n.º 6
0
public class URLProcessor extends DynamoServlet {

  // -------------------------------------
  /** Class version string */
  public static String CLASS_VERSION =
      "$Id: //hosting-blueprint/B2CBlueprint/version/10.2.1/EStore/src/atg/projects/store/droplet/URLProcessor.java#2 $$Change: 801870 $";

  /** Url for processing. */
  private String mUrl;

  /** Type of processing, f.e. 'addOrReplaceParameter' */
  private String mOperation;

  /** Parameter name */
  private String mParameter;

  /** Parameter value */
  private String mParameterValue;

  static final String PARAM_URL = "url";
  static final String PARAM_OPERATION = "operation";
  static final String PARAM_NAME = "parameter";
  static final String PARAM_VALUE = "parameterValue";

  static final ParameterName OUTPUT_OPARAM = ParameterName.getParameterName("output");
  static final String ELEMENT = "element";
  static final String OPERATION_ADD_OR_REPLACE_PARAMETER = "addOrReplaceParameter";
  static final String OPERATION_DEFAULT = OPERATION_ADD_OR_REPLACE_PARAMETER;

  /**
   * This droplet transforms specified url according to the selected type of processing, that is
   * declared through "operation"-parameter.<br>
   * If operation isn't defined, droplet by default will add or replace request parameter value.<br>
   */
  @Override
  public void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
      throws ServletException, IOException {

    String operation = (String) pRequest.getLocalParameter(PARAM_OPERATION);
    if (operation == null) {
      operation = OPERATION_DEFAULT;
    }

    String url = (String) pRequest.getLocalParameter(PARAM_URL);
    String result = url;

    if (url != null && !url.isEmpty()) {
      if (OPERATION_ADD_OR_REPLACE_PARAMETER.equals(operation)) {
        String param = (String) pRequest.getLocalParameter(PARAM_NAME);

        if (param != null) {
          Object newValueObj = pRequest.getLocalParameter(PARAM_VALUE);
          String newValue = newValueObj != null ? newValueObj.toString() : "";

          String[] parts = url.split(param + "=");

          // if parameter is presented in url,
          // replace it's value to the new one
          if (parts != null && parts.length > 1) {
            String oldValue;
            int index = parts[1].indexOf("&");

            // parameter isn't last
            if (index != -1) {
              oldValue = parts[1].substring(0, index);
            } else {
                /* parameter is last */
              oldValue = parts[1];
            }

            result = url.replaceAll(param + "=" + oldValue, param + "=" + newValue);
          } else {
            // parameter is absent in url
            // add new parameter with a specified value
            String sep = (parts[0].indexOf("=") == -1 ? "?" : "&");
            result = url + sep + param + "=" + newValue;
          }
        }
      }
    }

    pRequest.setParameter(ELEMENT, result);
    pRequest.serviceLocalParameter(OUTPUT_OPARAM, pRequest, pResponse);
  }

  /**
   * Returns url of processing
   *
   * @return url of processing
   */
  public String getUrl() {
    return mUrl;
  }

  /**
   * Sets url for processing.
   *
   * @param pUrl new url value for processing
   */
  public void setUrl(String pUrl) {
    this.mUrl = pUrl;
  }

  /**
   * Returns type of processing
   *
   * @return type of processing
   */
  public String getOperation() {
    return mOperation;
  }

  /**
   * Sets type of processing
   *
   * @param pOperation new value for the type of processing
   */
  public void setOperation(String pOperation) {
    this.mOperation = pOperation;
  }

  /**
   * Returns parameter name
   *
   * @return parameter name
   */
  public String getParameter() {
    return mParameter;
  }

  /**
   * Sets new value for the parameter name
   *
   * @param pParameter new value of parameter name
   */
  public void setParameter(String pParameter) {
    this.mParameter = pParameter;
  }

  /**
   * Returns new value for the parameter
   *
   * @return parameter value
   */
  public String getParameterValue() {
    return mParameterValue;
  }

  /**
   * Sets new value for parameter
   *
   * @param pParameterValue parameter value
   */
  public void setParameterValue(String pParameterValue) {
    this.mParameterValue = pParameterValue;
  }
}
Exemplo n.º 7
0
/**
 * Forms correct trails for ajouters(pop-ups).
 *
 * @author Katsiaryna Sharstsiuk
 */
public class FacetedSearchPopUpFinder extends DynamoServlet {
  /*
   * Open parameters
   */
  /** OUTPUT constant. */
  public static final ParameterName OUTPUT = ParameterName.getParameterName("output");

  /** ERROR constant. */
  public static final ParameterName ERROR = ParameterName.getParameterName("error");

  /** TRAIL constant. */
  public static final String TRAIL = "trail";

  /** RESULTED_MAP_FACET_ID_TO_TRAIL constant. */
  public static final String RESULTED_MAP_FACET_ID_TO_TRAIL = "resultedMapFacetIdToTrail";

  /*
   * Properties
   */
  /** trailSeparator property */
  private String mTrailSeparator = ":";

  /** commerceFacetTrailTools property */
  private CommerceFacetTrailTools mCommerceFacetTrailTools;

  /**
   * Returns trailSeparator property.
   *
   * @return trailSeparator property.
   */
  public String getTrailSeparator() {
    return mTrailSeparator;
  }

  /**
   * Sets the value of the trailSeparator property.
   *
   * @param pTrailSeparator parameter to set.
   */
  public void setTrailSeparator(String pTrailSeparator) {
    mTrailSeparator = pTrailSeparator;
  }

  /**
   * Returns commerceFacetTrailTools property.
   *
   * @return commerceFacetTrailTools property.
   */
  public CommerceFacetTrailTools getCommerceFacetTrailTools() {
    return mCommerceFacetTrailTools;
  }

  /**
   * Sets the value of the commerceFacetTrailTools property.
   *
   * @param pCommerceFacetTrailTools parameter to set.
   */
  public void setCommerceFacetTrailTools(CommerceFacetTrailTools pCommerceFacetTrailTools) {
    mCommerceFacetTrailTools = pCommerceFacetTrailTools;
  }

  /**
   * Forms correct trails for ajouters(pop-ups). Save ajouter's trail as map :ajouter id to trail.
   * If trail is empty or contains only one value(case for product listing (we don't show pivot
   * category facet at the UI)) so no one facet value was selected, so re-running search for pop-up
   * isn't necessary. the same situation for question parameter(search re-run isn't necessary).
   *
   * @param pRequest dynamo http request
   * @param pResponse dynamo http response
   * @throws ServletException
   * @throws IOException
   */
  public void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
      throws ServletException, IOException {
    try {
      if (PerformanceMonitor.isEnabled()) {
        PerformanceMonitor.startOperation("search", "TEST:FacetedSearchPopUpFinder.service");
      }
      String initialTrail = pRequest.getParameter(TRAIL);

      if ((getCommerceFacetTrailTools() != null)
          && !StringUtils.isBlank(initialTrail)
          && (initialTrail.indexOf(":") != initialTrail.lastIndexOf(":"))) {
        List<FacetValue> trails =
            getCommerceFacetTrailTools().parseFacetValueString(initialTrail, null);

        Map<String, ArrayList<String>> facetIdToFacetValues =
            new HashMap<String, ArrayList<String>>();

        String firstSafeFacet;

        /*
         * pivot category || SRCH facet || root catgory facet - should stay the same; if this facet will be multiple
         * (facetId:facetValue1|facetValue2|...) So do check, the reason of this is .getTrailString() method returns
         * not correct value
         */
        if (trails.get(0) instanceof DisjunctionMultiValue) {
          firstSafeFacet = trails.get(0).toString();
          trails.remove(0);
        } else {
          firstSafeFacet = trails.get(0).getTrailString();
          trails.remove(0);
        }

        if (trails != null) {
          for (FacetValue fv : trails) {
            facetIdToFacetValues.put(fv.getFacet().getId(), new ArrayList());
          }

          for (FacetValue fv : trails) {
            if (facetIdToFacetValues.get(fv.getFacet().getId()) != null) {
              if (fv instanceof DisjunctionMultiValue) {
                ((ArrayList) facetIdToFacetValues.get(fv.getFacet().getId())).add(fv.toString());
              } else {
                ((ArrayList) facetIdToFacetValues.get(fv.getFacet().getId()))
                    .add(fv.getTrailString());
              }
            }
          }
          Map<String, String> resultedMapFacetIdToTrail = new HashMap<String, String>();

          // trails for queries
          for (Map.Entry<String, ArrayList<String>> excludedFacet :
              facetIdToFacetValues.entrySet()) {
            StringBuffer inludedFacetsSB = new StringBuffer();

            for (Map.Entry<String, ArrayList<String>> inludedFacets :
                facetIdToFacetValues.entrySet()) {
              if (!excludedFacet.getKey().equalsIgnoreCase(inludedFacets.getKey())) {
                for (String str : inludedFacets.getValue()) {
                  inludedFacetsSB.append(str).append(":");
                }
              }
            }

            // prepend first facet value (srch || pivot || root category)
            inludedFacetsSB.insert(0, ":").insert(0, firstSafeFacet);

            // delete extra last ":"
            if (inludedFacetsSB.lastIndexOf(":") == (inludedFacetsSB.length() - 1)) {
              inludedFacetsSB.replace(
                  inludedFacetsSB.lastIndexOf(":"), inludedFacetsSB.length(), "");
            }

            resultedMapFacetIdToTrail.put(excludedFacet.getKey(), inludedFacetsSB.toString());
          } // end for

          pRequest.setParameter(RESULTED_MAP_FACET_ID_TO_TRAIL, resultedMapFacetIdToTrail);
        } // end if
      } // end if
    } finally {
      if (PerformanceMonitor.isEnabled()) {
        PerformanceMonitor.endOperation("search", "TEST:FacetedSearchPopUpFinder.service");
      }
    } // end try-finally
    pRequest.serviceLocalParameter(OUTPUT, pRequest, pResponse);
  }
}