Changeset 1540 for MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java
- Timestamp:
- 09/19/11 10:39:55 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java
r1532 r1540 3 3 import java.io.BufferedInputStream; 4 4 import java.io.ByteArrayInputStream; 5 import java.io.ByteArrayOutputStream;6 5 import java.io.File; 7 6 import java.io.FileInputStream; … … 21 20 import javax.xml.parsers.ParserConfigurationException; 22 21 import javax.xml.transform.OutputKeys; 23 import javax.xml.transform.Result;24 import javax.xml.transform.Source;25 22 import javax.xml.transform.Transformer; 26 23 import javax.xml.transform.TransformerConfigurationException; … … 49 46 import org.xml.sax.SAXException; 50 47 51 import eu.clarin.cmdi.mdservice.internal.Admin; 52 import eu.clarin.cmdi.mdservice.internal.Helpers; 48 import eu.clarin.cmdi.mdservice.internal.Utils; 53 49 import eu.clarin.cmdi.mdservice.internal.MDTransformer; 54 50 import eu.clarin.cmdi.mdservice.model.Diagnostic; … … 164 160 public WorkspaceAction () { 165 161 this.elementtype = WorkspaceAction.SE_WORKSPACE; 166 workspacefilename = Admin.getConfig().getProperty("workspaceprofile.path") + Admin.getConfig().getProperty("workspace.file");162 workspacefilename = Utils.getConfig().getProperty("workspaceprofile.path") + Utils.getConfig().getProperty("workspace.file"); 167 163 if (workspace_doc == null){ 168 //workspacefilename = Admin.getConfig().getProperty("workspace.path") + Admin.getConfig().getProperty("workspace.file");164 //workspacefilename = Utils.getConfig().getProperty("workspace.path") + Utils.getConfig().getProperty("workspace.file"); 169 165 initDocument(); 170 166 } … … 228 224 public String getBasePath() { 229 225 if (base_path == null) { 230 base_path = Admin.getConfig().getProperty(getProxyKey() + ".path");226 base_path = Utils.getConfig().getProperty(getProxyKey() + ".path"); 231 227 } 232 228 return base_path; … … 248 244 File f = new File(getBasePath() + profilename); 249 245 if (! f.exists()){ 250 // Admin.notifyUser(" not exists");246 //log.debug(" not exists"); 251 247 profilename = "WorkspaceProfile_default.xml"; 252 248 } … … 260 256 if (profilename == null){ 261 257 profilename = PROFILENAME_DEFAULT; 262 Admin.notifyUser("WorkspaceProfilePath not specified (USER, SERVER)!");263 } 264 265 Admin.notifyUser("WorkspaceProfilename : " + profilename);258 log.debug("WorkspaceProfilePath not specified (USER, SERVER)!"); 259 } 260 261 log.debug("WorkspaceProfilename : " + profilename); 266 262 return profilename; 267 263 } … … 277 273 try{ 278 274 url=file.toURI().toURL(); 279 // Admin.notifyUser("url " + url);275 //log.debug("url " + url); 280 276 } catch (MalformedURLException e){ 281 // Admin.notifyUser("" + e);277 //log.debug("" + e); 282 278 } 283 279 return url; … … 308 304 } 309 305 310 /* 311 @Override 312 public void prepare() throws Exception { 313 314 //Admin.notifyUser("execute:"); 315 InputStream in = getSourceStream(); 316 this.setSourceStream(in); 317 if (getFormat().equals("xml")) { 318 setResultStream(in); 319 }else { //JSON 320 // set srcFile (for MDTransformer to pass to xsl-scripts) 321 MDTransformer transformer = new MDTransformer(); 322 transformer.setSrcFile(getURL()); 323 transformer.setParams(MDTransformer.createParamsMap(getFullFormat())); 324 setResultStream(transformer.transformXML(in));//, getFullFormat())); 325 //setSessionData(getResultStream()); 326 } 327 328 Admin.notifyUser(getProxyKey() + " success:" + (getResultStream()!=null)); 329 } 330 331 public void changeNodeName(Document doc, Node node, String new_name){ 332 // Create an element with the new name 333 Node node2 = (Node ) doc.createElement(new_name); 334 // Copy the attributes to the new element NamedNodeMap attrs = element.getAttributes(); for (int i=0; i<attrs.getLength(); i++) { Attr attr2 = (Attr)doc.importNode(attrs.item(i), true); element2.getAttributes().setNamedItem(attr2); } 335 // Move all the children 336 while (node.hasChildNodes()) { node2.appendChild(node.getFirstChild()); } 337 // Replace the old node with the new node 338 Admin.notifyUser("replace:" + node2.getNodeName() + "," + node.getNodeName()); 339 node.getParentNode().replaceChild(node2, node); 340 } 341 342 public void administrateQid() throws IOException, SAXException, ParserConfigurationException, TransformerException{ 343 WorkspaceAction wa = new WorkspaceAction(); 344 wa.setType("Admin"); 345 346 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 347 DocumentBuilder builder; 348 349 builder = factory.newDocumentBuilder(); 350 Document document = builder.parse(wa.getSourceStream()); 351 // find user-filename-id or create one 352 //add qid 353 //NodeList list = document.getElementsByTagName("e"); 354 //Admin.notifyUser("list:" + list.getLength()); 355 356 // save the changes 357 Transformer transformer; 358 transformer = TransformerFactory.newInstance().newTransformer(); 359 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 360 StreamResult result = new StreamResult(new StringWriter()); 361 DOMSource source = new DOMSource(document); 362 transformer.transform(source, result); 363 String xmlString = result.getWriter().toString(); 364 InputStream is_xml = new ByteArrayInputStream( xmlString.getBytes( ) ); 365 Admin.writeToFile(wa.getPath(), is_xml); 366 //wa.save(); 367 } 368 369 public String save() throws IOException, SAXException, ParserConfigurationException, TransformerException { 370 371 String jsonData = getData(); 372 373 Admin.notifyUser("JSON data:"+jsonData); 374 if ((!this.getType().equals(ADMIN)) && this.getQid() != null) { 375 administrateQid(); 376 } 377 378 XMLSerializer serializer = new XMLSerializer(); 379 JSON json = JSONSerializer.toJSON( jsonData ); 380 if (this.getType().equals(ADMIN)){ 381 serializer.setRootName("Admin"); 382 } else { 383 serializer.setRootName("WorkspaceProfile"); 384 } 385 serializer.setElementName("item"); 386 serializer.setTypeHintsEnabled(false); 387 String xml = serializer.write( json ); 388 Admin.notifyUser("XML:" + xml); 389 390 InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) ); 391 392 Admin.writeToFile(getPath(), is_xml); 393 394 String ret = "1"; 395 this.setResultStream( new ByteArrayInputStream(ret.getBytes())); 396 397 398 return SUCCESS; 399 } 400 */ 306 401 307 public void changeQueryId(Document doc, String from_id, String to_id) throws XPathExpressionException{ 402 308 InputStream is = null; … … 692 598 serializer.setTypeHintsEnabled(false); 693 599 String xml = serializer.write( json ); 694 // Admin.notifyUser("XML:" + xml);600 //log.debug("XML:" + xml); 695 601 InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) ); 696 602 // add to document 697 // Admin.writeToFile(getPath(), is_xml);603 //Utils.writeToFile(getPath(), is_xml); 698 604 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 699 605 DocumentBuilder builder = factory.newDocumentBuilder(); … … 970 876 } 971 877 // nodelistto stream 972 InputStream is = Helpers.DocumentToStream(list.item(0));878 InputStream is = Utils.document2Stream(list.item(0)); 973 879 this.setSourceStream(is); 974 880 … … 1022 928 this.saveDocument(); 1023 929 1024 // Admin.notifyUser("new document");930 //log.debug("new document"); 1025 931 } catch (ParserConfigurationException e) { 1026 932 // TODO Auto-generated catch block … … 1051 957 init = true; 1052 958 } catch (IOException ex){ 1053 // Admin.notifyUser("initCacheCounter:" + ex.toString());959 //log.debug("initCacheCounter:" + ex.toString()); 1054 960 ex.printStackTrace(); 1055 961 } … … 1070 976 //workspace_doc.getFirstChild().getAttributes().getNamedItem("idcounter").setNodeValue(i.toString()); 1071 977 1072 // Admin.notifyUser("writeCacheCounter:" + i.toString());978 //log.debug("writeCacheCounter:" + i.toString()); 1073 979 // write xml 1074 980 Transformer transformer;
Note: See TracChangeset
for help on using the changeset viewer.