001 /*
002 * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003 *
004 * This file is part of the Java Data Mining Package (JDMP).
005 * See the NOTICE file distributed with this work for additional
006 * information regarding copyright ownership and licensing.
007 *
008 * JDMP is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation; either version 2
011 * of the License, or (at your option) any later version.
012 *
013 * JDMP is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU Lesser General Public License for more details.
017 *
018 * You should have received a copy of the GNU Lesser General Public
019 * License along with JDMP; if not, write to the
020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021 * Boston, MA 02110-1301 USA
022 */
023
024 package org.jdmp.jetty.html.tags;
025
026 import java.util.Collection;
027 import java.util.LinkedList;
028 import java.util.List;
029 import java.util.Map;
030 import java.util.TreeMap;
031
032 import org.jdmp.jetty.html.Html;
033 import org.jdmp.jetty.html.Text;
034
035 public abstract class AbstractHtmlTag implements HtmlTag {
036 private static final long serialVersionUID = -7005029880318280836L;
037
038 private final List<Html> contentList = new LinkedList<Html>();
039
040 private final Map<String, String> parameterMap = new TreeMap<String, String>();
041
042 @Override
043 public void add(Html... content) {
044 for (Html h : content) {
045 contentList.add(h);
046 }
047 }
048
049 @Override
050 public void add(Collection<Html> content) {
051 for (Html h : content) {
052 contentList.add(h);
053 }
054 }
055
056 @Override
057 public void add(String... content) {
058 for (String h : content) {
059 contentList.add(new Text(h));
060 }
061 }
062
063 public void clear() {
064 parameterMap.clear();
065 contentList.clear();
066 }
067
068 @Override
069 public void setParameter(String name, String value) {
070 parameterMap.put(name, value);
071 }
072
073 public String toString() {
074 StringBuilder s = new StringBuilder();
075 s.append("<");
076 s.append(getTagName());
077 for (String name : parameterMap.keySet()) {
078 String value = parameterMap.get(name);
079 s.append(" ");
080 s.append(name);
081 s.append("=");
082 s.append("\"");
083 s.append(value);
084 s.append("\"");
085 }
086
087 s.append(">");
088 for (Html content : contentList) {
089 s.append(content);
090 }
091 s.append("</");
092 s.append(getTagName());
093 s.append(">\n");
094
095 return s.toString();
096 }
097
098 }