1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.devacfr.maven.skins.reflow.snippet;
20
21 import com.google.common.base.MoreObjects;
22 import org.jsoup.nodes.Element;
23
24 /**
25 * @author Christophe Friederich
26 * @version 2.4
27 */
28 public class ComponentToken {
29
30 /**
31 * @author Christophe Friederich
32 * @version 2.4
33 */
34 public enum Tag {
35 /** empty-tag */
36 empty,
37 /** start-tag */
38 start,
39 /** end-tag */
40 end,
41 /** end-tag */
42 html
43 }
44
45 /**
46 * type of snippet component
47 *
48 * @author Christophe Friederich
49 * @version 2.4
50 */
51 public enum Type {
52 /** web component */
53 webComponent,
54 /** shortcode component */
55 shortcode
56 }
57
58 /** */
59 private final Element element;
60
61 /** */
62 private final Tag tag;
63
64 /** */
65 private final Type type;
66
67 /** */
68 private final String name;
69
70 /**
71 * @param tag
72 * @param type
73 */
74 public ComponentToken(final Element element, final String name, final Tag tag, final Type type) {
75 this.element = element;
76 this.name = name;
77 this.tag = tag;
78 this.type = type;
79 }
80
81 public Element getElement() {
82 return element;
83 }
84
85 public String name() {
86 return name;
87 }
88
89 public Type type() {
90 return type;
91 }
92
93 public Tag tag() {
94 return tag;
95 }
96
97 public boolean isCloseTagOf(final ComponentToken startElement) {
98 return name.equals(startElement.name) && type.equals(startElement.type) && Tag.start.equals(startElement.tag)
99 && Tag.end.equals(tag);
100 }
101
102 /**
103 * {@inheritDoc}
104 */
105 @Override
106 public String toString() {
107 return MoreObjects.toStringHelper(this).add("name", name).add("type", type).add("tag", tag).toString();
108 }
109 }