当前位置: 首页>>代码示例>>Java>>正文


Java DocumentHelper.parseText方法代码示例

本文整理汇总了Java中org.dom4j.DocumentHelper.parseText方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentHelper.parseText方法的具体用法?Java DocumentHelper.parseText怎么用?Java DocumentHelper.parseText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.dom4j.DocumentHelper的用法示例。


在下文中一共展示了DocumentHelper.parseText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fileSource

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public void fileSource(HttpServletRequest req, HttpServletResponse resp) throws Exception {
	String path=req.getParameter("path");
	path=Utils.decodeURL(path);
	InputStream inputStream=repositoryService.readFile(path,null);
	String content=IOUtils.toString(inputStream,"utf-8");
	inputStream.close();
	String xml=null;
	try{
		Document doc=DocumentHelper.parseText(content);
		OutputFormat format=OutputFormat.createPrettyPrint();
		StringWriter out=new StringWriter();
		XMLWriter writer=new XMLWriter(out, format);
		writer.write(doc);
		xml=out.toString();
	}catch(Exception ex){
		xml=content;
	}
	Map<String,Object> result=new HashMap<String,Object>();
	result.put("content", xml);
	writeObjectToJson(resp, result);
}
 
开发者ID:youseries,项目名称:urule,代码行数:22,代码来源:FrameServletHandler.java

示例2: parseXml2Map

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
 * 解析XML并将其节点元素压入Dto返回(基于节点值形式的XML格式)
 * 
 * @param pStrXml 待解析的XML字符串
 * @param pXPath 节点路径(例如:"//paralist/row" 则表示根节点paralist下的row节点的xPath路径)
 * @return outDto 返回Dto
 */
