+++ /dev/null
-/*
- * jSite - a tool for uploading websites into Freenet
- * Copyright (C) 2006 David Roden
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-package de.todesbaum.jsite.application;
-
-/**
- * Project extension for edition-based projects. In Freenet 0.7 this is
- * currently the only project type.
- *
- * @author David Roden <droden@gmail.com>
- * @version $Id$
- */
-public class EditionProject extends Project {
-
- /** The edition to insert to. */
- private int edition;
-
- /**
- * Creates a new edition-based project.
- */
- public EditionProject() {
- }
-
- /**
- * Clones the specified project as an edition-based project.
- *
- * @param project
- * The project to clone
- */
- public EditionProject(Project project) {
- super(project);
- if (project instanceof EditionProject) {
- edition = ((EditionProject) project).edition;
- }
- }
-
- /**
- * Returns the edition of the project.
- *
- * @return The edition of the project
- */
- public int getEdition() {
- return edition;
- }
-
- /**
- * Sets the edition of the project.
- *
- * @param edition
- * The edition to set
- */
- public void setEdition(int edition) {
- this.edition = edition;
- }
-
- /**
- * Constructs the final request URI including the edition number.
- *
- * @return The final request URI
- */
- @Override
- public String getFinalRequestURI(int offset) {
- return "freenet:USK@" + requestURI + "/" + path + "/" + (edition + offset) + "/";
- }
-
-}
* @author David Roden <dr@todesbaum.dyndns.org>
* @version $Id$
*/
-public abstract class Project implements Comparable {
+public class Project implements Comparable {
protected String name;
protected String description;
protected String localPath;
protected String path;
protected long lastInsertionTime;
+ /** The edition to insert to. */
+ protected int edition;
protected Map<String, FileOption> fileOptions = new HashMap<String, FileOption>();
insertURI = project.insertURI;
requestURI = project.requestURI;
path = project.path;
+ edition = project.edition;
localPath = project.localPath;
indexFile = project.indexFile;
lastInsertionTime = project.lastInsertionTime;
if (uri.startsWith("SSK@")) {
uri = uri.substring("SSK@".length());
}
+ if (uri.startsWith("USK@")) {
+ uri = uri.substring("USK@".length());
+ }
if (uri.endsWith("/")) {
uri = uri.substring(0, uri.length() - 1);
}
this.fileOptions.putAll(fileOptions);
}
- public String getFinalRequestURI(int offset) {
- return "freenet:USK@" + requestURI + "/" + path + "/";
- }
-
/**
* {@inheritDoc}
*/
return name.compareToIgnoreCase(((Project) o).name);
}
+ /**
+ * Returns the edition of the project.
+ *
+ * @return The edition of the project
+ */
+ public int getEdition() {
+ return edition;
+ }
+
+ /**
+ * Sets the edition of the project.
+ *
+ * @param edition
+ * The edition to set
+ */
+ public void setEdition(int edition) {
+ this.edition = edition;
+ }
+
+ /**
+ * Constructs the final request URI including the edition number.
+ *
+ * @return The final request URI
+ */
+ public String getFinalRequestURI(int offset) {
+ return "freenet:USK@" + requestURI + "/" + path + "/" + (edition + offset) + "/";
+ }
+
}
createContainers(files, containers, containerFiles);
/* collect files */
- int edition = ((EditionProject) project).getEdition();
+ int edition = project.getEdition();
String dirURI = "freenet:USK@" + project.getInsertURI() + "/" + project.getPath() + "/" + edition + "/";
ClientPutComplexDir putDir = new ClientPutComplexDir("dir-" + counter++, dirURI);
putDir.setDefaultName(project.getIndexFile());
}
/* parse progress and success messages */
+ String finalURI = null;
boolean success = false;
boolean finished = false;
boolean disconnected = false;
if (!finished) {
String messageName = message.getName();
if ("URIGenerated".equals(messageName)) {
- fireProjectURIGenerated(message.get("URI"));
+ finalURI = message.get("URI");
+ fireProjectURIGenerated(finalURI);
}
if ("SimpleProgress".equals(messageName)) {
int total = Integer.parseInt(message.get("Total"));
/* post-insert work */
fireProjectInsertFinished(success, disconnected ? new IOException("Connection terminated") : null);
if (success) {
- if (project instanceof EditionProject) {
- ((EditionProject) project).setEdition(edition + 1);
- }
+ String editionPart = finalURI.substring(finalURI.lastIndexOf('/') + 1);
+ int newEdition = Integer.parseInt(editionPart);
+ project.setEdition(newEdition);
}
}
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
-import de.todesbaum.jsite.application.EditionProject;
import de.todesbaum.jsite.application.FileOption;
import de.todesbaum.jsite.application.Project;
import de.todesbaum.jsite.i18n.I18n;
addContainerAction.setEnabled(enabled);
editContainerAction.setEnabled(enabled);
deleteContainerAction.setEnabled(enabled);
- replacementCheckBox.setEnabled(enabled && insert && (project instanceof EditionProject));
+ replacementCheckBox.setEnabled(enabled && insert);
if (filename != null) {
FileOption fileOption = project.getFileOption(filename);
defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.ClipboardOwner;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.util.Date;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
* @author David Roden <droden@gmail.com>
* @version $Id$
*/
-public class ProjectInsertPage extends TWizardPage implements InsertListener {
+public class ProjectInsertPage extends TWizardPage implements InsertListener, ClipboardOwner {
protected TWizard wizard;
protected ProjectInserter projectInserter;
+ protected Action copyURIAction;
protected JTextField requestURITextField;
protected JLabel startTimeLabel;
protected JProgressBar progressBar;
public ProjectInsertPage() {
super();
+ createActions();
pageInit();
setHeading(I18n.getMessage("jsite.insert.heading"));
setDescription(I18n.getMessage("jsite.insert.description"));
projectInserter = new ProjectInserter();
projectInserter.addInsertListener(this);
}
+
+ private void createActions() {
+ copyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
+ public void actionPerformed(ActionEvent actionEvent) {
+ actionCopyURI();
+ }
+ };
+ copyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
+ copyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
+ copyURIAction.setEnabled(false);
+ }
private void pageInit() {
setLayout(new BorderLayout(12, 12));
projectInsertPanel.add(startTimeLabel, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
projectInsertPanel.add(new JLabel(I18n.getMessage("jsite.insert.progress") + ":"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
projectInsertPanel.add(progressBar, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
+ projectInsertPanel.add(new JButton(copyURIAction), new GridBagConstraints(0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
return projectInsertPanel;
}
wizard.setPreviousEnabled(false);
wizard.setNextEnabled(false);
wizard.setQuitEnabled(false);
+ copyURIAction.setEnabled(false);
progressBar.setValue(0);
projectInserter.start();
}
public void projectURIGenerated(Project project, final String uri) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
+ copyURIAction.setEnabled(true);
requestURITextField.setText(uri);
}
});
SwingUtilities.invokeLater(new Runnable() {
public void run() {
+ progressBar.setValue(progressBar.getMaximum());
wizard.setNextEnabled(true);
wizard.setQuitEnabled(true);
}
});
}
+
+ //
+ // ACTIONS
+ //
+
+ protected void actionCopyURI() {
+ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ clipboard.setContents(new StringSelection(requestURITextField.getText()), this);
+ }
+
+ //
+ // INTERFACE ClipboardOwner
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ public void lostOwnership(Clipboard clipboard, Transferable contents) {
+ }
}
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.ClipboardOwner;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
-import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
-import javax.swing.SpinnerNumberModel;
-import javax.swing.JSpinner.NumberEditor;
import javax.swing.border.EmptyBorder;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
-import de.todesbaum.jsite.application.EditionProject;
import de.todesbaum.jsite.application.Freenet7Interface;
import de.todesbaum.jsite.application.Project;
import de.todesbaum.jsite.i18n.I18n;
* @author David Roden <droden@gmail.com>
* @version $Id$
*/
-public class ProjectPage extends TWizardPage implements ListSelectionListener, ChangeListener, DocumentListener {
+public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
private Freenet7Interface freenetInterface;
private Action projectAddAction;
private Action projectDeleteAction;
private Action projectCloneAction;
+ private Action projectCopyURIAction;
private JFileChooser pathChooser;
private SortedListModel projectListModel;
projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
projectCloneAction.setEnabled(false);
+
+ projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
+ public void actionPerformed(ActionEvent actionEvent) {
+ actionCopyURI();
+ }
+ };
+ projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
+ projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
+ projectCopyURIAction.setEnabled(false);
}
private JComponent createInformationPanel() {
functionButtons.add(new JButton(projectAddAction));
functionButtons.add(new JButton(projectDeleteAction));
functionButtons.add(new JButton(projectCloneAction));
+ functionButtons.add(new JButton(projectCopyURIAction));
informationPanel.add(functionButtons, BorderLayout.PAGE_START);
informationPanel.add(informationTable, BorderLayout.CENTER);
JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
return;
}
- EditionProject newProject = new EditionProject();
+ Project newProject = new Project();
newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
newProject.setInsertURI(keyPair[0]);
newProject.setRequestURI(keyPair[1]);
protected void actionClone() {
int selectedIndex = projectList.getSelectedIndex();
if (selectedIndex > -1) {
- Project newProject = null;
- Project selectedProject = (Project) projectList.getSelectedValue();
- if (selectedProject instanceof EditionProject) {
- newProject = new EditionProject(selectedProject);
- } // else { /* BUG! */ }
+ Project newProject = new Project((Project) projectList.getSelectedValue());
newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
projectListModel.add(newProject);
projectList.setSelectedIndex(projectListModel.indexOf(newProject));
}
}
+
+ protected void actionCopyURI() {
+ int selectedIndex = projectList.getSelectedIndex();
+ if (selectedIndex > -1) {
+ Project selectedProject = (Project) projectList.getSelectedValue();
+ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
+ }
+ }
//
// INTERFACE ListSelectionListener
projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
projectDeleteAction.setEnabled(selectedRow > -1);
projectCloneAction.setEnabled(selectedRow > -1);
+ projectCopyURIAction.setEnabled(selectedRow > -1);
if (selectedRow > -1) {
projectNameTextField.setText(selectedProject.getName());
projectDescriptionTextField.setText(selectedProject.getDescription());
projectPublicKeyTextField.setText(selectedProject.getRequestURI());
projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
projectPathTextField.setText(selectedProject.getPath());
- if (selectedProject instanceof EditionProject) {
- EditionProject editionProject = (EditionProject) selectedProject;
- }
} else {
projectNameTextField.setText("");
projectDescriptionTextField.setText("");
// INTERFACE ChangeListener
//
- /**
- * {@inheritDoc}
- */
- public void stateChanged(ChangeEvent changeEvent) {
- Object source = changeEvent.getSource();
- if (source instanceof JSpinner) {
- JSpinner spinner = (JSpinner) source;
- Project currentProject = (Project) projectList.getSelectedValue();
- if (currentProject == null) {
- return;
- }
- if ("project.edition".equals(spinner.getName())) {
- ((EditionProject) currentProject).setEdition((Integer) spinner.getValue());
- }
- }
- }
-
//
// INTERFACE DocumentListener
//
public void changedUpdate(DocumentEvent documentEvent) {
setTextField(documentEvent);
}
+
+ //
+ // INTERFACE ClipboardOwner
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ public void lostOwnership(Clipboard clipboard, Transferable contents) {
+ }
}
jsite.project.action.clone-project=Clone project
jsite.project.action.clone-project.copy=Copy of {0}
jsite.project.action.clone-project.tooltip=Clone the selected project
+jsite.project.action.copy-uri=Copy URI to Clipboard
+jsite.project.action.copy-uri.tooltip=Copies the URI of the project to the clipboard
jsite.project.project.information=Project Information
jsite.project.project.name=Name
jsite.project.project.description=Description
jsite.project.action.clone-project=Projekt duplizieren
jsite.project.action.clone-project.copy=Kopie von {0}
jsite.project.action.clone-project.tooltip=Das ausgewählte Projekt duplizieren
+jsite.project.action.copy-uri=URI kopieren
+jsite.project.action.copy-uri.tooltip=Kopiert die URI des ausgewählten Projektes in die Zwischenablage
jsite.project.project.information=Projektinformation
jsite.project.project.name=Name
jsite.project.project.description=Beschreibung
import java.io.PrintWriter;
-import de.todesbaum.jsite.application.EditionProject;
import de.todesbaum.jsite.application.Freenet7Interface;
import de.todesbaum.jsite.application.InsertListener;
import de.todesbaum.jsite.application.Node;
outputWriter.println("You can't specify --edition before --project.");
return;
}
- if (currentProject instanceof EditionProject) {
- ((EditionProject) currentProject).setEdition(Integer.parseInt(value));
- } else {
- outputWriter.println("Project \"" + currentProject.getName() + "\" is not an edition-based project.");
- return;
- }
+ currentProject.setEdition(Integer.parseInt(value));
} else {
outputWriter.println("Unknown parameter: " + argument);
return;
public void projectInsertFinished(Project project, boolean success, Throwable cause) {
outputWriter.println("Request URI: " + project.getFinalRequestURI(0));
finished = true;
- if (success) {
- if (project instanceof EditionProject) {
- ((EditionProject) project).setEdition(((EditionProject) project).getEdition() + 1);
- }
- }
this.success = success;
synchronized (lockObject) {
lockObject.notify();
import java.util.Map;
import java.util.Map.Entry;
-import de.todesbaum.jsite.application.EditionProject;
import de.todesbaum.jsite.application.FileOption;
import de.todesbaum.jsite.application.Node;
import de.todesbaum.jsite.application.Project;
SimpleXML[] projectNodes = projectsNode.getNodes("project");
for (SimpleXML projectNode: projectNodes) {
try {
- Project project = null;
- SimpleXML typeNode = projectNode.getNode("type");
- if ("edition".equals(typeNode.getValue())) {
- EditionProject editionProject = new EditionProject();
- project = editionProject;
- editionProject.setEdition(Integer.parseInt(projectNode.getNode("edition").getValue()));
- }
+ Project project = new Project();
projects.add(project);
project.setDescription(projectNode.getNode("description").getValue());
project.setIndexFile(projectNode.getNode("index-file").getValue());
project.setLocalPath(projectNode.getNode("local-path").getValue());
project.setName(projectNode.getNode("name").getValue());
project.setPath(projectNode.getNode("path").getValue());
+ project.setEdition(Integer.parseInt(projectNode.getNode("edition").getValue()));
project.setInsertURI(projectNode.getNode("insert-uri").getValue());
project.setRequestURI(projectNode.getNode("request-uri").getValue());
SimpleXML fileOptionsNode = projectNode.getNode("file-options");
SimpleXML projectsNode = new SimpleXML("project-list");
for (Project project: projects) {
SimpleXML projectNode = projectsNode.append("project");
- if (project instanceof EditionProject) {
- projectNode.append("type", "edition");
- projectNode.append("edition", String.valueOf(((EditionProject) project).getEdition()));
- }
+ projectNode.append("edition", String.valueOf(project.getEdition()));
projectNode.append("description", project.getDescription());
projectNode.append("index-file", project.getIndexFile());
projectNode.append("last-insertion-time", String.valueOf(project.getLastInsertionTime()));
*/
public class Version {
- private static final String VERSION = "0.4.7";
+ private static final String VERSION = "0.4.8";
public static final String getVersion() {
return VERSION;
Message message = null;
while (line != null) {
line = nodeReader.readLine();
- System.err.println("> " + line);
+ // System.err.println("> " + line);
if (line == null) {
break;
}