View Javadoc
1   /* 
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   *
14   */
15  package org.esigate.parser.future;
16  
17  import java.io.IOException;
18  import java.util.concurrent.Future;
19  
20  import org.esigate.HttpErrorPage;
21  
22  /**
23   * An element represents a tag inside a document.
24   * 
25   * <p>
26   * This class is based on Element
27   * 
28   * @see org.esigate.parser.Element
29   * @author Nicolas Richeton
30   * 
31   */
32  public interface FutureElement {
33      /**
34       * Method called by the parser when it finds an opening tag.
35       * 
36       * @param tag
37       *            The tag
38       * @param ctx
39       *            The parser context
40       * @return true if the body of this tag should be evaluated
41       * @throws IOException
42       * @throws HttpErrorPage
43       */
44      boolean onTagStart(String tag, FutureParserContext ctx) throws IOException, HttpErrorPage;
45  
46      /**
47       * Method called by the parser when it finds the matching closing tag.
48       * 
49       * @param tag
50       *            The tag
51       * @param ctx
52       * @throws IOException
53       * @throws HttpErrorPage
54       */
55      void onTagEnd(String tag, FutureParserContext ctx) throws IOException, HttpErrorPage;
56  
57      /**
58       * @param e
59       * @param ctx
60       * @return <code>true</code> if error has been handled by this element and it should not be propagated further.
61       */
62      boolean onError(Exception e, FutureParserContext ctx);
63  
64      /**
65       * Method called by the parser when it finds characters between starting and closing tags.
66       * 
67       * @param csq
68       * @throws IOException
69       */
70      void characters(Future<CharSequence> csq) throws IOException;
71  
72      /**
73       * Get the parent element of this element.
74       * 
75       * @return the parent Element or null if this item is the Root element.
76       */
77      FutureElement getParent();
78  }