1 14 15 package webEditor.interfaces; 16 17 import java.io.*; 18 import java.util.Hashtable ; 19 import java.lang.reflect.*; 20 21 import javax.servlet.*; 22 import javax.servlet.http.*; 23 import org.w3c.dom.*; 24 25 import webEditor.core.*; 26 27 31 32 public class imageMode { 33 34 37 private configuration initValues; 38 39 42 private String myDocName; 43 44 47 private presentation myEditor= null; 48 49 52 private images myImage= null; 53 54 57 private article myDocument= null; 58 59 63 public imageMode (configuration initParam) { 64 this.initValues = initParam; 67 } 68 69 75 public void edition (HttpServletRequest request, PrintWriter out) 76 throws ServletException, 77 IOException { 78 79 String outputString = null; 80 this.myEditor = new presentation (this.initValues); 81 this.myDocument = new article (this.initValues); 82 this.myImage = new images (this.initValues); 83 84 this.myDocName = this.initValues.readValue("HTTP Parameters", "docID"); 85 String opCode = this.initValues.readValue ("HTTP Parameters", "code"); 86 87 if (this.myDocName == null) { 88 this.myDocName = "document.xml"; 90 } 91 String imgWrite = this.initValues.readValue 93 ("HTTP Parameters", "Write.x"); 94 if (imgWrite != null) { 95 opCode = "Write"; 96 } 97 98 if (opCode != null) { 99 try { 100 Method m = getClass().getMethod(opCode, new Class [0]); 102 m.invoke(this,new Object [0]); 103 } 104 catch (Exception e) { 105 out.println (opCode + " : Code not supported"); 106 e.printStackTrace(); 107 } 108 } 109 110 Document doc = this.myDocument.docRead (this.myDocName); 111 Document imgDoc = this.myDocument.readSubtree (doc, "image"); 112 if (imgDoc == null) { 113 imgDoc = this.myDocument.docRead ("image.xml"); 116 } 117 imgDoc = this.myImage.changeDocID (imgDoc, this.myDocName); 118 outputString = this.myEditor.showImgEditor (imgDoc , ""); 119 120 out.println (outputString); 121 } 122 123 127 public void Write () 128 throws ServletException, IOException 129 { 130 Document doc = this.myDocument.docRead (this.myDocName); 131 132 Hashtable http_params = this.initValues.readCategory ("HTTP Parameters"); 134 Document imageTemplate = this.myDocument.docRead ("image.xml"); 135 imageTemplate = this.myDocument.writeDoc (http_params, imageTemplate, "image_content"); 137 138 imageTemplate = this.myImage.changeDocID (imageTemplate, this.myDocName); 139 String imagePath = this.myImage.writeImage (this.myDocName); 141 if ( imagePath != null ) { 142 imageTemplate = this.myImage.changeImageURL (imageTemplate, imagePath); 143 } 144 else { 145 imagePath = this.myImage.getImageURL (doc); 146 if (imagePath != null) { 147 imageTemplate = this.myImage.changeImageURL (imageTemplate, imagePath); 149 } 150 } 151 152 String position = this.myImage.getImagePosition (imageTemplate); 154 155 String imagePosition = this.initValues.readValue 157 ("HTTP Parameters", "position").trim(); 158 if ( (!imagePosition.equals("")) && (!position.equals (imagePosition)) ) { 159 doc = this.myDocument.deleteImgDoc (doc, imagePosition); 160 } 161 162 if ( !position.trim().equals("") ) { 163 doc = this.myDocument.writeImgDoc (imageTemplate, doc, position); 165 this.myDocument.saveFile (this.myDocName, doc); 166 } 167 } 168 169 173 public void delete () 174 throws ServletException, IOException 175 { 176 String imagePosition = this.initValues.readValue 177 ("HTTP Parameters", "position").trim(); 178 if ( !imagePosition.equals("") ) { 179 Document doc = this.myDocument.docRead (this.myDocName); 180 doc = this.myDocument.deleteImgDoc (doc, imagePosition); 181 this.myDocument.saveFile (this.myDocName, doc); 182 } 183 184 } 185 186 } 187 | Popular Tags |