/**
   * Init digester for components syntax. This is an old set of rules, left for backward
   * compatibility.
   *
   * @param digester Digester instance to use.
   */
  private void initDigesterForComponentsDefinitionsSyntax(Digester digester) {
    // Common constants
    String PACKAGE_NAME = "org.apache.struts.tiles.xmlDefinition";
    String DEFINITION_TAG = "component-definitions/definition";
    String definitionHandlerClass = PACKAGE_NAME + ".XmlDefinition";

    String PUT_TAG = DEFINITION_TAG + "/put";
    String putAttributeHandlerClass = PACKAGE_NAME + ".XmlAttribute";

    String LIST_TAG = DEFINITION_TAG + "/putList";
    String listHandlerClass = PACKAGE_NAME + ".XmlListAttribute";

    String ADD_LIST_ELE_TAG = LIST_TAG + "/add";

    // syntax rules
    digester.addObjectCreate(DEFINITION_TAG, definitionHandlerClass);
    digester.addSetProperties(DEFINITION_TAG);
    digester.addSetNext(DEFINITION_TAG, "putDefinition", definitionHandlerClass);
    // put / putAttribute rules
    digester.addObjectCreate(PUT_TAG, putAttributeHandlerClass);
    digester.addSetNext(PUT_TAG, "addAttribute", putAttributeHandlerClass);
    digester.addSetProperties(PUT_TAG);
    digester.addCallMethod(PUT_TAG, "setBody", 0);
    // list rules
    digester.addObjectCreate(LIST_TAG, listHandlerClass);
    digester.addSetProperties(LIST_TAG);
    digester.addSetNext(LIST_TAG, "addAttribute", putAttributeHandlerClass);
    // list elements rules
    // We use Attribute class to avoid rewriting a new class.
    // Name part can't be used in listElement attribute.
    digester.addObjectCreate(ADD_LIST_ELE_TAG, putAttributeHandlerClass);
    digester.addSetNext(ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass);
    digester.addSetProperties(ADD_LIST_ELE_TAG);
    digester.addCallMethod(ADD_LIST_ELE_TAG, "setBody", 0);
  }
 protected Digester createSoftwareCategoryDigester() {
   Digester digester = new Digester();
   digester.addObjectCreate("*/SoftwareCategory", SoftwareCategoryItem.class);
   digester.addBeanPropertySetter("*/SoftwareCategory/Name", "name");
   digester.addBeanPropertySetter("*/SoftwareCategory/Description", "description");
   digester.addSetNext("*/SoftwareCategory", "add");
   digester.addObjectCreate("*/SoftwareCategory/SoftwareCategory", SoftwareCategoryItem.class);
   digester.addBeanPropertySetter("*/SoftwareCategory/SoftwareCategory/Name", "name");
   digester.addBeanPropertySetter(
       "*/SoftwareCategory/SoftwareCategory/Description", "description");
   digester.addSetNext("*/SoftwareCategory/SoftwareCategory", "addSoftwareCategory");
   return digester;
 }
Beispiel #3
0
 /** Add rules for digesting tool elements. */
 protected void addToolRules(Digester digester) {
   digester.addObjectCreate("toolbox/tool", getToolInfoClass());
   digester.addBeanPropertySetter("toolbox/tool/key", "key");
   digester.addBeanPropertySetter("toolbox/tool/class", "classname");
   digester.addRule("toolbox/tool/parameter", new ParameterRule());
   digester.addSetNext("toolbox/tool", "addTool");
 }
 public void addRuleInstances(Digester digester) {
   digester.addObjectCreate(prefix, clazz);
   digester.addBeanPropertySetter(prefix + "/" + TAG_NAME, "name");
   digester.addBeanPropertySetter(prefix + "/" + TAG_GROUP, "group");
   digester.addBeanPropertySetter(prefix + "/" + TAG_DESCRIPTION, "description");
   digester.addBeanPropertySetter(prefix + "/" + TAG_VOLATILITY, "volatility");
   digester.addRule(
       prefix + "/" + TAG_MISFIRE_INSTRUCTION, new MisfireInstructionRule("misfireInstruction"));
   digester.addBeanPropertySetter(prefix + "/" + TAG_CALENDAR_NAME, "calendarName");
   digester.addObjectCreate(prefix + "/" + TAG_JOB_DATA_MAP, JobDataMap.class);
   digester.addCallMethod(
       prefix + "/" + TAG_JOB_DATA_MAP + "/" + TAG_ENTRY,
       "put",
       2,
       new Class[] {Object.class, Object.class});
   digester.addCallParam(prefix + "/" + TAG_JOB_DATA_MAP + "/" + TAG_ENTRY + "/" + TAG_KEY, 0);
   digester.addCallParam(prefix + "/" + TAG_JOB_DATA_MAP + "/" + TAG_ENTRY + "/" + TAG_VALUE, 1);
   digester.addSetNext(prefix + "/" + TAG_JOB_DATA_MAP, "setJobDataMap");
   digester.addBeanPropertySetter(prefix + "/" + TAG_JOB_NAME, "jobName");
   digester.addBeanPropertySetter(prefix + "/" + TAG_JOB_GROUP, "jobGroup");
   Converter converter = new DateConverter(new String[] {XSD_DATE_FORMAT, DTD_DATE_FORMAT});
   digester.addRule(
       prefix + "/" + TAG_START_TIME,
       new SimpleConverterRule("startTime", converter, Date.class));
   digester.addRule(
       prefix + "/" + TAG_END_TIME, new SimpleConverterRule("endTime", converter, Date.class));
 }
 public void addRuleInstances(Digester digester) {
   digester.addObjectCreate(prefix, CalendarBundle.class);
   digester.addSetProperties(prefix, TAG_CLASS_NAME, "className");
   digester.addBeanPropertySetter(prefix + "/" + TAG_NAME, "calendarName");
   digester.addBeanPropertySetter(prefix + "/" + TAG_DESCRIPTION, "description");
   digester.addSetNext(prefix, setNextMethodName);
 }
Beispiel #6
0
 /** Add rules for digesting data elements. */
 protected void addDataRules(Digester digester) {
   digester.addObjectCreate("toolbox/data", getDataInfoClass());
   digester.addSetProperties("toolbox/data");
   digester.addBeanPropertySetter("toolbox/data/key", "key");
   digester.addBeanPropertySetter("toolbox/data/value", "value");
   digester.addSetNext("toolbox/data", "addData");
 }
 @Override
 protected Digester getDigester() {
   Digester digester = super.getDigester();
   digester.addObjectCreate("*/rowset/row", ApiAsset.class);
   digester.addSetProperties("*/rowset/row");
   digester.addSetNext("*/rowset/row", "addAsset");
   return digester;
 }
 @Override
 protected Digester getDigester() {
   Digester digester = super.getDigester();
   digester.addSetProperties("eveapi/result/rowset/row");
   digester.addObjectCreate("eveapi/result/rowset/row/rowset/row", ApiMemberCorporation.class);
   digester.addSetProperties("eveapi/result/rowset/row/rowset/row");
   digester.addSetNext("eveapi/result/rowset/row/rowset/row", "add");
   return digester;
 }
  protected Digester createSoftwareDigester() {
    Digester digester = new Digester();
    digester.setValidating(false);
    digester.addObjectCreate("*/Software", SoftwareItem.class);
    digester.addBeanPropertySetter("*/Software/ExternalId", "externalId");
    digester.addBeanPropertySetter("*/Software/Vendor", "vendor");
    digester.addBeanPropertySetter("*/Software/Category", "category");
    digester.addBeanPropertySetter("*/Software/Name", "name");
    digester.addBeanPropertySetter("*/Software/Version", "version");
    digester.addBeanPropertySetter("*/Software/Status", "status");
    digester.addBeanPropertySetter("*/Software/LicenseType", "licenseType");
    digester.addBeanPropertySetter("*/Software/Description", "description");
    digester.addObjectCreate("*/Software/Packages/Package", SoftwarePackageItem.class);
    digester.addBeanPropertySetter("*/Software/Packages/Package/Name", "name");

    digester.addObjectCreate(
        "*/Software/Packages/Package/Remote", SoftwarePackage4RemoteItem.class);
    digester.addBeanPropertySetter("*/Software/Packages/Package/Remote/Url", "url");
    digester.addSetNext("*/Software/Packages/Package/Remote", "setRemote");

    digester.addObjectCreate("*/Software/Packages/Package/Local", SoftwarePackage4LocalItem.class);
    digester.addBeanPropertySetter("*/Software/Packages/Package/Local/MimeType", "mimeType");
    digester.addBeanPropertySetter("*/Software/Packages/Package/Local/File", "file");
    digester.addSetNext("*/Software/Packages/Package/Local", "setLocal");

    digester.addObjectCreate(
        "*/Software/Packages/Package/InstallOptions/InstOpts",
        SoftwarePackage4InstallOptionsItem.class);
    digester.addObjectCreate(
        "*/Software/Packages/Package/InstallOptions/InstOpts/StdOpt",
        SoftwarePackage4StdOptItem.class);
    digester.addSetProperties("*/Software/Packages/Package/InstallOptions/InstOpts/StdOpt");
    digester.addSetNext("*/Software/Packages/Package/InstallOptions/InstOpts/StdOpt", "addStdOpt");
    digester.addObjectCreate(
        "*/Software/Packages/Package/InstallOptions/InstOpts/StdSymOpt",
        SoftwarePackage4StdSymOptItem.class);
    digester.addSetProperties("*/Software/Packages/Package/InstallOptions/InstOpts/StdSymOpt");
    digester.addSetNext(
        "*/Software/Packages/Package/InstallOptions/InstOpts/StdSymOpt", "addStdSymOpt");
    digester.addSetNext("*/Software/Packages/Package/InstallOptions/InstOpts", "addInstallOptions");

    digester.addObjectCreate(
        "*/Software/Packages/Package/TargetModels/Model", SoftwarePackage4TargetModelsItem.class);
    digester.addBeanPropertySetter(
        "*/Software/Packages/Package/TargetModels/Model/Vendor", "vendor");
    digester.addBeanPropertySetter("*/Software/Packages/Package/TargetModels/Model/Name", "name");
    digester.addSetNext("*/Software/Packages/Package/TargetModels/Model", "addModels");
    digester.addSetNext("*/Software/Packages/Package", "addSoftwarePackage");
    digester.addSetNext("*/Software", "add");

    return digester;
  }
