org.magicwerk.brownies.html.HtmlDoclet Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2010 by Thomas Mauch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id$
*/
package org.magicwerk.brownies.html;
import org.magicwerk.brownies.jdom.JdomTools;
/**
* Class representing HTML element with resources.
* The element can be added to a HTML document.
*
* @author Thomas Mauch
* @version $Id$
*/
public class HtmlDoclet implements IHtmlDoclet, IHtmlContent {
HtmlResources resources = new HtmlResources();
IHtmlElement element;
public HtmlDoclet() {
}
@Override
public IHtmlElement getContent() {
HtmlDocument doc = new HtmlDocument();
doc.addDoclet(this);
return doc;
}
public HtmlDoclet(IHtmlElement element) {
doSetElement(element);
}
public HtmlDoclet(IHtmlElement element, HtmlResource resource) {
doSetElement(element);
addResource(resource);
}
public HtmlDoclet(IHtmlElement element, HtmlResources resources) {
doSetElement(element);
setResources(resources);
}
void doSetElement(IHtmlElement element) {
if (element instanceof HtmlDocument) {
HtmlDocument doc = (HtmlDocument) element;
this.element = doc.getBody();
} else {
this.element = element;
}
}
public IHtmlElement getElement() {
return element;
}
public void setElement(IHtmlElement element) {
doSetElement(element);
}
public HtmlResources getResources() {
return resources;
}
public void setResources(HtmlResources resources) {
this.resources = resources;
}
@Override
public void addResource(HtmlResource resource) {
this.resources.addIfAbsent(resource);
}
@Override
public void addDoclet(HtmlDoclet doc) {
addResources(doc.getResources());
JdomTools.copyElementContent(element.getElement(), doc.getElement().getElement());
}
}