Методы, используемые...
Листинг 4.18. Методы, используемые для полного описания товара (Product Formatter.java)
public String doImageTag( Element el ){
NodeList nl = el.getElementsByTagName( "image" );
int ct = nl.getLength();
if( ct == 0 ) { return null ;
}
Element img = (Element)nl.item(0);
StringBuffer sb = new StringBuffer( );
addText( sb, "image", img );
return sb.toString();
}
// element is the complete product
public String doProdName( Element el ){
NodeList nl = el.getElementsByTagName( "name" );
if( nl.getLength() == 0 ) return "";
StringBuffer sb = new StringBuffer( );
sb.append( "<span class=\"");
sb.append( "ch3" );
sb.append("\">
");
addText( sb, "prname", (Element)nl.item(0) );
sb.append( " </span>
<br />
");
return sb.toString();
}
// element is the complete product
public String doAuthorArtist( Element el ){
NodeList unl = el.getElementsByTagName( "author" );
NodeList rnl = el.getElementsByTagName( "artist" );
if( rnl.getLength() == 0 &&
unl.getLength() == 0 ) return "";
StringBuffer sb = new StringBuffer( );
int i ;
int ct = rnl.getLength();
if( ct >
0 ){
sb.append("<span class=\"au1\" >
" );
if( ct == 1 ) sb.append( "<i>
Artist:</i>
" );
else sb.append("<i>
Artists:>
/i>
");
for( i = 0 ; i < ct ; i++ ){
addText( sb, "artist",(Element) rnl.item(i) );
if( ct >
1 && ( i + 1) < ct ) sb.append(", ");
}
sb.append("<br />
");
}
ct = unl.getLength();
if( ct >
0 ){
sb.append("<span class=\"au1\" >
" );
if( ct == 1 ) sb.append( "<i>
Author:</i>
" );
else sb.append("<i>
Authors:</i>
");
for( i = 0 ; i < unl.getLength() ; i++ ){
addText( sb, "author",(Element) unl.item(i) );
if( ct >
1 && ( i + 1) < ct ) sb.append(", ");
}
sb.append("<br />
");
}
return sb.toString();
}
// element is the complete product
public String doDescription( Element el ){
NodeList nl = el.getElementsByTagName( "description" );
if( nl.getLength() == 0 ) return "No Description Available";
StringBuffer sb = new StringBuffer( );
addText( sb, "description",(Element) nl.item(0) );
return sb.toString();
}
public String doPrice( Element el ){
NodeList nl = el.getElementsByTagName( "price" );
if( nl.getLength() == 0 ) return "Contact XMLgifts";
StringBuffer sb = new StringBuffer( );
addText( sb, "price", el );
return sb.toString();
}
Содержание раздела