001: /*
002: * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xtpdoc;
031:
032: import javax.xml.stream.XMLStreamException;
033: import javax.xml.stream.XMLStreamWriter;
034: import java.io.IOException;
035: import java.io.PrintWriter;
036:
037: public class Example extends VerboseFormattedTextWithAnchors {
038: private String _title;
039: private String _file;
040: private String _language;
041:
042: public Example(Document document) {
043: super (document);
044: }
045:
046: public void setTitle(String title) {
047: _title = title;
048: }
049:
050: public void setLanguage(String language) {
051: _language = language;
052: }
053:
054: public void setFile(String file) {
055: _file = file;
056: }
057:
058: public void writeHtml(XMLStreamWriter out)
059: throws XMLStreamException {
060: out.writeCharacters("\n");
061: if (_title != null) {
062: out.writeStartElement("div");
063: out.writeAttribute("class", "caption");
064: out.writeCharacters(_title);
065: out.writeEndElement();
066: }
067:
068: /*
069: if (_file != null) {
070: out.writeEmptyElement("br");
071: out.writeCharacters("See it in: ");
072: out.writeStartElement("a");
073: out.writeAttribute("href", _file);
074: out.writeCharacters(_file);
075: out.writeEndElement();
076: }
077: */
078:
079: out.writeStartElement("div");
080: out.writeAttribute("class", "example");
081: out.writeStartElement("pre");
082:
083: super .writeHtml(out);
084:
085: out.writeEndElement();
086: out.writeEndElement();
087: }
088:
089: public void writeLaTeX(PrintWriter out) throws IOException {
090: if (_language != null) {
091: out
092: .println("\\lstset{fancyvrb,language=" + _language
093: + ",");
094: out
095: .println(" showstringspaces=false,basicstyle=\\small,");
096: out.println(" stringstyle=\\color[gray]{0.6}}");
097: }
098:
099: out.println("\\begin{center}");
100: out
101: .println("\\begin{Verbatim}[frame=single,fontfamily=courier,");
102: out.println(" framerule=1pt,");
103: out.println(" fontsize=\\footnotesize,");
104:
105: if (_title != null) {
106: out
107: .print(" labelposition=bottomline,label=\\fbox{");
108: out.println(LaTeXUtil.escapeForLaTeX(_title) + "},");
109: }
110:
111: out.println(" samepage=true]");
112:
113: super .writeLaTeX(out);
114:
115: // make room for the title box
116: if (_title != null)
117: out.println();
118:
119: out.println();
120: out.println("\\end{Verbatim}");
121:
122: out.println("\\end{center}");
123:
124: if (_language != null)
125: out.println("\\lstset{fancyvrb=false}");
126: }
127: }
|