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


Java XQConnection.createExpression方法代码示例

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


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

示例1: testGetBoolean

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
@Test
public void testGetBoolean() throws XQException {

       SaxonXQDataSource xqds = new SaxonXQDataSource();
       XQConnection xqc = xqds.getConnection();
	XQExpression xqe = xqc.createExpression();
    xqe.bindObject(new QName("v"), Boolean.valueOf(true), null);
    XQSequence xqs = xqe.executeQuery("declare variable $v external; $v instance of xs:boolean");
    xqs.next();
    assertTrue("expected true but got false", xqs.getBoolean());
    
    xqe.bindObject(new QName("v"), new Byte((byte) 1), null);
    xqs = xqe.executeQuery("declare variable $v external; $v instance of xs:byte");
    xqs.next();
    assertTrue("expected true (byte) but got false", xqs.getBoolean());
    
    xqs.close();
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:19,代码来源:SaxonParserTest.java

示例2: testSaxon

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
@Test
  public void testSaxon() throws XQException {
      SaxonXQDataSource xqds = new SaxonXQDataSource();
      XQConnection xqc = xqds.getConnection();
XQExpression xqe = xqc.createExpression();
   XQSequence xqs = xqe.executeQuery("<e>Hello world!</e>");
   //XQSequence xqs = xqe.executeQuery("<a b='c'>{5+2}</a>");
      while (xqs.next()) {
          System.out.println(xqs.getItemAsString(null));
      }
      //System.out.println(xqds.getSchemaValidationMode());
  }
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:13,代码来源:SaxonParserTest.java

示例3: testGetByte

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
@Test
public void testGetByte() throws XQException {
	
       SaxonXQDataSource xqds = new SaxonXQDataSource();
       XQConnection xqc = xqds.getConnection();
	XQExpression xqe = xqc.createExpression();
	XQSequence xqs = xqe.executeQuery("xs:byte('1')");
    xqs.next();
    Object o = xqs.getObject();
       assertTrue(o instanceof Byte);
    xqe.close();
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:13,代码来源:SaxonParserTest.java

示例4: tearDownAfterClass

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
@AfterClass
public static void tearDownAfterClass() throws Exception {

	XQConnection xqc = xqds.getConnection();
	try {
		XQExpression xqe = xqc.createExpression();
		xqe.bindLong(new QName("docId"), axisId, xqc.createAtomicType(XQItemType.XQBASETYPE_LONG));
	    xqe.executeCommand("removeDocument($docId)");
	    xqe.close();
	} finally {
		xqc.close();
	}
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:14,代码来源:BagriXQAxisTest.java

示例5: sort

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
public static ArrayList<String> sort(String xmlns, String fileName, String elementName, boolean isAsc)
		throws XQException {
	URI uri = new File(fileName).toURI();
	String uriPath = uri.getPath();

	ArrayList<String> rowIds = new ArrayList<String>();
	XQDataSource dataSource = new SaxonXQDataSource();

	XQConnection conn = dataSource.getConnection();
	String queryString = "for $file in doc(\'" + uriPath + "')/xliff/file,"
			+ " $tu in $file/body//trans-unit order by $tu/" + elementName + " " + (isAsc ? "" : "descending")
			+ " return <file original='{$file/@original}' tuid='{$tu/@id}'></file>";
	if (xmlns != null) {
		queryString = "declare default element namespace '" + xmlns + "';" + queryString;
	}
	XQExpression expression = conn.createExpression();
	XQSequence results = expression.executeQuery(queryString);
	while (results.next()) {
		Node node = results.getNode();
		String original = node.getAttributes().getNamedItem("original").getNodeValue();
		String tuid = node.getAttributes().getNamedItem("tuid").getNodeValue();
		String rowId = RowIdUtil.getRowId(fileName, original, tuid);
		rowIds.add(rowId);
	}
	// 释放资源
	results.close();
	expression.close();
	conn.close();

	return rowIds;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:32,代码来源:SaxonSearcher.java

示例6: createExpression

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
/**
 * Helper method to retrieve {@link XQExpression} from {@link XQConnection}
 * 
 * @param xqConnection
 *            the {@link XQConnection} to retrieve the expression from
 * @return a XQExpression
 * @throws ApplicationException
 *             if an exception occurs while trying to create the expression
 */
public static XQExpression createExpression(final XQConnection xqConnection)
{
	try
	{
		return xqConnection.createExpression();
	}
	catch (final XQException e)
	{
		throw new ApplicationException("Unable to get XQExpression", e);
	}
}
 
开发者ID:openfurther,项目名称:further-open-core,代码行数:21,代码来源:XQueryUtil.java

示例7: qurey

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
/**
 * 查询
 * @param queryString 
 * 			  XQuery查询语句
 * @return	  RowId集合
 * @throws XQException ;
 */
private static ArrayList<String> qurey(String queryString) throws XQException {
	XQDataSource dataSource = new SaxonXQDataSource();
	XQConnection conn = null;
	XQExpression expression = null;
	XQSequence results = null;
	try {
		conn = dataSource.getConnection();
		expression = conn.createExpression();
		
		results = expression.executeQuery(queryString);
		LinkedHashSet<String> set = new LinkedHashSet<String>();
		while (results.next()) {
			Node node = results.getNode();
			String fileName = node.getAttributes().getNamedItem("fileName").getNodeValue();
			String original = node.getAttributes().getNamedItem("original").getNodeValue();
			String tuid = node.getAttributes().getNamedItem("tuid").getNodeValue();

			// 解决 Windows 平台下,无法查询“重复文本段”的问题“:
			// 这里返回的是 URI,因此需要转成操作系统的标准文件路径。
			// 注:在 Winodws 平台中文件路径分隔符使用“\”,而在 URI 标准中文件路径分隔符使用“/”,并且会以“/”为根,
			//    因此,Windows 的路径“c:\test.txt”,使用 URI 表示为“/c:/test.txt”。
			fileName = new File(fileName).getAbsolutePath();

			String rowId = RowIdUtil.getRowId(fileName, original, tuid);
			set.add(rowId);
		}
		return new ArrayList<String>(set);
	} finally {			
		// 释放资源
		if (results != null && !results.isClosed()) {				
			results.close();
		}
		if (expression != null && !expression.isClosed()) {				
			expression.close();
		}
		if (conn != null && !conn.isClosed()) {
			conn.close();
		}
	}
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:48,代码来源:SaxonSearcher.java

示例8: PropagateQurey

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
/**
	 * 繁殖翻译文本段的查询 robert 2012-04-03
	 * @param queryString
	 *            XQuery查询语句
	 * @return RowId集合
	 * @throws XQException
	 *             ;
	 */
	public static Map<String, List<String>> PropagateQurey(String queryString) throws XQException {
		XQDataSource dataSource = new SaxonXQDataSource();
		XQConnection conn = null;
		XQExpression expression = null;
		XQSequence results = null;
		try {
			conn = dataSource.getConnection();
			expression = conn.createExpression();
			
			results = expression.executeQuery(queryString);
			Map<String, List<String>> resultMap = new HashMap<String, List<String>>();
			while (results.next()) {
				Node node = results.getNode();
//				System.out.println("node.getChildNodes().getLength() = " + node.getChildNodes().getLength());
				if (node.getChildNodes().getLength() >= 1) {
					String rootFileName = node.getAttributes().getNamedItem("fileName").getNodeValue();
					rootFileName = new File(rootFileName).getAbsolutePath();
					String rootOriginal = node.getAttributes().getNamedItem("original").getNodeValue();
					String rootTuid = node.getAttributes().getNamedItem("tuid").getNodeValue();
					String rootRowId = RowIdUtil.getRowId(rootFileName, rootOriginal, rootTuid);
					if (!resultMap.keySet().contains(rootRowId)) {
						resultMap.put(rootRowId, new ArrayList<String>());
					}
					NodeList nodeList = node.getChildNodes();
					for (int i = 0; i < nodeList.getLength(); i++) {
						if (nodeList.item(i).getAttributes() == null) {
							continue;
						}
						String fileName = nodeList.item(i).getAttributes().getNamedItem("fileName").getNodeValue();
						fileName = new File(fileName).getAbsolutePath();
						String original = nodeList.item(i).getAttributes().getNamedItem("original").getNodeValue();
						String tuid = nodeList.item(i).getAttributes().getNamedItem("tuid").getNodeValue();
						
						String rowId = RowIdUtil.getRowId(fileName, original, tuid);
						resultMap.get(rootRowId).add(rowId);
					}
				}
				
			}
			return resultMap;
		} finally {			
			// 释放资源
			if (results != null && !results.isClosed()) {				
				results.close();
			}
			if (expression != null && !expression.isClosed()) {				
				expression.close();
			}
			if (conn != null && !conn.isClosed()) {
				conn.close();
			}
		}
	}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:62,代码来源:SaxonSearcher.java

示例9: testRpeateed

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
/**
	 * 测试过滤重复文本段	robert	2012-06-11
	 * @throws XQException 
	 */
	private static void testRpeateed() throws XQException{
		String xqueryStr_1 = "declare namespace ns0='urn:oasis:names:tc:xliff:document:1.2'; " +
				"for $t in (let $allTU_1 := ( " +
				"	for $file0 in doc('/home/robert/workspace/runtime-UltimateEdition.product/test/XLIFF/zh-CN/user_defineed_filter4.doc.xlf')/ns0:xliff/ns0:file[upper-case(@source-language)='EN-US' " +
				"		and upper-case(@target-language)='ZH-CN'], " +
				"	$tu0 in $file0/ns0:body//ns0:trans-unit " +
				"		return <tu fileName='/home/robert/workspace/runtime-UltimateEdition.product/test/XLIFF/zh-CN/user_defineed_filter4.doc.xlf' original='{$file0/@original}' tuid='{$tu0/@id}' source='{$tu0/ns0:source/text()}' />), " +
				"	$allTU := for $allTU1 in $allTU_1  return <tu fileName='{$allTU1/@fileName}'  original='{$allTU1/@original}'  tuid='{$allTU1/@tuid}'  source='{normalize-space($allTU1/@source)}' /> ," +
				"	$id := (for $src in distinct-values($allTU/@source) " +
				"		return <root>{if (count($allTU[@source=$src])>1) then <src>{$src}</src> else ''}</root>)/src/text(), " +
				"	$tu := $allTU[@source=$id] return $tu) order by $t/@source " +
				"		return <tu fileName='{$t/@fileName}' original='{$t/@original}' tuid='{$t/@tuid}' /> ";
		
		String xqueryStr = "declare namespace ns0='urn:oasis:names:tc:xliff:document:1.2'; \n" +
		"declare function local:getPureText ($srcText1 as xs:anyType) as xs:anyType {\n" +
		"let $result := srcText1 \n" +
		"return  $result };  \n" +
		
		"for $t in (let $allTU := ( \n" +
		"	for $file0 in doc('/home/robert/workspace/runtime-UltimateEdition.product/test/XLIFF/zh-CN/user_defineed_filter4.doc.xlf')/ns0:xliff/ns0:file[upper-case(@source-language)='EN-US'  \n" +
		"		and upper-case(@target-language)='ZH-CN'],  \n" +
		"	$tu0 in $file0/ns0:body//ns0:trans-unit  \n" +
		"		return <tu fileName='/home/robert/workspace/runtime-UltimateEdition.product/test/XLIFF/zh-CN/user_defineed_filter4.doc.xlf' original='{$file0/@original}' tuid='{$tu0/@id}' source='{$tu0/ns0:source/text()}' />) \n" +
		" 	return $allTU )\n " +
		"	return <tu fileName='{$t/@fileName}' original='{$t/@original}' tuid='{$t/@tuid}' source='{$t/@source}'/>  \n";
		
		XQDataSource dataSource = new SaxonXQDataSource();
		XQConnection conn = null;
		XQExpression expression = null;
		XQSequence results = null;
		try {
			conn = dataSource.getConnection();
			expression = conn.createExpression();
			
			results = expression.executeQuery(xqueryStr);
			while (results.next()) {
				Node node = results.getNode();
				String fileName = node.getAttributes().getNamedItem("fileName").getNodeValue();
				String original = node.getAttributes().getNamedItem("original").getNodeValue();
				String tuid = node.getAttributes().getNamedItem("tuid").getNodeValue();
				String source = node.getAttributes().getNamedItem("source").getNodeValue();
				System.out.println(source);
//				System.out.println(tuid);
			}
			return;
		} finally {			
			// 释放资源
			if (results != null && !results.isClosed()) {				
				results.close();
			}
			if (expression != null && !expression.isClosed()) {				
				expression.close();
			}
			if (conn != null && !conn.isClosed()) {
				conn.close();
			}
		}
	}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:63,代码来源:SaxonSearcher.java

示例10: main

import javax.xml.xquery.XQConnection; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
    
    //get the command line arguments
    if(args.length < 5) {
        printUseage();
        System.exit(1);
        return;
    }
    final String server = args[0];
    final String port = args[1];
    
    final String query = args[2];
    final File queryFile;
    if(query.charAt(0) == '@') {
       queryFile = new File(query.substring(1));
       if(!queryFile.exists()) {
           System.err.println("Query file '" + queryFile.getAbsolutePath() + "' does not exist!");
           System.exit(2);
        } 
    } else {
        queryFile = null;
    }
    
    final String path = args[3];
    final String username = args[4];
    final String password;
    if(args.length == 6) {
        password = args[5];
    } else {
        password = "";
    }
    
    //setup the Data Source
    final XQDataSource dataSource = new ExistXQDataSource();
    dataSource.setProperty("serverName", server);
    dataSource.setProperty("port", port);
    
    //get connection with authenticated credentials
    XQConnection connection = null;
    try {
        connection = dataSource.getConnection(username, password);
    
        final String uri = "http://" + server + ":" + port + "/exist/rest" + path;
        logger.info("Starting Query of {}...", uri);

        //execute the query expression
        final XQExpression expression = connection.createExpression();
        final XQResultSequence result;
        if(queryFile == null) {
            result = expression.executeQuery(query);
        } else {
            InputStream is = null;
            try {
                is = new FileInputStream(queryFile);
                result = expression.executeQuery(is);
            } finally {
                if(is != null) {
                    is.close();
                }
            }
        }
        
        //output the results
        boolean producedResults = false;
        while(result.next()) {
            result.writeItem(System.out, null);    
            producedResults = true;
        }
        if(producedResults) {
            System.out.println();
        } else {
            logger.warn("Your XQuery produced no results!");
        }
        logger.info("Finished Query OK.");
        
    } finally {
        if(connection != null) {
            connection.close();
        }
    }
}
 
开发者ID:eXist-book,项目名称:book-code,代码行数:82,代码来源:QueryApp.java


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