Есть класс который генерит тег :
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
public class Pie3DTag extends TagSupport{
private Vector datasetValues;
private int index;
private String title;
public void setDatasetValues(Vector pDatasetValues) {
this .datasetValues = pDatasetValues;
}
public Vector getDatasetValues() {
return this .datasetValues;
}
public void setIndex( int pIndex) {
this .index = pIndex;
}
public int getIndex() {
return this .index;
}
public void setTitle(String pTitle) {
this .title = pTitle;
}
public String getTitle() {
return this .title;
}
// Get pie with necessary properties
public pieApp getPie() {
Iterator iterator = getDatasetValues().iterator();
//int value = 0;
String stringOfValues = "";
while (iterator.hasNext()) {
int value = ((Integer)iterator.next()).intValue();
stringOfValues = stringOfValues + new String( String.valueOf(value) + ",");
}
pieApp pie3D = new pieApp();
pie3D.setProperty("mapName", "pieMap");
pie3D.setProperty("width", "200");
pie3D.setProperty("height", "130");
pie3D.setProperty("pieWidth", "0.94");
pie3D.setProperty("pieHeight", "0.78");
pie3D.setProperty("xLoc", "0.50");
pie3D.setProperty("yLoc", "0.56");
pie3D.setProperty("antialiasOn", "true");
pie3D.setProperty("startDegrees", "25");
pie3D.setProperty("percentLabelsOff", "true");
pie3D.setProperty("backgroundColor", "DCDCDC");
pie3D.setProperty("3D", "true");
pie3D.setProperty("YDepth", "22");
pie3D.setProperty("dataset0yValues",stringOfValues);
pie3D.setProperty("dataset0Colors", "FFA500, FF7F50, DC143C, A52A2A");
pie3D.setProperty("toolTips", "true");
pie3D.setProperty("useLinkMap", "true");
pie3D.setProperty("dataset0Links", "1.html,2.html,3.html,4.html");
pie3D.setProperty("dwellUseXValue", "false");
pie3D.setProperty("dwellYString", "value: XX");
pie3D.setProperty("writeDirectory", pageContext.getServletContext().getRealPath("cache"));
pie3D.setProperty("readDirectory", pageContext.getServletContext().getRealPath("cache"));
return pie3D;
}
// Out pie
public void outPie(pieApp pPie3D) {
String fileName = "";
String linkMap = "";
try {
linkMap = pPie3D.getLinkMap();
fileName = pPie3D.getProperty("readDirectory") + "/" +pPie3D.getFileName();
} catch (Exception e) {
System.out.println("Error in Pie3DTag" + e.getMessage());
}
JspWriter out = pageContext.getOut();
try {
out.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#DCDCDC\" >");
out.println("<tr>");
out.println("<td>");
out.println(linkMap);
out.println("<img src=" + fileName);
out.println("BORDER=0 ISMAP USEMAP=\"#pieMap\">");
out.println("</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td align=\"center\" >");
out.println("<font size=\"5\" color=\"#CD853F\" face=\"Arial\" ><B>" + getDatasetValues().get(getIndex()) + "</B></font> <font size=\"2\" color=\"A9A9A9\" face=\"Arial\">" + getTitle() + "</font>");
out.println("</td>");
out.println("</tr>");
out.println("</table>");
} catch (IOException ioe) {
System.out.println("Error in Pie3DTag" + ioe.getMessage());
}
}
// Start Tag
public int doStartTag() throws JspException {
pieApp pie3D = getPie();
outPie(pie3D);
return EVAL_BODY_INCLUDE;
}
// End Tag
public int doEndTag() throws JspException {
return EVAL_PAGE;
}
}
есть класс который тестирует Pie3DTag с помощью Cactus :
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
public class Pie3DTagTestCactus extends JspTestCase {
private Pie3DTag tag;
public Pie3DTagTestCactus(String name) {
super (name);
}
public void setUp() throws Exception {
tag = new Pie3DTag();
BodyContent bodyContent = pageContext.pushBody();
//pageContext.getServletContext().setAttribute("cache", "/");
//tag.setPageContext(pageContext);
}
public void testTag() {
Vector dataset = new Vector();
dataset.add( 0 , new Integer( 110 ));
dataset.add( 1 , new Integer( 65 ));
dataset.add( 2 , new Integer( 60 ));
dataset.add( 3 , new Integer( 90 ));
tag.setDatasetValues(dataset);
tag.setIndex( 1 );
tag.setTitle("My title");
try {
assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
} catch (JspException e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
public void endTag(WebResponse response) throws IOException, ParserConfigurationException, SAXException, TransformerException {
String outputXhtml = response.getText();
try {
XMLAssert.assertXpathExists("//table", outputXhtml);
XMLAssert.assertXpathEvaluatesTo("0", "//table/@border", outputXhtml);
}
catch (SAXException e) {
fail("Wrong XHTML code: " + e);
}
}
}
И после тестирования генериться
war файл.
но тестирование постоянно валиться на строке :
1.
pie3D.setProperty("writeDirectory", pageContext.getServletContext().getRealPath("cache"));
так во время тестирования не известная ссылка(null)
pageContext.getServletContext().getRealPath("cache"))
но я узнал что с помомощью метода :
tag.setPageContext(pageContext);
можна задать pageContext но
не знаю как в нем можна задать путь к папке cache
Может кто знает как это сделать????
Зарание благодарен за Ваше внимание.