Beispiel #10
0
  /**
   * Add the set of Rule instances defined in this RuleSet to the specified <code>Digester</code>
   * instance, associating them with our namespace URI (if any). This method should only be called
   * by a Digester instance.
   *
   * @param digester Digester instance to which the new Rule instances should be added.
   */
  public void addRuleInstances(Digester digester) {

    digester.addObjectCreate(
        prefix + "Engine", "org.apache.catalina.core.StandardEngine", "className");
    digester.addSetProperties(prefix + "Engine");
    digester.addRule(
        prefix + "Engine",
        new LifecycleListenerRule(
            digester, "org.apache.catalina.startup.EngineConfig", "engineConfigClass"));
    digester.addSetNext(prefix + "Engine", "setContainer", "org.apache.catalina.Container");

    digester.addObjectCreate(
        prefix + "Engine/Listener",
        null, // MUST be specified in the element
        "className");
    digester.addSetProperties(prefix + "Engine/Listener");
    digester.addSetNext(
        prefix + "Engine/Listener",
        "addLifecycleListener",
        "org.apache.catalina.LifecycleListener");

    digester.addObjectCreate(
        prefix + "Engine/Logger",
        null, // MUST be specified in the element
        "className");
    digester.addSetProperties(prefix + "Engine/Logger");
    digester.addSetNext(prefix + "Engine/Logger", "setLogger", "org.apache.catalina.Logger");

    digester.addObjectCreate(
        prefix + "Engine/Realm",
        null, // MUST be specified in the element
        "className");
    digester.addSetProperties(prefix + "Engine/Realm");
    digester.addSetNext(prefix + "Engine/Realm", "setRealm", "org.apache.catalina.Realm");

    digester.addObjectCreate(
        prefix + "Engine/Valve",
        null, // MUST be specified in the element
        "className");
    digester.addSetProperties(prefix + "Engine/Valve");
    digester.addSetNext(prefix + "Engine/Valve", "addValve", "org.apache.catalina.Valve");
  }
Beispiel #11
0
  protected Digester createSoftwareVenderDigester() {
    // Initialize the digester
    Digester digester = new Digester();
    digester.setValidating(false);

    digester.addObjectCreate("*/SoftwareVendor", SoftwareVenderItem.class);
    digester.addBeanPropertySetter("*/SoftwareVendor/Name", "name");
    digester.addBeanPropertySetter("*/SoftwareVendor/Description", "description");
    digester.addSetNext("*/SoftwareVendor", "add");
    return digester;
  }
  /**
   * @param parent
   * @param digester
   */
  public static void registerDigester(String parent, Digester digester) {
    final String myPath = parent + _SEP + _DBPROCEDURECALLER_TAG;
    final String[] properties =
        new String[] {
          "id", "dbMethodName", "connectionJndiName", "resourceFactoryId", "returnMapId"
        };

    digester.addObjectCreate(myPath, DBProcedureCallerConfig.class);
    digester.addSetNext(myPath, ADD_DB_PROCEDURE_CALLER_CONFIG);
    digester.addSetProperties(myPath, properties, properties);
    DBResourceFactoryConfig.registerDigester(myPath, digester);
    DBReturnMapConfig.registerDigester(myPath, digester);
  }
Beispiel #13
0
  @Override
  protected Digester getDigester() {
    Digester digester = super.getDigester();
    digester.addBeanPropertySetter("eveapi/result/characterID");
    digester.addBeanPropertySetter("eveapi/result/name");
    digester.addBeanPropertySetter("eveapi/result/race");
    digester.addBeanPropertySetter("eveapi/result/bloodLine");
    digester.addBeanPropertySetter("eveapi/result/gender");
    digester.addBeanPropertySetter("eveapi/result/corporationName");
    digester.addBeanPropertySetter("eveapi/result/corporationID");
    digester.addBeanPropertySetter("eveapi/result/balance");
    digester.addObjectCreate(
        "eveapi/result/attributeEnhancers/intelligenceBonus", IntelligenceBonus.class);
    digester.addBeanPropertySetter(
        "eveapi/result/attributeEnhancers/intelligenceBonus/augmentatorName");
    digester.addBeanPropertySetter(
        "eveapi/result/attributeEnhancers/intelligenceBonus/augmentatorValue");
    digester.addSetNext(
        "eveapi/result/attributeEnhancers/intelligenceBonus", "addAttributeEnhancer");

    digester.addObjectCreate("eveapi/result/attributeEnhancers/memoryBonus", MemoryBonus.class);
    digester.addBeanPropertySetter("eveapi/result/attributeEnhancers/memoryBonus/augmentatorName");
    digester.addBeanPropertySetter("eveapi/result/attributeEnhancers/memoryBonus/augmentatorValue");
    digester.addSetNext("eveapi/result/attributeEnhancers/memoryBonus", "addAttributeEnhancer");

    digester.addObjectCreate("eveapi/result/attributeEnhancers/charismaBonus", CharismaBonus.class);
    digester.addBeanPropertySetter(
        "eveapi/result/attributeEnhancers/charismaBonus/augmentatorName");
    digester.addBeanPropertySetter(
        "eveapi/result/attributeEnhancers/charismaBonus/augmentatorValue");
    digester.addSetNext("eveapi/result/attributeEnhancers/charismaBonus", "addAttributeEnhancer");

    digester.addObjectCreate(
        "eveapi/result/attributeEnhancers/perceptionBonus", PerceptionBonus.class);
    digester.addBeanPropertySetter(
        "eveapi/result/attributeEnhancers/perceptionBonus/augmentatorName");
    digester.addBeanPropertySetter(
        "eveapi/result/attributeEnhancers/perceptionBonus/augmentatorValue");
    digester.addSetNext("eveapi/result/attributeEnhancers/perceptionBonus", "addAttributeEnhancer");

    digester.addObjectCreate(
        "eveapi/result/attributeEnhancers/willpowerBonus", WillpowerBonus.class);
    digester.addBeanPropertySetter(
        "eveapi/result/attributeEnhancers/willpowerBonus/augmentatorName");
    digester.addBeanPropertySetter(
        "eveapi/result/attributeEnhancers/willpowerBonus/augmentatorValue");
    digester.addSetNext("eveapi/result/attributeEnhancers/willpowerBonus", "addAttributeEnhancer");

    digester.addBeanPropertySetter("eveapi/result/attributes/intelligence");
    digester.addBeanPropertySetter("eveapi/result/attributes/memory");
    digester.addBeanPropertySetter("eveapi/result/attributes/charisma");
    digester.addBeanPropertySetter("eveapi/result/attributes/perception");
    digester.addBeanPropertySetter("eveapi/result/attributes/willpower");

    digester.addObjectCreate("eveapi/result/rowset/row", ApiSkill.class);
    digester.addSetProperties("eveapi/result/rowset/row");
    digester.addSetNext("eveapi/result/rowset/row", "addSkill");
    return digester;
  }
  public TVShow getShowInfo(String name) {
    log.info("getting show info for {}", name);

    ConvertUtils.register(getDateConverter(), Date.class);
    try {
      int showid = getShowId(name);
      if (showid == -1) {
        return null;
      } // no show by that name
      Response response =
          client.get("http://www.tvrage.com/feeds/full_show_info.php?sid=" + showid);

      log.debug("Found TV Show named {} at http://www.tvrage.com/feeds/full_show_info.php", name);

      Digester digest = new Digester();
      digest.addObjectCreate("Show", TVShow.class);
      digest.addBeanPropertySetter("Show/name");
      digest.addBeanPropertySetter("Show/showid", "id");
      digest.addBeanPropertySetter("Show/started", "startedDate");
      digest.addBeanPropertySetter("Show/origin_country", "country");
      digest.addBeanPropertySetter("Show/status");
      digest.addBeanPropertySetter("Show/runtime");
      digest.addObjectCreate("Show/Episodelist/Season", Season.class);
      digest.addSetProperties("Show/Episodelist/Season", "no", "number");
      digest.addSetNext("Show/Episodelist/Season", "addSeason");
      digest.addObjectCreate("Show/Episodelist/Season/episode", Episode.class);
      digest.addSetNext("Show/Episodelist/Season/episode", "addEpisode");
      digest.addBeanPropertySetter("Show/Episodelist/Season/episode/seasonnum", "episodeNum");
      digest.addBeanPropertySetter("Show/Episodelist/Season/episode/epnum", "absoluteEpisodeNum");
      digest.addBeanPropertySetter("Show/Episodelist/Season/episode/prodnum", "productionNum");
      digest.addBeanPropertySetter("Show/Episodelist/Season/episode/airdate", "airDate");
      digest.addBeanPropertySetter("Show/Episodelist/Season/episode/link", "detailsLink");
      digest.addBeanPropertySetter("Show/Episodelist/Season/episode/title");
      return (TVShow) digest.parse(response.getBody());
    } catch (Exception e) {
      log.error("error fetching TV show data for show " + name, e);
      return null;
    }
  }
