Ignore:
Timestamp:
09/27/10 11:27:07 (14 years ago)
Author:
gaba
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java

    r713 r715  
    1212import java.io.StringReader;
    1313import java.io.StringWriter;
     14
     15import javax.servlet.http.HttpServletRequest;
    1416import javax.xml.parsers.DocumentBuilder;
    1517import javax.xml.parsers.DocumentBuilderFactory;
     
    2931import net.sf.json.xml.XMLSerializer;
    3032
     33import org.apache.struts2.interceptor.ServletRequestAware;
    3134import org.w3c.dom.Document;
    3235import org.w3c.dom.Node;
     
    4346 *
    4447 */
    45 public class WorkspaceAction extends ActionSupport
     48public class WorkspaceAction extends GenericProxyAction
     49//implements ServletRequestAware
    4650{
    4751
    4852        private static final long serialVersionUID = 1L;
     53       
     54        public static String USER = "user";
     55        public static String SERVER = "server";
    4956       
    5057        /**
    5158         * Properties to be filled by Struts with according request-parameters
    5259         */     
    53         private String actionkey;
     60        //private String actionkey;
    5461        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;
    5965        private String base_path;
    6066       
     67        //private HttpServletRequest request;
     68         
    6169        public String getData() {
    6270                return data;
     
    6775        }
    6876
    69         public String getID() {
    70                 return id;
    71         }
    72 
    73         public void setID(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        /*
    7785        public String getFormat() {
    7886                return format;
     
    9098                actionkey = actionKey;
    9199        }
    92 
     100*/
    93101        /**
    94102         * primitive identification of the target-proxy
     
    100108                return "workspaceprofile";
    101109        }
    102        
     110        /*
    103111        public String getUserMsg() {
    104112                return userMsg;
     
    109117        }
    110118
     119        @Override
     120        public void setServletRequest(HttpServletRequest arg0) {
     121                request = arg0;
     122               
     123        }
    111124
    112125        private InputStream resultStream;
    113126        private InputStream sourceStream;
    114 
     127*/
    115128        /**
    116129         * The stream holding the resulting data to be sent back to the user as response
    117130         * @return
    118131         */
     132        /*
    119133        public InputStream getResultStream() {
    120134                return resultStream;
     
    126140                sourceStream = _sourceStream;
    127141        }
    128        
    129        
     142        */
     143        @Override
    130144        public URL getBaseURL() {
    131145                File file=new File(getPath());
     
    147161                return base_path;
    148162        }
    149         //TODO identification of WOrkspaceProfile (user, name, id)
     163       
     164       
    150165        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
    154197        public String getFullFormat() {
    155198                return "xml2json";
     
    171214        public String getPath() {
    172215                String targetPath = getBasePath() + getWorkspaceProfile();         
    173         Admin.notifyUser(targetPath);             
     216        Admin.notifyUser("WorkspaceAction TARGETPATH: " + targetPath);             
    174217        return targetPath;
    175218        }
    176219
     220        @Override
    177221        public InputStream getSourceStream() throws IOException {       
    178222                InputStream stream = new BufferedInputStream( new FileInputStream(getPath()));
     
    182226        }
    183227       
     228        @Override
    184229        public void prepare() throws Exception {               
    185230               
    186231                //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);   
    190236                }else { //JSON
    191237                        // set srcFile (for MDTransformer to pass to xsl-scripts)
    192238                        MDTransformer.getMDTransformer().setSrcFile(getURL());
    193                         resultStream =  MDTransformer.getMDTransformer().transformXML(sourceStream, getFullFormat());
     239                        setResultStream(MDTransformer.getMDTransformer().transformXML(in, getFullFormat()));
    194240                }
    195241                       
    196                 Admin.notifyUser(getProxyKey() + " success:" + (resultStream!=null));
     242                Admin.notifyUser(getProxyKey() + " success:" + (getResultStream()!=null));
    197243        }
    198244
     
    318364       
    319365        InputStream is_xml = new ByteArrayInputStream( xml.getBytes( ) );
     366       
    320367        Admin.writeToFile(getPath(), is_xml);
    321368   
    322369        String ret = "1";
    323                 resultStream = new ByteArrayInputStream(ret.getBytes());
     370                this.setResultStream( new ByteArrayInputStream(ret.getBytes()));
    324371                               
    325372
     
    330377         * default Action method
    331378         */
     379        /*
    332380        public String execute() throws Exception {
    333381               
     
    339387                }               
    340388        }
    341        
     389        */
    342390       
    343391
Note: See TracChangeset for help on using the changeset viewer.