/** * 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); }
public static GoPluginDescriptor parseXML( InputStream pluginXML, String pluginJarFileLocation, File pluginBundleLocation, boolean isBundledPlugin) throws IOException, SAXException { Digester digester = initDigester(); GoPluginDescriptorParser parserForThisXML = new GoPluginDescriptorParser(pluginJarFileLocation, pluginBundleLocation, isBundledPlugin); digester.push(parserForThisXML); digester.addCallMethod("go-plugin", "createPlugin", 2); digester.addCallParam("go-plugin", 0, "id"); digester.addCallParam("go-plugin", 1, "version"); digester.addCallMethod("go-plugin/about", "createAbout", 4); digester.addCallParam("go-plugin/about/name", 0); digester.addCallParam("go-plugin/about/version", 1); digester.addCallParam("go-plugin/about/target-go-version", 2); digester.addCallParam("go-plugin/about/description", 3); digester.addCallMethod("go-plugin/about/vendor", "createVendor", 2); digester.addCallParam("go-plugin/about/vendor/name", 0); digester.addCallParam("go-plugin/about/vendor/url", 1); digester.addCallMethod("go-plugin/about/target-os/value", "addTargetOS", 1); digester.addCallParam("go-plugin/about/target-os/value", 0); digester.parse(pluginXML); return parserForThisXML.descriptor; }
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 } } } }
private Set<String> getListenerClassNames(final String xml, final String path) throws IOException, SAXException { final Digester digester = getDigester(); digester.addObjectCreate(XmlConfiguration.listeners, ArrayList.class); digester.addObjectCreate(path, StringBuffer.class); // TODO rather than StringBuffer can digester.addCallMethod(path, "append", 0); // TODO this be a String? digester.addSetRoot(path, "add"); final Set<String> classNames = new HashSet<String>(); final StringReader includeReader = new StringReader(xml); Object o = digester.parse(includeReader); if (o == null) { // return empty Set return classNames; } Collection<StringBuffer> classNamesAsStringBuffers = (Collection<StringBuffer>) o; /** When the configuration contains no listener settings, return the empty Set */ if (classNamesAsStringBuffers == null) { return classNames; } for (StringBuffer classNamesAsStringBuffer : classNamesAsStringBuffers) { classNames.add(classNamesAsStringBuffer.toString()); } return classNames; }
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)); }
/** * 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); } }
/** * Reading of the configuration * * @param pStream stream * @throws ConfigurationException exception if an error occurs */ public void parse(InputStream pStream) throws ConfigurationException { StringBuffer errors = new StringBuffer(); Digester digester = preSetupDigester( "-//Quartz Configuration DTD //EN", "/config/quartz-timer-config.dtd", errors); // Root directory treatment digester.addCallMethod( "quartz-timer-configuration/quartzKey", "setQuartzKey", 1, new Class[] {String.class}); digester.addCallParam("quartz-timer-configuration/quartzKey", 0); digester.push(this); // Parser call parse(digester, pStream, errors); if (errors.length() > 0) { throw new ConfigurationException( QuartzMessages.getString( "quartz.exception.configuration.parse", new Object[] {errors.toString()})); } }
void processProperties(final String xml) throws IOException, SAXException { final Digester digester = getDigester(); digester.addObjectCreate(XmlConfiguration.properties, Properties.class); digester.addCallMethod(XmlConfiguration.property, "put", 2); digester.addCallParam(XmlConfiguration.property, 0, "key"); digester.addCallParam(XmlConfiguration.property, 1, "value"); final StringReader reader = new StringReader(xml.trim()); final Object o; try { o = digester.parse(reader); } catch (SAXException e) { if (e.getException().toString().equals("java.lang.NullPointerException")) { throw new InvalidConfigurationException( "Invalid XML configuration for <properties>. <property> must only contain both a key and a value attribute.", e); } // at this time, I don't even know how to get to this path, but I'm sure some user will figure // it out : P throw new InvalidConfigurationException( "Unable to parse XML configuration for <properties>: " + e.getMessage(), e); } if (o == null) { return; } final Properties properties = (Properties) o; addProperties(properties); }
/** * 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); } } }
/** 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"); }
/** * 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); } }
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; }
/** * 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"); }
/** * 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); }