Beispiel #15
0
  public void addRuleInstances(Digester digester) {
    // allow client package conversions to be configured.
    digester.addObjectCreate(
        "enunciate/modules/php/package-conversions/convert", PackageModuleConversion.class);
    digester.addSetProperties("enunciate/modules/php/package-conversions/convert");
    digester.addSetNext(
        "enunciate/modules/php/package-conversions/convert", "addClientPackageConversion");

    digester.addCallMethod("enunciate/modules/php/facets/include", "addFacetInclude", 1);
    digester.addCallParam("enunciate/modules/php/facets/include", 0, "name");
    digester.addCallMethod("enunciate/modules/php/facets/exclude", "addFacetExclude", 1);
    digester.addCallParam("enunciate/modules/php/facets/exclude", 0, "name");
  }
  /**
   * Process a single <code>faces-config.xml</code> file and add all beans found to the supplied
   * list of {@link FacesConfigEntry} objects.
   *
   * @param url The faces-config.xml file
   * @param facesConfigEntries list of entries to add the beans to
   */
  private void processFacesConfig(URL url, List<FacesConfigEntry> facesConfigEntries) {

    // log name of current file
    if (log.isTraceEnabled()) {
      log.trace("Loading bean names from: " + url.toString());
    }

    // setup digester
    Digester digester = new Digester();

    /*
     * We use the context class loader to resolve classes.
     * This fixes ClassNotFoundExceptions on Geronimo.
     */
    digester.setUseContextClassLoader(true);

    // prevent downloading of DTDs
    digester.setEntityResolver(new EmptyEntityResolver());

    digester.setValidating(false);
    digester.push(facesConfigEntries);
    digester.addObjectCreate("faces-config/managed-bean", FacesConfigEntry.class);
    digester.addCallMethod("faces-config/managed-bean/managed-bean-name", "setName", 0);
    digester.addCallMethod("faces-config/managed-bean/managed-bean-class", "setBeanClass", 0);
    digester.addSetNext("faces-config/managed-bean", "add");

    // stream used to read faces-config.xml file
    InputStream stream = null;

    try {
      // open the file and let digester pares it
      stream = url.openStream();
      digester.parse(stream);

    } catch (IOException e) {
      // may be thrown when reading the file
      log.error("Failed to parse: " + url.toString(), e);
    } catch (SAXException e) {
      // parsing errors
      log.error("Failed to parse: " + url.toString(), e);
    } finally {
      // close stream
      if (stream != null) {
        try {
          stream.close();
        } catch (IOException e) {
          // ignore IOExceptions on close
        }
      }
    }
  }
  /**
   * Init digester in order to parse instances definition file syntax. Instances is an old name for
   * "definition". This method is left for backwards compatibility.
   *
   * @param digester Digester instance to use.
   */
  private void initDigesterForInstancesSyntax(Digester digester) {
    // Build a digester to process our configuration resource
    String PACKAGE_NAME = "org.apache.struts.tiles.xmlDefinition";
    String INSTANCE_TAG = "component-instances/instance";
    String instanceHandlerClass = PACKAGE_NAME + ".XmlDefinition";

    String PUT_TAG = INSTANCE_TAG + "/put";
    String PUTATTRIBUTE_TAG = INSTANCE_TAG + "/putAttribute";
    String putAttributeHandlerClass = PACKAGE_NAME + ".XmlAttribute";

    String LIST_TAG = INSTANCE_TAG + "/putList";
    String listHandlerClass = PACKAGE_NAME + ".XmlListAttribute";

    String ADD_LIST_ELE_TAG = LIST_TAG + "/add";

    // component instance rules
    digester.addObjectCreate(INSTANCE_TAG, instanceHandlerClass);
    digester.addSetProperties(INSTANCE_TAG);
    digester.addSetNext(INSTANCE_TAG, "putDefinition", instanceHandlerClass);
    // put / putAttribute rules
    digester.addObjectCreate(PUTATTRIBUTE_TAG, putAttributeHandlerClass);
    digester.addSetProperties(PUTATTRIBUTE_TAG);
    digester.addSetNext(PUTATTRIBUTE_TAG, "addAttribute", putAttributeHandlerClass);
    // put / putAttribute rules
    digester.addObjectCreate(PUT_TAG, putAttributeHandlerClass);
    digester.addSetProperties(PUT_TAG);
    digester.addSetNext(PUT_TAG, "addAttribute", putAttributeHandlerClass);
    // list rules
    digester.addObjectCreate(LIST_TAG, listHandlerClass);
    digester.addSetProperties(LIST_TAG);
    digester.addSetNext(LIST_TAG, "addAttribute", putAttributeHandlerClass);
    // list elements rules
    // We use Attribute class to avoid rewriting a new class.
    // Name part can't be used in listElement attribute.
    digester.addObjectCreate(ADD_LIST_ELE_TAG, putAttributeHandlerClass);
    digester.addSetProperties(ADD_LIST_ELE_TAG);
    digester.addSetNext(ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass);
  }
Beispiel #18
0
 protected Digester getDigester() {
   Digester digester = new Digester();
   ConvertUtils.register(DateUtils.getGMTConverter(), Date.class);
   ConvertUtils.register(new EveRaceConverter(), EveRace.class);
   ConvertUtils.register(new EveBloodlineConverter(), EveBloodline.class);
   ConvertUtils.register(new EveAncestryConverter(), EveAncestry.class);
   digester.setValidating(false);
   digester.addObjectCreate("eveapi", clazz);
   digester.addSetProperties("eveapi");
   digester.addObjectCreate("eveapi/error", ApiError.class);
   digester.addSetProperties("eveapi/error");
   digester.addBeanPropertySetter("eveapi/error");
   digester.addSetNext("eveapi/error", "setError");
   digester.addBeanPropertySetter("eveapi/currentTime");
   digester.addBeanPropertySetter("eveapi/cachedUntil");
   return digester;
 }
  /**
   * Process XML configuration to read rules elements into <code>Rules</code>
   *
   * <p>
   *
   * <p>package scope so that it could be individually tested
   *
   * @param xml String xml to parse
   * @throws IOException when an input/output error occurs
   * @throws SAXException when given xml can not be parsed
   */
  void processRules(final String xml) throws IOException, SAXException {

    final Digester digester = getDigester();

    digester.addObjectCreate(XmlConfiguration.rules, ArrayList.class);
    digester.addObjectCreate(XmlConfiguration.rule, Rule.class);
    digester.addSetProperties(XmlConfiguration.rule, "id", "idString");
    digester.addCallMethod(XmlConfiguration.ruleComment, "setComment", 0);
    digester.addCallMethod(XmlConfiguration.rulePackage, "addPackage", 0);
    digester.addCallMethod(XmlConfiguration.ruleViolation, "addViolation", 0);
    digester.addSetNext(XmlConfiguration.rule, "add");

    final StringReader reader = new StringReader(xml);

    Object o = digester.parse(reader);

    if (o != null) {

      final List<Rule> parsedRules = (ArrayList<Rule>) o;
      getRules().addAll(parsedRules);
    }
  }
  /**
   * Read xml configuration for source directories into SourceDirectory instances.
   *
   * <p>
   *
   * <p>package scope so that it could be individually tested
   *
   * @param xml String xml to parse
   * @throws IOException when an input/output error occurs
   * @throws SAXException when given xml can not be parsed
   */
  void processSources(final String xml) throws IOException, SAXException {

    final Digester digester = getDigester();

    digester.addObjectCreate(XmlConfiguration.sources, ArrayList.class);
    digester.addObjectCreate(XmlConfiguration.source, SourceDirectory.class);
    digester.addCallMethod(XmlConfiguration.source, "setPath", 0);
    digester.addSetProperties(XmlConfiguration.source, "not-found", "notFound");
    digester.addSetNext(XmlConfiguration.source, "add");

    final StringReader reader = new StringReader(xml);
    Object o = digester.parse(reader);

    if ((o != null) && o instanceof List) {

      final List<SourceDirectory> parsedSources = (ArrayList<SourceDirectory>) o;

      for (final SourceDirectory sourceDirectory : parsedSources) {

        getSources().add(sourceDirectory);
      }
    }
  }
