001package com.hfg.svg; 002 003import java.io.BufferedInputStream; 004import java.io.File; 005import java.io.IOException; 006import java.io.OutputStream; 007import java.io.PrintWriter; 008import java.io.Writer; 009import javax.servlet.http.HttpServletResponse; 010 011import com.hfg.html.HTML; 012import com.hfg.xml.XMLBasedDoc; 013import com.hfg.xml.XMLException; 014import com.hfg.xml.XMLNode; 015import com.hfg.xml.XMLTag; 016 017//------------------------------------------------------------------------------ 018/** 019 * Container for an SVG (Scalable Vector Graphics) document. 020 * 021 * @author J. Alex Taylor, hairyfatguy.com 022 */ 023//------------------------------------------------------------------------------ 024// com.hfg XML/HTML Coding Library 025// 026// This library is free software; you can redistribute it and/or 027// modify it under the terms of the GNU Lesser General Public 028// License as published by the Free Software Foundation; either 029// version 2.1 of the License, or (at your option) any later version. 030// 031// This library is distributed in the hope that it will be useful, 032// but WITHOUT ANY WARRANTY; without even the implied warranty of 033// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 034// Lesser General Public License for more details. 035// 036// You should have received a copy of the GNU Lesser General Public 037// License along with this library; if not, write to the Free Software 038// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 039// 040// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 041// jataylor@hairyfatguy.com 042//------------------------------------------------------------------------------ 043 044public class SvgDoc extends XMLBasedDoc<SvgNode> 045{ 046 047 //########################################################################### 048 // CONSTRUCTORS 049 //########################################################################### 050 051 //--------------------------------------------------------------------------- 052 public SvgDoc() 053 { 054 super(); 055 setRootNode(new SVG()); 056 } 057 058 //--------------------------------------------------------------------------- 059 public SvgDoc(SVG inRootTag) 060 { 061 super(inRootTag); 062// init(); 063 } 064 065 //--------------------------------------------------------------------------- 066 public SvgDoc(File inFile) 067 throws XMLException, IOException 068 { 069 super(inFile); 070// init(); 071 } 072 073 //--------------------------------------------------------------------------- 074 public SvgDoc(BufferedInputStream inStream) 075 { 076 super(inStream); 077 } 078 079 //########################################################################### 080 // PUBLIC METHODS 081 //########################################################################### 082 083 //--------------------------------------------------------------------------- 084 @Override 085 public SVG getRootNode() 086 { 087 XMLNode rootNode = super.getRootNode(); 088 if (!(rootNode instanceof SVG)) 089 { 090 rootNode = new SVG(rootNode); 091 setRootNode((SVG) rootNode); 092 } 093 094 return (SVG) rootNode; 095 } 096 097 //--------------------------------------------------------------------------- 098 @Override 099 public SvgDoc setName(String inValue) 100 { 101 return (SvgDoc) super.setName(inValue); 102 } 103 104 //--------------------------------------------------------------------------- 105 public String toSVG() 106 { 107 return toXML(); 108 } 109 110 //--------------------------------------------------------------------------- 111 public void toSVG(OutputStream inStream) 112 { 113 toXML(inStream); 114 } 115 116 //--------------------------------------------------------------------------- 117 public void toSVG(PrintWriter inWriter) 118 { 119 toXML(inWriter); 120 } 121 122 //--------------------------------------------------------------------------- 123 public void toSVG(File inFile) 124 { 125 toXML(inFile); 126 } 127 128 //--------------------------------------------------------------------------- 129 public void toSVG(HttpServletResponse inResponse) 130 { 131 try 132 { 133 Writer writer = null; 134 try 135 { 136 writer = inResponse.getWriter(); 137 toXML(writer); 138 } 139 finally 140 { 141 if (writer != null) 142 { 143 writer.close(); 144 } 145 } 146 } 147 catch (IOException e) 148 { 149 throw new XMLException(e); 150 } 151 } 152 153 //-------------------------------------------------------------------------- 154 public String toIndentedSVG(int inInitialIndentLevel, int inIndentSize) 155 { 156 return toIndentedXML(inInitialIndentLevel, inIndentSize); 157 } 158 159 //-------------------------------------------------------------------------- 160 public void toIndentedSVG(OutputStream inOutputStream, int inInitialIndentLevel, int inIndentSize) 161 { 162 toIndentedXML(inOutputStream, inInitialIndentLevel, inIndentSize); 163 } 164 165 //-------------------------------------------------------------------------- 166 public void toIndentedSVG(PrintWriter inWriter, int inInitialIndentLevel, int inIndentSize) 167 { 168 toIndentedXML(inWriter, inInitialIndentLevel, inIndentSize); 169 } 170 171 172 //-------------------------------------------------------------------------- 173 public void toIndentedSVG(File inFile, int inInitialIndentLevel, int inIndentSize) 174 { 175 toIndentedXML(inFile, inInitialIndentLevel, inIndentSize); 176 } 177 178 179}