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.extension.parallelesi;
16  
17  import java.io.IOException;
18  import java.util.concurrent.Future;
19  
20  import org.esigate.HttpErrorPage;
21  import org.esigate.parser.future.FutureElement;
22  import org.esigate.parser.future.FutureParserContext;
23  
24  abstract class BaseElement implements FutureElement {
25      private FutureElement parent = null;
26  
27      protected BaseElement() {
28      }
29  
30      /**
31       * Additional tag initialization callback.
32       * 
33       * @throws HttpErrorPage
34       * @throws IOException
35       * 
36       **/
37      protected boolean parseTag(Tag tag, FutureParserContext ctx) throws HttpErrorPage, IOException {
38          // Default implementation does nothing
39          return true;
40      }
41  
42      @Override
43      public boolean onTagStart(String tag, FutureParserContext ctx) throws IOException, HttpErrorPage {
44          Tag tagObj = Tag.create(tag);
45          this.parent = ctx.getCurrent();
46          return parseTag(tagObj, ctx);
47      }
48  
49      @Override
50      public boolean onError(Exception e, FutureParserContext ctx) {
51          return false;
52      }
53  
54      @Override
55      public void characters(Future<CharSequence> csq) throws IOException {
56          this.parent.characters(csq);
57      }
58  
59      @Override
60      public FutureElement getParent() {
61          return this.parent;
62      }
63  
64  }