Author: samindaw Date: Thu Jul 24 08:23:49 2008 New Revision: 19957 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19957
Log: adding location attribute so that a file can be uploaded to a given location on a given name Modified: trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/GeneralServices.java Modified: trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/GeneralServices.java URL: http://wso2.org/svn/browse/wso2/trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/GeneralServices.java?rev=19957&r1=19956&r2=19957&view=diff ============================================================================== --- trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/GeneralServices.java (original) +++ trunk/wsas/java/modules/admin/src/org/wso2/wsas/admin/service/GeneralServices.java Thu Jul 24 08:23:49 2008 @@ -55,6 +55,7 @@ public class GeneralServices { private final static String ATTACHMENT_ELE = "attachment"; private final static String TYPE_ELE = "type"; + private final static String LOCATION_ELE = "location"; private final static String[] EXTENSIONS = {".aar", ".mar", ".jar", ".xml"}; private static Log log = LogFactory.getLog(GeneralServices.class); @@ -100,10 +101,13 @@ OMText attachment = (OMText) child; DataHandler dh = (DataHandler) attachment.getDataHandler(); OMElement typeEle = payload.getFirstChildWithName(new QName(TYPE_ELE)); + OMElement locationEle = payload.getFirstChildWithName(new QName(LOCATION_ELE)); if (typeEle != null) { String value = typeEle.getText(); + String location =null; + if (locationEle != null) location = locationEle.getText(); if (value != null) { - uuid = write(dh, value); + uuid = write(dh, value, location); } else { String msg = "Type text is not available"; log.error(msg); @@ -141,17 +145,29 @@ * @return String uuid * @throws AxisFault will be thrown */ - private String write(DataHandler dh, String type) throws AxisFault { + private String write(DataHandler dh, String type, String location) throws AxisFault { ConfigurationContext configCtx = MessageContext.getCurrentMessageContext().getConfigurationContext(); - String tmpDir = (String) configCtx.getProperty(WSO2Constants.WORK_DIR); - String uuid = String.valueOf(System.currentTimeMillis() + Math.random()); - tmpDir = tmpDir + File.separator + "attachments" + File.separator + uuid + File.separator; - new File(tmpDir).mkdirs(); - if (!type.startsWith(".")) { - type = ".".concat(type); + String tmpDir; + String uuid; + String fileName; + File outFile; + if (location == null){ + tmpDir = (String) configCtx.getProperty(WSO2Constants.WORK_DIR); + uuid = String.valueOf(System.currentTimeMillis() + Math.random()); + tmpDir = tmpDir + File.separator + "attachments" + File.separator + uuid + File.separator; + new File(tmpDir).mkdirs(); + if (!type.startsWith(".")) { + type = ".".concat(type); + } + outFile = new File(tmpDir, uuid + type); + } + else{ + tmpDir = System.getProperty("wso2wsas.home")+File.separator+location; + outFile = new File(tmpDir); + uuid = outFile.getName(); } - File outFile = new File(tmpDir, uuid + type); + try { FileOutputStream outStream = new FileOutputStream(outFile); dh.writeTo(outStream); _______________________________________________ Wsas-java-dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev
