Java 类javax.xml.xquery.XQDataSource 实例源码

项目:bagri    文件:BagriTPoXPlugin.java   
protected static XQDataSource initDataSource() throws XQException {
    XQDataSource xqds = new BagriXQDataSource();
 xqds.setProperty(ADDRESS, System.getProperty(pn_schema_address));
 xqds.setProperty(SCHEMA, System.getProperty(pn_schema_name));
 xqds.setProperty(USER, System.getProperty(pn_schema_user));
 xqds.setProperty(PASSWORD, System.getProperty(pn_schema_password));
 xqds.setProperty(XQ_PROCESSOR, "com.bagri.xquery.saxon.XQProcessorClient");
 xqds.setProperty(XDM_REPOSITORY, "com.bagri.client.hazelcast.impl.SchemaRepositoryImpl");
 String value = System.getProperty(pn_client_loginTimeout);
 if (value != null) {
    xqds.setProperty(pn_client_loginTimeout, value);
 }
 value = System.getProperty(pn_client_bufferSize);
 if (value != null) {
    xqds.setProperty(pn_client_bufferSize, value);
 }
 value = System.getProperty(pn_client_connectAttempts);
 if (value != null) {
    xqds.setProperty(pn_client_connectAttempts, value);
 }
 return xqds;
}
项目:XMLVersioningFramework    文件:XChroniclerHandler.java   
private static String runQuery(String query) throws XQException {
    System.out.println("runQuery: \n\t" + query);
    XQDataSource xqs = new ExistXQDataSource();
    String returnString = "";
    xqs.setProperty("serverName", "localhost");

    xqs.setProperty("port", "8080");

    XQConnection conn = xqs.getConnection();
    XQPreparedExpression xqpe = conn.prepareExpression(query);

    XQResultSequence rs = xqpe.executeQuery();

    while (rs.next()) {
        returnString += rs.getItemAsString(null).replace("xmlns=\"\"", "")
                + "\n";
    }

    System.out.println("Query result: \n\t" + returnString);

    return returnString;

}
项目:intellij-xquery    文件:DataSourceFactory.java   
public XQDataSource getDataSource() throws Exception {
    XQueryDataSourceType dataSourceType = config.getDataSourceType();
    XQDataSource dataSource = getXQDataSource(dataSourceType, config);
    if (dataSourceType.connectionPropertiesAreSupported()) {
        if (config.getHost() != null && config.getHost().length() > 0) {
            dataSource.setProperty(SERVER_NAME, config.getHost());
        }
        if (config.getPort() != null && config.getPort().length() > 0) {
            dataSource.setProperty(PORT, config.getPort());
        }
        if (config.getDatabaseName() != null && config.getDatabaseName().length() > 0) {
            dataSource.setProperty(DATABASE_NAME, config.getDatabaseName());
        }
    }
    return dataSource;
}
项目:bagri    文件:SchemaManagement.java   
private void setupXQConnection(ApplicationContext ctx) throws XQException {
    XQDataSource xqds = ctx.getBean("xqDataSource", XQDataSource.class);
    String username = srvUser.getCurrentUser();
    String password = srvUser.getUserPassword(username);
    if (password == null) {
        throw new XQException("no credentials found for user " + username);
    }

    XQConnection xqConn = xqds.getConnection(username, password);
    QueryManagement qMgr = ctx.getBean("queryManager", QueryManagement.class);
    qMgr.setXQConnection(xqConn);
}
项目:translationstudio8    文件:SaxonSearcher.java   
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;
}
项目:tmxeditor8    文件:SaxonSearcher.java   
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;
}
项目:intellij-xquery    文件:SaxonXQDataSourceFactory.java   
@Override
public XQDataSource getXQDataSource(XQueryRunConfig config) throws Exception {
    if (config.isConfigFileEnabled()) {
        File configFile = new File(config.getConfigFile());
        Configuration configuration = Configuration.readConfiguration(new StreamSource(configFile));
        return new SaxonXQDataSource(configuration);
    }
    return new SaxonXQDataSource();
}
项目:intellij-xquery    文件:ConnectionFactory.java   
public XQConnection getConnection(XQDataSource dataSource) throws Exception {
    XQConnection connection;
    if (config.getDataSourceType().connectionPropertiesAreSupported()
            && config.getUsername() != null && config.getUsername().length() > 0) {
        connection = dataSource.getConnection(config.getUsername(), config.getPassword());
    } else {
        connection = dataSource.getConnection();
    }
    return connection;
}
项目:intellij-xquery    文件:XQJRunnerApp.java   
public void runApp() throws Exception {
    XQDataSource xqs = dataSourceFactory.getDataSource();
    XQConnection connection = null;
    try {
        connection = connectionFactory.getConnection(xqs);
        XQPreparedExpression preparedExpression = expressionFactory.getExpression(connection);
        XQResultSequence rs = preparedExpression.executeQuery();
        rs.writeSequence(output, outputMethodFactory.getOutputMethodProperties());
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
项目:intellij-xquery    文件:DataSourceFactoryTest.java   
@Before
public void setUp() {
    config = mock(XQueryRunConfig.class);
    dataSource = mock(XQDataSource.class);
    factory = new DataSourceFactory(config) {
        @Override
        public XQDataSource getXQDataSource(XQueryDataSourceType dataSourceType,
                                            XQueryRunConfig config) throws Exception {
            return dataSource;
        }
    };
}
项目:intellij-xquery    文件:DataSourceFactoryTest.java   
@Test
public void shouldGetDataSourceBasedOnDataSourceType() throws Exception {
    factory = new DataSourceFactory(config);
    given(config.getDataSourceType()).willReturn(XQueryDataSourceType.SEDNA);
    given(config.getHost()).willReturn("host");
    given(config.getPort()).willReturn("123");

    XQDataSource result = factory.getDataSource();

    assertThat(result, is(not(nullValue())));
}
项目:further-open-core    文件:XQueryUtil.java   
/**
 * Helper method to retrieve an {@link XQConnection} from a {@link XQDataSource}
 * 
 * @param xqDataSource
 *            the data source to retrieve the connection from
 * @return an XQConnection
 * @throws ApplicationException
 *             if the connection could not be retrieved
 */
public static XQConnection getConnection(final XQDataSource xqDataSource)
{
    try
    {
        return xqDataSource.getConnection();
    }
    catch (final XQException e)
    {
        throw new ApplicationException("Unable to get XQConnection", e);
    }
}
项目:mathosphere    文件:ServerTest.java   
@Test
public void testXQConnection() throws Exception {
    final Server srv = Server.getInstance();
    final URL fname = BaseXTestSuite.class.getClassLoader().getResource( "sampleHarvest.xml" );
    File file = new File(fname.toURI());
    srv.startup(file);
    final XQDataSource xqs = new BaseXXQDataSource();
    xqs.setProperty("serverName", Server.SERVER_NAME);
    xqs.setProperty("port", String.valueOf(Server.PORT));
    xqs.setProperty("databaseName", Server.DATABASE_NAME);
    xqs.setProperty("user", Client.USER);
    xqs.setProperty("password", Client.PASSWORD);

    final XQConnection conn = xqs.getConnection();
    try {
        final String query = "declare default element namespace \"http://www.w3.org/1998/Math/MathML\";\n" +
                "for $m in //*:expr return \n" +
                "for $x in $m//*:apply\n" +
                "[*[1]/name() = 'divide']\n" +
                "where\n" +
                "fn:count($x/*) = 3\n" +
                "return\n" +
                "<result>{$m/@url}</result>";

        final XQPreparedExpression xqpe = conn.prepareExpression( query );
        final XQResultSequence rs = xqpe.executeQuery();

        final String res = rs.getSequenceAsString( null );

        Assert.assertEquals( "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"4#math.4.5\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"4#math.4.5\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.2\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.17\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.18\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.18\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.19\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.19\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.19\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.20\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.21\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.22\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"5#math.5.23\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"6#math.6.11\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"6#math.6.14\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"6#math.6.15\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"6#math.6.15\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"6#math.6.15\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"6#math.6.15\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"6#math.6.20\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"7#math.7.0\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"7#math.7.1\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"7#math.7.1\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"7#math.7.2\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"7#math.7.2\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"7#math.7.3\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"7#math.7.3\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"7#math.7.4\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"8#math.8.6\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"8#math.8.7\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"8#math.8.21\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"8#math.8.22\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"8#math.8.23\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"8#math.8.33\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"8#math.8.34\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"8#math.8.35\"/> " +
                "<result xmlns=\"http://www.w3.org/1998/Math/MathML\" url=\"dummy29\"/>"
                , res );
    } finally {
        conn.close();
    }
}
项目:bagri    文件:XQJClientApp.java   
public XQJClientApp(Properties props) throws XQException {
    XQDataSource xqds = new BagriXQDataSource();
    xqds.setProperty(ADDRESS, props.getProperty(pn_schema_address));
    xqds.setProperty(SCHEMA, props.getProperty(pn_schema_name));
    xqds.setProperty(USER, props.getProperty(pn_schema_user));
    xqds.setProperty(PASSWORD, props.getProperty(pn_schema_password));
    xqds.setProperty(XQ_PROCESSOR, "com.bagri.xquery.saxon.XQProcessorClient");
    xqds.setProperty(XDM_REPOSITORY, "com.bagri.client.hazelcast.impl.SchemaRepositoryImpl");
    xqConn = xqds.getConnection();
}
项目:bagri    文件:BagriXQSequenceTest.java   
@Before
public void setUp() throws Exception {
    XQDataSource xqds = new BagriXQDataSource();
    xqds.setProperty(BagriXQDataSource.ADDRESS, "localhost:10500");
    xqds.setProperty(BagriXQDataSource.SCHEMA, "default");
    xqds.setProperty(BagriXQDataSource.USER, "guest");
    xqds.setProperty(BagriXQDataSource.PASSWORD, "password");
    xqds.setProperty(BagriXQDataSource.XQ_PROCESSOR, "com.bagri.xquery.saxon.XQProcessorClient");
    xqds.setProperty(BagriXQDataSource.XDM_REPOSITORY, "com.bagri.client.hazelcast.impl.SchemaRepositoryImpl");
    xqc = xqds.getConnection();
}
项目:bagri    文件:BagriXQItemAccessorTest.java   
@Before
public void setUp() throws Exception {
    XQDataSource xqds = new BagriXQDataSource();
    //xqds.setProperty(BagriXQDataSource.HOST, "127.0.0.1");
    //xqds.setProperty(BagriXQDataSource.PORT, "5701");
    xqds.setProperty(BagriXQDataSource.ADDRESS, "localhost:10500");
    xqds.setProperty(BagriXQDataSource.SCHEMA, "default");
    xqds.setProperty(BagriXQDataSource.USER, "guest");
    xqds.setProperty(BagriXQDataSource.PASSWORD, "password");
    xqds.setProperty(BagriXQDataSource.XQ_PROCESSOR, "com.bagri.xquery.saxon.XQProcessorClient");
    xqds.setProperty(BagriXQDataSource.XDM_REPOSITORY, "com.bagri.client.hazelcast.impl.SchemaRepositoryImpl");
    xqc = xqds.getConnection();
}
项目:bagri    文件:BagriXQDynamicContextTest.java   
@Before
public void setUp() throws Exception {
    XQDataSource xqds = new BagriXQDataSource();
    xqds.setProperty(BagriXQDataSource.ADDRESS, "localhost:10500");
    xqds.setProperty(BagriXQDataSource.SCHEMA, "default");
    xqds.setProperty(BagriXQDataSource.USER, "guest");
    xqds.setProperty(BagriXQDataSource.PASSWORD, "password");
    xqds.setProperty(BagriXQDataSource.XQ_PROCESSOR, "com.bagri.xquery.saxon.XQProcessorClient");
    xqds.setProperty(BagriXQDataSource.XDM_REPOSITORY, "com.bagri.client.hazelcast.impl.SchemaRepositoryImpl");
    xqc = xqds.getConnection();
}
项目:translationstudio8    文件:SaxonSearcher.java   
/**
 * 查询
 * @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();
        }
    }
}
项目:translationstudio8    文件:SaxonSearcher.java   
/**
     * 繁殖翻译文本段的查询 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();
            }
        }
    }
项目:translationstudio8    文件:SaxonSearcher.java   
/**
     * 测试过滤重复文本段    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();
            }
        }
    }
项目:tmxeditor8    文件:SaxonSearcher.java   
/**
 * 查询
 * @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();
        }
    }
}
项目:tmxeditor8    文件:SaxonSearcher.java   
/**
     * 繁殖翻译文本段的查询 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();
            }
        }
    }
项目:tmxeditor8    文件:SaxonSearcher.java   
/**
     * 测试过滤重复文本段    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();
            }
        }
    }
项目:intellij-xquery    文件:BaseXLocalXQDataSourceFactory.java   
@Override
public XQDataSource getXQDataSource(XQueryRunConfig config) throws Exception {
    return new BaseXXQDataSource();
}
项目:intellij-xquery    文件:MarklogicXQDataSourceFactory.java   
@Override
public XQDataSource getXQDataSource(XQueryRunConfig config) throws Exception {
    return new MarkLogicXQDataSource();
}
项目:intellij-xquery    文件:ExistXQDataSourceFactory.java   
@Override
public XQDataSource getXQDataSource(XQueryRunConfig config) throws Exception {
    return new ExistXQDataSource();
}
项目:intellij-xquery    文件:SednaXQDataSourceFactory.java   
@Override
public XQDataSource getXQDataSource(XQueryRunConfig config) throws Exception {
    return new SednaXQDataSource();
}
项目:intellij-xquery    文件:BaseXXQDataSourceFactory.java   
@Override
public XQDataSource getXQDataSource(XQueryRunConfig config) throws Exception {
    return new BaseXXQDataSource();
}
项目:intellij-xquery    文件:ZorbaXQDataSourceFactory.java   
@Override
public XQDataSource getXQDataSource(XQueryRunConfig config) throws Exception {
    return new ZorbaXQDataSource();
}
项目:intellij-xquery    文件:DataSourceFactory.java   
protected XQDataSource getXQDataSource(XQueryDataSourceType dataSourceType,
                                       XQueryRunConfig config) throws Exception {
    return getXQDataSourceFactory(dataSourceType).getXQDataSource(config);
}
项目:intellij-xquery    文件:ConnectionFactoryTest.java   
@Before
public void setUp() {
    dataSource = mock(XQDataSource.class);
    config = mock(XQueryRunConfig.class);
    factory = new ConnectionFactory(config);
}
项目:book-code    文件:QueryApp.java   
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();
        }
    }
}
项目:further-open-core    文件:XQueryUtil.java   
/**
 * Helper method to retrieve a {@link XQPreparedExpression} from a
 * {@link XQDataSource} and a String of XQuery.
 * 
 * @param xqDataSource
 *            the XQuery data source to use
 * @param xquery
 *            the XQuery program to create the {@link XQPreparedExpression} from
 * @return a XQPreparedExpression
 * @throws ApplicationException
 *             if there is an error creating the prepared expression
 */
public static XQPreparedExpression createPreparedExpression(
        final XQDataSource xqDataSource, final String xquery)
{
    return createPreparedExpression(xqDataSource,
            new ByteArrayInputStream(xquery.getBytes()));
}
项目:further-open-core    文件:XQueryUtil.java   
/**
 * Helper method to retrieve a {@link XQPreparedExpression} from a
 * {@link XQDataSource} and a {@link InputStream} of XQuery.
 * 
 * @param xqDataSource
 *            the XQuery data source to use
 * @param inputStream
 *            the XQuery program input stream to create the
 *            {@link XQPreparedExpression} from
 * @return a XQPreparedExpression
 * @throws ApplicationException
 *             if there is an error creating the prepared expression
 */
public static XQPreparedExpression createPreparedExpression(
        final XQDataSource xqDataSource, final InputStream inputStream)
{
    try
    {
        return getConnection(xqDataSource).prepareExpression(inputStream);
    }
    catch (final XQException e)
    {
        throw new ApplicationException("Unable to get XQPreparedExpression", e);
    }
}
项目:further-open-core    文件:XQueryDataSource.java   
/**
 * Return a new XQuery data source. Method-injected by Spring.
 * 
 * @return a new XQuery data source
 */
XQDataSource newXQDataSource();
项目:further-open-core    文件:XQueryUtil.java   
/**
 * Helper method to retrieve a {@link XQExpression} from a {@link XQDataSource}
 * 
 * @param xqDataSource
 *            the {@link XQDataSource} TO USE
 * @return a XQExpression
 * @throws ApplicationException
 *             if an exception occurs while trying to create the expression
 */
public static XQExpression createExpression(final XQDataSource xqDataSource)
{
    return createExpression(getConnection(xqDataSource));
}
项目:intellij-xquery    文件:XQDataSourceFactory.java   
XQDataSource getXQDataSource(XQueryRunConfig config) throws Exception;