Листинг 4.16. Статические переменные класса ProductFormatter (ProductFormatter.java)
package com.XmlEcomBook.catalog;
import java.util.* ;
import java.io.* ;
import org.xml.sax.* ;
import org.w3c.dom.* ;
public class ProductFormatter
{
static String brcrlf = "<br /> \r\n" ; // xhtml style br
static String[] shortEl = { "prname", "price" // for product name
};
static String[] shortSt = { "ch3", "ch4"
};
// as used in doListOutput
static String[] fullEl = { "prname",
"author","artist","description",
"price" // for product name
};
static String[] fullSt = { "ch3",
"au1", "au1", "ch4", "ch4"
};
static Hashtable fieldHash ;
// field names for lookup
static String[] fields = { "id", "keywords",
"prname", "price", "author", "artist", "description",
"image", "caption", "quantity_in_stock", "onsale_date",
"shipping_info"
} ;
static { fieldHash = new Hashtable() ;
for( int i = 0 ; i < fields.length ; i++ ){
fieldHash.put( fields[i], new Integer( i ) );
}
}
В листинге 4.17 показано начало кода для методов и переменных экземпляра и конструктора ProductFormatter. Заметим, что конструктор задает формат в соответствии с переданной ему переменной frmt, которая может принимать значение "short" или "full".