Beispiel #21
0
  private Digester createDigester() {
    Digester d = new Digester();

    d.addObjectCreate("configuration/accounts", ArrayList.class);
    d.addObjectCreate("configuration/accounts/account", Account.class);
    d.addSetProperties("configuration/accounts/account");

    d.addObjectCreate("configuration/accounts/account/folders", ArrayList.class);
    d.addObjectCreate("configuration/accounts/account/folders/folder", FolderDefinition.class);
    d.addSetProperties("configuration/accounts/account/folders/folder");

    d.addObjectCreate("configuration/accounts/account/folders/folder/rules", ArrayList.class);

    d.addFactoryCreate(
        "configuration/accounts/account/folders/folder/rules/groovy",
        new GroovyRuleObjectCreationFactory());
    // d.addObjectCreate(
    // "configuration/accounts/account/folders/folder/rules/groovy",
    // GroovyRuleDefinition.class);
    //
    // d
    // .addSetProperties("configuration/accounts/account/folders/folder/rules/groovy");

    d.addSetNext("configuration/accounts/account/folders/folder/rules/groovy", "add");

    d.addFactoryCreate(
        "configuration/accounts/account/folders/folder/rules/rule",
        new BuiltinRuleObjectCreationFactory());
    d.addSetNext("configuration/accounts/account/folders/folder/rules/rule", "add");

    d.addSetNext("configuration/accounts/account/folders/folder/rules", "setRules");

    d.addSetNext("configuration/accounts/account/folders/folder", "add");

    d.addSetNext("configuration/accounts/account/folders", "setFolders");

    d.addSetNext("configuration/accounts/account", "add");

    return d;
  }
  /**
   * Init digester for Tiles syntax. Same as components, but with first element = tiles-definitions
   *
   * @param digester Digester instance to use.
   */
  private void initDigesterForTilesDefinitionsSyntax(Digester digester) {
    // Common constants
    String PACKAGE_NAME = "org.apache.struts.tiles.xmlDefinition";
    String DEFINITION_TAG = "tiles-definitions/definition";
    String definitionHandlerClass = PACKAGE_NAME + ".XmlDefinition";

    String PUT_TAG = DEFINITION_TAG + "/put";
    String putAttributeHandlerClass = PACKAGE_NAME + ".XmlAttribute";

    // String LIST_TAG = DEFINITION_TAG + "/putList";
    // List tag value
    String LIST_TAG = "putList";
    String DEF_LIST_TAG = DEFINITION_TAG + "/" + LIST_TAG;
    String listHandlerClass = PACKAGE_NAME + ".XmlListAttribute";
    // Tag value for adding an element in a list
    String ADD_LIST_ELE_TAG = "*/" + LIST_TAG + "/add";

    // syntax rules
    digester.addObjectCreate(DEFINITION_TAG, definitionHandlerClass);
    digester.addSetProperties(DEFINITION_TAG);
    digester.addSetNext(DEFINITION_TAG, "putDefinition", definitionHandlerClass);
    // put / putAttribute rules
    // Rules for a same pattern are called in order, but rule.end() are called
    // in reverse order.
    // SetNext and CallMethod use rule.end() method. So, placing SetNext in
    // first position ensure it will be called last (sic).
    digester.addObjectCreate(PUT_TAG, putAttributeHandlerClass);
    digester.addSetNext(PUT_TAG, "addAttribute", putAttributeHandlerClass);
    digester.addSetProperties(PUT_TAG);
    digester.addCallMethod(PUT_TAG, "setBody", 0);
    // Definition level list rules
    // This is rules for lists nested in a definition
    digester.addObjectCreate(DEF_LIST_TAG, listHandlerClass);
    digester.addSetProperties(DEF_LIST_TAG);
    digester.addSetNext(DEF_LIST_TAG, "addAttribute", putAttributeHandlerClass);
    // list elements rules
    // We use Attribute class to avoid rewriting a new class.
    // Name part can't be used in listElement attribute.
    digester.addObjectCreate(ADD_LIST_ELE_TAG, putAttributeHandlerClass);
    digester.addSetNext(ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass);
    digester.addSetProperties(ADD_LIST_ELE_TAG);
    digester.addCallMethod(ADD_LIST_ELE_TAG, "setBody", 0);

    // nested list elements rules
    // Create a list handler, and add it to parent list
    String NESTED_LIST = "*/" + LIST_TAG + "/" + LIST_TAG;
    digester.addObjectCreate(NESTED_LIST, listHandlerClass);
    digester.addSetProperties(NESTED_LIST);
    digester.addSetNext(NESTED_LIST, "add", putAttributeHandlerClass);

    // item elements rules
    // We use Attribute class to avoid rewriting a new class.
    // Name part can't be used in listElement attribute.
    // String ADD_WILDCARD = LIST_TAG + "/addItem";
    // non String ADD_WILDCARD = LIST_TAG + "/addx*";
    String ADD_WILDCARD = "*/item";
    String menuItemDefaultClass = "org.apache.struts.tiles.beans.SimpleMenuItem";
    digester.addObjectCreate(ADD_WILDCARD, menuItemDefaultClass, "classtype");
    digester.addSetNext(ADD_WILDCARD, "add", "java.lang.Object");
    digester.addSetProperties(ADD_WILDCARD);

    // bean elements rules
    String BEAN_TAG = "*/bean";
    String beanDefaultClass = "org.apache.struts.tiles.beans.SimpleMenuItem";
    digester.addObjectCreate(BEAN_TAG, beanDefaultClass, "classtype");
    digester.addSetNext(BEAN_TAG, "add", "java.lang.Object");
    digester.addSetProperties(BEAN_TAG);

    // Set properties to surrounding element
    digester.addSetProperty(BEAN_TAG + "/set-property", "property", "value");
  }
  /**
   * execute sql query
   *
   * @throws Exception
   */
  private void executeQuery() {
    Connection con = null;
    try {
      InputStream catExtIs =
          ScriptableMondrianDrillThroughTableModel.class
              .getClassLoader()
              .getResourceAsStream("/" + catalogExtension);
      if (catExtIs != null) {
        Digester catExtDigester = new Digester();
        catExtDigester.setClassLoader(
            ScriptableMondrianDrillThroughTableModel.class.getClassLoader());
        catExtDigester.push(this);
        catExtDigester.addSetProperties("extension");
        catExtDigester.addObjectCreate(
            "extension/script", "com.tonbeller.jpivot.mondrian.script.ScriptColumn");
        catExtDigester.addSetProperties("extension/script");
        catExtDigester.addSetNext("extension/script", "addScript");
        catExtDigester.parse(catExtIs);

        URL scriptsBaseURL =
            Thread.currentThread().getContextClassLoader().getResource(scriptRootUrl);
        scriptEngine = new GroovyScriptEngine(new URL[] {scriptsBaseURL});
      }
      con = getConnection();
      Statement s = con.createStatement();
      s.setMaxRows(maxResults);
      ResultSet rs = s.executeQuery(sql);
      ResultSetMetaData md = rs.getMetaData();
      int numCols = md.getColumnCount();
      List columnTitlesList = new ArrayList();
      // set column headings
      for (int i = 0; i < numCols; i++) {
        //	columns are 1 based
        columnTitlesList.add(i, md.getColumnName(i + 1));
      }
      // loop on script columns
      for (ListIterator sIt = scripts.listIterator(); sIt.hasNext(); ) {
        final ScriptColumn sc = (ScriptColumn) sIt.next();
        columnTitlesList.add(sc.getPosition() - 1, sc.getTitle());
      }
      columnTitles = (String[]) columnTitlesList.toArray(new String[0]);
      // loop through rows
      List tempRows = new ArrayList();
      Map scriptInput = new HashMap();
      Binding binding = new Binding();
      while (rs.next()) {
        List rowList = new ArrayList();
        scriptInput.clear();
        // loop on columns, 1 based
        for (int i = 0; i < numCols; i++) {
          rowList.add(i, rs.getObject(i + 1));
          scriptInput.put(columnTitles[i], rs.getObject(i + 1));
        }
        binding.setVariable("input", scriptInput);
        // loop on script columns
        for (ListIterator sIt = scripts.listIterator(); sIt.hasNext(); ) {
          final ScriptColumn sc = (ScriptColumn) sIt.next();
          scriptEngine.run(sc.getFile(), binding);
          final Object output = binding.getVariable("output");
          if (output instanceof Map) {
            Map outMap = (Map) output;
            rowList.add(
                sc.getPosition() - 1,
                new DefaultCell((String) outMap.get("URL"), (String) outMap.get("Value")));
          } else if (output instanceof String) {
            rowList.add(sc.getPosition() - 1, (String) output);
          } else {
            throw new Exception("Unknown groovy script return type (not a Map nor String).");
          }
        }
        tempRows.add(new DefaultTableRow(rowList.toArray()));
      }
      rs.close();
      rows = (TableRow[]) tempRows.toArray(new TableRow[0]);
    } catch (Exception e) {
      e.printStackTrace();
      logger.error("?", e);
      // problem occured, set table model to zero size
      rows = new TableRow[1];
      columnTitles = new String[1];
      columnTitles[0] = "An error occured";
      Object[] row = new Object[1];
      row[0] = e.toString();
      rows[0] = new DefaultTableRow(row);
      ready = false;
      return;
    } finally {
      try {
        con.close();
      } catch (Exception e1) {
        // ignore
      }
    }
    ready = true;
  }
 /** Add the default set of digest rules */
 protected void addDefaultDigesterRules(Digester digester) {
   digester.addSetProperties(TAG_QUARTZ, TAG_OVERWRITE_EXISTING_JOBS, "overWriteExistingJobs");
   digester.addObjectCreate(TAG_QUARTZ + "/" + TAG_JOB_LISTENER, "jobListener", "class-name");
   digester.addCallMethod(TAG_QUARTZ + "/" + TAG_JOB_LISTENER, "setName", 1);
   digester.addCallParam(TAG_QUARTZ + "/" + TAG_JOB_LISTENER, 0, "name");
   digester.addSetNext(TAG_QUARTZ + "/" + TAG_JOB_LISTENER, "addListenerToSchedule");
   digester.addRuleSet(
       new CalendarRuleSet(TAG_QUARTZ + "/" + TAG_CALENDAR, "addCalendarToSchedule"));
   digester.addRuleSet(new CalendarRuleSet("*/" + TAG_BASE_CALENDAR, "setBaseCalendar"));
   digester.addObjectCreate(TAG_QUARTZ + "/" + TAG_JOB, JobSchedulingBundle.class);
   digester.addObjectCreate(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL, JobDetail.class);
   digester.addBeanPropertySetter(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_NAME, "name");
   digester.addBeanPropertySetter(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_GROUP, "group");
   digester.addBeanPropertySetter(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_DESCRIPTION, "description");
   digester.addBeanPropertySetter(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_CLASS, "jobClass");
   digester.addCallMethod(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_LISTENER_REF,
       "addJobListener",
       0);
   digester.addBeanPropertySetter(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_VOLATILITY, "volatility");
   digester.addBeanPropertySetter(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_DURABILITY, "durability");
   digester.addBeanPropertySetter(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_RECOVER, "requestsRecovery");
   digester.addObjectCreate(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_DATA_MAP,
       JobDataMap.class);
   digester.addCallMethod(
       TAG_QUARTZ
           + "/"
           + TAG_JOB
           + "/"
           + TAG_JOB_DETAIL
           + "/"
           + TAG_JOB_DATA_MAP
           + "/"
           + TAG_ENTRY,
       "put",
       2,
       new Class[] {Object.class, Object.class});
   digester.addCallParam(
       TAG_QUARTZ
           + "/"
           + TAG_JOB
           + "/"
           + TAG_JOB_DETAIL
           + "/"
           + TAG_JOB_DATA_MAP
           + "/"
           + TAG_ENTRY
           + "/"
           + TAG_KEY,
       0);
   digester.addCallParam(
       TAG_QUARTZ
           + "/"
           + TAG_JOB
           + "/"
           + TAG_JOB_DETAIL
           + "/"
           + TAG_JOB_DATA_MAP
           + "/"
           + TAG_ENTRY
           + "/"
           + TAG_VALUE,
       1);
   digester.addSetNext(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL + "/" + TAG_JOB_DATA_MAP,
       "setJobDataMap");
   digester.addSetNext(TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_JOB_DETAIL, "setJobDetail");
   digester.addRuleSet(
       new TriggerRuleSet(
           TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_SIMPLE,
           SimpleTrigger.class));
   digester.addBeanPropertySetter(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_SIMPLE + "/" + TAG_REPEAT_COUNT,
       "repeatCount");
   digester.addBeanPropertySetter(
       TAG_QUARTZ
           + "/"
           + TAG_JOB
           + "/"
           + TAG_TRIGGER
           + "/"
           + TAG_SIMPLE
           + "/"
           + TAG_REPEAT_INTERVAL,
       "repeatInterval");
   digester.addSetNext(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_SIMPLE, "addTrigger");
   digester.addRuleSet(
       new TriggerRuleSet(
           TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_CRON, CronTrigger.class));
   digester.addBeanPropertySetter(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_CRON + "/" + TAG_CRON_EXPRESSION,
       "cronExpression");
   digester.addRule(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_CRON + "/" + TAG_TIME_ZONE,
       new SimpleConverterRule("timeZone", new TimeZoneConverter(), TimeZone.class));
   digester.addSetNext(
       TAG_QUARTZ + "/" + TAG_JOB + "/" + TAG_TRIGGER + "/" + TAG_CRON, "addTrigger");
   digester.addSetNext(TAG_QUARTZ + "/" + TAG_JOB, "addJobToSchedule");
 }
  /**
   * Add the set of Rule instances defined in this RuleSet to the specified <code>Digester</code>
   * instance, associating them with our namespace URI (if any). This method should only be called
   * by a Digester instance. These rules assume that an instance of <code>
   * org.apache.struts.config.ModuleConfig</code> is pushed onto the evaluation stack before parsing
   * begins.
   *
   * @param digester Digester instance to which the new Rule instances should be added.
   */
  public void addRuleInstances(Digester digester) {

    digester.addObjectCreate(
        "struts-config/data-sources/data-source",
        "org.apache.struts.config.DataSourceConfig",
        "className");
    digester.addSetProperties("struts-config/data-sources/data-source");
    digester.addSetNext(
        "struts-config/data-sources/data-source",
        "addDataSourceConfig",
        "org.apache.struts.config.DataSourceConfig");

    digester.addRule(
        "struts-config/data-sources/data-source/set-property", new AddDataSourcePropertyRule());

    digester.addRule("struts-config/action-mappings", new SetActionMappingClassRule());

    digester.addFactoryCreate("struts-config/action-mappings/action", new ActionMappingFactory());
    digester.addSetProperties("struts-config/action-mappings/action");
    digester.addSetNext(
        "struts-config/action-mappings/action",
        "addActionConfig",
        "org.apache.struts.config.ActionConfig");

    digester.addSetProperty(
        "struts-config/action-mappings/action/set-property", "property", "value");

    digester.addObjectCreate(
        "struts-config/action-mappings/action/exception",
        "org.apache.struts.config.ExceptionConfig",
        "className");
    digester.addSetProperties("struts-config/action-mappings/action/exception");
    digester.addSetNext(
        "struts-config/action-mappings/action/exception",
        "addExceptionConfig",
        "org.apache.struts.config.ExceptionConfig");

    digester.addSetProperty(
        "struts-config/action-mappings/action/exception/set-property", "property", "value");

    digester.addFactoryCreate(
        "struts-config/action-mappings/action/forward", new ActionForwardFactory());
    digester.addSetProperties("struts-config/action-mappings/action/forward");
    digester.addSetNext(
        "struts-config/action-mappings/action/forward",
        "addForwardConfig",
        "org.apache.struts.config.ForwardConfig");

    digester.addSetProperty(
        "struts-config/action-mappings/action/forward/set-property", "property", "value");

    digester.addObjectCreate(
        "struts-config/controller", "org.apache.struts.config.ControllerConfig", "className");
    digester.addSetProperties("struts-config/controller");
    digester.addSetNext(
        "struts-config/controller",
        "setControllerConfig",
        "org.apache.struts.config.ControllerConfig");

    digester.addSetProperty("struts-config/controller/set-property", "property", "value");

    digester.addRule("struts-config/form-beans", new SetActionFormBeanClassRule());

    digester.addFactoryCreate("struts-config/form-beans/form-bean", new ActionFormBeanFactory());
    digester.addSetProperties("struts-config/form-beans/form-bean");
    digester.addSetNext(
        "struts-config/form-beans/form-bean",
        "addFormBeanConfig",
        "org.apache.struts.config.FormBeanConfig");

    digester.addObjectCreate(
        "struts-config/form-beans/form-bean/form-property",
        "org.apache.struts.config.FormPropertyConfig",
        "className");
    digester.addSetProperties("struts-config/form-beans/form-bean/form-property");
    digester.addSetNext(
        "struts-config/form-beans/form-bean/form-property",
        "addFormPropertyConfig",
        "org.apache.struts.config.FormPropertyConfig");

    digester.addSetProperty(
        "struts-config/form-beans/form-bean/form-property/set-property", "property", "value");

    digester.addSetProperty("struts-config/form-beans/form-bean/set-property", "property", "value");

    digester.addObjectCreate(
        "struts-config/global-exceptions/exception",
        "org.apache.struts.config.ExceptionConfig",
        "className");
    digester.addSetProperties("struts-config/global-exceptions/exception");
    digester.addSetNext(
        "struts-config/global-exceptions/exception",
        "addExceptionConfig",
        "org.apache.struts.config.ExceptionConfig");

    digester.addSetProperty(
        "struts-config/global-exceptions/exception/set-property", "property", "value");

    digester.addRule("struts-config/global-forwards", new SetActionForwardClassRule());

    digester.addFactoryCreate("struts-config/global-forwards/forward", new GlobalForwardFactory());
    digester.addSetProperties("struts-config/global-forwards/forward");
    digester.addSetNext(
        "struts-config/global-forwards/forward",
        "addForwardConfig",
        "org.apache.struts.config.ForwardConfig");

    digester.addSetProperty(
        "struts-config/global-forwards/forward/set-property", "property", "value");

    digester.addObjectCreate(
        "struts-config/message-resources",
        "org.apache.struts.config.MessageResourcesConfig",
        "className");
    digester.addSetProperties("struts-config/message-resources");
    digester.addSetNext(
        "struts-config/message-resources",
        "addMessageResourcesConfig",
        "org.apache.struts.config.MessageResourcesConfig");

    digester.addSetProperty("struts-config/message-resources/set-property", "property", "value");

    digester.addObjectCreate("struts-config/plug-in", "org.apache.struts.config.PlugInConfig");
    digester.addSetProperties("struts-config/plug-in");
    digester.addSetNext(
        "struts-config/plug-in", "addPlugInConfig", "org.apache.struts.config.PlugInConfig");

    digester.addRule("struts-config/plug-in/set-property", new PlugInSetPropertyRule());
  }
  public Collection<ShippingOption> getShippingQuote(
      ConfigurationResponse config,
      BigDecimal orderTotal,
      Collection<PackageDetail> packages,
      Customer customer,
      MerchantStore store,
      Locale locale) {

    BigDecimal total = orderTotal;

    if (packages == null) {
      return null;
    }

    // only applies to Canada and US
    if (customer.getCustomerCountryId() != 38 && customer.getCustomerCountryId() != 223) {
      return null;
    }

    // supports en and fr
    String language = locale.getLanguage();
    if (!language.equals(Constants.FRENCH_CODE) && !language.equals(Constants.ENGLISH_CODE)) {
      language = Constants.ENGLISH_CODE;
    }

    // get canadapost credentials
    if (config == null) {
      log.error(
          "CanadaPostQuotesImp.getShippingQuote requires ConfigurationVO for key SHP_RT_CRED");
      return null;
    }

    // if store is not CAD
    if (!store.getCurrency().equals(Constants.CURRENCY_CODE_CAD)) {
      total =
          CurrencyUtil.convertToCurrency(total, store.getCurrency(), Constants.CURRENCY_CODE_CAD);
    }

    PostMethod httppost = null;

    CanadaPostParsedElements canadaPost = null;

    try {

      int icountry = store.getCountry();
      String country = CountryUtil.getCountryIsoCodeById(icountry);

      ShippingService sservice =
          (ShippingService) ServiceFactory.getService(ServiceFactory.ShippingService);
      CoreModuleService cms = sservice.getRealTimeQuoteShippingService(country, "canadapost");

      IntegrationKeys keys = (IntegrationKeys) config.getConfiguration("canadapost-keys");
      IntegrationProperties props =
          (IntegrationProperties) config.getConfiguration("canadapost-properties");

      if (cms == null) {
        // throw new
        // Exception("Central integration services not configured for "
        // + PaymentConstants.PAYMENT_PSIGATENAME + " and country id " +
        // origincountryid);
        log.error("CoreModuleService not configured for  canadapost and country id " + icountry);
        return null;
      }

      String host = cms.getCoreModuleServiceProdDomain();
      String protocol = cms.getCoreModuleServiceProdProtocol();
      String port = cms.getCoreModuleServiceProdPort();
      String url = cms.getCoreModuleServiceProdEnv();
      if (props.getProperties1().equals(String.valueOf(ShippingConstants.TEST_ENVIRONMENT))) {
        host = cms.getCoreModuleServiceDevDomain();
        protocol = cms.getCoreModuleServiceDevProtocol();
        port = cms.getCoreModuleServiceDevPort();
        url = cms.getCoreModuleServiceDevEnv();
      }

      // accept KG and CM

      StringBuffer request = new StringBuffer();

      request.append("<?xml version=\"1.0\" ?>");
      request.append("<eparcel>");
      request.append("<language>").append(language).append("</language>");

      request.append("<ratesAndServicesRequest>");
      request.append("<merchantCPCID>").append(keys.getUserid()).append("</merchantCPCID>");
      request
          .append("<fromPostalCode>")
          .append(
              com.salesmanager.core.util.ShippingUtil.trimPostalCode(store.getStorepostalcode()))
          .append("</fromPostalCode>");
      request.append("<turnAroundTime>").append("24").append("</turnAroundTime>");
      request
          .append("<itemsPrice>")
          .append(CurrencyUtil.displayFormatedAmountNoCurrency(total, "CAD"))
          .append("</itemsPrice>");
      request.append("<lineItems>");

      Iterator packageIterator = packages.iterator();
      while (packageIterator.hasNext()) {
        PackageDetail pack = (PackageDetail) packageIterator.next();
        request.append("<item>");
        request.append("<quantity>").append(pack.getShippingQuantity()).append("</quantity>");
        request
            .append("<weight>")
            .append(
                String.valueOf(
                    CurrencyUtil.getWeight(
                        pack.getShippingWeight(), store, Constants.KG_WEIGHT_UNIT)))
            .append("</weight>");
        request
            .append("<length>")
            .append(
                String.valueOf(
                    CurrencyUtil.getMeasure(
                        pack.getShippingLength(), store, Constants.CM_SIZE_UNIT)))
            .append("</length>");
        request
            .append("<width>")
            .append(
                String.valueOf(
                    CurrencyUtil.getMeasure(
                        pack.getShippingWidth(), store, Constants.CM_SIZE_UNIT)))
            .append("</width>");
        request
            .append("<height>")
            .append(
                String.valueOf(
                    CurrencyUtil.getMeasure(
                        pack.getShippingHeight(), store, Constants.CM_SIZE_UNIT)))
            .append("</height>");
        request.append("<description>").append(pack.getProductName()).append("</description>");
        request.append("<readyToShip/>");
        request.append("</item>");
      }

      Country c = null;
      Map countries =
          (Map)
              RefCache.getAllcountriesmap(LanguageUtil.getLanguageNumberCode(locale.getLanguage()));
      c = (Country) countries.get(store.getCountry());

      request.append("</lineItems>");
      request.append("<city>").append(customer.getCustomerCity()).append("</city>");

      request.append("<provOrState>").append(customer.getShippingSate()).append("</provOrState>");
      Map cs =
          (Map)
              RefCache.getAllcountriesmap(LanguageUtil.getLanguageNumberCode(locale.getLanguage()));
      Country customerCountry = (Country) cs.get(customer.getCustomerCountryId());
      request.append("<country>").append(customerCountry.getCountryName()).append("</country>");
      request
          .append("<postalCode>")
          .append(
              com.salesmanager.core.util.ShippingUtil.trimPostalCode(
                  customer.getCustomerPostalCode()))
          .append("</postalCode>");
      request.append("</ratesAndServicesRequest>");
      request.append("</eparcel>");

      /**
       * <?xml version="1.0" ?> <eparcel>
       * <!--********************************-->
       * <!-- Prefered language
       * for the -->
       * <!-- response (FR/EN) (optional) -->
       * <!--********************************-->
       * <language>en</language>
       *
       * <p><ratesAndServicesRequest>
       * <!--**********************************-->
       * <!-- Merchant
       * Identification assigned -->
       * <!-- by Canada Post -->
       * <!-- -->
       * <!--
       * Note: Use 'CPC_DEMO_HTML' or ask -->
       * <!-- our Help Desk to change
       * your -->
       * <!-- profile if you want HTML to be -->
       * <!-- returned to
       * you -->
       * <!--**********************************-->
       * <merchantCPCID> CPC_DEMO_XML </merchantCPCID>
       * <!--*********************************-->
       * <!--Origin Postal Code
       * -->
       * <!--This parameter is optional -->
       * <!--*********************************-->
       * <fromPostalCode>m1p1c0</fromPostalCode>
       * <!--**********************************-->
       * <!-- Turn Around Time
       * (hours) -->
       * <!-- This parameter is optional -->
       * <!--**********************************-->
       * <turnAroundTime> 24 </turnAroundTime>
       * <!--**********************************-->
       * <!-- Total amount in $
       * of the items -->
       * <!-- for insurance calculation -->
       * <!-- This
       * parameter is optional -->
       * <!--**********************************-->
       * <itemsPrice>0.00</itemsPrice>
       * <!--**********************************-->
       * <!-- List of items in
       * the shopping -->
       * <!-- cart -->
       * <!-- Each item is defined by : -->
       * <!-- - quantity (mandatory) -->
       * <!-- - size (mandatory) -->
       * <!--
       * - weight (mandatory) -->
       * <!-- - description (mandatory) -->
       * <!--
       * - ready to ship (optional) -->
       * <!--**********************************-->
       * <lineItems> <item> <quantity> 1 </quantity> <weight> 1.491 </weight> <length> 1 </length>
       * <width> 1 </width> <height> 1 </height> <description> KAO Diskettes </description> </item>
       *
       * <p><item> <quantity> 1 </quantity> <weight> 1.5 </weight> <length> 20 </length> <width> 30
       * </width> <height> 20 </height> <description> My Ready To Ship Item</description>
       * <!--**********************************************-->
       * <!-- By
       * adding the 'readyToShip' tag, Sell Online -->
       * <!-- will not pack
       * this item in the boxes -->
       * <!-- defined in the merchant profile.
       * -->
       * <!-- Instead, this item will be shipped in its -->
       * <!--
       * original box: 1.5 kg and 20x30x20 cm -->
       * <!--**********************************************-->
       * <readyToShip/> </item> </lineItems>
       * <!--********************************-->
       * <!-- City where the
       * parcel will be -->
       * <!-- shipped to -->
       * <!--********************************-->
       * <city> </city>
       * <!--********************************-->
       * <!-- Province (Canada) or
       * State (US)-->
       * <!-- where the parcel will be -->
       * <!-- shipped to
       * -->
       * <!--********************************-->
       * <provOrState> Wisconsin </provOrState>
       * <!--********************************-->
       * <!-- Country or ISO
       * Country code -->
       * <!-- where the parcel will be -->
       * <!-- shipped
       * to -->
       * <!--********************************-->
       * <country> CANADA </country>
       * <!--********************************-->
       * <!-- Postal Code (or ZIP)
       * where the -->
       * <!-- parcel will be shipped to -->
       * <!--********************************-->
       * <postalCode> H3K1E5</postalCode> </ratesAndServicesRequest> </eparcel>
       */
      log.debug("canadapost request " + request.toString());

      HttpClient client = new HttpClient();

      StringBuilder u =
          new StringBuilder().append(protocol).append("://").append(host).append(":").append(port);
      if (!StringUtils.isBlank(url)) {
        u.append(url);
      }

      log.debug("Canadapost URL " + u.toString());

      httppost = new PostMethod(u.toString());
      RequestEntity entity = new StringRequestEntity(request.toString(), "text/plain", "UTF-8");
      httppost.setRequestEntity(entity);

      int result = client.executeMethod(httppost);

      if (result != 200) {
        log.error(
            "Communication Error with canadapost " + protocol + "://" + host + ":" + port + url);
        throw new Exception(
            "Communication Error with canadapost " + protocol + "://" + host + ":" + port + url);
      }
      String stringresult = httppost.getResponseBodyAsString();
      log.debug("canadapost response " + stringresult);

      canadaPost = new CanadaPostParsedElements();
      Digester digester = new Digester();
      digester.push(canadaPost);

      digester.addCallMethod("eparcel/ratesAndServicesResponse/statusCode", "setStatusCode", 0);
      digester.addCallMethod(
          "eparcel/ratesAndServicesResponse/statusMessage", "setStatusMessage", 0);
      digester.addObjectCreate(
          "eparcel/ratesAndServicesResponse/product",
          com.salesmanager.core.entity.shipping.ShippingOption.class);
      digester.addSetProperties("eparcel/ratesAndServicesResponse/product", "sequence", "optionId");
      digester.addCallMethod(
          "eparcel/ratesAndServicesResponse/product/shippingDate", "setShippingDate", 0);
      digester.addCallMethod(
          "eparcel/ratesAndServicesResponse/product/deliveryDate", "setDeliveryDate", 0);
      digester.addCallMethod("eparcel/ratesAndServicesResponse/product/name", "setOptionName", 0);
      digester.addCallMethod(
          "eparcel/ratesAndServicesResponse/product/rate", "setOptionPriceText", 0);
      digester.addSetNext("eparcel/ratesAndServicesResponse/product", "addOption");

      /**
       * response
       *
       * <p><?xml version="1.0" ?> <!DOCTYPE eparcel (View Source for full doctype...)> - <eparcel>
       * - <ratesAndServicesResponse> <statusCode>1</statusCode> <statusMessage>OK</statusMessage>
       * <requestID>1769506</requestID> <handling>0.0</handling> <language>0</language> - <product
       * id="1040" sequence="1"> <name>Priority Courier</name> <rate>38.44</rate>
       * <shippingDate>2008-12-22</shippingDate> <deliveryDate>2008-12-23</deliveryDate>
       * <deliveryDayOfWeek>3</deliveryDayOfWeek> <nextDayAM>true</nextDayAM>
       * <packingID>P_0</packingID> </product> - <product id="1020" sequence="2">
       * <name>Expedited</name> <rate>16.08</rate> <shippingDate>2008-12-22</shippingDate>
       * <deliveryDate>2008-12-23</deliveryDate> <deliveryDayOfWeek>3</deliveryDayOfWeek>
       * <nextDayAM>false</nextDayAM> <packingID>P_0</packingID> </product> - <product id="1010"
       * sequence="3"> <name>Regular</name> <rate>16.08</rate>
       * <shippingDate>2008-12-22</shippingDate> <deliveryDate>2008-12-29</deliveryDate>
       * <deliveryDayOfWeek>2</deliveryDayOfWeek> <nextDayAM>false</nextDayAM>
       * <packingID>P_0</packingID> </product> - <packing> <packingID>P_0</packingID> - <box>
       * <name>Small Box</name> <weight>1.691</weight> <expediterWeight>1.691</expediterWeight>
       * <length>25.0</length> <width>17.0</width> <height>16.0</height> - <packedItem>
       * <quantity>1</quantity> <description>KAO Diskettes</description> </packedItem> </box> -
       * <box> <name>My Ready To Ship Item</name> <weight>2.0</weight>
       * <expediterWeight>1.5</expediterWeight> <length>30.0</length> <width>20.0</width>
       * <height>20.0</height> - <packedItem> <quantity>1</quantity> <description>My Ready To Ship
       * Item</description> </packedItem> </box> </packing> - <shippingOptions>
       * <insurance>No</insurance> <deliveryConfirmation>Yes</deliveryConfirmation>
       * <signature>No</signature> </shippingOptions> <comment /> </ratesAndServicesResponse>
       * </eparcel> -
       * <!-- END_OF_EPARCEL -->
       */
      Reader reader = new StringReader(stringresult);

      digester.parse(reader);

    } catch (Exception e) {
      log.error(e);
    } finally {
      if (httppost != null) {
        httppost.releaseConnection();
      }
    }

    if (canadaPost == null || canadaPost.getStatusCode() == null) {
      return null;
    }

    if (canadaPost.getStatusCode().equals("-6") || canadaPost.getStatusCode().equals("-7")) {
      LogMerchantUtil.log(
          store.getMerchantId(),
          "Can't process CanadaPost statusCode="
              + canadaPost.getStatusCode()
              + " message= "
              + canadaPost.getStatusMessage());
    }

    if (!canadaPost.getStatusCode().equals("1")) {
      log.error(
          "An error occured with canadapost request (code-> "
              + canadaPost.getStatusCode()
              + " message-> "
              + canadaPost.getStatusMessage()
              + ")");
      return null;
    }

    String carrier = getShippingMethodDescription(locale);
    // cost is in CAD, need to do conversion

    boolean requiresCurrencyConversion = false;
    String storeCurrency = store.getCurrency();
    if (!storeCurrency.equals(Constants.CURRENCY_CODE_CAD)) {
      requiresCurrencyConversion = true;
    }

    /** Details on whit RT quote information to display * */
    MerchantConfiguration rtdetails =
        config.getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_DISPLAY_REALTIME_QUOTES);
    int displayQuoteDeliveryTime = ShippingConstants.NO_DISPLAY_RT_QUOTE_TIME;
    if (rtdetails != null) {

      if (!StringUtils.isBlank(rtdetails.getConfigurationValue1())) { // display
        // or
        // not
        // quotes
        try {
          displayQuoteDeliveryTime = Integer.parseInt(rtdetails.getConfigurationValue1());

        } catch (Exception e) {
          log.error(
              "Display quote is not an integer value [" + rtdetails.getConfigurationValue1() + "]");
        }
      }
    }
    /**/

    List options = canadaPost.getOptions();
    if (options != null) {
      Iterator i = options.iterator();
      while (i.hasNext()) {
        ShippingOption option = (ShippingOption) i.next();
        option.setCurrency(store.getCurrency());
        StringBuffer description = new StringBuffer();
        description.append(option.getOptionName());
        if (displayQuoteDeliveryTime == ShippingConstants.DISPLAY_RT_QUOTE_TIME) {
          description.append(" (").append(option.getDeliveryDate()).append(")");
        }
        option.setDescription(description.toString());
        if (requiresCurrencyConversion) {
          option.setOptionPrice(
              CurrencyUtil.convertToCurrency(
                  option.getOptionPrice(), Constants.CURRENCY_CODE_CAD, store.getCurrency()));
        }
        // System.out.println(option.getOptionPrice().toString());

      }
    }

    return options;
  }
  static {
    MockeyXmlFileConfigurationParser.fullSetDigester = new Digester();

    fullSetDigester.setValidating(false);
    fullSetDigester.addObjectCreate(ROOT, InMemoryMockeyStorage.class);

    fullSetDigester.addSetProperties(ROOT, "universal_error_service_id", "universalErrorServiceId");
    fullSetDigester.addSetProperties(
        ROOT, "universal_error_scenario_id", "universalErrorScenarioId");
    fullSetDigester.addSetProperties(ROOT, "universal_twist_info_id", "universalTwistInfoId");

    fullSetDigester.addObjectCreate(ROOT_PROXYSERVER, ProxyServerModel.class);
    fullSetDigester.addSetProperties(ROOT_PROXYSERVER, "proxy_url", "proxyUrl");
    fullSetDigester.addSetProperties(ROOT_PROXYSERVER, "proxy_enabled", "proxyEnabled");
    fullSetDigester.addSetNext(ROOT_PROXYSERVER, "setProxy");

    fullSetDigester.addObjectCreate(ROOT_SERVICEREF, ServiceRef.class);
    fullSetDigester.addSetProperties(ROOT_SERVICEREF, "file", "fileName");
    fullSetDigester.addSetNext(ROOT_SERVICEREF, "saveOrUpdateServiceRef");

    fullSetDigester.addObjectCreate(ROOT_SERVICE, Service.class);
    fullSetDigester.addSetNext(ROOT_SERVICE, "saveOrUpdateService");

    fullSetDigester.addSetProperties(ROOT_SERVICE, "name", "serviceName");
    fullSetDigester.addSetProperties(ROOT_SERVICE, "description", "description");
    fullSetDigester.addSetProperties(ROOT_SERVICE, "http_content_type", "httpContentType");
    fullSetDigester.addSetProperties(ROOT_SERVICE, "hang_time", "hangTime");
    fullSetDigester.addSetProperties(ROOT_SERVICE, "url", "url");
    fullSetDigester.addSetProperties(ROOT_SERVICE, "tag", "tag");
    fullSetDigester.addSetProperties(ROOT_SERVICE, "last_visit", "lastVisit");

    fullSetDigester.addSetProperties(ROOT_SERVICE, "proxyurl", "realServiceUrlByString");
    fullSetDigester.addSetProperties(ROOT_SERVICE, "default_real_url_index", "defaultRealUrlIndex");

    fullSetDigester.addSetProperties(ROOT_SERVICE, "service_response_type", "serviceResponseType");
    fullSetDigester.addSetProperties(ROOT_SERVICE, "default_scenario_id", "defaultScenarioId");

    fullSetDigester.addObjectCreate(ROOT_SERVICE_REAL_URL, Url.class);
    fullSetDigester.addSetProperties(ROOT_SERVICE_REAL_URL, "url", "url");
    fullSetDigester.addSetNext(ROOT_SERVICE_REAL_URL, "saveOrUpdateRealServiceUrl");

    fullSetDigester.addObjectCreate(ROOT_SERVICE_SCENARIO, Scenario.class);
    fullSetDigester.addSetProperties(ROOT_SERVICE_SCENARIO, "id", "id");
    fullSetDigester.addSetProperties(ROOT_SERVICE_SCENARIO, "name", "scenarioName");
    fullSetDigester.addSetProperties(ROOT_SERVICE_SCENARIO, "last_visit", "lastVisit");
    fullSetDigester.addSetProperties(ROOT_SERVICE_SCENARIO, "tag", "tag");
    fullSetDigester.addBeanPropertySetter(SCENARIO_MATCH, "matchStringArg");
    fullSetDigester.addBeanPropertySetter(SCENARIO_REQUEST, "requestMessage");
    fullSetDigester.addBeanPropertySetter(SCENARIO_RESPONSE, "responseMessage");

    fullSetDigester.addSetNext(ROOT_SERVICE_SCENARIO, "saveOrUpdateScenario");

    // PLAN
    fullSetDigester.addObjectCreate(ROOT_PLAN, ServicePlan.class);
    fullSetDigester.addSetProperties(ROOT_PLAN, "name", "name"); //
    fullSetDigester.addSetProperties(ROOT_PLAN, "description", "description"); //
    fullSetDigester.addSetProperties(ROOT_PLAN, "id", "id");
    fullSetDigester.addSetProperties(ROOT_PLAN, "tag", "tag");
    fullSetDigester.addSetProperties(ROOT_PLAN, "last_visit", "lastVisit");
    fullSetDigester.addSetNext(ROOT_PLAN, "saveOrUpdateServicePlan");
    fullSetDigester.addObjectCreate(ROOT_PLAN_ITEM, PlanItem.class);
    fullSetDigester.addSetProperties(ROOT_PLAN_ITEM, "hang_time", "hangTime");
    fullSetDigester.addSetProperties(ROOT_PLAN_ITEM, "service_id", "serviceId");
    fullSetDigester.addSetProperties(ROOT_PLAN_ITEM, "scenario_id", "scenarioId");
    fullSetDigester.addSetProperties(
        ROOT_PLAN_ITEM, "service_response_type", "serviceResponseType");
    fullSetDigester.addSetNext(ROOT_PLAN_ITEM, "addPlanItem");

    // TWIST CONFIGURATION
    fullSetDigester.addObjectCreate(ROOT_TWIST_CONFIG, TwistInfo.class);
    fullSetDigester.addSetProperties(ROOT_TWIST_CONFIG, "name", "name"); //
    fullSetDigester.addSetProperties(ROOT_TWIST_CONFIG, "id", "id");
    fullSetDigester.addSetNext(ROOT_TWIST_CONFIG, "saveOrUpdateTwistInfo");
    fullSetDigester.addObjectCreate(ROOT_TWIST_CONFIG_ITEM, PatternPair.class);
    fullSetDigester.addSetProperties(ROOT_TWIST_CONFIG_ITEM, "origination", "origination");
    fullSetDigester.addSetProperties(ROOT_TWIST_CONFIG_ITEM, "destination", "destination");
    fullSetDigester.addSetNext(ROOT_TWIST_CONFIG_ITEM, "addPatternPair");
  }
  /**
   * Method that uses the {@link org.apache.commons.digester.Digester} to read the objects from the
   * given xml-File an build the java-Objects in a parent-child Hirachy.
   *
   * @param _xml URL to the XML-File
   */
  public void readXMLFile(final URL _xml) {
    Digester digester = new Digester();

    digester.setValidating(false);

    digester.addObjectCreate("import", RootObject.class);

    // Read the Definitions
    digester.addCallMethod("import/definition/date", "setDateFormat", 1);
    digester.addCallParam("import/definition/date", 0, "format");

    // Read OrderObject
    digester.addFactoryCreate("import/definition/order", new OrderObjectFactory(), false);
    digester.addCallMethod(
        "import/definition/order/attribute",
        "addAttribute",
        3,
        new Class[] {Integer.class, String.class, String.class});
    digester.addCallParam("import/definition/order/attribute", 0, "index");
    digester.addCallParam("import/definition/order/attribute", 1, "name");
    digester.addCallParam("import/definition/order/attribute", 2, "criteria");
    digester.addSetNext("import/definition/order", "addOrder", "org.efaps.importer.OrderObject");

    // Read DefaultObject
    digester.addObjectCreate("import/definition/default", DefaultObject.class);
    digester.addCallMethod("import/definition/default", "addDefault", 3);
    digester.addCallParam("import/definition/default", 0, "type");
    digester.addCallParam("import/definition/default", 1, "name");
    digester.addCallParam("import/definition/default", 2);

    digester.addObjectCreate("import/definition/default/linkattribute", ForeignObject.class);
    digester.addCallMethod("import/definition/default/linkattribute", "setLinkAttribute", 2);
    digester.addCallParam("import/definition/default/linkattribute", 0, "name");
    digester.addCallParam("import/definition/default/linkattribute", 1, "type");

    digester.addCallMethod(
        "import/definition/default/linkattribute/queryattribute", "addAttribute", 2);
    digester.addCallParam("import/definition/default/linkattribute/queryattribute", 0, "name");
    digester.addCallParam("import/definition/default/linkattribute/queryattribute", 1);

    digester.addSetNext(
        "import/definition/default/linkattribute", "addLink", "org.efaps.importer.ForeignObject");

    // Create the Objects
    digester.addFactoryCreate("*/object", new InsertObjectFactory(), false);

    digester.addCallMethod("*/object/attribute", "addAttribute", 3);
    digester.addCallParam("*/object/attribute", 0, "name");
    digester.addCallParam("*/object/attribute", 1);
    digester.addCallParam("*/object/attribute", 2, "unique");

    digester.addCallMethod("*/object/file", "setCheckinObject", 2);
    digester.addCallParam("*/object/file", 0, "name");
    digester.addCallParam("*/object/file", 1, "url");

    digester.addCallMethod("*/object/parentattribute", "setParentAttribute", 2);
    digester.addCallParam("*/object/parentattribute", 0, "name");
    digester.addCallParam("*/object/parentattribute", 1, "unique");

    digester.addCallMethod("*/object/linkattribute", "addUniqueAttribute", 2);
    digester.addCallParam("*/object/linkattribute", 0, "unique");
    digester.addCallParam("*/object/linkattribute", 1, "name");

    digester.addSetNext("*/object", "addChild", "org.efaps.importer.InsertObject");

    digester.addObjectCreate("*/object/linkattribute", ForeignObject.class);
    digester.addCallMethod("*/object/linkattribute", "setLinkAttribute", 2);
    digester.addCallParam("*/object/linkattribute", 0, "name");
    digester.addCallParam("*/object/linkattribute", 1, "type");

    digester.addCallMethod("*/object/linkattribute/queryattribute", "addAttribute", 2);
    digester.addCallParam("*/object/linkattribute/queryattribute", 0, "name");
    digester.addCallParam("*/object/linkattribute/queryattribute", 1);

    digester.addSetNext("*/object/linkattribute", "addLink", "org.efaps.importer.ForeignObject");

    try {
      this.root = (RootObject) digester.parse(_xml);
    } catch (IOException e) {
      e.printStackTrace(System.err);
    } catch (SAXException e) {
      e.printStackTrace(System.err);
    }
  }
