List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:com.xebia.mojo.dashboard.util.HtmlUtil.java
License:Apache License
/** * Adds a "style" {@link Attribute} containing the passed in styles to an {@link Element}. * * @param element The {@link Element} to stylize with the styles passed in. * @param styles The value of the "style" {@link Attribute} that needs to be applied to the {@link Element}. *///from w w w .j a v a 2 s. c om public static final void addStyles(Element element, String styles) { if (element != null) { Attribute attribute = element.attribute("style"); if (attribute != null) { styles += attribute.getValue(); } element.addAttribute("style", styles); } }
From source file:com.xia.ssm.tools.ocr.CheckPic.java
/** * ?//from w w w . j a va 2 s . c o m * @Title: sendPicToWt * @param thPhoneDTO * @return * @createDate 20161026;?3:26:55 * @author xjf */ public static ClaimPhoneDTO sendPicToWt(ClaimPhoneDTO thPhoneDTO) { String result = ""; String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//? long beginTime = System.currentTimeMillis(); try { log.info("file======" + file); result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK, WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl()); log.info("result======" + result); } catch (Exception e) { // TODO: handle exception thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } String[] encData = result.split("==@@"); long times = System.currentTimeMillis() - beginTime; log.info("" + times); String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", ""); Document doc; String insertString = ""; try { doc = DocumentHelper.parseText(dataString); String status = doc.selectSingleNode("/data/message/status").getText(); String value = doc.selectSingleNode("/data/message/value").getText(); StringBuffer sql = new StringBuffer(); if ("?".equals(value)) { List list = doc.selectNodes("/data/cardsinfo/card/item"); StringBuffer json = new StringBuffer(); for (int j = 1; j < list.size() - 1; j++) { Element term = (Element) list.get(j); String returString = term.getText(); insertString += "'" + returString + "'" + ","; String name = term.attribute("desc").getText(); if ("???".equals(name)) { thPhoneDTO.setPlateNo(returString); } if ("".equals(name)) { thPhoneDTO.setVehicleType(returString); } if ("".equals(name)) { thPhoneDTO.setCustomerName(returString); } if ("??".equals(name)) { thPhoneDTO.setAddress(returString); } if ("??".equals(name)) { thPhoneDTO.setVehicleModels(returString); } if ("?".equals(name)) { thPhoneDTO.setVin(returString); } if ("???".equals(name)) { thPhoneDTO.setEngineNo(returString); } if ("".equals(name)) { thPhoneDTO.setRegisterDate(returString); } if ("??".equals(name)) { thPhoneDTO.setIssueDate(returString); } if ("".equals(name)) { thPhoneDTO.setUseType(returString); } thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); } } else { thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); } } catch (Exception e) { thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } return thPhoneDTO; }
From source file:com.xia.ssm.tools.ocr.CheckPic.java
/** * //from w w w . ja va 2 s. c om * @Title: sendPlateNoPicToWt * @param thPhoneDTO * @return * @createDate 20161026;?3:31:45 * @author luy */ public static ClaimPhoneDTO sendPlateNoPicToWt(ClaimPhoneDTO thPhoneDTO) { String result = ""; String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//? long beginTime = System.currentTimeMillis(); try { log.info("file======" + file); result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK, WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl()); log.info("result======" + result); } catch (Exception e) { // TODO: handle exception thPhoneDTO.setResponseCode(ExceptionClaimCode.PLATENO_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } String[] encData = result.split("==@@"); long times = System.currentTimeMillis() - beginTime; log.info("" + times); String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", ""); Document doc; String insertString = ""; try { doc = DocumentHelper.parseText(dataString); String status = doc.selectSingleNode("/data/message/status").getText(); String value = doc.selectSingleNode("/data/message/value").getText(); if ("?".equals(value)) { List list = doc.selectNodes("/data/cardsinfo/card/item"); for (int j = 0; j < list.size(); j++) { Element term = (Element) list.get(j); String returString = term.getText(); insertString += "'" + returString + "'" + ","; String name = term.attribute("desc").getText(); if ("?".equals(name)) { thPhoneDTO.setPlateNo(returString); } thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); } } else { thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); thPhoneDTO.setResponseCode(ExceptionClaimCode.PLATENO_FAILED); } } catch (Exception e) { thPhoneDTO.setResponseCode(ExceptionClaimCode.PLATENO_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } return thPhoneDTO; }
From source file:com.xia.ssm.tools.ocr.CheckPic.java
/** * ?/* ww w. j a va 2 s . co m*/ * @Title: sendIdCardToWt * @param thPhoneDTO * @return * @createDate 20161026;?3:32:41 * @author xjf */ public static ClaimPhoneDTO sendIdCardToWt(ClaimPhoneDTO thPhoneDTO) { String result = ""; String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//? long beginTime = System.currentTimeMillis(); try { log.info("file======" + file); result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK, WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl()); log.info("result======" + result); } catch (Exception e) { // TODO: handle exception thPhoneDTO.setResponseCode(ExceptionClaimCode.IDCARD_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } String[] encData = result.split("==@@"); long times = System.currentTimeMillis() - beginTime; log.info("" + times); String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", ""); Document doc; String insertString = ""; try { doc = DocumentHelper.parseText(dataString); String status = doc.selectSingleNode("/data/message/status").getText(); String value = doc.selectSingleNode("/data/message/value").getText(); if ("?".equals(value)) { List list = doc.selectNodes("/data/cardsinfo/card/item"); for (int j = 1; j < list.size() - 1; j++) { Element term = (Element) list.get(j); String returString = term.getText(); insertString += "'" + returString + "'" + ","; String name = term.attribute("desc").getText(); if ("??".equals(name)) { thPhoneDTO.setUserName(returString); } if ("".equals(name)) { thPhoneDTO.setSex(returString); } if ("?".equals(name)) { thPhoneDTO.setNation(returString); } if ("".equals(name)) { thPhoneDTO.setBirthday(returString); } if ("??".equals(name)) { thPhoneDTO.setAddress(returString); } if ("??".equals(name)) { thPhoneDTO.setIdCardNo(returString); } if ("?".equals(name)) { thPhoneDTO.setIdCardPhoto(returString); } thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); } } else { thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); } } catch (Exception e) { thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } return thPhoneDTO; }
From source file:com.xia.ssm.tools.ocr.CheckPic.java
/** * ?/*from w ww. jav a2s. c o m*/ * @Title: sendDriverToWt * @param thPhoneDTO * @return * @createDate 20161026;?3:33:28 * @author luy */ public static ClaimPhoneDTO sendDriverToWt(ClaimPhoneDTO thPhoneDTO) { String result = ""; String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//? long beginTime = System.currentTimeMillis(); try { log.info("file======" + file); result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK, WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl()); log.info("result======" + result); } catch (Exception e) { // TODO: handle exception thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVER_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } String[] encData = result.split("==@@"); long times = System.currentTimeMillis() - beginTime; log.info("" + times); String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", ""); Document doc; String insertString = ""; try { doc = DocumentHelper.parseText(dataString); String status = doc.selectSingleNode("/data/message/status").getText(); String value = doc.selectSingleNode("/data/message/value").getText(); if ("?".equals(value)) { List list = doc.selectNodes("/data/cardsinfo/card/item"); for (int j = 1; j < list.size() - 1; j++) { Element term = (Element) list.get(j); String returString = term.getText(); insertString += "'" + returString + "'" + ","; String name = term.attribute("desc").getText(); if ("??".equals(name)) { thPhoneDTO.setCardNo(returString); } if ("??".equals(name)) { thPhoneDTO.setUserName(returString); } if ("".equals(name)) { thPhoneDTO.setSex(returString); } if ("??".equals(name)) { thPhoneDTO.setAddress(returString); } if ("".equals(name)) { thPhoneDTO.setBirthday(returString); } if ("??".equals(name)) { thPhoneDTO.setRegisterTime(returString); } if ("".equals(name)) { thPhoneDTO.setDrivingType(returString); } if ("".equals(name)) { thPhoneDTO.setStartTime(returString); } if ("?".equals(name)) { thPhoneDTO.setLimitTime(returString); } if ("".equals(name)) { thPhoneDTO.setEndTime(returString); } thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); } } else { thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); } } catch (Exception e) { thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } return thPhoneDTO; }
From source file:com.xia.ssm.tools.ocr.CheckPic.java
/** * ?/*from ww w. j ava2 s . co m*/ * @Title: sendBankToWt * @param thPhoneDTO * @return * @createDate 20161026;?6:39:23 * @author luy */ public static ClaimPhoneDTO sendBankToWt(ClaimPhoneDTO thPhoneDTO) { String result = ""; String file = thPhoneDTO.getAppPath() + thPhoneDTO.getPhotoNames();//? long beginTime = System.currentTimeMillis(); try { log.info("file======" + file); result = WTUtils.invokeRemoteFuc(thPhoneDTO.getPicType(), WTUtils.WT_USERNAME, file, WTUtils.WT_PAR_BAK, WTUtils.WT_PIC_KIND, thPhoneDTO.getWtAddrUrl()); log.info("result======" + result); } catch (Exception e) { // TODO: handle exception thPhoneDTO.setResponseCode(ExceptionClaimCode.BANK_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } String[] encData = result.split("==@@"); long times = System.currentTimeMillis() - beginTime; log.info("" + times); String dataString = encData[0].replaceAll("<!\\[CDATA\\[", "").replaceAll("\\]\\]>", ""); Document doc; String insertString = ""; try { doc = DocumentHelper.parseText(dataString); String status = doc.selectSingleNode("/data/message/status").getText(); String value = doc.selectSingleNode("/data/message/value").getText(); if ("?".equals(value)) { List list = doc.selectNodes("/data/cardsinfo/card/item"); for (int j = 1; j < list.size() - 1; j++) { Element term = (Element) list.get(j); String returString = term.getText(); insertString += "'" + returString + "'" + ","; String name = term.attribute("desc").getText(); if ("???".equals(name)) { thPhoneDTO.setPlateNo(returString); } if ("".equals(name)) { thPhoneDTO.setVehicleType(returString); } if ("".equals(name)) { thPhoneDTO.setCustomerName(returString); } if ("??".equals(name)) { thPhoneDTO.setAddress(returString); } if ("??".equals(name)) { thPhoneDTO.setVehicleModels(returString); } if ("?".equals(name)) { thPhoneDTO.setVin(returString); } if ("???".equals(name)) { thPhoneDTO.setEngineNo(returString); } if ("".equals(name)) { thPhoneDTO.setRegisterDate(returString); } if ("??".equals(name)) { thPhoneDTO.setIssueDate(returString); } if ("".equals(name)) { thPhoneDTO.setUseType(returString); } thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); } } else { thPhoneDTO.setConsumeTime("" + String.valueOf(times) + ""); thPhoneDTO.setState(value); thPhoneDTO.setStatus(status); thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); } } catch (Exception e) { thPhoneDTO.setResponseCode(ExceptionClaimCode.DRIVERLICENSE_FAILED); ErrorsLogPrintUtil.printToLog4j(log, e); } return thPhoneDTO; }
From source file:com.zero.service.impl.TemplateServiceImpl.java
License:Open Source License
public void Update(Template template) { try {/*from ww w . j av a 2s .c o m*/ File configXmlFile = new ClassPathResource(com.zero.CommonAttributes.CONFIG_XML_PATH).getFile(); Document document = new SAXReader().read(configXmlFile); Element element = (Element) document .selectSingleNode("/config/transfer[@id='" + template.getId() + "']"); if (element != null) { element.attribute("stm").setText(template.getStm()); } Dom4jUtil.write(document, configXmlFile.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.zimbra.cs.dav.resource.MailItemResource.java
License:Open Source License
@Override public void patchProperties(DavContext ctxt, java.util.Collection<Element> set, java.util.Collection<QName> remove) throws DavException, IOException { List<QName> reqProps = new ArrayList<QName>(); for (QName n : remove) { mDeadProps.remove(n);//from w w w.j a v a 2 s . c o m reqProps.add(n); } for (Element e : set) { QName name = e.getQName(); if (name.equals(DavElements.E_DISPLAYNAME) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) { // rename folder try { String val = e.getText(); String uri = getUri(); Mailbox mbox = getMailbox(ctxt); mbox.rename(ctxt.getOperationContext(), mId, type, val, mFolderId); setProperty(DavElements.P_DISPLAYNAME, val); UrlNamespace.addToRenamedResource(getOwner(), uri, this); UrlNamespace.addToRenamedResource(getOwner(), uri.substring(0, uri.length() - 1), this); } catch (ServiceException se) { ctxt.getResponseProp().addPropError(DavElements.E_DISPLAYNAME, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY)); } mDeadProps.remove(name); continue; } else if (name.equals(DavElements.E_CALENDAR_COLOR) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) { // change color String colorStr = e.getText(); Color color = new Color(colorStr.substring(0, 7)); byte col = (byte) COLOR_LIST.indexOf(colorStr); if (col >= 0) color.setColor(col); try { Mailbox mbox = getMailbox(ctxt); mbox.setColor(ctxt.getOperationContext(), new int[] { mId }, type, color); } catch (ServiceException se) { ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_COLOR, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY)); } mDeadProps.remove(name); continue; } else if (name.equals(DavElements.E_SUPPORTED_CALENDAR_COMPONENT_SET)) { // change default view @SuppressWarnings("unchecked") List<Element> elements = e.elements(DavElements.E_COMP); boolean isTodo = false; boolean isEvent = false; for (Element element : elements) { Attribute attr = element.attribute(DavElements.P_NAME); if (attr != null && CalComponent.VTODO.name().equals(attr.getValue())) { isTodo = true; } else if (attr != null && CalComponent.VEVENT.name().equals(attr.getValue())) { isEvent = true; } } if (isEvent ^ isTodo) { // we support a calendar collection of type event or todo, not both or none. Type type = (isEvent) ? Type.APPOINTMENT : Type.TASK; try { Mailbox mbox = getMailbox(ctxt); mbox.setFolderDefaultView(ctxt.getOperationContext(), mId, type); // Update the view for this collection. This collection may get cached if display name is modified. // See UrlNamespace.addToRenamedResource() if (this instanceof Collection) { ((Collection) this).view = type; } } catch (ServiceException se) { ctxt.getResponseProp().addPropError(name, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY)); } } else { ctxt.getResponseProp().addPropError(name, new DavException.CannotModifyProtectedProperty(name)); } continue; } mDeadProps.put(name, e); reqProps.add(name); } String configVal = ""; if (mDeadProps.size() > 0) { org.dom4j.Document doc = org.dom4j.DocumentHelper.createDocument(); Element top = doc.addElement(CONFIG_KEY); for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) top.add(entry.getValue().detach()); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputFormat format = OutputFormat.createCompactFormat(); XMLWriter writer = new XMLWriter(out, format); writer.write(doc); configVal = new String(out.toByteArray(), "UTF-8"); if (configVal.length() > PROP_LENGTH_LIMIT) for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) ctxt.getResponseProp().addPropError(entry.getKey(), new DavException("prop length exceeded", DavProtocol.STATUS_INSUFFICIENT_STORAGE)); } Mailbox mbox = null; try { mbox = getMailbox(ctxt); mbox.lock.lock(); Metadata data = mbox.getConfig(ctxt.getOperationContext(), CONFIG_KEY); if (data == null) { data = new Metadata(); } data.put(Integer.toString(mId), configVal); mbox.setConfig(ctxt.getOperationContext(), CONFIG_KEY, data); } catch (ServiceException se) { for (QName qname : reqProps) ctxt.getResponseProp().addPropError(qname, new DavException(se.getMessage(), HttpServletResponse.SC_FORBIDDEN)); } finally { if (mbox != null) mbox.lock.release(); } }
From source file:condorclient.utilities.XMLHandler.java
public void modifyJob(String name, String clusterId) { SAXReader saxReader = new SAXReader(); Document document = null;/*from www .j ava2 s.c om*/ try { document = saxReader.read(new File("niInfo.xml")); } catch (DocumentException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } List list = document.selectNodes("/root/info/job"); Iterator iter = list.iterator(); while (iter.hasNext()) { Element job = (Element) iter.next(); String id = job.attributeValue("id"); if (id.equals(clusterId)) { job.attribute("name").setValue(name); } } XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(new File("niInfo.xml"))); writer.write(document); writer.close(); } catch (IOException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:condorclient.utilities.XMLHandler.java
void setTransfer(String clusterId) { SAXReader saxReader = new SAXReader(); Document document = null;//w w w. j av a2s . c o m try { document = saxReader.read(new File("niInfo.xml")); } catch (DocumentException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } List list = document.selectNodes("/root/info/job"); Iterator iter = list.iterator(); while (iter.hasNext()) { Element job = (Element) iter.next(); String id = job.attributeValue("id"); if (id.equals(clusterId)) { job.attribute("transfer").setValue("1"); } } XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(new File("niInfo.xml"))); writer.write(document); writer.close(); } catch (IOException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } }