posts - 161, comments - 175, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

2008年6月4日



     public   static  String filter(String input) {
        
if  (input  ==   null ) {
            
return   null ;
        }
        StringReader stringReader 
=   new  StringReader(input);
        BufferedReader reader 
=   new  BufferedReader(stringReader);

        StringBuffer ret 
=   new  StringBuffer(input.length()  +   200 ); //  add more room to the result String

        String line 
=   null ;
        
try  {
            //换行后添加<br/>
            
while  ((line  =  reader.readLine())  !=   null ) {
                //wap 对 <  >的替换
                ret.append(line.replaceAll(
" < " " &lt; " ).replaceAll( " > " " &gt; " ). replaceAll( "&""&amp;" ) ).append( " <br/>&nbsp;&nbsp; " );
            }
// while
            
// 如果是最后一行
        }  catch  (IOException ex) {}

       
return   " &nbsp;&nbsp; " + ret.toString() ;

    }

    

posted @ 2008-06-04 17:19 G_G 阅读(85) | 评论 (0)编辑 收藏

官方:
BaseX Logo
eg:xquery使用
import org.basex.core.Commands;
import org.basex.core.proc.Proc;
import org.basex.data.Result;
import org.basex.io.ConsoleOutput;
import org.basex.query.QueryException;
import org.basex.query.QueryProcessor;
import org.basex.query.xquery.XQueryProcessor;

/**
 * This class serves an example for executing XQuery requests.
 
*/
public final class XQueryExample {
  
/** Sample query. */
  
private static final String XMLFILE = XPathExample.class.getClassLoader().getSystemResource(
              
"xx.xml"
         ).getPath();
  
  
  
private static final String QUERY = " for $x in doc('"+XMLFILE+"')//property " +
                                              
" return <child>{data($x/@name)}</child>";

  
/** Private constructor. */
  
private XQueryExample() { }
  
/**
   * Main method of the example class.
   * 
@param args (ignored) command-line arguments
   * 
@throws Exception exception
   
*/
  
public static void main(final String[] args) throws Exception {

    
// FIRST EXAMPLE:
    System.out.println("First example:");

    
// create standard output stream
    final ConsoleOutput out = new ConsoleOutput(System.out);

    
// Create a BaseX process
    final Proc proc = Proc.get(Commands.XQUERY, QUERY);
    
// launch process
    if(proc.execute()) {
      
// successful execution: print result
      proc.output(out);
    } 
else {
      
// execution failed: print result
      proc.info(out);
    }
    out.flush();
    System.out.println();
    
    
// SECOND EXAMPLE (ALTERNATIVE):
    System.out.println("Second example:");

    
// Execute XQuery request
    try {
      
// create query instance
      final QueryProcessor xquery = new XQueryProcessor(QUERY);
      
// execute query; no initial context set is specified (null)
      final Result result = xquery.query(null);
      
// print output
      result.serialize(out, false);
      out.println();
    } 
catch(final QueryException e) {
      
// dump stack trace
      e.printStackTrace();
    }

    
// close output stream
    out.close();
  }
}


结果:
First example:
<child>connection.datasource</child>
<child>dialect</child>
<child>show_sql</child>
<child>hibernate.cache.provider_class</child>
<child>cache.use_query_cache</child>

Second example:
<child>connection.datasource</child>
<child>dialect</child>
<child>show_sql</child>
<child>hibernate.cache.provider_class</child>
<child>cache.use_query_cache</child>


数据来源:
xx.xml
<?xml version='1.0' encoding='utf-8'?>

<hibernate-configuration>

    
<session-factory>

        
<property name="connection.datasource">java:comp/env/jdbc/USERPORTAL1</property>
        
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
         
<property name="show_sql">true</property>
         
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
         
<property name="cache.use_query_cache">true</property>
    
<!-- JDBC connection pool (use the built-in) -->

    
</session-factory>

</hibernate-configuration>


posted @ 2008-06-04 16:04 G_G 阅读(1154) | 评论 (0)编辑 收藏