Comment.java

  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. import java.io.IOException;

  17. import org.esigate.HttpErrorPage;
  18. import org.esigate.parser.ElementType;
  19. import org.esigate.parser.ParserContext;

  20. /**
  21.  * This is a special construct to allow HTML marked up with ESI to render without processing. ESI Processors will remove
  22.  * the start ("<!--esi") and end ("-->") when the page is processed, while still processing the contents. If the
  23.  * page is not processed, it will remain, becoming an HTML/XML comment tag.
  24.  *
  25.  * @author Francois-Xavier Bonnet
  26.  * @see <a href="http://www.w3.org/TR/esi-lang">ESI Language Specification 1.0</a>
  27.  *
  28.  */
  29. class Comment extends BaseElement {
  30.     public static final ElementType TYPE = new BaseElementType("<!--esi", "-->") {
  31.         @Override
  32.         public Comment newInstance() {
  33.             return new Comment();
  34.         }

  35.         @Override
  36.         public boolean isSelfClosing(String tag) {
  37.             return false;
  38.         }

  39.     };

  40.     Comment() {
  41.     }

  42.     @Override
  43.     public boolean onTagStart(String tag, ParserContext ctx) throws IOException, HttpErrorPage {
  44.         // do not try to parse tag string
  45.         super.onTagStart("<esi!-->", ctx);
  46.         return true;
  47.     }

  48.     @Override
  49.     public void onTagEnd(String tag, ParserContext ctx) {
  50.         // Nothing to do
  51.     }
  52. }