List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:ch.epfl.codimsd.qep.QEPFactory.java
License:Open Source License
/** * Creates the xml structure where we embed the operators. * //from w w w. ja v a 2 s . co m * @param type type of the xml template. * @return dom4j Document. */ private static Document createTemplate(String type) { // Create empty dom4j document. Document document = DocumentHelper.createDocument(); // Add "QEPTemlate", "op", "qep", tags. Element root = document.addElement("QEPTemplate", "http://giga03.lncc.br/DIP/WP4/CoDIMS-D"); root.addNamespace("op", "http://giga03.lncc.br/DIP/WP4/CoDIMS-D/Operator"); root.addNamespace("qep", "http://giga03.lncc.br/DIP/WP4/CoDIMS-D/QEP"); root.addElement("qep:QEP").addAttribute("type", type); return document; }
From source file:ch.javasoft.xml.config.XmlConfig.java
License:BSD License
private static Document createDocument(Element configElement, String configName) { final Document doc = DocumentHelper.createDocument(); final Element configList = DocumentHelper.createElement(XmlElement.config_list.getXmlName()); configElement.addAttribute(XmlAttribute.name.getXmlName(), configName); configList.addAttribute(XmlAttribute.def.getXmlName(), configName); configList.add(configElement);//from ww w. j ava2 s. c o m doc.setRootElement(configList); return doc; }
From source file:client.ManageNets.java
License:Open Source License
private void buttonOpenActionPerformed(ActionEvent evt) { System.out.println("buttonOpen.actionPerformed, event=" + evt); int i1 = comboUser.getSelectedIndex(); int i2 = comboNet.getSelectedIndex(); int i3 = comboVersion.getSelectedIndex(); String user = null;/* ww w . j ava2s.co m*/ String name = null; String version = null; if (i1 != -1 && i2 != -1 && i3 != -1) { user = names[i1]; name = nets[i1][i2]; version = convVerToSave(versions[i1][i2][i3]); } else { JOptionPane.showMessageDialog(this, "Choose user, net and version.", "Information", JOptionPane.INFORMATION_MESSAGE); return; } Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("open"); root.addAttribute("user", user); root.addAttribute("name", name); root.addAttribute("version", version); Data data = new Data(MessageType.OPEN, null, null, doc); try { ClConf.server.send(data); data = ClConf.server.receive(); } catch (BadConnect e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Bad connection to server. Disconnection recommended.", "Error", JOptionPane.ERROR_MESSAGE); this.dispose(); } if (data.getType() == MessageType.ERR) { JOptionPane.showMessageDialog(this, "Net wasn't transmitted.", "Error", JOptionPane.ERROR_MESSAGE); return; } //vytvorim novou sit v novem panelu //novy panel MyPanel jpanel = new MyPanel(frame); try { jpanel.fromDoc(data.getDoc()); } catch (FalseXML e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Net is badly formatted.", "Error", JOptionPane.ERROR_MESSAGE); return; } catch (DocumentException e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Net is badly formatted.", "Error", JOptionPane.ERROR_MESSAGE); return; } jpanel.setBackground(NetConf.getColorBack()); jpanel.setServername(name); //pridame tab do paneu pane.addTab(null, jpanel); //prepne aktivitu na vytvoreny tab pane.setSelectedIndex(pane.getTabCount() - 1); //nastavim headline pane.setTabComponentAt(pane.getSelectedIndex(), new MyPanelHeadline(name, pane)); pane.repaint(); this.dispose(); }
From source file:client.ManageNets.java
License:Open Source License
private void buttonDeleteActionPerformed(ActionEvent evt) { System.out.println("buttonDelete.actionPerformed, event=" + evt); int i1 = comboUser.getSelectedIndex(); int i2 = comboNet.getSelectedIndex(); int i3 = comboVersion.getSelectedIndex(); String user = null;/*from w w w. j ava 2 s .co m*/ String name = null; String version = null; if (i1 != -1 && i2 != -1 && i3 != -1) { user = names[i1]; name = nets[i1][i2]; version = convVerToSave(versions[i1][i2][i3]); } else { JOptionPane.showMessageDialog(this, "Choose user, net and version.", "Information", JOptionPane.INFORMATION_MESSAGE); return; } Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("delete"); root.addAttribute("user", user); root.addAttribute("name", name); root.addAttribute("version", version); Data data = new Data(MessageType.DELETE, null, null, doc); try { ClConf.server.send(data); data = ClConf.server.receive(); } catch (BadConnect e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Bad connection to server. Disconnection recommended.", "Error", JOptionPane.ERROR_MESSAGE); this.dispose(); } if (data.getType() == MessageType.ERR) { JOptionPane.showMessageDialog(this, "Net wasn't deleted.", "Error", JOptionPane.ERROR_MESSAGE); return; } try { init(); } catch (BadConnect e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Bad connection to server. Disconnection recommended.", "Error", JOptionPane.ERROR_MESSAGE); this.dispose(); return; } //zmenim uzivatele na toho co tam byl comboUser.setSelectedItem(user); int index = comboUser.getSelectedIndex(); comboNet.setModel(new DefaultComboBoxModel(nets[index])); comboNet.setSelectedItem(name); int ind2 = comboNet.getSelectedIndex(); try { comboVersion.setModel(new DefaultComboBoxModel(versions[index][ind2])); } catch (ArrayIndexOutOfBoundsException e) { comboVersion.setModel(new DefaultComboBoxModel(new String[] {})); } this.repaint(); }
From source file:cmcc.gz.adc.message.CorpBindRsp.java
public String toString() { try {/*from www . ja v a 2 s. c o m*/ Document document = DocumentHelper.createDocument(); Element root = document.addElement("CorpBindRsp"); Element head = root.addElement("HEAD"); head.addElement("CODE").addText(header.getCode()); head.addElement("SID").addText(header.getSid()); head.addElement("TIMESTAMP").addText(header.getTimestamp()); head.addElement("SERVICEID").addText(header.getServiceId()); root.addElement("BODY").setText(encodeBody()); return root.asXML(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:cmcc.gz.adc.message.CorpBindRsp.java
private String encodeBody() { Document document = DocumentHelper.createDocument(); try {/*from w w w .j a v a 2s . c om*/ Element root = document.addElement("BODY"); root.addElement("RESULTCODE").addText(resultcode); root.addElement("RESULTMSG").addText(resultmsg); root.addElement("URL").addText(url); return SecurityTool.encrypt(root.asXML()); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:cn.buk.api.service.CtripHotelServiceImpl.java
License:LGPL
/** * ??/*from w w w .j a v a2 s.c o m*/ * @param cityId ? * @return ?? */ @Override public String searchHotel(int cityId) { if (cityId <= 0) return "ER#CITYID IS " + cityId; //headerAPI? Cache cache = getCache(); String cacheKey = ConfigData.OTA_HotelSearch_Request; net.sf.ehcache.Element cacheElement = cache.get(cacheKey); if (cacheElement != null) { Element headerElement = (Element) cacheElement.getValue(); int accessCount = Integer.parseInt(headerElement.attributeValue("AccessCount")); int currentCount = Integer.parseInt(headerElement.attributeValue("CurrentCount")) + 1; logger.info("AccessCount=" + headerElement.attributeValue("AccessCount") + ", CurrentCount=" + headerElement.attributeValue("CurrentCount") + ", ResetTime=" + headerElement.attributeValue("ResetTime")); if (currentCount >= accessCount) { try { logger.info("Sleep for one minute."); Thread.sleep(60000); } catch (InterruptedException ex) { logger.warn(Thread.currentThread().getName() + " is interrupted."); return "ER#Thread.sleep is interrupted."; } } } HotelRequestBody request = new HotelRequestBody(); request.createHotelRequestRQ(); request.getHotelRequestRQ().getCriteria().getCriterion().getHotelRef().setHotelCityCode(cityId); String xml; try { JAXBContext jc = JAXBContext.newInstance(HotelRequestBody.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); DocumentResult documentResult = new DocumentResult(); m.marshal(request, documentResult); org.dom4j.Document document = documentResult.getDocument(); org.dom4j.Element requestElement = document.getRootElement(); Element ele = requestElement.element("OTA_HotelSearchRQ"); ele.addNamespace("", "http://www.opentravel.org/OTA/2003/05"); org.dom4j.Document doc1 = DocumentHelper.createDocument(); org.dom4j.Element rootElement = createRequestHeaderElement(doc1, ConfigData.OTA_HotelSearch_Request); rootElement.add(requestElement); xml = doc1.asXML(); } catch (JAXBException ex) { logger.error(ex.getMessage()); return "ER"; } if (serviceStopped) return "ER#Service stopped."; String response = execApiRequest(xml, ConfigData.OTA_HotelSearch_Url, "requestXML"); //? SAXReader reader = new SAXReader(); Document document;// ?XML try { document = reader.read(new StringReader(response)); if (serviceStopped) return "ER#Service stopped."; response = processHotelSearchResponse(document); } catch (Exception ex) { logger.error(ex.getMessage()); return "ER"; } return response; }
From source file:cn.buk.api.service.CtripHotelServiceImpl.java
License:LGPL
@Override public synchronized String searchHotelDetail(List<String> hotelCodes, boolean returnXml) { if (hotelCodes == null || hotelCodes.size() == 0) return "ER#hotelcodes is null"; //headerAPI?//from w ww . j a v a2 s. co m net.sf.ehcache.Element cacheElement = getCache().get(ConfigData.OTA_HotelDetail_Request); if (cacheElement != null) { Element headerElement = (Element) cacheElement.getValue(); int accessCount = Integer.parseInt(headerElement.attributeValue("AccessCount")); int currentCount = Integer.parseInt(headerElement.attributeValue("CurrentCount")) + 1; logger.info(ConfigData.OTA_HotelDetail_Request + " AccessCount=" + headerElement.attributeValue("AccessCount") + ", CurrentCount=" + headerElement.attributeValue("CurrentCount") + ", ResetTime=" + headerElement.attributeValue("ResetTime")); if (currentCount >= accessCount) { try { logger.info("Sleep for one minute."); Thread.sleep(60000); } catch (InterruptedException ex) { logger.warn(Thread.currentThread().getName() + " is interrupted."); return "ER#SearchHotelDetail thread.sleep is interrupted."; } } } if (this.serviceStopped) return "ER#Service stopped."; HotelRequestBody request = new HotelRequestBody(); request.createHotelDetailRequest(); for (String hotelCode : hotelCodes) { if (this.serviceStopped) return "ER#Service stopped."; HotelDescriptiveInfo hotelDescriptiveInfo = new HotelDescriptiveInfo(); hotelDescriptiveInfo.setHotelCode(hotelCode); cn.buk.hotel.entity.HotelInfo hotelInfo = hotelDao.getHotelDetailInfoByHotelCode(hotelCode); if (hotelInfo != null) { //if (hotelInfo.getGuestRooms().size() == 0) { hotelDescriptiveInfo.setHotelInfoFacilityInfo(new HotelInfoFacilityInfo()); hotelDescriptiveInfo.getHotelInfoFacilityInfo().setSendGuestRooms(true); //} if (hotelInfo.getRefPoints().size() == 0) { hotelDescriptiveInfo.setHotelInfoAreaInfo(new HotelInfoAreaInfo()); hotelDescriptiveInfo.getHotelInfoAreaInfo().setSendAttractions(true); hotelDescriptiveInfo.getHotelInfoAreaInfo().setSendRecreations(true); } if (hotelInfo.getMedias().size() == 0) { hotelDescriptiveInfo.setHotelInfoMultimedia(new HotelInfoMultimedia()); hotelDescriptiveInfo.getHotelInfoMultimedia().setSendData(true); } } request.getHotelDetailRequest().getHotelDescriptiveInfos().add(hotelDescriptiveInfo); } String requestXml; try { JAXBContext jc = JAXBContext.newInstance(HotelRequestBody.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); DocumentResult documentResult = new DocumentResult(); m.marshal(request, documentResult); org.dom4j.Document document = documentResult.getDocument(); org.dom4j.Element requestElement = document.getRootElement(); Element ele = requestElement.element("OTA_HotelDescriptiveInfoRQ"); ele.addNamespace("", "http://www.opentravel.org/OTA/2003/05"); org.dom4j.Document doc1 = DocumentHelper.createDocument(); if (this.serviceStopped) return "ER#Service stopped."; org.dom4j.Element rootElement = createRequestHeaderElement(doc1, ConfigData.OTA_HotelDetail_Request); rootElement.add(requestElement); requestXml = doc1.asXML(); } catch (JAXBException e) { e.printStackTrace(); return "ER#OTA_exception"; } Date date0 = DateUtil.getCurDateTime(); logger.debug(ConfigData.OTA_HotelDetail_Request + ": begin"); logger.debug(requestXml); if (this.serviceStopped) return "ER#Service stopped."; String response = execApiRequest(requestXml, ConfigData.OTA_HotelDetail_Url, "requestXML"); logger.debug(response); int apiElapsedTime = DateUtil.getPastTime(date0); logger.debug(ConfigData.OTA_HotelDetail_Request + ": end, " + apiElapsedTime + "ms"); if (returnXml) return response; //? String rs; SAXReader reader = new SAXReader(); Document document;// ?XML try { document = reader.read(new StringReader(response)); Element headerElement = document.getRootElement().element("Header"); //header? getCache().put(new net.sf.ehcache.Element(ConfigData.OTA_HotelDetail_Request, headerElement)); if (!headerElement.attribute("ResultCode").getValue().equalsIgnoreCase("Success")) { logger.error(requestXml); logger.error(document.asXML()); return "ER#ResultCode is not Success."; } DocumentDto documentDto = new DocumentDto(); documentDto.setDocument(document); if (hotelDetailQueue.size() == MAX_HOTEL_DETAIL_QUEUE) { logger.warn("hotelDetailQueue is full, thread will be blocked here."); } hotelDetailQueue.put(documentDto); hotelDetailDaoExecutor.execute(new HotelDetailDaoThread()); rs = "OK#save to the queue."; } catch (InterruptedException ex) { return "ER#Interrupt occured."; } catch (Exception ex) { logger.error(ex.getMessage()); return "ER#searchHotelDetail"; } return rs; }
From source file:cn.buk.api.service.CtripHotelServiceImpl.java
License:LGPL
private String createXml4HotelRequestBody(HotelRequestBody request, String requestType) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(HotelRequestBody.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); DocumentResult documentResult = new DocumentResult(); m.marshal(request, documentResult);//w w w . j a v a2s . co m org.dom4j.Document document = documentResult.getDocument(); org.dom4j.Element requestElement = document.getRootElement(); org.dom4j.Document doc1 = DocumentHelper.createDocument(); org.dom4j.Element rootElement = createRequestHeaderElement(doc1, requestType); rootElement.add(requestElement); return doc1.asXML(); }
From source file:cn.com.sunjiesh.wechat.helper.WechatMessageConvertDocumentHelper.java
/** * ?XML/* ww w .ja v a 2 s.c o m*/ * * @param toUserName ??OpenID * @param fromUserName ?? * @param msgType ? * @return XML */ private static Document initRespDoc(final String toUserName, final String fromUserName, final String msgType) { Document respDoc = DocumentHelper.createDocument(); Element rootEle = respDoc.addElement("xml"); Element toUserNameEle = rootEle.addElement("ToUserName"); Element fromUserNameEle = rootEle.addElement("FromUserName"); Element createTimeEle = rootEle.addElement("CreateTime"); Element msgTypeEle = rootEle.addElement("MsgType"); toUserNameEle.setText(toUserName); fromUserNameEle.setText(fromUserName); createTimeEle.setText(String.valueOf(System.currentTimeMillis())); msgTypeEle.setText(msgType); return respDoc; }