01: package com.meterware.httpunit;
02:
03: /********************************************************************************************************************
04: * $Id: WebList.java,v 1.2 2004/09/29 17:15:25 russgold Exp $
05: *
06: * Copyright (c) 2004, Russell Gold
07: *
08: * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
09: * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
10: * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
11: * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included in all copies or substantial portions
14: * of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
17: * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19: * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20: * DEALINGS IN THE SOFTWARE.
21: *
22: *******************************************************************************************************************/
23:
24: import org.w3c.dom.Element;
25:
26: import java.net.URL;
27: import java.util.ArrayList;
28:
29: import com.meterware.httpunit.scripting.ScriptableDelegate;
30:
31: /**
32: * Represents an HTML list. Experimental.
33: *
34: * @author <a href="mailto:russgold@httpunit.org">Russell Gold</a>
35: * @since 1.6
36: **/
37: public class WebList extends HTMLElementBase {
38:
39: /** Indicator of an ordered list (HTML tag <ol>) */
40: public static final int ORDERED_LIST = 1;
41:
42: /** Indicator of a bullet list (HTML tag <ul>) */
43: public static final int BULLET_LIST = 2;
44:
45: private WebResponse _response;
46: private FrameSelector _frame;
47: private URL _baseURL;
48: private String _baseTarget;
49: private String _characterSet;
50:
51: private ArrayList _items = new ArrayList();
52: private int _listType;
53:
54: public WebList(WebResponse response, FrameSelector frame,
55: URL baseURL, String baseTarget, Element element,
56: String characterSet) {
57: super (element);
58: if (element.getNodeName().equalsIgnoreCase("ol")) {
59: _listType = ORDERED_LIST;
60: } else if (element.getNodeName().equalsIgnoreCase("ul")) {
61: _listType = BULLET_LIST;
62: }
63: _response = response;
64: _frame = frame;
65: _baseURL = baseURL;
66: _baseTarget = baseTarget;
67: _characterSet = characterSet;
68: }
69:
70: public int getListType() {
71: return _listType;
72: }
73:
74: public TextBlock[] getItems() {
75: return (TextBlock[]) _items
76: .toArray(new TextBlock[_items.size()]);
77: }
78:
79: protected ScriptableDelegate newScriptable() {
80: return new HTMLElementScriptable(this );
81: }
82:
83: protected ScriptableDelegate getParentDelegate() {
84: return _response.getScriptableObject().getDocument();
85: }
86:
87: TextBlock addNewItem(Element element) {
88: TextBlock listItem = new TextBlock(_response, _frame, _baseURL,
89: _baseTarget, element, _characterSet);
90: _items.add(listItem);
91: return listItem;
92: }
93: }
|