/* $Id: ExportHtmlCreater.java 125 2011-03-09 09:49:51Z ohura $ */
package smart_gs.menu.export;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import javax.swing.JTextPane;
import javax.swing.text.html.StyleSheet;

import com.hexidec.ekit.component.ExtendedHTMLDocument;
import com.hexidec.ekit.component.ExtendedHTMLEditorKit;

public class ExportHtmlCreater {

	public static String getHTMLStr(){
		ExtendedHTMLEditorKit htmlKit = new ExtendedHTMLEditorKit();
		ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) (htmlKit.createDefaultDocument());
		JTextPane jTextPane = new JTextPane();
		jTextPane.setEditorKit(htmlKit);
		jTextPane.setDocument(htmlDoc);

//		 スタイルシート
		String sStyleSheet = "css.txt";
		if (sStyleSheet != null) {
			File defCSS = new File(sStyleSheet);
			if (defCSS.exists()) {
				try {
					if (defCSS != null) {
						htmlDoc = (ExtendedHTMLDocument) (htmlKit.createDefaultDocument());
						StyleSheet styleSheet = htmlDoc.getStyleSheet();
						URL cssUrl = defCSS.toURL();
						InputStream is = cssUrl.openStream();
						BufferedReader br = new BufferedReader(new InputStreamReader(is));
						styleSheet.loadRules(br, cssUrl);
						br.close();
						htmlDoc = new ExtendedHTMLDocument(styleSheet);
						jTextPane.setDocument(htmlDoc);
					}
				} catch (Exception e) {
				}
			}
		}
		jTextPane.setText("$BODY$");
		return jTextPane.getText();
	}
}