public static final Map parseXml2Map(String pStrXml, String pXPath) {
	Map map = new HashMap();
	String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
	Document document = null;
	try {
		if (pStrXml.indexOf("<?xml") < 0)
			pStrXml = strTitle + pStrXml;
		document = DocumentHelper.parseText(pStrXml);
	} catch (DocumentException e) {
		log.error("==开发人员请注意:==\n将XML格式的字符串转换为XML DOM对象时发生错误啦!" + "\n详细错误信息如下:", e);
	}
	// 获取根节点
	Element elNode = document.getRootElement();
	// 遍历节点属性值将其压入Dto
	for (Iterator it = elNode.elementIterator(); it.hasNext();) {
		Element leaf = (Element) it.next();
		map.put(leaf.getName().toLowerCase(), leaf.getData());
	}
	return map;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:28,代码来源:XmlUtil.java

示例3: loadResourceSecurityConfigs

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
@Override
public List<UserPermission> loadResourceSecurityConfigs(String companyId) throws Exception{
	List<UserPermission> configs=new ArrayList<UserPermission>();
	String filePath=RESOURCE_SECURITY_CONFIG_FILE+(companyId == null ? "" : companyId);
	Node rootNode=getRootNode();
	Node fileNode = rootNode.getNode(filePath);
	Property property = fileNode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	InputStream inputStream = fileBinary.getStream();
	String content = IOUtils.toString(inputStream, "utf-8");
	inputStream.close();
	Document document = DocumentHelper.parseText(content);
	Element rootElement = document.getRootElement();
	for (Object obj : rootElement.elements()) {
		if (!(obj instanceof Element)) {
			continue;
		}
		Element element = (Element) obj;
		if (!element.getName().equals("user-permission")) {
			continue;
		}
		UserPermission userResource=new UserPermission();
		userResource.setUsername(element.attributeValue("username"));
		userResource.setProjectConfigs(parseProjectConfigs(element));
		configs.add(userResource);
	}
	return configs;
}
 
开发者ID:youseries,项目名称:urule,代码行数:29,代码来源:RepositoryServiceImpl.java

示例4: parseInitData

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
private Map<String, String> parseInitData(String data) {
    try {
        Map<String, String> ussData = new HashMap<>();
        Document document = DocumentHelper.parseText(data);
        Element root = document.getRootElement();
        Iterator iter = root.elementIterator();
        while (iter.hasNext()) {
            Element ele = (Element) iter.next();
            log.debug("name:" + ele.getName() + " value:" + ele.getStringValue());
            ussData.put(ele.getName(), ele.getStringValue());
        }

        // 随机device id
        String deviceID = "e";
        for (int i = 0; i < 3; i++) {
            int randomNum = ThreadLocalRandom.current().nextInt(10000, 99999);
            deviceID += randomNum;
        }
        ussData.put("deviceID", deviceID);
        return ussData;
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:ingbyr,项目名称:WechatBot,代码行数:26,代码来源:WechatBot.java

示例5: creator

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
 * 生成请求消息
 * @param xmlText
 * @return
 * @throws DocumentException
 * @throws WeixinInMsgHandleException 
 */
public InMessage creator(String xmlText) throws DocumentException, WeixinInMsgHandleException{
	// 获取xml文本document对象
	Document document = DocumentHelper.parseText(xmlText);
	// 得到 xml 根元素
	Element root = document.getRootElement();
	String msgType = root.element("MsgType").getTextTrim();
	
	InMessage in = null;
	
	if(REQUEST_EVENT_MESSAGE_TYPE.equals(msgType)){
		in = creatEventMsg(root);
	} else {
		in = creatPlainMsg(root, msgType);
	}
	
	if(in == null){
		throw new WeixinInMsgHandleException("无法识别的消息请求类型");
	}
	
	return in;
}
 
开发者ID:jweixin,项目名称:jwx,代码行数:29,代码来源:InMessageFactory.java

示例6: handleNdrProxy

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
 *  Execute an ndrRequest (constructed from request parameters) and store the
 *  results in the Form as an XML document before forwarding to "proxy.response".
 *
 * @param  mapping        NOT YET DOCUMENTED
 * @param  form           NOT YET DOCUMENTED
 * @param  request        NOT YET DOCUMENTED
 * @param  response       NOT YET DOCUMENTED
 * @return                NOT YET DOCUMENTED
 * @exception  Exception  NOT YET DOCUMENTED
 */
private ActionForward handleNdrProxy(ActionMapping mapping,
                                     ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws Exception {
	NDRForm ndrForm = (NDRForm) form;

	String verb = request.getParameter("verb");
	if (verb == null || verb.trim().length() == 0)
		throw new Exception("no verb supplied");

	String handle = request.getParameter("handle");
	if (handle == null || handle.trim().length() == 0) {
		handle = null;
	}

	String inputXML = request.getParameter("inputXML");
	if (inputXML == null || inputXML.trim().length() == 0)
		throw new Exception("no inputXML supplied");

	// make sure the inputXML is well-formed
	Document doc = null;
	try {
		doc = DocumentHelper.parseText(inputXML);
		// prtln("\n===============\nproxyRequest\n" + inputXML);
	} catch (Throwable t) {
		prtlnErr("BAD inputXML: " + inputXML);
		throw new Exception("inputXML was not parsable XML");
	}

	NdrRequest ndrRequest = new NdrRequest();
	ndrRequest.setVerb(verb);
	ndrRequest.setHandle(handle);
	InfoXML proxyResponse = ndrRequest.submit(inputXML);

	doc = DocumentHelper.parseText(proxyResponse.getResponse());
	ndrForm.setProxyResponse(Dom4jUtils.prettyPrint(doc));
	return mapping.findForward("proxy.response");
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:50,代码来源:NDRAction.java

示例7: parseDocument

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public Document parseDocument(String xml) {
    Document document = null;
    try {
        document = DocumentHelper.parseText(xml);
    } catch (DocumentException e) {
        throw new IllegalArgumentException(e);
    }
    return document;
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:10,代码来源:XmlParser.java

示例8: update

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public String update(String oldPath, String newPath, String xml) {
	try{
		boolean modify=false;
		Document doc=DocumentHelper.parseText(xml);
		Element element=doc.getRootElement();
		for(Object obj:element.elements()){
			if(!(obj instanceof Element)){
				continue;
			}
			Element ele=(Element)obj;
			String name=ele.getName();
			boolean match=false;
			if(name.equals("import-variable-library")){
				match=true;
			}else if(name.equals("import-constant-library")){
				match=true;
			}else if(name.equals("import-action-library")){
				match=true;
			}else if(name.equals("import-parameter-library")){
				match=true;
			}
			if(!match){
				continue;
			}
			String path=ele.attributeValue("path");
			if(path.endsWith(oldPath)){
				ele.addAttribute("path", newPath);
				modify=true;
			}
		}
		if(modify){
			return xmlToString(doc);
		}
		return null;
	}catch(Exception ex){
		throw new RuleException(ex);
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:39,代码来源:RuleSetReferenceUpdater.java

示例9: parseXml2List

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
 * 将XML规范的字符串转为List对象(XML基于节点属性值的方式)
 * 
 * @param pStrXml 传入的符合XML格式规范的字符串
 * @return list 返回List对象
 */
public static final List parseXml2List(String pStrXml) {
    List lst = new ArrayList();
    String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    Document document = null;
    try {
        if (pStrXml.indexOf("<?xml") < 0) pStrXml = strTitle + pStrXml;
        document = DocumentHelper.parseText(pStrXml);
    } catch (DocumentException e) {
        logger.error("==开发人员请注意:==\n将XML格式的字符串转换为XML DOM对象时发生错误啦!" + "\n详细错误信息如下:", e);
    }
    // 获取到根节点
    Element elRoot = document.getRootElement();
    // 获取根节点的所有子节点元素
    Iterator elIt = elRoot.elementIterator();
    while (elIt.hasNext()) {
        Element el = (Element)elIt.next();
        Iterator attrIt = el.attributeIterator();
        Map map = new HashMap();
        while (attrIt.hasNext()) {
            Attribute attribute = (Attribute)attrIt.next();
            map.put(attribute.getName().toLowerCase(), attribute.getData());
        }
        lst.add(map);
    }
    return lst;
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:33,代码来源:XmlUtil.java

示例10: parse

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
 * @param xml xml description
 * @throws DocumentException 
 */
public static OozieGraph parse(String xml) throws DocumentException {
	OozieGraph graph = new OozieGraph();
	Document doc =DocumentHelper.parseText(xml);
	Element root = doc.getRootElement();
	// parse widgets
	List<Element> nodes = root.elements("widget");
	for( Element node: nodes){
		String type = node.attributeValue("type");
		if (type.equals("dataset")) {
			OozieDatasetNode odn = parseDatasetNode(node);
			graph.addDatasetNode(odn);
		} else if(type.equals("program")){
			OozieProgramNode opn = parseProgramNode(node);
			graph.addProgramNode(opn);
			graph.addActiveNode(opn.getId());
		}

	}

	// parse edges
	List<Element> enodes = root.elements("edge");
	for(Element elem: enodes){
		OozieEdge edge = parseOozieEdge( elem);
		if (edge != null)
			graph.addEdge(edge);
	}

	return graph;
}
 
开发者ID:ICT-BDA,项目名称:EasyML,代码行数:34,代码来源:OozieGraphXMLParser.java

示例11: parseXml2List

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
 * 将XML规范的字符串转为List对象(XML基于节点属性值的方式)
 * 
 * @param pStrXml 传入的符合XML格式规范的字符串
 * @return list 返回List对象
 */
public static final List parseXml2List(String pStrXml) {
	List lst = new ArrayList();
	String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
	Document document = null;
	try {
		if (pStrXml.indexOf("<?xml") < 0)
			pStrXml = strTitle + pStrXml;
		document = DocumentHelper.parseText(pStrXml);
	} catch (DocumentException e) {
		log.error("==开发人员请注意:==\n将XML格式的字符串转换为XML DOM对象时发生错误啦!" + "\n详细错误信息如下:", e);
	}
	// 获取到根节点
	Element elRoot = document.getRootElement();
	// 获取根节点的所有子节点元素
	Iterator elIt = elRoot.elementIterator();
	while (elIt.hasNext()) {
		Element el = (Element) elIt.next();
		Iterator attrIt = el.attributeIterator();
		Map map = new HashMap();
		while (attrIt.hasNext()) {
			Attribute attribute = (Attribute) attrIt.next();
			map.put(attribute.getName().toLowerCase(), attribute.getData());
		}
		lst.add(map);
	}
	return lst;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:34,代码来源:XmlUtil.java

示例12: InfoXML

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
/**
 * Constructs the infoXML abstraction based on the input
 * given.
 * 
 * @param _xml
 */
public InfoXML ( String _xml )
{
	try {
		// TODO : BARFS on the xsi: attribute on return saying :
		//			org.dom4j.DocumentException: Error on line 1 of document  : 
		//			The prefix "xsi" for attribute "xsi:schemaLocation" associated with 
		//			an element type "NSDLDataRepository" is not bound. 
		//			Nested exception: The prefix "xsi" for attribute "xsi:schemaLocation" 
		//			associated with an element type "NSDLDataRepository" is not bound.

		this.contentRaw = _xml;
		this.infoxmlDoc = DocumentHelper.parseText( this.contentRaw );
					
		XPath xpath = DocumentHelper.createXPath( "//ndr:error" ); // for error node checks

		// TODO : though the default namespace is NOT called NDR,
		// http://www.xslt.com/html/xsl-list/2005-03/msg01059.html indicates we must give
		// it one if we are to use it in an XPath.  How fun is that!
		SimpleNamespaceContext ns = new SimpleNamespaceContext();
		ns.addNamespace("ndr", "http://ns.nsdl.org/ndr/response_v1.00/");
		
		xpath.setNamespaceContext(ns);
		
		// select the error node
    	Element error = (Element)xpath.selectSingleNode(this.infoxmlDoc);
    	
    	if ( error != null )
    	{
    		this.hasErrors = true;
    		this.errorString = error.getText();
    	}
    	
	} catch ( Exception e ) {
		this.contentRaw = _xml;
		this.errorString = "Fatal error in InfoXML construction.";
		// e.printStackTrace();
	}		
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:45,代码来源:InfoXML.java

示例13: loadClientConfigs

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
@Override
public List<ClientConfig> loadClientConfigs(String project) throws Exception{
	if(!permissionService.isAdmin()){
		throw new NoPermissionException();
	}
	List<ClientConfig> clients=new ArrayList<ClientConfig>();
	Node rootNode=getRootNode();
	String filePath = processPath(project) + "/" + CLIENT_CONFIG_FILE;
	Node fileNode = rootNode.getNode(filePath);
	Property property = fileNode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	InputStream inputStream = fileBinary.getStream();
	String content = IOUtils.toString(inputStream, "utf-8");
	inputStream.close();
	Document document = DocumentHelper.parseText(content);
	Element rootElement = document.getRootElement();
	for (Object obj : rootElement.elements()) {
		if (!(obj instanceof Element)) {
			continue;
		}
		Element element = (Element) obj;
		if (!element.getName().equals("item")) {
			continue;
		}
		ClientConfig client = new ClientConfig();
		client.setName(element.attributeValue("name"));
		client.setClient(element.attributeValue("client"));
		client.setProject(project);
		clients.add(client);
	}
	return clients;
}
 
开发者ID:youseries,项目名称:urule,代码行数:33,代码来源:RepositoryServiceImpl.java

示例14: getAssetDatas

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
public static List<PageData> getAssetDatas(String xmlStr) throws Exception {
		Document document = DocumentHelper.parseText(xmlStr);
		List<PageData> res = null;
		if(null != document){
			res = new ArrayList<PageData>();
			//获取文档的根节点
			Element root = document.getRootElement();
			//取得某个节点的子节点
			Element element_sentence_list = root.element("ContentList");
			//取得某节点下所有名为“Program”的子节点,并进行遍历
			List nodes = element_sentence_list.elements("Program");
			for (Iterator it = nodes.iterator(); it.hasNext();) {
				PageData pd_tmp = new PageData();
				Element elm = (Element) it.next();
				pd_tmp.put("name", elm.attribute("name").getText());
				pd_tmp.put("resourceCode", elm.attribute("contentID").getText());
				//取得某节点下所有名为“Series”的子节点,并进行遍历
				List nodes1 = elm.elements("PictureList");
				for (Iterator it1 = nodes1.iterator(); it1.hasNext();) {
					Element elm1 = (Element) it1.next();
					List nodes2 = elm1.elements("Picture"); 
					for (Iterator it2 = nodes2.iterator(); it2.hasNext();) {
						Element elm2 = (Element) it2.next();
						pd_tmp.put("picFileURL", elm2.attribute("fileURL").getText());
//						System.out.println(elm.attribute("contentId").getText() + "-" + elm.attribute("name").getText() + "-" + elm2.attribute("fileURL").getText());
						res.add(pd_tmp);
					}
					break;
				}
			}
		}
		return res;
	}
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:34,代码来源:XmlUtils.java

示例15: onSend

import org.dom4j.DocumentHelper; //导入方法依赖的package包/类
@Override
public String onSend(String phone, String content,String source,HttpServletRequest request) {
	
	//短信发送前
	Map<String,String> smslog=new HashMap<String,String>();
	smslog.put("log_type", "1");
	smslog.put("send_source", source);
	smslog.put("phone_number", phone);
	smslog.put("content", content);
	smslog.put("attenchment", "");
	smslog.put("send_time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
	daoSupport.insert("pub_sms_log", smslog);
	
	
	// 创建StringBuffer对象用来操作字符串
	StringBuffer sb = new StringBuffer(URL);
	// 向StringBuffer追加用户名
	sb.append("?action=sendOnce&ac=").append(AC);
	// 向StringBuffer追加密码(密码采用MD5 32位 小写)
	sb.append("&authkey=").append(AUTHKEY+"test");
	sb.append("&cgid=").append(CGID);
	// 向StringBuffer追加手机号码
	sb.append("&m=").append(phone);
	// 向StringBuffer追加消息内容转URL标准码
	sb.append("&c=").append(URLEncoder.encode(content));
	sb.append("&encode=utf8");
	System.out.println(sb.toString());
	
	//向短信平台发请求
	String result=Utils.request(sb.toString());
	
	String messagecode="";
	try {
		//将String转换为XML文档 
		Document doc= DocumentHelper.parseText(result);
		messagecode=Utils.parseDOM4J(doc);
		String message=this.getResponse(messagecode);
		//网关回送
		Map<String,String> smsSendLog=new HashMap<String,String>();
		smsSendLog.put("phone_number", phone);
		smsSendLog.put("content", content);
		smsSendLog.put("send_msg", sb.toString());
		smsSendLog.put("is_success", (messagecode=="1"?"1":"0"));
		smsSendLog.put("callback_msg", result);
		smsSendLog.put("send_time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.daoSupport.insert("pub_sms_send_log", smsSendLog);
		
		System.out.println("网关信息:"+Utils.decodeUnicode(result));
		System.out.println(message);
		//模拟发送信息
		String path= request.getSession().getServletContext().getRealPath("/")+"sms\\";
		String flag=app.getSimilar_sms();//发送标记
		this.mockSend(message,path,flag);
	} catch (DocumentException e) {
		e.printStackTrace();
	}
	return str2json(messagecode);
}
 
开发者ID:yulele166,项目名称:pub-service,代码行数:59,代码来源:SmsSenderCM.java


注:本文中的org.dom4j.DocumentHelper.parseText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。