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 Image implements ContentItem {
038: private int _height = -1;
039: private int _width = -1;
040: private String _source;
041: private Document _document;
042:
043: public Image(Document document) {
044: _document = document;
045: }
046:
047: public Document getDocument() {
048: return _document;
049: }
050:
051: public void setHeight(int height) {
052: _height = height;
053: }
054:
055: public void setWidth(int width) {
056: _width = width;
057: }
058:
059: public void setSrc(String source) {
060: _source = source;
061: }
062:
063: public void writeHtml(XMLStreamWriter out)
064: throws XMLStreamException {
065: out.writeEmptyElement("img");
066:
067: if (_height >= 0)
068: out.writeAttribute("height", Integer.toString(_height));
069:
070: if (_width >= 0)
071: out.writeAttribute("width", Integer.toString(_width));
072:
073: out.writeAttribute("src", _document.getContextPath()
074: + "/images/" + _source);
075: }
076:
077: public void writeLaTeX(PrintWriter out) throws IOException {
078: //out.println("\\begin{figure}[h]");
079:
080: int dot = _source.lastIndexOf('.');
081:
082: String basename = _source.substring(0, dot);
083:
084: out.println("\\epsfig{file=../images/" + basename
085: + ",width=\\linewidth}");
086:
087: /*
088: if (_height >= 0)
089: out.print(",height=" + _height);
090:
091: if (_width >= 0)
092: out.print(",width=" + _width);
093:
094: out.println("}");
095: */
096:
097: //out.println("\\end{figure}");
098: }
099:
100: public void writeLaTeXEnclosed(PrintWriter out) throws IOException {
101: writeLaTeX(out);
102: }
103:
104: public void writeLaTeXTop(PrintWriter out) throws IOException {
105: writeLaTeX(out);
106: }
107: }
|