KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xtpdoc > Image


1 /*
2  * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Emil Ong
28  */

29
30 package com.caucho.xtpdoc;
31 import javax.xml.stream.XMLStreamException;
32 import javax.xml.stream.XMLStreamWriter;
33 import java.io.IOException JavaDoc;
34 import java.io.PrintWriter JavaDoc;
35
36 public class Image implements ContentItem {
37   private int _height = -1;
38   private int _width = -1;
39   private String JavaDoc _source;
40   private Document _document;
41
42   public Image(Document document)
43   {
44     _document = document;
45   }
46
47   public Document getDocument()
48   {
49     return _document;
50   }
51
52   public void setHeight(int height)
53   {
54     _height = height;
55   }
56
57   public void setWidth(int width)
58   {
59     _width = width;
60   }
61
62   public void setSrc(String JavaDoc source)
63   {
64     _source = source;
65   }
66
67   public void writeHtml(XMLStreamWriter out)
68     throws XMLStreamException
69   {
70     out.writeEmptyElement("img");
71
72     if (_height >= 0)
73       out.writeAttribute("height", Integer.toString(_height));
74
75     if (_width >= 0)
76       out.writeAttribute("width", Integer.toString(_width));
77
78     out.writeAttribute("src", _document.getContextPath() + "/images/" + _source);
79   }
80
81   public void writeLaTeX(PrintWriter JavaDoc out)
82     throws IOException JavaDoc
83   {
84     //out.println("\\begin{figure}[h]");
85

86     int dot = _source.lastIndexOf('.');
87
88     String JavaDoc basename = _source.substring(0, dot);
89
90     out.println("\\epsfig{file=../images/" + basename + ",width=\\linewidth}");
91
92     /*
93     if (_height >= 0)
94       out.print(",height=" + _height);
95
96     if (_width >= 0)
97       out.print(",width=" + _width);
98
99     out.println("}");
100     */

101
102     //out.println("\\end{figure}");
103
}
104
105   public void writeLaTeXEnclosed(PrintWriter JavaDoc out)
106     throws IOException JavaDoc
107   {
108     writeLaTeX(out);
109   }
110
111   public void writeLaTeXTop(PrintWriter JavaDoc out)
112     throws IOException JavaDoc
113   {
114     writeLaTeX(out);
115   }
116 }
117
Popular Tags