private void assertErrorContains(boolean squareTags, String ftl, String... expectedSubstrings) { try { if (squareTags) { ftl = ftl.replace('<', '[').replace('>', ']'); } new Template("adhoc", ftl, cfg); fail("The tempalte had to fail"); } catch (ParseException e) { String msg = e.getMessage(); for (String needle : expectedSubstrings) { if (needle.startsWith("\\!")) { String netNeedle = needle.substring(2); if (msg.contains(netNeedle)) { fail( "The message shouldn't contain substring " + StringUtil.jQuote(netNeedle) + ":\n" + msg); } } else if (!msg.contains(needle)) { fail("The message didn't contain substring " + StringUtil.jQuote(needle) + ":\n" + msg); } } showError(e); } catch (IOException e) { // Won't happen throw new RuntimeException(e); } }
public TemplateModel get(String key) throws TemplateModelException { if (size() == 1) { NodeModel nm = (NodeModel) get(0); return nm.get(key); } if (key.startsWith("@@") && (key.equals("@@markup") || key.equals("@@nested_markup") || key.equals("@@text"))) { StringBuffer result = new StringBuffer(); for (int i = 0; i < size(); i++) { NodeModel nm = (NodeModel) get(i); TemplateScalarModel textModel = (TemplateScalarModel) nm.get(key); result.append(textModel.getAsString()); } return new SimpleScalar(result.toString()); } if (StringUtil.isXMLID(key) || ((key.startsWith("@") && StringUtil.isXMLID(key.substring(1)))) || key.equals("*") || key.equals("**") || key.equals("@@") || key.equals("@*")) { NodeListModel result = new NodeListModel(contextNode); for (int i = 0; i < size(); i++) { NodeModel nm = (NodeModel) get(i); if (nm instanceof ElementModel) { TemplateSequenceModel tsm = (TemplateSequenceModel) ((ElementModel) nm).get(key); if (tsm != null) { int size = tsm.size(); for (int j = 0; j < size; j++) { result.add(tsm.get(j)); } } } } if (result.size() == 1) { return result.get(0); } return result; } XPathSupport xps = getXPathSupport(); if (xps != null) { Object context = (size() == 0) ? null : rawNodeList(); return xps.executeQuery(context, key); } throw new TemplateModelException( "Key: '" + key + "' is not legal for a node sequence (" + this.getClass().getName() + "). This node sequence contains " + size() + " node(s). " + "Some keys are valid only for node sequences of size 1. " + "If you use Xalan (instead of Jaxen), XPath expression keys work only with " + "node lists of size 1."); }
/** * Show class name and some details that are useful in template-not-found errors. * * @since 2.3.21 */ @Override public String toString() { return TemplateLoaderUtils.getClassNameForToString(this) + "(subdirPath=" + StringUtil.jQuote(subdirPath) + ", servletContext={contextPath=" + StringUtil.jQuote(getContextPath()) + ", displayName=" + StringUtil.jQuote(servletContext.getServletContextName()) + "})"; }
public NestedContentNotSupportedException(String description, Exception cause, Environment env) { super( "Nested content (body) not supported." + (description == null ? " " + StringUtil.jQuote(description) : ""), cause, env); }
public Object findTemplateSource(String name) throws IOException { String fullPath = subdirPath + name; if (attemptFileAccess) { // First try to open as plain file (to bypass servlet container resource caches). try { String realPath = servletContext.getRealPath(fullPath); if (realPath != null) { File file = new File(realPath); if (file.canRead() && file.isFile()) { return file; } } } catch (SecurityException e) {; // ignore } } // If it fails, try to open it with servletContext.getResource. URL url = null; try { url = servletContext.getResource(fullPath); } catch (MalformedURLException e) { LOG.warn("Could not retrieve resource " + StringUtil.jQuoteNoXSS(fullPath), e); return null; } return url == null ? null : new URLTemplateSource(url, getURLConnectionUsesCaches()); }
/** * Extract the template name from the template object which will be matched against the trusted * template names and pattern. */ protected String safeGetTemplateName(Template template) { if (template == null) return null; String name = template.getName(); if (name == null) return null; // Detect exploits, return null if one is suspected: String decodedName = name; if (decodedName.indexOf('%') != -1) { decodedName = StringUtil.replace(decodedName, "%2e", ".", false, false); decodedName = StringUtil.replace(decodedName, "%2E", ".", false, false); decodedName = StringUtil.replace(decodedName, "%2f", "/", false, false); decodedName = StringUtil.replace(decodedName, "%2F", "/", false, false); decodedName = StringUtil.replace(decodedName, "%5c", "\\", false, false); decodedName = StringUtil.replace(decodedName, "%5C", "\\", false, false); } int dotDotIdx = decodedName.indexOf(".."); if (dotDotIdx != -1) { int before = dotDotIdx - 1 >= 0 ? decodedName.charAt(dotDotIdx - 1) : -1; int after = dotDotIdx + 2 < decodedName.length() ? decodedName.charAt(dotDotIdx + 2) : -1; if ((before == -1 || before == '/' || before == '\\') && (after == -1 || after == '/' || after == '\\')) { return null; } } return name.startsWith("/") ? name.substring(1) : name; }
private DELVRY03E1EDL24 prepareE1EDL24(int position, DeliveryOrderDetail deliveryOrderDetail) { DELVRY03E1EDL24 E1EDL24 = new DELVRY03E1EDL24(); E1EDL24.setSEGMENT("1"); E1EDL24.setPOSNR(StringUtil.leftPad(String.valueOf(position * 10), 4, '0')); E1EDL24.setKDMAT(deliveryOrderDetail.getItem().getCode()); E1EDL24.setLFIMG(String.valueOf(deliveryOrderDetail.getQty())); E1EDL24.setVRKME(deliveryOrderDetail.getUom()); List<DELVRY03E1EDL41> E1EDL41List = E1EDL24.getE1EDL41(); addE1EDL41List(E1EDL41List, deliveryOrderDetail); return E1EDL24; }
@Test public void shouldSetBaseSonarConfig() throws IOException { writeValidConfigFiles(); List<String> files = ImmutableList.of("first", "second"); SonarRunner runner = new SonarRunner(files, sonarRunner, config); Properties props = new Properties(); runner.setAdditionalProperties(props); assertThat(props.getProperty(SonarProperties.INCLUDE_FILES)).contains("first"); assertThat(props.getProperty(SonarProperties.INCLUDE_FILES)).contains("second"); assertThat(StringUtil.split(props.getProperty(SonarProperties.INCLUDE_FILES), ',')).hasSize(2); assertThat(props.getProperty(SonarProperties.ANALISYS_MODE)).isEqualTo("incremental"); assertThat(props.getProperty(SonarProperties.SCM_ENABLED)).isEqualTo("false"); assertThat(props.getProperty(SonarProperties.SCM_STAT_ENABLED)).isEqualTo("false"); assertThat(props.getProperty(SonarProperties.ISSUEASSIGN_PLUGIN)).isEqualTo("false"); assertThat(props.getProperty(SonarProperties.EXPORT_PATH)).isEqualTo(SonarRunner.OUTPUT_FILE); assertThat(props.getProperty(SonarProperties.WORKDIR)).isEqualTo(SonarRunner.OUTPUT_DIR); assertThat(props.getProperty(SonarProperties.PROJECT_BASEDIR)).isEqualTo("."); }
private DeliveryOrder parseDelivery(ManifestFile.Delivery delivery, Plant plant, String fileId) throws DataConvertException { DateFormat dtFormat = new SimpleDateFormat("yyyyMMddHHmmss"); ManifestFile.Delivery.Recheader header = delivery.getRecheader().get(0); DeliveryOrder deliveryOrder = new DeliveryOrder(); deliveryOrder.setFileIdentitfier(fileId); try { String supplierCode = header.getSUCODE(); Supplier supplier = null; try { // 供应商号如果是全数字,则要把前置0去掉 supplierCode = Long.toString((Long.parseLong(supplierCode))); } catch (NumberFormatException ex) { } try { supplier = this.supplierManager.get(supplierCode); // supplier } catch (ObjectRetrievalFailureException ex) { log.info( "Supplier not found with the given supplier code: " + supplierCode + ", try to create a new one."); supplier = new Supplier(); supplier.setCode(supplierCode); supplier.setName(header.getSUNAME()); supplier = this.supplierManager.save(supplier); log.info("Creating supplier user account."); // 生成供应商帐号 User supplierUser = new User(); supplierUser.setUsername(supplier.getCode()); // 使用供应商编码作为用户名称 supplierUser.setEnabled(true); supplierUser.setAccountExpired(false); supplierUser.setAccountLocked(false); supplierUser.setEmail(plant.getSupplierNotifyEmail()); supplierUser.setPassword(RandomStringUtils.random(6, true, true)); supplierUser.setConfirmPassword(supplierUser.getPassword()); supplierUser.setFirstName( supplier.getName() != null ? supplier.getName() : supplier.getCode()); // supplierUser.setLastName(supplier.getName() != null ? // supplier.getName() : supplier.getCode()); supplierUser.setLastName(""); supplierUser.setUserSupplier(supplier); // supplierUser.setUserPlant(plant); Set<Role> roles = new HashSet<Role>(); roles.add(roleManager.getRole(Constants.VENDOR_ROLE)); supplierUser.setRoles(roles); this.userManager.saveUser(supplierUser); try { // Email通知 log.info("Send supplier created email to " + plant.getSupplierNotifyEmail()); mailMessage.setTo(plant.getSupplierNotifyEmail()); Map<String, Object> model = new HashMap<String, Object>(); model.put("supplier", supplier); model.put("user", supplierUser); mailMessage.setSubject("Supplier " + supplier.getCode() + " Created"); mailEngine.sendMessage(mailMessage, supplierCreatedTemplateName, model); log.info("Send supplier created email successful."); } catch (MailException mailEx) { log.error("Error when send supplier create mail.", mailEx); } } PlantSupplier plantSupplier = this.plantSupplierManager.getPlantSupplier(plant, supplier); if (plantSupplier == null) { log.info( "The relationship between Plant: " + plant.getCode() + " and Supplier: " + supplier.getCode() + " not found, try to create a new one."); plantSupplier = new PlantSupplier(); plantSupplier.setSupplierName(header.getSUNAME()); plantSupplier.setSupplierAddress1(header.getSUPADDR1()); plantSupplier.setSupplierAddress2(header.getSUPADDR2()); plantSupplier.setSupplierContactPerson(header.getSUCONTACT()); plantSupplier.setSupplierPhone(header.getSUPTEL()); plantSupplier.setSupplierFax(header.getSUFAX()); plantSupplier.setPlant(plant); plantSupplier.setSupplier(supplier); plantSupplier.setDoNoPrefix( String.valueOf(this.numberControlManager.getNextNumber(Constants.DO_NO_PREFIX))); PlantScheduleGroup defaultPlantScheduleGroup = this.plantScheduleGroupManager.getDefaultPlantScheduleGroupByPlantCode(plant.getCode()); if (defaultPlantScheduleGroup != null) { plantSupplier.setPlantScheduleGroup(defaultPlantScheduleGroup); } plantSupplier = this.plantSupplierManager.save(plantSupplier); } deliveryOrder.setPlantSupplier(plantSupplier); deliveryOrder.setDoNo( this.numberControlManager.generateNumber(plantSupplier.getDoNoPrefix(), 10)); deliveryOrder.setExternalDoNo(header.getMANCODE()); deliveryOrder.setPlantName(header.getFAUPLANT()); deliveryOrder.setPlantAddress1(header.getFAUADDR1()); deliveryOrder.setPlantAddress2(header.getFAUADDR2()); deliveryOrder.setPlantAddress3(header.getFAUADDR3()); deliveryOrder.setPlantContactPerson(header.getFAUCONTACT()); deliveryOrder.setPlantPhone(header.getFAUTEL()); deliveryOrder.setPlantFax(header.getFAUFAX()); deliveryOrder.setPlantPostCode(header.getPOSTCODE()); deliveryOrder.setPlantCity(header.getCITY()); deliveryOrder.setPlantCountry(header.getFAUCTRY()); deliveryOrder.setSupplierName(header.getSUNAME()); deliveryOrder.setSupplierAddress1(header.getSUPADDR1()); deliveryOrder.setSupplierAddress2(header.getSUPADDR2()); deliveryOrder.setSupplierAddress3(header.getSUPADDR3()); deliveryOrder.setSupplierContactPerson(header.getSUCONTACT()); deliveryOrder.setSupplierPhone(header.getSUPTEL()); deliveryOrder.setSupplierFax(header.getSUFAX()); deliveryOrder.setSupplierPostCode(header.getSUPPCOD()); deliveryOrder.setSupplierCity(header.getSUPCITY()); deliveryOrder.setSupplierCountry(header.getSUPCTRY()); deliveryOrder.setCreateDate(new Date()); try { deliveryOrder.setStartDate(dtFormat.parse(header.getPICKUP())); } catch (Exception ex) { log.warn("Error when convert PICKUP into datetime.", ex); deliveryOrder.setStartDate(null); } try { deliveryOrder.setEndDate(dtFormat.parse(header.getRECEPT())); } catch (Exception ex) { log.warn("Error when convert RECEPT into datetime.", ex); deliveryOrder.setEndDate(null); } deliveryOrder.setIsExport(false); deliveryOrder.setIsPrint(false); deliveryOrder.setIsRead(false); deliveryOrder.setFirstReadDate(null); deliveryOrder.setStatus("Confirm"); deliveryOrder.setMurn(header.getMURN()); deliveryOrder.setOrderGroup(header.getORDERG()); deliveryOrder.setDeliveryOrderGroup(header.getDELORDGR()); deliveryOrder.setDock(header.getFDCODE()); deliveryOrder.setRoute(header.getROUTE()); deliveryOrder.setMainRoute(header.getMROUTE()); try { deliveryOrder.setTotalWeight(new BigDecimal(header.getTOTWEIGHT())); } catch (Exception ex) { log.warn("Error when convert TOTWEIGHT into decimal.", ex); } deliveryOrder.setUnitWeight(header.getUNITWEIGHT()); try { deliveryOrder.setTotalVolume(new BigDecimal(header.getTOTVOL())); } catch (Exception ex) { log.warn("Error when convert TOTVOL into decimal.", ex); } deliveryOrder.setUnitVolume(header.getUNITVOL()); try { deliveryOrder.setTotalNbPallets(new BigDecimal(header.getTOTPAL())); } catch (Exception ex) { log.warn("Error when convert TOTPAL into decimal.", ex); } deliveryOrder.setTitle(header.getMANTITLE()); int i = 0; for (ManifestFile.Delivery.Recpos recpos : delivery.getRecpos()) { i++; String itemCode = recpos.getPNUMBER(); try { // 零件号如果是全数字,则要把前置0去掉 itemCode = Long.toString((Long.parseLong(itemCode))); } catch (NumberFormatException ex) { } Item item = this.itemManager.getItemByPlantAndItem(plant, itemCode); String itemDescription = recpos.getDESC(); if (item == null) { log.info( "Item not found with the given item code: " + itemCode + ", try to create a new one."); item = new Item(); item.setCode(itemCode); item.setDescription(itemDescription); item.setPlant(plant); item.setUom(""); item = this.itemManager.save(item); } DeliveryOrderDetail detail = new DeliveryOrderDetail(); detail.setDeliveryOrder(deliveryOrder); detail.setItem(item); detail.setItemDescription(itemDescription); try { detail.setLabel(Integer.parseInt(recpos.getLABELID())); } catch (Exception ex) { log.warn("Error when convert LABELID into int.", ex); } try { detail.setOrderLot(new BigDecimal(recpos.getOLOT())); } catch (Exception ex) { log.warn("Error when convert OLOT into decimal.", ex); } detail.setSequence(String.valueOf(i)); detail.setReferenceSequence(StringUtil.leftPad(String.valueOf(i), 4, '0')); try { detail.setUnitCount(new BigDecimal(recpos.getPCSPU())); } catch (Exception ex) { log.warn("Error when convert PCSPU into decimal.", ex); } try { detail.setIndice(Integer.parseInt(recpos.getPNUMIND())); } catch (Exception ex) { log.warn("Error when convert PNUMIND into int.", ex); } try { detail.setBoxCount(new BigDecimal(recpos.getNBPU())); } catch (Exception ex) { log.warn("Error when convert NBPU into decimal.", ex); } if (detail.getUnitCount() != null && detail.getBoxCount() != null) { detail.setOrderedQty(detail.getUnitCount().multiply(detail.getBoxCount())); detail.setQty(detail.getOrderedQty()); } detail.setUom(item.getUom()); detail.setPackageType(recpos.getPACKTYPE()); detail.setSebango(recpos.getSEBANGO()); detail.setStorageCode(recpos.getSCODE()); deliveryOrder.addDeliveryOrderDetail(detail); } return deliveryOrder; } catch (Exception e) { throw new DataConvertException(e, deliveryOrder); } }