01: package com.meterware.httpunit;
02:
03: /********************************************************************************************************************
04: * $Id: TextBlock.java,v 1.2 2004/09/29 17:15:24 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: import org.w3c.dom.Node;
24:
25: import java.net.URL;
26: import java.util.ArrayList;
27:
28: /**
29: * A class which represents a block of text in a web page. Experimental.
30: *
31: * @author <a href="mailto:russgold@httpunit.org">Russell Gold</a>
32: * @since 1.6
33: **/
34: public class TextBlock extends BlockElement {
35:
36: private ArrayList _lists = new ArrayList();
37: /** Predicate to match part or all of a block's class attribute. **/
38: public final static HTMLElementPredicate MATCH_CLASS;
39: /** Predicate to match the tag associated with a block (case insensitive). **/
40: public final static HTMLElementPredicate MATCH_TAG;
41:
42: public TextBlock(WebResponse response, FrameSelector frame,
43: URL baseURL, String baseTarget, Node rootNode,
44: String characterSet) {
45: super (response, frame, baseURL, baseTarget, rootNode,
46: characterSet);
47: }
48:
49: /**
50: * Returns any lists embedded in this text block.
51: */
52: public WebList[] getLists() {
53: return (WebList[]) (_lists.toArray(new WebList[_lists.size()]));
54: }
55:
56: void addList(WebList webList) {
57: _lists.add(webList);
58: }
59:
60: String[] getFormats(int characterPosition) {
61: return null;
62: }
63:
64: static {
65: MATCH_CLASS = new HTMLElementPredicate() {
66: public boolean matchesCriteria(Object htmlElement,
67: Object criteria) {
68: if (criteria == null)
69: criteria = "";
70: return ((BlockElement) htmlElement).getClassName()
71: .equalsIgnoreCase(criteria.toString());
72: };
73: };
74:
75: MATCH_TAG = new HTMLElementPredicate() {
76: public boolean matchesCriteria(Object htmlElement,
77: Object criteria) {
78: if (criteria == null)
79: criteria = "";
80: return criteria.toString().equalsIgnoreCase(
81: ((BlockElement) htmlElement).getTagName());
82: };
83: };
84: }
85: }
|