hf.Yao

 
每一天,都有一些事情将会发生
每段路,都有即将要来的旅程
每颗心,都有值得期待的成分
每个人,都有爱上另一个人的可能
hf.Yao @ 2006-03-29 12:06

作为脆弱的一方。任何关于和解和共赢的想法都是幼稚的。除非你积累了足够反抗的资本,除非你的妥协能够引起对方的妥协。而所谓的共赢,对弱势群体而言,恐怕永远都是一种梦想和可耻的谎言。

所以,作为弱势群体的你,除了积累反抗的资本外,别无选择!


 
hf.Yao @ 2006-03-24 11:17

Log4j由三个重要的组件构成:日志信息的优先级,日志信息的输出目的地,日志信息的输出格式。日志信息的优先级从高到低有ERROR、WARN、INFO、DEBUG,分别用来指定这条日志信息的重要程度;日志信息的输出目的地指定了日志将打印到控制台还是文件中;而输出格式则控制了日志信息的显示内容。

3.1.定义配置文件

其实您也可以完全不使用配置文件,而是在代码中配置Log4j环境。但是,使用配置文件将使您的应用程序更加灵活。

Log4j支持两种配置文件格式,一种是XML格式的文件,一种是Java特性文件(键=值)。下面我们介绍使用Java特性文件做为配置文件的方法:

  1. 配置根Logger,其语法为:

    log4j.rootLogger = [ level ] , appenderName, appenderName, …

    其中,level 是日志记录的优先级,分为OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL或者您定义的级别。Log4j建议只使用四个级别,优先级从高到低分别是ERROR、WARN、INFO、DEBUG。通过在这里定义的级别,您可以控制到应用程序中相应级别的日志信息的开关。比如在这里定义了INFO级别,则应用程序中所有DEBUG级别的日志信息将不被打印出来。
    appenderName就是指定日志信息输出到哪个地方。您可以同时指定多个输出目的地。
  2. 配置日志信息输出目的地Appender,其语法为
    log4j.appender.appenderName = fully.qualified.name.of.appender.class
      log4j.appender.appenderName.option1 = value1
      …
      log4j.appender.appenderName.option = valueN
    其中,Log4j提供的appender有以下几种:
    org.apache.log4j.ConsoleAppender(控制台),
    org.apache.log4j.FileAppender(文件),
    org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件),org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生一个新的文件),
    org.apache.log4j.WriterAppender(将日志信息以流格式发送到任意指定的地方)
  3. 配置日志信息的格式(布局),其语法为:
    log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class
      log4j.appender.appenderName.layout.option1 = value1
      …
      log4j.appender.appenderName.layout.option = valueN
    其中,Log4j提供的layout有以下几种:
    org.apache.log4j.HTMLLayout(以HTML表格形式布局),
    org.apache.log4j.PatternLayout(可以灵活地指定布局模式),
    org.apache.log4j.SimpleLayout(包含日志信息的级别和信息字符串),
    org.apache.log4j.TTCCLayout(包含日志产生的时间、线程、类别等等信息)

3.2.在代码中使用Log4j

下面将讲述在程序代码中怎样使用Log4j。

3.2.1.得到记录器

使用Log4j,第一步就是获取日志记录器,这个记录器将负责控制日志信息。其语法为:

public static Logger getLogger( String name),

通过指定的名字获得记录器,如果必要的话,则为这个名字创建一个新的记录器。Name一般取本类的名字,比如:

static Logger logger = Logger.getLogger ( ServerWithLog4j.class.getName () ) ;

3.2.2.读取配置文件

当获得了日志记录器之后,第二步将配置Log4j环境,其语法为:
BasicConfigurator.configure (): 自动快速地使用缺省Log4j环境。
PropertyConfigurator.configure ( String configFilename) :读取使用Java的特性文件编写的配置文件。
DOMConfigurator.configure ( String filename ) :读取XML形式的配置文件。

3.2.3.插入记录信息(格式化日志信息)

当上两个必要步骤执行完毕,您就可以轻松地使用不同优先级别的日志记录语句插入到您想记录日志的任何地方,其语法如下:

Logger.debug ( Object message ) ;
Logger.info ( Object message ) ;
Logger.warn ( Object message ) ;
Logger.error ( Object message ) ; 

【引用于:http://www-128.ibm.com/developerworks/cn/java/l-log4j/index.html



 
hf.Yao @ 2006-03-23 15:20

The following is a brief description of the different utility classes provided by OSCore. Along with each short description is some example Java code that takes advantage of some of the features provided by each utility class. However, we recommend that you read the JavaDocs to completely discover all the methods and features each class provides.

  • TextUtils - useful functions for manipulating Strings. Examples include: extracting primitive types, verifying e-mail addresses, splitting and joining, escaping characters, hyperlinking text, indentation, etc.
  • XMLUtils - common XML functions such as parsing and printing DOM documents, performing XSL transformations and selecting nodes using XPATH.
  • EJBUtils - common EJB and JNDI based functions such as looking up and narrowing home interfaces and looking up entity-beans directly.
  • BeanUtils - useful methods for accessing values of objects using reflection.
  • MultipartException - a special type of Exception designed to be subclassed for holding many child Exceptions. Useful if validation can throw many Exceptions and they all need to be wrapped up into and report (for example).
  • Data - an Object wrapper for binary data.
  • OrderedMap - a java.util.Map implementation that retains the order items were added in.
  • DataUtil - a small class that helps convert Objects to their primitive types.
  • DateUtil - a small class for handling ISO 8601 International Date formats.

TextUtils

TextUtils provides helpers for common operations on text (mainly Strings and numbers).

int a = TextUtils.parseInt("1"); // returns 1
int b = TextUtils.parseInt("-45345"); // returns -45345
int c = TextUtils.parseInt("abc"); // returns 0 (instead of throwing    exception)
long d = TextUtils.parseLong("12345678901234");
float fl = TextUtils.parseFloat("123.456");
double db = TextUtils.parseDouble("12345678.901234");
boolean e = TextUtils.parseBoolean("yes"); // true
boolean f = TextUtils.parseBoolean("true"); // true
boolean g = TextUtils.parseBoolean("1"); // true
boolean h = TextUtils.parseBoolean("false"); // false
boolean i = TextUtils.parseBoolean("blah"); // false
int p = TextUtils.parseInt( TextUtils.extractNumber(",000,000 only!")    ); // 1000000
String lower = TextUtils.noNull(myStr).toLowerCase(); // prevent NullPointerException
// if myStr is null by returning ""
boolean v1 = TextUtils.verifyEmail("joe@bloggs.com"); // true
boolean v2 = TextUtils.verifyEmail("a.b-d.c@def.ghi.co.jp"); // true
boolean v3 = TextUtils.verifyEmail("nothing@blah"); // false
boolean v4 = TextUtils.verifyEmail("la la la"); // false
java.awt.Color col = TextUtils.hexToColor("#ff3300");
String hexCol = TextUtils.colorToHex( col.darker() );

 


EJBUtils

EJBUtils simply provides some shortcuts for common EJB/JNDI operations (namely looking up JNDI bound objects and narrowing them).

// standard method
Context ctx = new InitialContext();
Object obj = ctx.lookup("java:comp/env/ejb/MyBean");
MyBeanHome myBeanHome = (MyBeanHome)PortableRemoteObject.narrow( obj, MyBeanHome.class    );
// shortcut
MyBeanHome myBeanHome = (MyBeanHome) EJBUtils.lookup("ejb/MyBean",    MyBeanHome.class);

XMLUtils

XMLUtils provides common operations for parsing, printing, navigating, manipulating and transforming XML data. XMLUtils acts a wrapper to JAXP providers.

