Changeset 715 for MDService2/trunk/MDService2/src/eu/clarin
- Timestamp:
- 09/27/10 11:27:07 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java
r713 r715 12 12 import java.io.StringReader; 13 13 import java.io.StringWriter; 14 15 import javax.servlet.http.HttpServletRequest; 14 16 import javax.xml.parsers.DocumentBuilder; 15 17 import javax.xml.parsers.DocumentBuilderFactory; … … 29 31 import net.sf.json.xml.XMLSerializer; 30 32 33 import org.apache.struts2.interceptor.ServletRequestAware; 31 34 import org.w3c.dom.Document; 32 35 import org.w3c.dom.Node; … … 43 46 * 44 47 */ 45 public class WorkspaceAction extends ActionSupport 48 public class WorkspaceAction extends GenericProxyAction 49 //implements ServletRequestAware 46 50 { 47 51 48 52 private static final long serialVersionUID = 1L; 53 54 public static String USER = "user"; 55 public static String SERVER = "server"; 49 56 50 57 /** 51 58 * Properties to be filled by Struts with according request-parameters 52 59 */ 53 private String actionkey;60 //private String actionkey; 54 61 private String data; 55 private String id; 56 private String format; 57 private String userMsg; 58 62 private String type; 63 //private String format; 64 //private String userMsg; 59 65 private String base_path; 60 66 67 //private HttpServletRequest request; 68 61 69 public String getData() { 62 70 return data; … … 67 75 } 68 76 69 public String get ID() {70 return id;71 } 72 73 public void set ID(String _id) {74 this. id = _id;75 } 76 77 public String getType() { 78 return type; 79 } 80 81 public void setType(String type) { 82 this.type = type; 83 } 84 /* 77 85 public String getFormat() { 78 86 return format; … … 90 98 actionkey = actionKey; 91 99 } 92 100 */ 93 101 /** 94 102 * primitive identification of the target-proxy … … 100 108 return "workspaceprofile"; 101 109 } 102 110 /* 103 111 public String getUserMsg() { 104 112 return userMsg; … … 109 117 } 110 118 119 @Override 120 public void setServletRequest(HttpServletRequest arg0) { 121 request = arg0; 122 123 } 111 124 112 125 private InputStream resultStream; 113 126 private InputStream sourceStream; 114 127 */ 115 128 /** 116 129 * The stream holding the resulting data to be sent back to the user as response 117 130 * @return 118 131 */ 132 /* 119 133 public InputStream getResultStream() { 120 134 return resultStream; … … 126 140 sourceStream = _sourceStream; 127 141 } 128 129 142 */ 143 @Override 130 144 public URL getBaseURL() { 131 145 File file=new File(getPath()); … … 147 161 return base_path; 148 162 } 149 //TODO identification of WOrkspaceProfile (user, name, id) 163 164 150 165 public String getWorkspaceProfile() { 151 return "WorkspaceProfile.xml"; 152 } 153 166 String profilename = null; 167 168 Admin.notifyUser("QQQremoteUSER:" + type.toLowerCase()); 169 Admin.notifyUser("QQQremoteUSER:" + USER); 170 Admin.notifyUser("QQQremoteUSER:" + getServletRequest().getRemoteUser()); 171 if (type.toLowerCase().equals(USER)) { 172 Admin.notifyUser("WWWaaaremoteUSER:" + getServletRequest().getRemoteUser()); 173 if (getServletRequest().getRemoteUser() != null) { 174 Admin.notifyUser("WWWremoteUSER:" + getServletRequest().getRemoteUser()); 175 profilename = "WorkspaceProfile_" + getServletRequest().getRemoteUser() + ".xml"; 176 } else { 177 profilename = "WorkspaceProfile_default.xml"; 178 } 179 } else if (type.toLowerCase().equals(SERVER)) { 180 profilename = "WorkspaceProfileServer.xml"; 181 File f = new File(profilename); 182 if (! f.exists()){ 183 profilename = "WorkspaceProfile_default.xml"; 184 } 185 } 186 187 if (profilename == null){ 188 profilename = "WorkspaceProfile_default.xml"; 189 Admin.notifyUser("WorkspaceProfilePath not specified (USER, SERVER)!"); 190 } 191 192 Admin.notifyUser("WorkspaceProfilename : " + profilename); 193 return profilename; 194 } 195 196 @Override 154 197 public String getFullFormat() { 155 198 return "xml2json"; … … 171 214 public String getPath() { 172 215 String targetPath = getBasePath() + getWorkspaceProfile(); 173 Admin.notifyUser( targetPath);216 Admin.notifyUser("WorkspaceAction TARGETPATH: " + targetPath); 174 217 return targetPath; 175 218 } 176 219 220 @Override 177 221 public InputStream getSourceStream() throws IOException { 178 222 InputStream stream = new BufferedInputStream( new FileInputStream(getPath())); … … 182 226 } 183 227 228 @Override 184 229 public void prepare() throws Exception { 185 230 186 231 //Admin.notifyUser("execute:"); 187 sourceStream = getSourceStream(); 188 if (format.equals("xml")) { 189 resultStream = sourceStream; 232 InputStream in = getSourceStream(); 233 this.setSourceStream(in); 234 if (getFormat().equals("xml")) { 235 setResultStream(in); 190 236 }else { //JSON 191 237 // set srcFile (for MDTransformer to pass to xsl-scripts) 192 238 MDTransformer.getMDTransformer().setSrcFile(getURL()); 193 resultStream = MDTransformer.getMDTransformer().transformXML(sourceStream, getFullFormat());239 setResultStream(MDTransformer.getMDTransformer().transformXML(in, getFullFormat())); 194 240 } 195 241 196 Admin.notifyUser(getProxyKey() + " success:" + ( resultStream!=null));242 Admin.notifyUser(getProxyKey() + " success:" + (getResultStream()!=null)); 197 243 } 198 244 … … 318 364 319 365 InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) ); 366 320 367 Admin.writeToFile(getPath(), is_xml); 321 368 322 369 String ret = "1"; 323 resultStream = new ByteArrayInputStream(ret.getBytes());370 this.setResultStream( new ByteArrayInputStream(ret.getBytes())); 324 371 325 372 … … 330 377 * default Action method 331 378 */ 379 /* 332 380 public String execute() throws Exception { 333 381 … … 339 387 } 340 388 } 341 389 */ 342 390 343 391
Note: See TracChangeset
for help on using the changeset viewer.