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   * Handle unknown tag.
24   * 
25   * @author Alexis thaveau
26   */
27  public class UnknownElement implements FutureElement {
28      /***
29       * UnknownElement type.
30       */
31      public static final FutureElementType TYPE = new FutureElementType() {
32  
33          private final UnknownElement instance = new UnknownElement();
34  
35          @Override
36          public boolean isStartTag(String tag) {
37              return true;
38          }
39  
40          @Override
41          public boolean isEndTag(String tag) {
42              return false;
43          }
44  
45          @Override
46          public FutureElement newInstance() {
47              return instance;
48          }
49  
50          @Override
51          public boolean isSelfClosing(String tag) {
52              return true;
53          }
54      };
55  
56      @Override
57      public boolean onTagStart(String tag, FutureParserContext ctx) throws IOException, HttpErrorPage {
58  
59          ctx.characters(new CharSequenceFuture(tag));
60          return true;
61      }
62  
63      @Override
64      public void onTagEnd(String tag, FutureParserContext ctx) throws IOException, HttpErrorPage {
65  
66      }
67  
68      @Override
69      public boolean onError(Exception e, FutureParserContext ctx) {
70          return false;
71      }
72  
73      @Override
74      public void characters(Future<CharSequence> csq) throws IOException {
75          throw new UnsupportedOperationException("characters are appended in onTagStart method");
76      }
77  
78      @Override
79      public FutureElement getParent() {
80          return null;
81      }
82  }