All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.gluebooster.java.booster.basic.text.html.MapContent2HtmlDocument Maven / Gradle / Ivy

Go to download

Basic classes to support the development of applications. There should be as few dependencies on other frameworks as possible.

The newest version!
package net.sf.gluebooster.java.booster.basic.text.html;


import java.util.Iterator;
import java.util.Map;

import javax.swing.text.Element;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;

import net.sf.gluebooster.java.booster.essentials.eventsCommands.CallableAbstraction;

/**
 * Writes the contents of a map as html table. Transforms a Map to a
 * HTMLDocument.
 * 
 * @author Christian Bauer
 * 
 */
@SuppressWarnings("rawtypes")
public class MapContent2HtmlDocument extends CallableAbstraction
{
   /**
    * Default constructor.
    */
   public MapContent2HtmlDocument()
   {
      
   } 

	/**
	 * @param mapInstance
	 *            Map
	 * @return HTMLDocument
	 */
	@Override
	protected HTMLDocument callImpl(Map... parameters) throws Exception {
		Map map = parameters[0];

		HTMLEditorKit kit = new HTMLEditorKit();
		HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
		Element root = doc.getDefaultRootElement();// html
		Element element = root.getElement(0);// body
		// doc.insertAfterStart(element, "
anfangende
anfang2ende2
"); doc.insertAfterStart(element, ""); Element table = element.getElement(0);// table Iterator iterator = ((Map) map).entrySet().iterator(); while (iterator.hasNext()) { Map.Entry nextEntry = iterator.next(); Element tr; doc.insertBeforeEnd(table, ""); tr = table.getElement(table.getElementCount() - 1); // doc.insertBeforeEnd(tr, ""); doc.insertBeforeEnd(tr, ""); // todo use text node (there may be markup in // the entry) } return doc; /* * FileWriter writer = new FileWriter("c:/temp/test.html"); HTMLWriter htmlwriter = new HTMLWriter(writer, doc); htmlwriter.write(); writer.close(); */ } }









" + nextEntry.getKey() + "" + nextEntry.getValue() + "