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; 16 17 import java.io.IOException; 18 19 import org.esigate.HttpErrorPage; 20 21 /** 22 * An element represents a tag inside a document. 23 * 24 * @author Francois-Xavier Bonnet 25 * 26 */ 27 public interface Element { 28 /** 29 * Method called by the parser when it finds an opening tag. 30 * 31 * @param tag 32 * The tag 33 * @param ctx 34 * The parser context 35 * @return true if the body of this tag should be evaluated 36 * @throws IOException 37 * @throws HttpErrorPage 38 */ 39 boolean onTagStart(String tag, ParserContext ctx) throws IOException, HttpErrorPage; 40 41 /** 42 * Method called by the parser when it finds the matching closing tag. 43 * 44 * @param tag 45 * The tag 46 * @param ctx 47 * @throws IOException 48 * @throws HttpErrorPage 49 */ 50 void onTagEnd(String tag, ParserContext ctx) throws IOException, HttpErrorPage; 51 52 /** 53 * @param e 54 * @param ctx 55 * @return <code>true</code> if error has been handled by this element and it should not be propagated further. 56 */ 57 boolean onError(Exception e, ParserContext ctx); 58 59 /** 60 * Method called by the parser when it finds characters between starting and closing tags. 61 * 62 * @param csq 63 * the {@link CharSequence} to append 64 * @param start 65 * the start index in the {@link CharSequence}. Allows to append only a subset of the 66 * {@link CharSequence}. 67 * @param end 68 * the end index in the {@link CharSequence}. Allows to append only a subset of the {@link CharSequence}. 69 * @throws IOException 70 */ 71 void characters(CharSequence csq, int start, int end) throws IOException; 72 73 }