Document doc1 = XMLUtils.parse( new File("blah.xml") ); // parse    from file
Document doc2 = XMLUtils.parse( new URL("http://blah.com/blah.xml")    ); // parse from URL
Document doc3 = XMLUtils.parse( myReader ); // parse from Reader
..... // and so on...
// parse XML directly from String
Document doc = XMLUtils.parse( "<test name='blah'><nodes><x>hello</x><x>world</x></nodes></test>"    );
// retrieve first <x> node
Element xTag = (Element)XMLUtils.xpath( doc, "/test/nodes/x" );
// get contents of <x> tag ('hello')
String hello = XMLUtils.getElementText( xTag );
// return all <x> tags
NodeList xTags = XMLUtils.xpathList( doc, "/test/nodes/x" );
// create new document with root tag of <mydoc name='blah'>
Document newDoc = XMLUtils.newDocument("mydoc");
newDoc.getDocumentElement().setAttribute("name","blah");
// pretty-print DOM document into String
String final = XMLUtils.print(newDoc);
// perform XSL transformation, caching the compiled XSL
XMLUtils.transform( new FileReader("input.xml"),
new FileReader("input.xsl"),
new FileWriter("output.html") );
// clone the contents of xTag into a brand new document
Document anotherDoc = XMLUtils.newDocument();
XMLUtils.cloneNode( xTag, anotherDoc, true );

BeanUtils

BeanUtils provides a simple interface to accessing properties of an object. It is particularly useful for developing JSP Tags that need to read/write bean values.

