1 14 15 package webEditor.core; 16 17 import java.io.*; 18 19 import javax.servlet.*; 20 import javax.servlet.http.*; 21 import org.apache.regexp.RE; 22 import org.w3c.dom.*; 23 import org.apache.xerces.parsers.DOMParser; 24 import org.apache.xml.serialize.*; 25 26 import webEditor.util.*; 27 28 33 public class images 34 { 35 38 private configuration initValues; 39 40 43 private String wEd_root; 44 45 48 private String imgDir; 49 50 53 private String imgURL; 54 55 58 private String tmpDir; 59 60 public images (configuration initParam) 61 { 62 this.initValues = initParam; 63 String categoryName = "directories"; 64 65 this.wEd_root = initParam.readValue ("webEditor_Root","wEd_root"); 66 this.imgURL = "/" + initParam.readValue (categoryName,"imgDir"); 67 this.imgDir = initParam.readValue (categoryName,"serverRoot") + this.imgURL; 68 69 this.tmpDir = initParam.readValue (categoryName,"tmpDir"); 70 } 71 72 73 78 public String writeImage(String docID) 79 { 80 String imgPath = null; 81 String uploadImg = null; 82 try { 83 FileAccess fileHandler = new FileAccess (); 84 85 String filePath = this.imgDir + "/" + docID; 86 fileHandler.createDocDir (docID, this.imgDir + "/"); 88 89 RE r = new RE("([:alnum:]*).xml$"); 92 imgPath = r.subst (docID,""); 93 94 uploadImg = this.initValues.readValue ("HTTP Parameters", "art_image"); 95 if ( uploadImg == null ) { 96 return (null); 98 } 99 100 File uploadedFile = new File (this.tmpDir, uploadImg); 101 File destinationFile = new File (this.imgDir + "/" + imgPath, uploadImg); 102 103 uploadedFile.renameTo (destinationFile); 104 } 105 catch (Exception e) { 106 e.printStackTrace(); 107 } 108 109 return (this.imgURL + "/" + imgPath + uploadImg); 110 } 111 112 118 public Document changeDocID (Document imageDoc, String docID) 119 { 120 Node sourceIDNode = (Node) imageDoc.getElementsByTagName("docID").item(0); 121 122 Node newIDNode = sourceIDNode.cloneNode(true); 123 newIDNode.getFirstChild().setNodeValue (docID); 124 125 Node parent = sourceIDNode.getParentNode (); 126 parent.replaceChild (newIDNode, sourceIDNode); 127 128 return (imageDoc); 129 } 130 131 136 public String getImagePosition (Document imageDoc) 137 { 138 String position = null; 139 140 Node imagePosition = imageDoc.getElementsByTagName("art_image_position").item(0).getFirstChild(); 141 if (imagePosition == null) { 142 return ("none"); 143 } 144 else { 145 position = imagePosition.getNodeValue(); 146 } 147 return (position); 148 } 149 150 156 public Document changeImageURL (Document imageDoc, String imgURL) 157 { 158 Node sourceIDNode = (Node) imageDoc.getElementsByTagName("art_image").item(0); 159 160 Node newIDNode = sourceIDNode.cloneNode(true); 161 newIDNode.getFirstChild().setNodeValue (imgURL); 162 163 Node parent = sourceIDNode.getParentNode (); 164 parent.replaceChild (newIDNode, sourceIDNode); 165 166 return (imageDoc); 167 } 168 169 174 public String getImageURL (Document imageDoc) 175 { 176 String url = null; 177 178 Node imageURL = imageDoc.getElementsByTagName("art_image").item(0).getFirstChild(); 179 if (imageURL == null) { 180 return (null); 181 } 182 else { 183 url = imageURL.getNodeValue(); 184 } 185 return (url); 186 } 187 188 189 } 190 | Popular Tags |