Simple GIS

GISプログラムの練習

epub

package epub;

import java.io.FileOutputStream;

import com.adobe.dp.epub.io.OCFContainerWriter;
import com.adobe.dp.epub.ncx.TOCEntry;
import com.adobe.dp.epub.opf.NCXResource;
import com.adobe.dp.epub.opf.OPSResource;
import com.adobe.dp.epub.opf.Publication;
import com.adobe.dp.epub.opf.StyleResource;
import com.adobe.dp.epub.ops.Element;
import com.adobe.dp.epub.ops.OPSDocument;
import com.adobe.dp.epub.style.Rule;
import com.adobe.dp.epub.style.Selector;
import com.adobe.dp.epub.style.Stylesheet;


public class pro {

public static void main(String[] args) {

try {

Publication epub = new Publication();
epub.addDCMetadata("title", "猫は猫");
epub.addDCMetadata("creator", "Rice Coast");
epub.addDCMetadata("language", "ja");

NCXResource toc = epub.getTOC();
TOCEntry rootTOCEntry = toc.getRootTOCEntry();

StyleResource style = epub.createStyleResource("OPS/styles.css");
Stylesheet stylesheet = style.getStylesheet();

Selector h1Selector = stylesheet.getSimpleSelector("h1", null);
Rule h1Rule = stylesheet.getRuleForSelector(h1Selector);
h1Rule.set("color", "gray");
h1Rule.set("border-bottom", "2px solid gray");
h1Rule.set("text-align", "right");
h1Rule.set("margin", "2em 8px 1em 0px");

Selector pSelector = stylesheet.getSimpleSelector("p", null);
Rule pRule = stylesheet.getRuleForSelector(pSelector);
pRule.set("margin", "0px");
pRule.set("text-indent", "1em");
pRule.set("text-align", "justify");

OPSResource chapter1 = epub.createOPSResource("OPS/chapter1.html");
epub.addToSpine(chapter1);

OPSDocument chapter1Doc = chapter1.getDocument();

chapter1Doc.addStyleResource(style);

TOCEntry chapter1TOCEntry = toc.createTOCEntry("Chapter 1",chapter1Doc.getRootXRef());
rootTOCEntry.add(chapter1TOCEntry);

Element body1 = chapter1Doc.getBody();

Element header1 = chapter1Doc.createElement("h1");
header1.add("亀");
body1.add(header1);

Element paragraph1 = chapter1Doc.createElement("p");
StringBuffer sb1 = new StringBuffer();
for (int i = 1; i <= 6; i++)
sb1.append("犬と猫は恥ずかしい");
paragraph1.add(sb1.toString());
body1.add(paragraph1);

OPSResource chapter2 = epub.createOPSResource("OPS/chapter2.html");
epub.addToSpine(chapter2);

OPSDocument chapter2Doc = chapter2.getDocument();
chapter2Doc.addStyleResource(style);

TOCEntry chapter2TOCEntry = toc.createTOCEntry("Chapter 2",chapter2Doc.getRootXRef());
rootTOCEntry.add(chapter2TOCEntry);
Element body2 = chapter2Doc.getBody();

Element header2 = chapter1Doc.createElement("h1");
header2.add("山");
body2.add(header2);

Element paragraph2 = chapter2Doc.createElement("p");
StringBuffer sb2 = new StringBuffer();
for (int i = 1; i <100; i++)
sb2.append("浅間は遅い");
paragraph2.add(sb2.toString());
body2.add(paragraph2);

Element paragraph3 = chapter2Doc.createElement("p");
StringBuffer sb3 = new StringBuffer();
for (int i = 1; i < 10000; i++)
sb3.append("風は風。");
paragraph3.add(sb3.toString());
body2.add(paragraph3);

OCFContainerWriter writer = new OCFContainerWriter(new FileOutputStream("ren2.epub"));
epub.serialize(writer);

} catch (Exception e) {e.printStackTrace();}
}
}