001: /*
002: * (C) Copyright SimulacraMedia 2003. All rights reserved.
003: *
004: * Created on Dec 1, 2004
005: *
006: */
007: package org.openharmonise.him.actions.system;
008:
009: import java.awt.Dimension;
010: import java.awt.event.ActionEvent;
011: import java.net.MalformedURLException;
012: import java.net.URI;
013: import java.net.URL;
014: import java.rmi.RemoteException;
015:
016: import javax.swing.Icon;
017: import javax.swing.ImageIcon;
018: import javax.swing.JFrame;
019: import javax.xml.rpc.ServiceException;
020:
021: import org.openharmonise.him.actions.AbstractHIMAction;
022: import org.openharmonise.him.actions.HIMAction;
023: import org.openharmonise.him.configuration.EmailDialog;
024: import org.openharmonise.him.publish.PublishServiceClient;
025: import org.openharmonise.him.window.messages.MessageHandler;
026: import org.openharmonise.vfs.AbstractVirtualFileSystem;
027: import org.openharmonise.vfs.VirtualFile;
028: import org.openharmonise.vfs.context.ContextEvent;
029: import org.openharmonise.vfs.gui.IconManager;
030: import org.openharmonise.vfs.servers.ServerList;
031: import org.openharmonise.vfs.status.StatusData;
032: import org.openharmonise.vfs.status.VFSStatus;
033:
034: /**
035: * Action to download all the published Sections, Documents and Metadata into an
036: * XML file.
037: *
038: * @author MATT TREANOR
039: * @version $Revision: 1.2 $
040: *
041: */
042: public class ActionExportContent extends AbstractHIMAction implements
043: HIMAction {
044:
045: /**
046: *
047: */
048: public ActionExportContent() {
049: super ();
050: // TODO Auto-generated constructor stub
051: }
052:
053: /**
054: * @param vfFile
055: */
056: public ActionExportContent(VirtualFile vfFile) {
057: super (vfFile);
058: // TODO Auto-generated constructor stub
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
065: */
066: public void actionPerformed(ActionEvent arg0) {
067: JFrame frame = new JFrame();
068: frame.setIconImage(((ImageIcon) IconManager.getInstance()
069: .getIcon("32-sim-logo.gif")).getImage());
070: EmailDialog emailDialog = new EmailDialog(frame);
071:
072: frame.setVisible(true);
073: frame.setTitle("Export Content");
074: Dimension dims = frame.getGraphicsConfiguration().getBounds()
075: .getSize();
076: frame.setLocation(dims.width, dims.height);
077:
078: emailDialog.show();
079:
080: String sEmail = emailDialog.getEmail();
081: String sType = emailDialog.getType();
082:
083: frame.setVisible(false);
084:
085: if (sEmail != null && sEmail.length() > 0) {
086: boolean bShowContent = true;
087: boolean bShowMetadata = true;
088: if (sType.equals(emailDialog.TYPE_CONTENTS)) {
089: bShowMetadata = false;
090: } else if (sType.equals(emailDialog.TYPE_METADATA)) {
091: bShowContent = false;
092: }
093: StatusData statusOverall = new VFSStatus();
094: try {
095: invokeExportService(sEmail, bShowContent, bShowMetadata);
096: } catch (Exception e) {
097: e.printStackTrace();
098: String sMsg = "There was a problem exporting the content.";
099: MessageHandler.getInstance().fireMessageEvent(sMsg,
100: MessageHandler.TYPE_ERROR);
101: }
102: }
103: }
104:
105: public void invokeExportService(String sEmailAddress,
106: boolean bShowContent, boolean bShowMetadata)
107: throws MalformedURLException, RemoteException,
108: ServiceException {
109: AbstractVirtualFileSystem vfs = ServerList.getInstance()
110: .getHarmoniseServer().getVFS();
111: URI uri = vfs.getURI();
112: String sURL = uri.getScheme() + "://" + uri.getHost() + ":"
113: + uri.getPort() + "/webdav/services/PublishService";
114: URL endPointURL = new URL(sURL);
115: PublishServiceClient.exportContent(endPointURL, sEmailAddress,
116: bShowContent, bShowMetadata);
117: }
118:
119: /*
120: * (non-Javadoc)
121: *
122: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getText()
123: */
124: public String getText() {
125: return "Export Content";
126: }
127:
128: /*
129: * (non-Javadoc)
130: *
131: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getToolTip()
132: */
133: public String getToolTip() {
134: return this .getDescription();
135: }
136:
137: /*
138: * (non-Javadoc)
139: *
140: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getIcon()
141: */
142: public Icon getIcon() {
143: return IconManager.getInstance().getIcon("16-blank.gif");
144: }
145:
146: /*
147: * (non-Javadoc)
148: *
149: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#getMnemonic()
150: */
151: public String getMnemonic() {
152: return "O";
153: }
154:
155: /*
156: * (non-Javadoc)
157: *
158: * @see com.simulacramedia.contentmanager.actions.CMAction#getDescription()
159: */
160: public String getDescription() {
161: return "Download all the Sections, Documents and Metadata";
162: }
163:
164: /*
165: * (non-Javadoc)
166: *
167: * @see com.simulacramedia.contentmanager.actions.AbstractCMAction#isEnabled(com.simulacramedia.contentmanager.context.ContextEvent)
168: */
169: public boolean isEnabled(ContextEvent ce) {
170: if (!m_bUserChecked) {
171: checkUser();
172: }
173: this .setEnabled(m_bShow);
174: return m_bShow;
175: }
176:
177: /*
178: * (non-Javadoc)
179: *
180: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorKeycode()
181: */
182: public int getAcceleratorKeycode() {
183: // TODO Auto-generated method stub
184: return 0;
185: }
186:
187: /*
188: * (non-Javadoc)
189: *
190: * @see com.simulacramedia.contentmanager.actions.CMAction#getAcceleratorMask()
191: */
192: public int getAcceleratorMask() {
193: // TODO Auto-generated method stub
194: return 0;
195: }
196:
197: public static void main(String[] args) {
198: ActionExportContent myAction = new ActionExportContent();
199: myAction.actionPerformed(null);
200: System.out.println("Done");
201: System.exit(0);
202: }
203: }
|