1 29 30 package com.caucho.xtpdoc; 31 import javax.xml.stream.XMLStreamException; 32 import javax.xml.stream.XMLStreamWriter; 33 import java.io.IOException ; 34 import java.io.PrintWriter ; 35 36 public class Image implements ContentItem { 37 private int _height = -1; 38 private int _width = -1; 39 private String _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 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 out) 82 throws IOException 83 { 84 86 int dot = _source.lastIndexOf('.'); 87 88 String basename = _source.substring(0, dot); 89 90 out.println("\\epsfig{file=../images/" + basename + ",width=\\linewidth}"); 91 92 101 102 } 104 105 public void writeLaTeXEnclosed(PrintWriter out) 106 throws IOException 107 { 108 writeLaTeX(out); 109 } 110 111 public void writeLaTeXTop(PrintWriter out) 112 throws IOException 113 { 114 writeLaTeX(out); 115 } 116 } 117 | Popular Tags |