001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * ExportPanel.java
044: *
045: * Created on May 31, 2004
046: */
047: package org.netbeans.modules.mobility.project.ui.security;
048:
049: import org.openide.DialogDescriptor;
050: import org.openide.DialogDisplayer;
051: import org.openide.NotifyDescriptor;
052: import org.openide.filesystems.FileUtil;
053: import org.openide.util.HelpCtx;
054: import org.openide.util.NbBundle;
055: import org.netbeans.modules.mobility.project.security.KeyStoreRepository;
056: import org.netbeans.modules.mobility.project.security.MEKeyTool;
057: import org.netbeans.modules.mobility.cldcplatform.J2MEPlatform;
058: import org.netbeans.api.java.platform.JavaPlatformManager;
059: import org.netbeans.api.java.platform.JavaPlatform;
060: import org.netbeans.api.java.platform.Specification;
061:
062: import javax.swing.*;
063: import javax.swing.event.ListSelectionListener;
064: import javax.swing.event.ListSelectionEvent;
065: import java.awt.*;
066: import java.awt.event.ActionEvent;
067: import java.awt.event.ActionListener;
068: import java.awt.event.ItemListener;
069: import java.awt.event.ItemEvent;
070: import java.util.ArrayList;
071: import java.io.IOException;
072: import java.io.File;
073: import java.io.FileInputStream;
074: import java.io.FileOutputStream;
075:
076: /**
077: *
078: * @author David Kaspar
079: */
080: public class ExportPanel extends javax.swing.JPanel implements
081: ItemListener, ListSelectionListener {
082:
083: private static final Dimension PREFERRED_SIZE = new Dimension(500,
084: 500);
085:
086: private DialogDescriptor dd;
087: final private KeyStoreRepository.KeyStoreBean bean;
088: final private KeyStoreRepository.KeyStoreBean.KeyAliasBean alias;
089: final private JButton bExport;
090: String keyString = NbBundle
091: .getMessage(ExportPanel.class, "LBL_Key"); // NOI18N
092:
093: /** Creates new form ExportPanel */
094: public ExportPanel(KeyStoreRepository.KeyStoreBean bean,
095: KeyStoreRepository.KeyStoreBean.KeyAliasBean alias,
096: J2MEPlatform preselectedPlatform, String preselectedDomain) {
097: this .bean = bean;
098: this .alias = alias;
099: initComponents();
100: initAccessibility();
101: bDelete.setEnabled(false);
102: bExport = new JButton(NbBundle.getMessage(ExportPanel.class,
103: "LBL_Export")); // NOI18N
104: bExport.setDefaultCapable(true);
105: bExport.setEnabled(false);
106: bExport.addActionListener(new ActionListener() {
107: @SuppressWarnings("synthetic-access")
108: public void actionPerformed(@SuppressWarnings("unused")
109: final ActionEvent evt) {
110: export();
111: reloadList((J2MEPlatform) cPlatform.getSelectedItem());
112: }
113: });
114: tKeystore.setText(bean.getKeyStorePath());
115: tAlias.setText(alias.getAlias());
116: lDetails.setText(KeyAliasCellRenderer
117: .getHtmlFormattedText(alias));
118: cPlatform.addItemListener(this );
119: list.setCellRenderer(new DefaultListCellRenderer() {
120: public Component getListCellRendererComponent(
121: final JList list, Object value, final int index,
122: final boolean isSelected, final boolean cellHasFocus) {
123: if (value instanceof MEKeyTool.KeyDetail) {
124: final MEKeyTool.KeyDetail key = (MEKeyTool.KeyDetail) value;
125: final Color color = isSelected ? list
126: .getSelectionForeground() : list
127: .getForeground();
128: final StringBuffer sb = new StringBuffer(
129: "<html><font color=\"#"
130: + Integer.toHexString(color
131: .getRGB() & 0xffffff)
132: + "\"><b>" + keyString + ": "
133: + key.getOrder() + "</b>"); // NOI18N
134: final String[] lines = key.getInfo();
135: if (lines != null)
136: for (int i = 0; i < lines.length; i++)
137: sb.append("<br>").append(lines[i]); // NOI18N
138: value = sb.toString();
139: }
140: return super .getListCellRendererComponent(list, value,
141: index, isSelected, cellHasFocus);
142: }
143: });
144: list.addListSelectionListener(this );
145: JavaPlatform[] platforms = JavaPlatformManager.getDefault()
146: .getPlatforms(
147: null,
148: new Specification(
149: J2MEPlatform.SPECIFICATION_NAME, null));
150: cPlatform.removeAllItems();
151: if (platforms != null)
152: for (int i = 0; i < platforms.length; i++) {
153: JavaPlatform platform = platforms[i];
154: if (platform instanceof J2MEPlatform)
155: cPlatform.addItem(platform);
156: }
157: if (preselectedPlatform != null) {
158: cPlatform.setSelectedItem(preselectedPlatform);
159: if (preselectedDomain != null)
160: cDomain.setSelectedItem(preselectedDomain);
161: }
162: }
163:
164: /** This method is called from within the constructor to
165: * initialize the form.
166: * WARNING: Do NOT modify this code. The content of this method is
167: * always regenerated by the Form Editor.
168: */
169: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
170: private void initComponents() {
171: java.awt.GridBagConstraints gridBagConstraints;
172:
173: lKeystore = new javax.swing.JLabel();
174: tKeystore = new javax.swing.JTextField();
175: lAlias = new javax.swing.JLabel();
176: tAlias = new javax.swing.JTextField();
177: pDetails = new javax.swing.JPanel();
178: lDetails = new javax.swing.JLabel();
179: lPlatform = new javax.swing.JLabel();
180: cPlatform = new javax.swing.JComboBox();
181: lDomain = new javax.swing.JLabel();
182: cDomain = new javax.swing.JComboBox();
183: lKeys = new javax.swing.JLabel();
184: jScrollPane1 = new javax.swing.JScrollPane();
185: list = new javax.swing.JList();
186: bDelete = new javax.swing.JButton();
187: pError = new org.netbeans.modules.mobility.project.ui.customizer.ErrorPanel();
188:
189: setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12,
190: 12, 12));
191: setMinimumSize(new java.awt.Dimension(500, 250));
192: setPreferredSize(new java.awt.Dimension(500, 250));
193: setLayout(new java.awt.GridBagLayout());
194:
195: lKeystore.setLabelFor(tKeystore);
196: org.openide.awt.Mnemonics.setLocalizedText(lKeystore,
197: org.openide.util.NbBundle.getMessage(ExportPanel.class,
198: "LBL_Export_File")); // NOI18N
199: gridBagConstraints = new java.awt.GridBagConstraints();
200: gridBagConstraints.gridx = 0;
201: gridBagConstraints.gridy = 0;
202: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
203: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
204: add(lKeystore, gridBagConstraints);
205:
206: tKeystore.setEditable(false);
207: gridBagConstraints = new java.awt.GridBagConstraints();
208: gridBagConstraints.gridx = 1;
209: gridBagConstraints.gridy = 0;
210: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
211: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212: gridBagConstraints.weightx = 1.0;
213: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
214: add(tKeystore, gridBagConstraints);
215: tKeystore.getAccessibleContext().setAccessibleDescription(
216: NbBundle.getMessage(ExportPanel.class,
217: "ACSD_Export_Keystore")); // NOI18N
218:
219: lAlias.setLabelFor(tAlias);
220: org.openide.awt.Mnemonics.setLocalizedText(lAlias,
221: org.openide.util.NbBundle.getMessage(ExportPanel.class,
222: "LBL_Export_Alias")); // NOI18N
223: gridBagConstraints = new java.awt.GridBagConstraints();
224: gridBagConstraints.gridx = 0;
225: gridBagConstraints.gridy = 1;
226: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
227: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
228: add(lAlias, gridBagConstraints);
229:
230: tAlias.setEditable(false);
231: gridBagConstraints = new java.awt.GridBagConstraints();
232: gridBagConstraints.gridx = 1;
233: gridBagConstraints.gridy = 1;
234: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
235: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
236: gridBagConstraints.weightx = 1.0;
237: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
238: add(tAlias, gridBagConstraints);
239: tAlias.getAccessibleContext().setAccessibleDescription(
240: NbBundle.getMessage(ExportPanel.class,
241: "ACSD_Export_Alias")); // NOI18N
242:
243: pDetails.setBorder(javax.swing.BorderFactory
244: .createTitledBorder(org.openide.util.NbBundle
245: .getMessage(ExportPanel.class,
246: "LBL_Export_Details"))); // NOI18N
247: pDetails.setPreferredSize(new java.awt.Dimension(300, 100));
248: pDetails.setEnabled(false);
249: pDetails.setLayout(new java.awt.GridBagLayout());
250:
251: lDetails.setVerticalAlignment(javax.swing.SwingConstants.TOP);
252: gridBagConstraints = new java.awt.GridBagConstraints();
253: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
254: gridBagConstraints.weightx = 1.0;
255: gridBagConstraints.weighty = 1.0;
256: pDetails.add(lDetails, gridBagConstraints);
257:
258: gridBagConstraints = new java.awt.GridBagConstraints();
259: gridBagConstraints.gridx = 0;
260: gridBagConstraints.gridy = 2;
261: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
262: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
263: gridBagConstraints.weightx = 1.0;
264: gridBagConstraints.weighty = 1.0;
265: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
266: add(pDetails, gridBagConstraints);
267:
268: lPlatform.setLabelFor(cPlatform);
269: org.openide.awt.Mnemonics.setLocalizedText(lPlatform,
270: org.openide.util.NbBundle.getMessage(ExportPanel.class,
271: "LBL_Export_Platform")); // NOI18N
272: gridBagConstraints = new java.awt.GridBagConstraints();
273: gridBagConstraints.gridx = 0;
274: gridBagConstraints.gridy = 3;
275: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
276: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
277: add(lPlatform, gridBagConstraints);
278: gridBagConstraints = new java.awt.GridBagConstraints();
279: gridBagConstraints.gridx = 1;
280: gridBagConstraints.gridy = 3;
281: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
282: gridBagConstraints.weightx = 1.0;
283: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
284: add(cPlatform, gridBagConstraints);
285: cPlatform.getAccessibleContext().setAccessibleDescription(
286: NbBundle.getMessage(ExportPanel.class,
287: "ACSD_Export_Platform")); // NOI18N
288:
289: lDomain.setLabelFor(cDomain);
290: org.openide.awt.Mnemonics.setLocalizedText(lDomain,
291: org.openide.util.NbBundle.getMessage(ExportPanel.class,
292: "LBL_Export_Domain")); // NOI18N
293: gridBagConstraints = new java.awt.GridBagConstraints();
294: gridBagConstraints.gridx = 0;
295: gridBagConstraints.gridy = 4;
296: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
297: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
298: add(lDomain, gridBagConstraints);
299: gridBagConstraints = new java.awt.GridBagConstraints();
300: gridBagConstraints.gridx = 1;
301: gridBagConstraints.gridy = 4;
302: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
303: gridBagConstraints.weightx = 1.0;
304: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
305: add(cDomain, gridBagConstraints);
306: cDomain.getAccessibleContext().setAccessibleDescription(
307: NbBundle.getMessage(ExportPanel.class,
308: "ACSD_Export_Domain")); // NOI18N
309:
310: lKeys.setLabelFor(list);
311: org.openide.awt.Mnemonics.setLocalizedText(lKeys,
312: org.openide.util.NbBundle.getMessage(ExportPanel.class,
313: "LBL_Export_Keys")); // NOI18N
314: gridBagConstraints = new java.awt.GridBagConstraints();
315: gridBagConstraints.gridx = 0;
316: gridBagConstraints.gridy = 5;
317: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
318: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
319: add(lKeys, gridBagConstraints);
320:
321: list
322: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
323: jScrollPane1.setViewportView(list);
324: list.getAccessibleContext().setAccessibleDescription(
325: NbBundle.getMessage(ExportPanel.class,
326: "ACSD_Export_Keys")); // NOI18N
327:
328: gridBagConstraints = new java.awt.GridBagConstraints();
329: gridBagConstraints.gridx = 0;
330: gridBagConstraints.gridy = 6;
331: gridBagConstraints.gridwidth = 2;
332: gridBagConstraints.gridheight = 2;
333: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
334: gridBagConstraints.weightx = 1.0;
335: gridBagConstraints.weighty = 3.0;
336: add(jScrollPane1, gridBagConstraints);
337:
338: org.openide.awt.Mnemonics.setLocalizedText(bDelete,
339: org.openide.util.NbBundle.getMessage(ExportPanel.class,
340: "LBL_Export_DeleteKey")); // NOI18N
341: bDelete.addActionListener(new java.awt.event.ActionListener() {
342: public void actionPerformed(java.awt.event.ActionEvent evt) {
343: bDeleteActionPerformed(evt);
344: }
345: });
346: gridBagConstraints = new java.awt.GridBagConstraints();
347: gridBagConstraints.gridx = 2;
348: gridBagConstraints.gridy = 6;
349: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
350: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
351: add(bDelete, gridBagConstraints);
352: bDelete.getAccessibleContext().setAccessibleDescription(
353: NbBundle.getMessage(ExportPanel.class,
354: "ACSD_Export_DeleteKey")); // NOI18N
355:
356: gridBagConstraints = new java.awt.GridBagConstraints();
357: gridBagConstraints.gridx = 0;
358: gridBagConstraints.gridy = 8;
359: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
360: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
361: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
362: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
363: gridBagConstraints.weightx = 1.0;
364: add(pError, gridBagConstraints);
365: }// </editor-fold>//GEN-END:initComponents
366:
367: private void initAccessibility() {
368: getAccessibleContext().setAccessibleName(
369: NbBundle.getMessage(ExportPanel.class, "ACSN_Export"));
370: getAccessibleContext().setAccessibleDescription(
371: NbBundle.getMessage(ExportPanel.class, "ACSD_Export"));
372: }
373:
374: public void valueChanged(@SuppressWarnings("unused")
375: final ListSelectionEvent e) {
376: bDelete
377: .setEnabled(list.getSelectedValue() instanceof MEKeyTool.KeyDetail);
378: }
379:
380: public Dimension getPreferredSize() {
381: return PREFERRED_SIZE;
382: }
383:
384: protected void setDialogDescriptor(final DialogDescriptor desc) {
385: this .dd = desc;
386: dd.setHelpCtx(new HelpCtx(ExportPanel.class));
387: checkErrors();
388: }
389:
390: public String getErrorMessage() {
391: final ListModel model = list.getModel();
392: for (int a = 0; a < model.getSize(); a++) {
393: final Object o = model.getElementAt(a);
394: if (o instanceof MEKeyTool.KeyDetail) {
395: final MEKeyTool.KeyDetail key = (MEKeyTool.KeyDetail) o;
396: final String owner = key.getOwner();
397: if (owner != null
398: && owner.equals(alias.getSubjectName()))
399: return NbBundle.getMessage(ExportPanel.class,
400: "ERR_KeyIsAlreadyInPlatform", owner,
401: Integer.toString(key.getOrder())); // NOI18N
402: }
403: }
404: return null;
405: }
406:
407: public void checkErrors() {
408: final String errorMessage = getErrorMessage();
409: pError.setErrorMessage(errorMessage);
410: final boolean valid = errorMessage == null;
411: bExport
412: .setEnabled(valid
413: && cPlatform.getSelectedItem() != null);
414: if (dd != null && valid != dd.isValid())
415: dd.setValid(valid);
416: }
417:
418: private void bDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDeleteActionPerformed
419: final J2MEPlatform platform = (J2MEPlatform) cPlatform
420: .getSelectedItem();
421: final Object value = list.getSelectedValue();
422: final String keytool = MEKeyTool.getMEKeyToolPath(platform);
423: if (value instanceof MEKeyTool.KeyDetail && keytool != null) {
424: final MEKeyTool.KeyDetail key = (MEKeyTool.KeyDetail) value;
425: if (DialogDisplayer.getDefault().notify(
426: new NotifyDescriptor.Confirmation(NbBundle
427: .getMessage(ExportPanel.class,
428: "MSG_DeleteKeyConfirmation",
429: Integer.toString(key.getOrder()),
430: platform.getDisplayName()),
431: NbBundle.getMessage(ExportPanel.class,
432: "TITLE_ConfirmKeyDeletion"),
433: NotifyDescriptor.YES_NO_OPTION)) == NotifyDescriptor.YES_OPTION) { // NOI18N
434: try {
435: MEKeyTool.execute(new String[] { keytool,
436: "-delete", "-number",
437: Integer.toString(key.getOrder()) }); // NOI18N
438: } catch (IOException e) {
439: e.printStackTrace();
440: DialogDisplayer.getDefault().notify(
441: new NotifyDescriptor.Message(NbBundle
442: .getMessage(ExportPanel.class,
443: "ERR_WhileDeletingKey"),
444: NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
445: }
446: reloadList(platform);
447: }
448: }
449: }//GEN-LAST:event_bDeleteActionPerformed
450:
451: public void itemStateChanged(@SuppressWarnings("unused")
452: final ItemEvent e) {
453: final J2MEPlatform platform = (J2MEPlatform) cPlatform
454: .getSelectedItem();
455: final ArrayList<String> list = new ArrayList<String>();
456: if (platform != null) {
457: final J2MEPlatform.Device[] devices = platform.getDevices();
458: if (devices != null)
459: for (int i = 0; i < devices.length; i++) {
460: final J2MEPlatform.Device device = devices[i];
461: final String[] domains = device
462: .getSecurityDomains();
463: if (domains != null)
464: for (int j = 0; j < domains.length; j++) {
465: final String domain = domains[j];
466: if (!list.contains(domain))
467: list.add(domain);
468: }
469: }
470: }
471: cDomain.removeAllItems();
472: for (int i = 0; i < list.size(); i++)
473: cDomain.addItem(list.get(i));
474: reloadList(platform);
475: }
476:
477: protected void reloadList(final J2MEPlatform platform) {
478: bDelete.setEnabled(false);
479: if (platform != null) {
480: setListLoading();
481: setList(MEKeyTool.listKeys(platform));
482: } else
483: setListNotLoaded();
484: checkErrors();
485: }
486:
487: private void setListNotLoaded() {
488: final DefaultListModel model = new DefaultListModel();
489: model.addElement(NbBundle.getMessage(ExportPanel.class,
490: "LBL_NotLoaded")); // NOI18N
491: list.setModel(model);
492: }
493:
494: private void setListLoading() {
495: final DefaultListModel model = new DefaultListModel();
496: model.addElement(NbBundle.getMessage(ExportPanel.class,
497: "LBL_Loading")); // NOI18N
498: list.setModel(model);
499: }
500:
501: private void setList(final MEKeyTool.KeyDetail[] keys) {
502: final DefaultListModel model = new DefaultListModel();
503: if (keys != null) {
504: if (keys.length > 0) {
505: for (int i = 0; i < keys.length; i++) {
506: final MEKeyTool.KeyDetail key = keys[i];
507: model.addElement(key);
508: }
509: } else {
510: model.addElement(NbBundle.getMessage(ExportPanel.class,
511: "LBL_NoKey")); // NOI18N
512: }
513: } else {
514: model.addElement(NbBundle.getMessage(ExportPanel.class,
515: "LBL_ErrorLoadingKeys")); // NOI18N
516: }
517: list.setModel(model);
518: }
519:
520: public static void showExportKeyIntoPlatform(
521: final KeyStoreRepository.KeyStoreBean bean,
522: final KeyStoreRepository.KeyStoreBean.KeyAliasBean alias,
523: final J2MEPlatform preselectedPlatform,
524: final String preselectedDomain) {
525: if (bean == null || alias == null || !bean.isOpened()
526: || !alias.isValid() || !alias.isOpened())
527: return;
528: final ExportPanel export = new ExportPanel(bean, alias,
529: preselectedPlatform, preselectedDomain);
530: final DialogDescriptor dd = new DialogDescriptor(export,
531: NbBundle.getMessage(ExportPanel.class,
532: "TITLE_ExportKey"), true, null); // NOI18N
533: dd.setOptions(new Object[] { export.bExport,
534: NotifyDescriptor.CLOSED_OPTION });
535: dd
536: .setClosingOptions(new Object[] { NotifyDescriptor.CLOSED_OPTION });
537: export.setDialogDescriptor(dd);
538: export.checkErrors();
539: final Dialog d = DialogDisplayer.getDefault().createDialog(dd);
540: d.setVisible(true);
541: }
542:
543: protected void export() {
544: final J2MEPlatform platform = (J2MEPlatform) cPlatform
545: .getSelectedItem();
546: final String domain = (String) cDomain.getSelectedItem();
547: final String keytool = MEKeyTool.getMEKeyToolPath(platform);
548: if (platform != null && domain != null && keytool != null) {
549: final File target = new File(System.getProperty(
550: "user.home", ""), ".keystore"); // NOI18N
551: if (target.exists()) {
552: if (DialogDisplayer.getDefault().notify(
553: new NotifyDescriptor.Confirmation(NbBundle
554: .getMessage(ExportPanel.class,
555: "MSG_PromptDeleteFile", bean
556: .getKeyStorePath(),
557: target.getAbsolutePath()),
558: NbBundle.getMessage(ExportPanel.class,
559: "MSG_PromptDeleteFileTitle"),
560: NotifyDescriptor.YES_NO_OPTION)) != NotifyDescriptor.YES_OPTION) // NOI18N
561: return;
562: if (!target.delete()) {
563: DialogDisplayer.getDefault().notify(
564: new NotifyDescriptor.Message(NbBundle
565: .getMessage(ExportPanel.class,
566: "ERR_CannotDeleteFile",
567: target.getAbsolutePath()),
568: NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
569: return;
570: }
571: }
572: boolean canDeleteTempKeystore = false;
573: if (!KeyStoreRepository.KeyStoreBean.equalFiles(bean
574: .getKeyStoreFile(), target)) {
575: canDeleteTempKeystore = true;
576: FileInputStream fis = null;
577: FileOutputStream fos = null;
578: try {
579: fis = new FileInputStream(bean.getKeyStoreFile());
580: fos = new FileOutputStream(target);
581: FileUtil.copy(fis, fos);
582: } catch (IOException e) {
583: DialogDisplayer.getDefault().notify(
584: new NotifyDescriptor.Message(NbBundle
585: .getMessage(ExportPanel.class,
586: "ERR_IOErrorWhileCopying",
587: bean.getKeyStorePath(),
588: target.getAbsolutePath()),
589: NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
590: e.printStackTrace();
591: return;
592: } finally {
593: if (fis != null)
594: try {
595: fis.close();
596: } catch (IOException e) {
597: }
598: if (fos != null)
599: try {
600: fos.close();
601: } catch (IOException e) {
602: }
603: }
604: }
605:
606: try {
607: MEKeyTool.execute(new String[] { keytool, "-import",
608: "-storepass", bean.getPassword(), "-alias",
609: alias.getAlias(), "-domain", domain }); // NOI18N
610: } catch (IOException e) {
611: e.printStackTrace();
612: DialogDisplayer.getDefault().notify(
613: new NotifyDescriptor.Message(NbBundle
614: .getMessage(ExportPanel.class,
615: "MSG_ErrorExportingKey"),
616: NotifyDescriptor.ERROR_MESSAGE)); // NOI18N
617: }
618:
619: if (canDeleteTempKeystore)
620: target.delete();
621: }
622: }
623:
624: // Variables declaration - do not modify//GEN-BEGIN:variables
625: private javax.swing.JButton bDelete;
626: private javax.swing.JComboBox cDomain;
627: private javax.swing.JComboBox cPlatform;
628: private javax.swing.JScrollPane jScrollPane1;
629: private javax.swing.JLabel lAlias;
630: private javax.swing.JLabel lDetails;
631: private javax.swing.JLabel lDomain;
632: private javax.swing.JLabel lKeys;
633: private javax.swing.JLabel lKeystore;
634: private javax.swing.JLabel lPlatform;
635: private javax.swing.JList list;
636: private javax.swing.JPanel pDetails;
637: private org.netbeans.modules.mobility.project.ui.customizer.ErrorPanel pError;
638: private javax.swing.JTextField tAlias;
639: private javax.swing.JTextField tKeystore;
640: // End of variables declaration//GEN-END:variables
641:
642: }
|