KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > actions > publish > ActionPublishToInternet


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.actions.publish;
20
21 import java.awt.event.*;
22
23 import javax.swing.*;
24
25 import org.openharmonise.him.actions.*;
26 import org.openharmonise.him.actions.rules.*;
27 import org.openharmonise.him.context.StateHandler;
28 import org.openharmonise.him.displaycomponents.table.*;
29 import org.openharmonise.him.harmonise.*;
30 import org.openharmonise.him.window.*;
31 import org.openharmonise.him.window.messages.builders.*;
32 import org.openharmonise.him.window.session.*;
33 import org.openharmonise.vfs.*;
34 import org.openharmonise.vfs.context.*;
35 import org.openharmonise.vfs.gui.*;
36 import org.openharmonise.vfs.status.*;
37
38
39 /**
40  * Action to publish a virtual file.
41  *
42  * @author Matthew Large
43  * @version $Revision: 1.1 $
44  *
45  */

46 public class ActionPublishToInternet
47     extends AbstractHIMAction
48     implements HIMAction {
49
50     public static String JavaDoc ACTION_NAME = "PUBLISH";
51
52     /**
53      * Wait identifier for state handler.
54      */

55     private static final String JavaDoc WAIT_LABEL = "PUBLISH-ACTION";
56
57     /**
58      *
59      */

60     public ActionPublishToInternet() {
61         super();
62         this.setup();
63     }
64
65     /**
66      * @param vfFile
67      */

68     public ActionPublishToInternet(VirtualFile vfFile) {
69         super(vfFile);
70         this.setup();
71     }
72
73     /**
74      * Configures this action.
75      *
76      */

77     private void setup() {
78         RuleGroup andGroup = new RuleGroup();
79         andGroup.setGroupType(RuleGroup.GROUPTYPE_AND);
80         PathRule pathRule = new PathRule("/webdav/Archive/");
81         pathRule.setResultComparator(false);
82         andGroup.addEnableRule(pathRule);
83         isMetadataValidRule metadataRule = new isMetadataValidRule();
84         metadataRule.setResultComparator(true);
85         andGroup.addEnableRule(metadataRule);
86         IsHistoricalRule histRule = new IsHistoricalRule();
87         histRule.setResultComparator(false);
88         andGroup.addEnableRule(histRule);
89         SecurityRule secRule = new SecurityRule(VirtualFile.METHOD_CHECKIN);
90         andGroup.addEnableRule(secRule);
91         TabRule tabRule = new TabRule("Search");
92         tabRule.setResultComparator(false);
93         andGroup.addEnableRule( tabRule );
94         this.addEnableRule(andGroup);
95     }
96
97     /* (non-Javadoc)
98      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
99      */

100     public void actionPerformed(ActionEvent arg0) {
101         VirtualFile vfFile = this.getLastContextFile();
102         StatusData statusOverall = new VFSStatus();
103         AbstractVirtualFileSystem vfs = vfFile.getVFS();
104         
105         if (vfFile.isVersionable()) {
106             VersionedVirtualFile vfVerFile = (VersionedVirtualFile) vfFile;
107             
108             String JavaDoc sLivePath = vfVerFile.getLiveVersionPath();
109             
110             StateHandler.getInstance().addWait(WAIT_LABEL);
111             String JavaDoc sFileName = null;
112             try {
113                 sFileName =
114                     vfFile.getVFS().getVirtualFileSystemView().getDisplayName(
115                         vfFile);
116                 String JavaDoc sMessage = null;
117                 StatusData status = vfVerFile.checkin();
118                 statusOverall.addStatusData(status);
119                 if(status.isOK()) {
120                     
121                     if(sLivePath!=null) {
122                         
123                         ResourceStatusWrapper pathStatus = vfs.getVirtualFile(sLivePath);
124                         if(pathStatus.getResource()!=null) {
125                             pathStatus.getResource().unlock();
126                         }
127                         
128                         TableView table = DisplayManager.getInstance().getTable();
129                         if(table!=null) {
130                             table.setSelectedPath(sLivePath);
131                         }
132                         if(sLivePath.startsWith(HarmonisePaths.PATH_PROPERTIES)) {
133                             ContextEvent ce = new ContextEvent(ContextType.CONTEXT_METADATA_DEFINITION_CHANGED, "", vfFile.getVFS(), sLivePath);
134                             ContextHandler.getInstance().fireContextEvent(ce);
135                         }
136                     }
137                     super.fireSessionEvent("Published", this.getLastContextFile().getVFS(), this.getLastContextFile().getFullPath(), SessionEventData.RESOURCE_PUBLISHED);
138                 } else {
139
140                 }
141             } catch (Exception JavaDoc e) {
142                 e.printStackTrace(System.err);
143                 statusOverall.setStatusLevel(StatusData.LEVEL_ERROR);
144             } finally {
145                 StatusMessage statusMessage = new StatusMessage(ActionPublishToInternet.ACTION_NAME, statusOverall);
146                 statusMessage.setResourceTitle(sFileName);
147                 if(sLivePath!=null) {
148                     statusMessage.setPath(sLivePath);
149                 } else {
150                     statusMessage.setPath(vfFile.getFullPath());
151                 }
152                 VFSMessageBuilder.getInstance().fireMessage( statusMessage );
153                 StateHandler.getInstance().removeWait(WAIT_LABEL);
154             }
155         }
156     }
157
158     /* (non-Javadoc)
159      * @see com.simulacramedia.contentmanager.actions.CMAction#getMenuItem()
160      */

161     public JMenuItem getMenuItem() {
162         JMenuItem menuItem = super.getMenuItem();
163         menuItem.setAccelerator(
164             KeyStroke.getKeyStroke(
165                 this.getAcceleratorKeycode(),
166                 this.getAcceleratorMask()));
167
168         return menuItem;
169     }
170
171     /* (non-Javadoc)
172      * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
173      */

174     public String JavaDoc getDescription() {
175         return "Publishes the currently seleted resource";
176     }
177
178     /* (non-Javadoc)
179      * @see com.simulacramedia.contentmanager.actions.CMAction#getText()
180      */

181     public String JavaDoc getText() {
182         return "Publish";
183     }
184
185     /* (non-Javadoc)
186      * @see com.simulacramedia.contentmanager.actions.CMAction#getToolTip()
187      */

188     public String JavaDoc getToolTip() {
189         return this.getDescription();
190     }
191
192     /* (non-Javadoc)
193      * @see com.simulacramedia.contentmanager.actions.CMAction#getIcon()
194      */

195     public Icon getIcon() {
196         return IconManager.getInstance().getIcon("16-command-publish.gif");
197     }
198
199     /* (non-Javadoc)
200      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
201      */

202     public int getAcceleratorKeycode() {
203         return KeyEvent.VK_P;
204     }
205
206     /* (non-Javadoc)
207      * @see com.simulacramedia.contentmanager.actions.CMAction#getMnemonic()
208      */

209     public String JavaDoc getMnemonic() {
210         return "P";
211     }
212
213     /* (non-Javadoc)
214      * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
215      */

216     public int getAcceleratorMask() {
217         return InputEvent.CTRL_MASK;
218     }
219
220     /* (non-Javadoc)
221      * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#isEnabled(com.simulacramedia.contentmanager.context.ContextEvent)
222      */

223     public boolean isEnabled(ContextEvent ce) {
224         // TODO Auto-generated method stub
225
return super.isEnabled(ce);
226     }
227
228 }
229
Popular Tags