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.esi;
16  
17  import java.io.IOException;
18  
19  import org.esigate.HttpErrorPage;
20  import org.esigate.parser.Element;
21  import org.esigate.parser.ParserContext;
22  
23  abstract class BaseElement implements Element {
24      private Element parent = null;
25  
26      protected BaseElement() {
27      }
28  
29      /** Additional tag initialization callback. */
30      protected boolean parseTag(Tag tag, ParserContext ctx) throws HttpErrorPage {
31          // Default implementation does nothing
32          return true;
33      }
34  
35      @Override
36      public boolean onTagStart(String tag, ParserContext ctx) throws IOException, HttpErrorPage {
37          Tag tagObj = Tag.create(tag);
38          parent = ctx.getCurrent();
39          return parseTag(tagObj, ctx);
40      }
41  
42      @Override
43      public boolean onError(Exception e, ParserContext ctx) {
44          return false;
45      }
46  
47      /*
48       * (non-Javadoc)
49       * 
50       * @see org.esigate.parser.Element#characters(java.lang.CharSequence, int, int)
51       */
52      @Override
53      public void characters(CharSequence csq, int start, int end) throws IOException {
54          parent.characters(csq, start, end);
55      }
56  
57  }