//// setup fictional Person object for example
Person person = new Person();
person.setName("Bob");
person.setEmail("b@ob.com");
person.setAge(43);
person.setPassword("blah");
// add Address object to person
Address address = new Address();
address.setNumber(12);
address.setStreet("Bobby Street");
address.setTown("Bobsville");
address.setCountry("US");
person.setAddress(address);
// add Child objects to Collection
person.getChildren().add( new Child("Jane" );
person.getChildren().add( new Child("Bob Jnr" );
//// end of example setup
// access simple properties
String name = (String) BeanUtils.getValue( person, "name" ); // returns    "Bob"
String email = (String) BeanUtils.getValue( person, "email" ); //    returns "b@ob.com"
Address addr = (Address) BeanUtils.getValue( person, "address" );    // returns Address object
Integer age = (Integer) BeanUtils.getValue( person, "age" ); // returns    43
// access nested properties
String town = (String) BeanUtils.getValue( person, "address.town"    ); // returns "Bobsville"
Integer number = (Integer) BeanUtils.getValue( person, "address.number"    ); // returns 12
// access Collection (notice how methods and elements in Collections/arrays    can be accessed)
Integer childCount = (Integer) BeanUtils.getValue( person, "children.size()"    ); // returns 2
Iterator allChildren = (Iterator) BeanUtils.getValue( person, "children.iterator()"    );
// returns iteration of all children
Child firstChild = (Child) BeanUtils.getValue( person, "children[0]"    ); // returns 'Jane'
// set values
BeanUtils.setValue( person, "name", "Bobby" ); // person.setName("Bobby")
BeanUtils.setValue( person, "age", new Integer(44) ); // person.setAge(44)
BeanUtils.setValue( person, "address.town", "Newsville"    );
// person.getAddress().setTown("Newsville");
// accessing properties in bulk
Map personFields = BeanUtils.getValues( person, null ); // return Map containing    name/value
// pairs of all properties of person.
Map someFields = BeanUtils.getValues( person, {"name","email"}    ); // return Map containing name/value
// pairs of 'name' and 'email' properties
// only.

DataUtil

The DataUtil class offers a few static methods that convert objects that represent a primitive in to an actual primitive. If the object passed in is null, a default primitive value is returned (usually 0).

long myLong = DataUtil.getLong(new Long(10)); // myLong == 10
int myInt = DataUtil.getInt(null); // myInt == 0

DateUtil

The Internet is a truly International method of communicating - there are no political or cultural boundaries drawn on the www page you call up - the page could have been stored in the Smithsonian Institute or on a small server in a basement in Ulan Bator, Mongolia. Often, you have no way of telling. So, if anyone in the world can read your page, why not ensure that any date references on that page can be read correctly and unambiguously by that person, by using the ISO 8601:1988 International Date Format.

The basic format is: "CCYYMMDDThhmmsssss±nnn"

Characters used in place of digits or signs
 [Y]   represents a digit used in the time element year
 [M]   represents a digit used in the time element month
 [D]   represents a digit used in the time element day
 [T]   place holder denoting time
 [h]   represents a digit used in the time element hour
 [m]   represents a digit used in the time element minute
 [s]   represents a digit used in the time element second
 [n]   represents digit(s), constituting a positive integer or zero
 [±]   represents a plus sign [+] if in combination with the following element a positive value or zero needs to be represented, or a minus sign [­] if in combination with the following element a negative value needs to be represented.

The expanded format includes formating: "CCYY-MM-DDThh:mm:ss,sss±nnn"



 
hf.Yao @ 2006-03-20 16:19



今天上班的时候就感觉很累,然后又没什么事情做,于是就很不知道该干吗。不知道为什么,虽然知道有很多事情去做,但就有这么段时间不知道自己要去干吗,连平时最喜欢的书也懒的去看一眼。

迷糊了一早上,然后又迷糊了大半个下午,看似快要下班的样子。一天就这么过了,心想怎么说公司也付了我一天20快的工资的,好像突然觉得很对不起这个20快钱似的,决定在下班前做点什么。虽然公司都不发工资给我。


从抽屉里把oracle的书拿出来,第7章还有3页,把它看完。。。。。



 
hf.Yao @ 2006-02-24 14:13

用JS实现多级级联下拉框

基本思想:
   把下拉框的数据全部读出,并存放在JS的Array中。
   当选择下拉框的时候触发onChange()事件动态的添加级联
   下拉框的内容。
<html>  
<script language="javascript">
 var areaArray = new Array();
  areaArray[areaArray.length]=new Array("1","杭州");
  areaArray[areaArray.length]=new Array("2","湖州");
  areaArray[areaArray.length]=new Array("3","温州");
 var townArray = new Array();
  townArray[townArray.length]=new Array("1","1","上城区"); 
  townArray[townArray.length]=new Array("1","2","下城区"); 
  townArray[townArray.length]=new Array("2","3","南浔镇"); 
  townArray[townArray.length]=new Array("2","4","菱湖镇"); 
  townArray[townArray.length]=new Array("3","5","乐清"); 
  townArray[townArray.length]=new Array("3","6","苍南");  
 function setTown(obj1ID,obj2ID){
        var objArea = document.getElementById(obj1ID);
        var objTown = document.getElementById(obj2ID);
        var i;
        var itemArray = null;
        if(objArea.value.length > 0){
             itemArray = new Array();
             for(i=0;i<townArray.length;i++){
                if(townArray[i][0]==objArea.value){
                    itemArray[itemArray.length]=new Array(townArray[i][1],townArray[i][2]);
                }
             }
        }
        for(i = objTown.options.length ; i >= 0 ; i--){
                objTown.options[i] = null;
        }
        objTown.options[0] = new Option("请选地区");
        objTown.options[0].value = "";
  
        if(itemArray != null){
                for(i = 0 ; i < itemArray.length; i++){
                        objTown.options[i+1] = new Option(itemArray[i][1]);
                        if(itemArray[i][0] != null){
                           objTown.options[i].value = itemArray[i][0];
                        }
                }
        }
   }  
 
</script>
  <body>
   <table width="99%" border="0" align="center" style="border-bottom:1px solid #cccccc">
      <tr>
       <td width="10"><select name="areaid" id="areaid" onChange="setTown('areaid','townid')">
          <option value="">请选市县</option>
          <option value="1">杭州</option>
    <option value="2">湖州</option>
    <option value="3">温州</option>
   </select>
       </td>
 <td  width="10"><select name="townid" id="townid">
    <option value="">请选地区</option>
   </select>
 </td>     
      </tr>    
   </table>
  </body>
</html>  



 
网志分类
所有网志 (40)
我的心情 (24)
JAVA天地 (11)
Oracle的魅力 (2)
WebService (0)
Linux技术 (0)
乱啊七啊八啊糟啊 (1)
未分类 (2)
最新的评论
日历

站内搜索
友情链接
· 我的歪酷 · 秋天 · 可儿 ·

订阅 RSS

0011377

歪酷博客