Beispiel #29
0
  /**
   * Create Digester rules for manufacturers and models
   *
   * @return
   */
  protected Digester createManufacturerDigester() {
    // Initialize the digester
    Digester digester = new Digester();
    digester.setValidating(false);
    // Manufacturer stage
    digester.addObjectCreate("*/Manufacturer", ManufacturerItem.class);
    digester.addBeanPropertySetter("*/Manufacturer/ExternalID", "externalID");
    digester.addBeanPropertySetter("*/Manufacturer/Name", "name");
    digester.addBeanPropertySetter("*/Manufacturer/Description", "description");
    digester.addSetNext("*/Manufacturer", "add");

    digester.addCallMethod("*/Models", "addIncludeFile4Model", 1);
    digester.addCallParam("*/Models", 0, "filename");

    // Model stage
    digester.addFactoryCreate("*/Models/Model", ModelItemObjectCreationFactory.class);
    // digester.addObjectCreate("*/Models/Model", ModelItem.class);
    digester.addSetNext("*/Models/Model", "addModel");

    // Basic information
    // digester.addCallMethod("*/Models/Model", "setFamilyID", 1);
    // digester.addCallParam("*/Models/Model", 0, "family");
    digester.addBeanPropertySetter("*/Models/Model/ExternalID", "externalID");
    digester.addBeanPropertySetter("*/Models/Model/Name", "name");
    digester.addBeanPropertySetter("*/Models/Model/Description", "description");
    // digester.addBeanPropertySetter("*/Models/Model/FamilyID", "familyID");
    digester.addBeanPropertySetter("*/Models/Model/IconFile", "iconFile");
    digester.addBeanPropertySetter("*/Models/Model/IsOmaDmEnabled", "isOmaDmEnabled");
    digester.addBeanPropertySetter("*/Models/Model/OmaDmVersion", "omaDmVersion");
    digester.addBeanPropertySetter("*/Models/Model/IsOmaCpEnabled", "isOmaCpEnabled");
    digester.addBeanPropertySetter("*/Models/Model/OmaCpVersion", "omaCpVersion");
    digester.addBeanPropertySetter("*/Models/Model/IsNokiaOtaEnabled", "isNokiaOtaEnabled");
    digester.addBeanPropertySetter("*/Models/Model/NokiaOtaVersion", "nokiaOtaVersion");
    digester.addBeanPropertySetter(
        "*/Models/Model/SupportedDownloadMethods", "supportedDownloadMethods");
    digester.addBeanPropertySetter("*/Models/Model/FirmwareVersionNode", "firmwareVersionNode");
    digester.addBeanPropertySetter("*/Models/Model/FirmwareUpdateNode", "firmwareUpdateNode");
    digester.addBeanPropertySetter("*/Models/Model/FirmwareDownloadNode", "firmwareDownloadNode");
    digester.addBeanPropertySetter(
        "*/Models/Model/FirmwareDownloadAndUpdateNode", "firmwareDownloadAndUpdateNode");
    digester.addBeanPropertySetter("*/Models/Model/FirmwareStatusNode", "firmwareStatusNode");
    // DDF Information
    digester.addCallMethod("*/Models/Model/DDFs/DDF", "addDdfFile", 1);
    digester.addCallParam("*/Models/Model/DDFs/DDF", 0, "filename");
    // DM Profile Mappings
    digester.addCallMethod(
        "*/Models/Model/ProfileMappings/ProfileMapping", "addProfileMappingFile", 1);
    digester.addCallParam("*/Models/Model/ProfileMappings/ProfileMapping", 0, "filename");
    // CP Templates
    digester.addCallMethod("*/Models/Model/CPTemplates", "addCpTemplatesFiles", 1);
    digester.addCallParam("*/Models/Model/CPTemplates", 0, "filename");
    // TAC Informations
    digester.addCallMethod("*/Models/Model/TACs/TAC", "addTac", 1);
    digester.addCallParam("*/Models/Model/TACs/TAC", 0);
    // Firmwares
    digester.addObjectCreate("*/Models/Model/Firmwares/Firmware", FirmwareItem.class);
    digester.addBeanPropertySetter("*/Models/Model/Firmwares/Firmware/FromVersion", "fromVersion");
    digester.addBeanPropertySetter("*/Models/Model/Firmwares/Firmware/ToVersion", "toVersion");
    digester.addBeanPropertySetter("*/Models/Model/Firmwares/Firmware/Status", "status");
    digester.addBeanPropertySetter("*/Models/Model/Firmwares/Firmware/Filename", "filename");
    digester.addSetNext("*/Models/Model/Firmwares/Firmware", "addFirmware");
    // Specifications
    digester.addCallMethod("*/Models/Model/Specifications/Specification", "setSpecification", 3);
    digester.addCallParam("*/Models/Model/Specifications/Specification", 0, "category");
    digester.addCallParam("*/Models/Model/Specifications/Specification", 1, "name");
    digester.addCallParam("*/Models/Model/Specifications/Specification", 2, "value");

    // Model Family stage
    digester.addFactoryCreate("*/Models/Family", ModelFamilyItemObjectCreationFactory.class);
    // digester.addObjectCreate("*/Models/Family", ModelFamilyItem.class);
    digester.addSetNext("*/Models/Family", "addModelFamily");
    // Basic information
    // digester.addCallMethod("*/Models/Family", "setParentID", 1);
    // digester.addCallParam("*/Models/Family", 0, "parent");
    // digester.addSetNestedProperties("*/Models/Family", "parent", "parentID");
    digester.addBeanPropertySetter("*/Models/Family/ExternalID", "externalID");
    digester.addBeanPropertySetter("*/Models/Family/Name", "name");
    digester.addBeanPropertySetter("*/Models/Family/Description", "description");
    // digester.addBeanPropertySetter("*/Models/Family/ParentID", "parentID");
    digester.addBeanPropertySetter("*/Models/Family/IconFile", "iconFile");
    digester.addBeanPropertySetter("*/Models/Family/IsOmaDmEnabled", "isOmaDmEnabled");
    digester.addBeanPropertySetter("*/Models/Family/OmaDmVersion", "omaDmVersion");
    digester.addBeanPropertySetter("*/Models/Family/IsOmaCpEnabled", "isOmaCpEnabled");
    digester.addBeanPropertySetter("*/Models/Family/OmaCpVersion", "omaCpVersion");
    digester.addBeanPropertySetter("*/Models/Family/IsNokiaOtaEnabled", "isNokiaOtaEnabled");
    digester.addBeanPropertySetter("*/Models/Family/NokiaOtaVersion", "nokiaOtaVersion");
    digester.addBeanPropertySetter(
        "*/Models/Family/SupportedDownloadMethods", "supportedDownloadMethods");
    digester.addBeanPropertySetter("*/Models/Family/FirmwareVersionNode", "firmwareVersionNode");
    digester.addBeanPropertySetter("*/Models/Family/FirmwareUpdateNode", "firmwareUpdateNode");
    digester.addBeanPropertySetter("*/Models/Family/FirmwareDownloadNode", "firmwareDownloadNode");
    digester.addBeanPropertySetter(
        "*/Models/Family/FirmwareDownloadAndUpdateNode", "firmwareDownloadAndUpdateNode");
    digester.addBeanPropertySetter("*/Models/Family/FirmwareStatusNode", "firmwareStatusNode");
    // DDF Information
    digester.addCallMethod("*/Models/Family/DDFs/DDF", "addDdfFile", 1);
    digester.addCallParam("*/Models/Family/DDFs/DDF", 0, "filename");
    // DM Profile Mappings
    digester.addCallMethod(
        "*/Models/Family/ProfileMappings/ProfileMapping", "addProfileMappingFile", 1);
    digester.addCallParam("*/Models/Family/ProfileMappings/ProfileMapping", 0, "filename");
    // CP Templates
    digester.addCallMethod("*/Models/Family/CPTemplates", "addCpTemplatesFiles", 1);
    digester.addCallParam("*/Models/Family/CPTemplates", 0, "filename");
    // Firmwares
    digester.addObjectCreate("*/Models/Family/Firmwares/Firmware", FirmwareItem.class);
    digester.addBeanPropertySetter("*/Models/Family/Firmwares/Firmware/FromVersion", "fromVersion");
    digester.addBeanPropertySetter("*/Models/Family/Firmwares/Firmware/ToVersion", "toVersion");
    digester.addBeanPropertySetter("*/Models/Family/Firmwares/Firmware/Status", "status");
    digester.addBeanPropertySetter("*/Models/Family/Firmwares/Firmware/Filename", "filename");
    digester.addSetNext("*/Models/Family/Firmwares/Firmware", "addFirmware");
    // Specifications
    digester.addCallMethod("*/Models/Family/Specifications/Specification", "setSpecification", 3);
    digester.addCallParam("*/Models/Family/Specifications/Specification", 0, "category");
    digester.addCallParam("*/Models/Family/Specifications/Specification", 1, "name");
    digester.addCallParam("*/Models/Family/Specifications/Specification", 2, "value");

    return (digester);
  }