mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-09 08:52:51 +00:00
Inventory open implementation, Html updates, Pathing generator,
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -22,8 +22,9 @@ import org.htmlparser.tags.BodyTag;
|
||||
import org.htmlparser.util.NodeList;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* Lineage 2 {@link Tag}: <tt>body</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2BodyTag extends BodyTag {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -17,21 +17,17 @@
|
||||
package com.l2jserver.util.html;
|
||||
|
||||
import org.htmlparser.Tag;
|
||||
import org.htmlparser.nodes.TagNode;
|
||||
import org.htmlparser.tags.Span;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* Lineage 2 {@link Tag}: <tt>br</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2BrTag extends Span {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public L2BrTag() {
|
||||
super.setTagName("br");
|
||||
Tag end = new TagNode();
|
||||
end.setTagName("/br");
|
||||
super.setEndTag(end);
|
||||
super.setEmptyXmlTag(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@ import org.htmlparser.nodes.TagNode;
|
||||
import org.htmlparser.tags.Span;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* Lineage 2 {@link Tag}: <tt>center</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2CenterTag extends Span {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -22,8 +22,9 @@ import org.htmlparser.tags.Div;
|
||||
import org.htmlparser.util.NodeList;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* Lineage 2 {@link Tag}: <tt>div</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2DivTag extends Div {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -22,8 +22,9 @@ import org.htmlparser.tags.Span;
|
||||
import org.htmlparser.util.NodeList;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* Lineage 2 {@link Tag}: <tt>font</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2FontTag extends Span {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.htmlparser.tags.HeadTag;
|
||||
import org.htmlparser.util.NodeList;
|
||||
|
||||
/**
|
||||
* Lineage 2 {@link Tag}: <tt>head</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2HeadTag extends HeadTag {
|
||||
|
||||
@@ -22,8 +22,9 @@ import org.htmlparser.tags.Html;
|
||||
import org.htmlparser.util.NodeList;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* Lineage 2 {@link Tag}: <tt>html</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2HtmlTag extends Html {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -21,6 +21,8 @@ import org.htmlparser.nodes.TagNode;
|
||||
import org.htmlparser.tags.ImageTag;
|
||||
|
||||
/**
|
||||
* Lineage 2 {@link Tag}: <tt>img</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2ImageTag extends ImageTag {
|
||||
@@ -31,6 +33,5 @@ public class L2ImageTag extends ImageTag {
|
||||
Tag end = new TagNode();
|
||||
end.setTagName("/img");
|
||||
super.setEndTag(end);
|
||||
super.setEmptyXmlTag(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.htmlparser.tags.LinkTag;
|
||||
import org.htmlparser.util.NodeList;
|
||||
|
||||
/**
|
||||
* Lineage 2 {@link Tag}: <tt>a</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2LinkTag extends LinkTag {
|
||||
@@ -33,6 +35,5 @@ public class L2LinkTag extends LinkTag {
|
||||
end.setTagName("/a");
|
||||
super.setEndTag(end);
|
||||
super.setChildren(new NodeList());
|
||||
super.setEmptyXmlTag(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,21 +17,17 @@
|
||||
package com.l2jserver.util.html;
|
||||
|
||||
import org.htmlparser.Tag;
|
||||
import org.htmlparser.nodes.TagNode;
|
||||
import org.htmlparser.tags.Span;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* Lineage 2 {@link Tag}: <tt>p</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2NewLineTag extends Span {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public L2NewLineTag() {
|
||||
super.setTagName("p");
|
||||
Tag end = new TagNode();
|
||||
end.setTagName("/pp");
|
||||
super.setEndTag(end);
|
||||
super.setEmptyXmlTag(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.htmlparser.tags.TitleTag;
|
||||
import org.htmlparser.util.NodeList;
|
||||
|
||||
/**
|
||||
* Lineage 2 {@link Tag}: <tt>title</tt>
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class L2TitleTag extends TitleTag {
|
||||
|
||||
151
src/main/java/com/l2jserver/util/html/markup/HtmlTemplate.java
Normal file
151
src/main/java/com/l2jserver/util/html/markup/HtmlTemplate.java
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* This file is part of l2jserver <l2jserver.com>.
|
||||
*
|
||||
* l2jserver is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.util.html.markup;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.htmlparser.Tag;
|
||||
import org.htmlparser.nodes.TextNode;
|
||||
import org.htmlparser.tags.HeadTag;
|
||||
import org.htmlparser.tags.Html;
|
||||
import org.htmlparser.tags.TitleTag;
|
||||
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
import com.l2jserver.util.html.L2BodyTag;
|
||||
import com.l2jserver.util.html.L2HeadTag;
|
||||
import com.l2jserver.util.html.L2HtmlTag;
|
||||
import com.l2jserver.util.html.L2TitleTag;
|
||||
|
||||
/**
|
||||
* This an helper class used to build HTML documents. You should implement
|
||||
* {@link HtmlTemplate} as an anonymous class:
|
||||
*
|
||||
* <pre>
|
||||
* final HtmlTemplate template = new HtmlTemplate("Template implementation sample") {
|
||||
* @Override
|
||||
* public void build(MarkupTag body) {
|
||||
* body.text("Hello world!").br().text("New line!");
|
||||
* }
|
||||
* };
|
||||
* final String html = template.toHtmlString();
|
||||
* </pre>
|
||||
*
|
||||
* Using the {@link Html} object (from {@link #build()}) you can obtain the HTML
|
||||
* code using {@link Html#toHtml()}.
|
||||
* <p>
|
||||
* The generated code will be the smaller possible because the client has packet
|
||||
* size limitations, it will not contain any formatting.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public abstract class HtmlTemplate {
|
||||
/**
|
||||
* The template title (will be displayed in the game window)
|
||||
*/
|
||||
private final String title;
|
||||
/**
|
||||
* The template variables
|
||||
*/
|
||||
private Map<String, String> variables = CollectionFactory.newMap();
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param title
|
||||
* the title
|
||||
*/
|
||||
public HtmlTemplate(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance without a title
|
||||
*/
|
||||
public HtmlTemplate() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the HTML structure
|
||||
*
|
||||
* @param body
|
||||
* the body HTML node
|
||||
*/
|
||||
protected abstract void build(MarkupTag body);
|
||||
|
||||
/**
|
||||
* Replace the variables in the template
|
||||
*
|
||||
* @param template
|
||||
* the generated template HTML
|
||||
* @return the HTML with variables replaced
|
||||
*/
|
||||
public String replace(String template) {
|
||||
for (final Entry<String, String> variable : variables.entrySet()) {
|
||||
template = template.replaceAll(
|
||||
Pattern.quote("${" + variable.getKey() + "}"),
|
||||
variable.getValue());
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an variable for this template
|
||||
*
|
||||
* @param name
|
||||
* the name
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
public void register(String name, String value) {
|
||||
variables.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Html} object using the {@link HtmlTemplate} provided
|
||||
* in the constructor. This method can be invoked multiple times.
|
||||
*
|
||||
* @return the {@link Html} object
|
||||
*/
|
||||
public Html build() {
|
||||
final Html html = new L2HtmlTag();
|
||||
if (title != null) {
|
||||
final HeadTag head = new L2HeadTag();
|
||||
final TitleTag title = new L2TitleTag();
|
||||
html.getChildren().add(head);
|
||||
head.getChildren().add(title);
|
||||
title.getChildren().add(new TextNode(this.title));
|
||||
}
|
||||
final Tag body = new L2BodyTag();
|
||||
html.getChildren().add(body);
|
||||
|
||||
this.build(new MarkupTag(body));
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the HTML code for this template. It also replaces the
|
||||
* variables.
|
||||
*
|
||||
* @return the HTML code
|
||||
*/
|
||||
public String toHtmlString() {
|
||||
return this.replace(build().toHtml());
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is part of l2jserver <l2jserver.com>.
|
||||
*
|
||||
* l2jserver is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* l2jserver is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.util.html.markup;
|
||||
|
||||
import org.htmlparser.nodes.TextNode;
|
||||
import org.htmlparser.tags.HeadTag;
|
||||
import org.htmlparser.tags.Html;
|
||||
import org.htmlparser.tags.TitleTag;
|
||||
|
||||
import com.l2jserver.util.html.L2HeadTag;
|
||||
import com.l2jserver.util.html.L2HtmlTag;
|
||||
import com.l2jserver.util.html.L2TitleTag;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class Markup {
|
||||
private final Builder builder;
|
||||
private final String title;
|
||||
|
||||
public Markup(String title, Builder builder) {
|
||||
this.builder = builder;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Html build() {
|
||||
final Html html = new L2HtmlTag();
|
||||
final HeadTag head = new L2HeadTag();
|
||||
final TitleTag title = new L2TitleTag();
|
||||
|
||||
head.getChildren().add(head);
|
||||
head.getChildren().add(title);
|
||||
title.getChildren().add(new TextNode(this.title));
|
||||
|
||||
this.builder.build(new MarkupTag(html));
|
||||
return html;
|
||||
}
|
||||
|
||||
public interface Builder {
|
||||
void build(MarkupTag body);
|
||||
}
|
||||
}
|
||||
@@ -28,32 +28,78 @@ import com.l2jserver.util.html.L2LinkTag;
|
||||
import com.l2jserver.util.html.L2NewLineTag;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* This is an helper class that helps creating new tags in the HTML document.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MarkupTag {
|
||||
/**
|
||||
* The current tag
|
||||
*/
|
||||
private final Tag tag;
|
||||
/**
|
||||
* The parent {@link MarkupTag}
|
||||
*/
|
||||
private final MarkupTag parent;
|
||||
|
||||
/**
|
||||
* Creates a new instance with a parent
|
||||
*
|
||||
* @param tag
|
||||
* the tag
|
||||
* @param parent
|
||||
* the parent
|
||||
*/
|
||||
public MarkupTag(Tag tag, MarkupTag parent) {
|
||||
this.tag = tag;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance without a parent
|
||||
*
|
||||
* @param tag
|
||||
* the tag
|
||||
*/
|
||||
public MarkupTag(Tag tag) {
|
||||
this(tag, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an attribute to the current tag
|
||||
*
|
||||
* @param name
|
||||
* the attribute name
|
||||
* @param value
|
||||
* the attribute value
|
||||
* @return this {@link MarkupTag}
|
||||
*/
|
||||
public MarkupTag attr(String name, String value) {
|
||||
tag.setAttribute(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a plain text to the tag. It will not use any formatting.
|
||||
*
|
||||
* @param text
|
||||
* the text
|
||||
* @return this {@link MarkupTag}
|
||||
*/
|
||||
public MarkupTag text(String text) {
|
||||
tag.getChildren().add(new TextNode(text));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a plain text to the tag, use the color formatting.
|
||||
*
|
||||
* @param text
|
||||
* the text
|
||||
* @param color
|
||||
* the text color
|
||||
* @return this {@link MarkupTag}
|
||||
*/
|
||||
public MarkupTag text(String text, String color) {
|
||||
final Tag font = new L2FontTag();
|
||||
font.setAttribute("color", color);
|
||||
@@ -62,30 +108,61 @@ public class MarkupTag {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new DIV element
|
||||
*
|
||||
* @return this div {@link MarkupTag}
|
||||
*/
|
||||
public MarkupTag div() {
|
||||
final Tag tag = new L2DivTag();
|
||||
this.tag.getChildren().add(tag);
|
||||
return new MarkupTag(tag, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a line break
|
||||
*
|
||||
* @return this {@link MarkupTag}
|
||||
*/
|
||||
public MarkupTag br() {
|
||||
final Tag tag = new L2BrTag();
|
||||
this.tag.getChildren().add(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a new paragraph
|
||||
*
|
||||
* @return this {@link MarkupTag}
|
||||
*/
|
||||
public MarkupTag p() {
|
||||
final Tag tag = new L2NewLineTag();
|
||||
this.tag.getChildren().add(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CENTER element. Text inside this element will be centered.
|
||||
*
|
||||
* @return this CENTER {@link MarkupTag}
|
||||
*/
|
||||
public MarkupTag center() {
|
||||
final Tag tag = new L2CenterTag();
|
||||
this.tag.getChildren().add(tag);
|
||||
return new MarkupTag(this.tag, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image
|
||||
*
|
||||
* @param src
|
||||
* the image source
|
||||
* @param height
|
||||
* the height
|
||||
* @param width
|
||||
* the width
|
||||
* @return this {@link MarkupTag}
|
||||
*/
|
||||
public MarkupTag addImage(String src, int height, int width) {
|
||||
final Tag tag = new L2ImageTag();
|
||||
this.tag.getChildren().add(tag);
|
||||
@@ -95,6 +172,15 @@ public class MarkupTag {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a link
|
||||
*
|
||||
* @param text
|
||||
* the link text
|
||||
* @param action
|
||||
* the link action (will automatically append "bypass -h")
|
||||
* @return
|
||||
*/
|
||||
public MarkupTag addLink(String text, String action) {
|
||||
final Tag tag = new L2LinkTag();
|
||||
this.tag.getChildren().add(tag);
|
||||
@@ -103,6 +189,11 @@ public class MarkupTag {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close this tag and return the parent element
|
||||
*
|
||||
* @return the parent element, if any.
|
||||
*/
|
||||
public MarkupTag close() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user