OLD | NEW |
(Empty) | |
| 1 package org.chromium.distiller.webdocument; |
| 2 |
| 3 import java.util.HashSet; |
| 4 import java.util.Set; |
| 5 |
| 6 /** |
| 7 * This class represents HTML tags that need to be preserved over |
| 8 * the distillation process. |
| 9 */ |
| 10 public class WebTag extends WebElement { |
| 11 private String tagName; |
| 12 private TagType tagType; |
| 13 |
| 14 public enum TagType { |
| 15 START, END |
| 16 } |
| 17 |
| 18 private static Set<String> nestingTags; |
| 19 static { |
| 20 nestingTags = new HashSet<String>(); |
| 21 nestingTags.add("UL"); |
| 22 nestingTags.add("OL"); |
| 23 nestingTags.add("LI"); |
| 24 } |
| 25 |
| 26 public WebTag(String tagName, TagType tagType) { |
| 27 this.tagName = tagName; |
| 28 this.tagType = tagType; |
| 29 } |
| 30 |
| 31 public boolean isStartTag() { |
| 32 return tagType == TagType.START; |
| 33 } |
| 34 |
| 35 public String getTagName() { |
| 36 return tagName; |
| 37 } |
| 38 |
| 39 @Override |
| 40 public String generateOutput(boolean textOnly) { |
| 41 if (textOnly) { |
| 42 return ""; |
| 43 } |
| 44 return "<" + (isStartTag() ? "" : "/") + tagName + ">"; |
| 45 } |
| 46 |
| 47 public static boolean canBeNested(String tagName) { |
| 48 return nestingTags.contains(tagName); |
| 49 } |
| 50 } |
OLD | NEW |