/** The edition of the last insert. */
private int lastInsertEdition;
+ /** The filename of the last insert. */
+ private String lastInsertFilename;
+
/** The current hash of the file. */
private String currentHash;
}
/**
+ * Returns the name of the file when it was last inserted.
+ *
+ * @return The name of the file at the last insert
+ */
+ public String getLastInsertFilename() {
+ return lastInsertFilename;
+ }
+
+ /**
+ * Sets the name of the file when it was last inserted.
+ *
+ * @param lastInsertFilename
+ * The name of the file at the last insert.
+ * @return These file options
+ */
+ public FileOption setLastInsertFilename(String lastInsertFilename) {
+ this.lastInsertFilename = lastInsertFilename;
+ return this;
+ }
+
+ /**
* Returns the current hash of the file. This value is ony a temporary value
* that is copied to {@link #getLastInsertHash()} when a project has
* finished inserting.
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import de.todesbaum.util.mime.DefaultMIMETypes;
* insert.
*/
public void onSuccessfulInsert() {
- for (FileOption fileOption : fileOptions.values()) {
- if ((fileOption.getCurrentHash() != null) && (fileOption.getCurrentHash().length() > 0) && !fileOption.getCurrentHash().equals(fileOption.getLastInsertHash())) {
+ for (Entry<String, FileOption> fileOptionEntry : fileOptions.entrySet()) {
+ FileOption fileOption = fileOptionEntry.getValue();
+ if ((fileOption.getCurrentHash() != null) && (fileOption.getCurrentHash().length() > 0) && (!fileOption.getCurrentHash().equals(fileOption.getLastInsertHash()) || fileOption.isForceInsert())) {
fileOption.setLastInsertEdition(edition);
fileOption.setLastInsertHash(fileOption.getCurrentHash());
+ fileOption.setLastInsertFilename(fileOption.hasChangedName() ? fileOption.getChangedName() : fileOptionEntry.getKey());
}
fileOption.setForceInsert(false);
}
/** The insert priority. */
private PriorityClass priority;
+ /** The manifest putter. */
+ private ManifestPutter manifestPutter;
+
/**
* Adds a listener to the list of registered listeners.
*
}
/**
+ * Sets the manifest putter to use for inserts.
+ *
+ * @param manifestPutter
+ * The manifest putter to use
+ */
+ public void setManifestPutter(ManifestPutter manifestPutter) {
+ this.manifestPutter = manifestPutter;
+ }
+
+ /**
* Starts the insert.
*
* @param progressListener
if (!fileOption.isForceInsert() && file.getHash().equals(fileOption.getLastInsertHash())) {
/* only insert a redirect. */
logger.log(Level.FINE, String.format("Inserting redirect to edition %d for %s.", fileOption.getLastInsertEdition(), filename));
- return new RedirectFileEntry(filename, fileOption.getMimeType(), "SSK@" + project.getRequestURI() + "/" + project.getPath() + "-" + fileOption.getLastInsertEdition() + "/" + filename);
+ return new RedirectFileEntry(fileOption.hasChangedName() ? fileOption.getChangedName() : filename, fileOption.getMimeType(), "SSK@" + project.getRequestURI() + "/" + project.getPath() + "-" + fileOption.getLastInsertEdition() + "/" + fileOption.getLastInsertFilename());
}
try {
long[] fileLength = new long[1];
InputStream fileEntryInputStream = createFileInputStream(filename, fileOption, edition, fileLength);
- fileEntry = new DirectFileEntry(filename, fileOption.getMimeType(), fileEntryInputStream, fileLength[0]);
+ fileEntry = new DirectFileEntry(fileOption.hasChangedName() ? fileOption.getChangedName() : filename, fileOption.getMimeType(), fileEntryInputStream, fileLength[0]);
} catch (IOException ioe1) {
/* ignore, null is returned. */
}
} else {
if (fileOption.isInsertRedirect()) {
- fileEntry = new RedirectFileEntry(filename, fileOption.getMimeType(), fileOption.getCustomKey());
+ fileEntry = new RedirectFileEntry(fileOption.hasChangedName() ? fileOption.getChangedName() : filename, fileOption.getMimeType(), fileOption.getCustomKey());
}
}
return fileEntry;
putDir.setMaxRetries(-1);
putDir.setEarlyEncode(useEarlyEncode);
putDir.setPriorityClass(priority);
- putDir.setManifestPutter(ManifestPutter.DEFAULT);
+ putDir.setManifestPutter(manifestPutter);
for (ScannedFile file : files) {
FileEntry fileEntry = createFileEntry(file, edition);
if (fileEntry != null) {
import de.todesbaum.jsite.i18n.I18n;
import de.todesbaum.jsite.i18n.I18nContainer;
import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation;
+import de.todesbaum.util.freenet.fcp2.ClientPutDir.ManifestPutter;
import de.todesbaum.util.freenet.fcp2.PriorityClass;
import de.todesbaum.util.swing.TWizard;
import de.todesbaum.util.swing.TWizardPage;
/** The insert priority select box. */
private JComboBox insertPriorityComboBox;
+ /** The manifest putter select box. */
+ private JComboBox manifestPutterComboBox;
+
/**
* Creates a new “preferences” page.
*
}
/**
+ * Returns the selected manifest putter.
+ *
+ * @return The selected manifest putter
+ */
+ public ManifestPutter getManifestPutter() {
+ return (ManifestPutter) manifestPutterComboBox.getSelectedItem();
+ }
+
+ /**
+ * Sets the manifest putter.
+ *
+ * @param manifestPutter
+ * The manifest putter
+ */
+ public void setManifestPutter(ManifestPutter manifestPutter) {
+ manifestPutterComboBox.setSelectedItem(manifestPutter);
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
insertPriorityComboBox = new JComboBox(new PriorityClass[] { PriorityClass.MINIMUM, PriorityClass.PREFETCH, PriorityClass.BULK, PriorityClass.UPDATABLE, PriorityClass.SEMI_INTERACTIVE, PriorityClass.INTERACTIVE, PriorityClass.MAXIMUM });
insertPriorityComboBox.setAction(priorityAction);
- preferencesPanel.add(insertPriorityComboBox, new GridBagConstraints(1, 9, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.VERTICAL, new Insets(0, 18, 0, 0), 0, 0));
+ preferencesPanel.add(insertPriorityComboBox, new GridBagConstraints(1, 9, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 0, 0), 0, 0));
+
+ final JLabel manifestPutterLabel = new JLabel(I18n.getMessage("jsite.preferences.insert-options.manifest-putter"));
+ preferencesPanel.add(manifestPutterLabel, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
+
+ manifestPutterComboBox = new JComboBox(ManifestPutter.values());
+ preferencesPanel.add(manifestPutterComboBox, new GridBagConstraints(1, 10, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 0, 0), 0, 0));
I18nContainer.getInstance().registerRunnable(new Runnable() {
configurationDirectoryLabel.setText("<html><b>" + I18n.getMessage("jsite.preferences.config-directory") + "</b></html>");
insertOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.preferences.insert-options") + "</b></html>");
insertPriorityLabel.setText(I18n.getMessage("jsite.preferences.insert-options.priority"));
+ manifestPutterLabel.setText(I18n.getMessage("jsite.preferences.insert-options.manifest-putter"));
}
});
@SuppressWarnings("synthetic-access")
private void storeText(DocumentEvent documentEvent) {
FileOption fileOption = getSelectedFile();
+ if (fileOption == null) {
+ /* no file selected. */
+ System.out.println("yfwdasd");
+ return;
+ }
Document document = documentEvent.getDocument();
int documentLength = document.getLength();
try {
import de.todesbaum.jsite.application.ProjectInserter;
import de.todesbaum.jsite.i18n.I18n;
import de.todesbaum.jsite.i18n.I18nContainer;
+import de.todesbaum.util.freenet.fcp2.ClientPutDir.ManifestPutter;
import de.todesbaum.util.freenet.fcp2.PriorityClass;
import de.todesbaum.util.io.StreamCopier.ProgressListener;
import de.todesbaum.util.swing.TWizard;
projectInserter.setPriority(priority);
}
+ /**
+ * Sets the manifest putter to use for the insert.
+ *
+ * @see ProjectInserter#setManifestPutter(ManifestPutter)
+ * @param manifestPutter
+ * The manifest putter
+ */
+ public void setManifestPutter(ManifestPutter manifestPutter) {
+ projectInserter.setManifestPutter(manifestPutter);
+ }
+
//
// INTERFACE InsertListener
//
jsite.preferences.insert-options=Insert options
jsite.preferences.insert-options.use-early-encode=Generate final URI early
jsite.preferences.insert-options.priority=Priority
+jsite.preferences.insert-options.manifest-putter=Manifest Putter
jsite.insert.heading=Project insert
jsite.insert.description=Please wait while the project is being inserted.
jsite.preferences.insert-options=Einf\u00fcgeoptionen
jsite.preferences.insert-options.use-early-encode=Endg\u00fcltige URI fr\u00fcher berechnen
jsite.preferences.insert-options.priority=Priorit\u00e4t
+jsite.preferences.insert-options.manifest-putter=Manifest Putter
jsite.insert.heading=Projekt einf\u00fcgen
jsite.insert.description=Bitte warten Sie, w\u00e4hrend das Projekt eingef\u00fcgt wird.
jsite.preferences.insert-options=Options d'insertion
jsite.preferences.insert-options.use-early-encode=Générer d'abord l'URI
jsite.preferences.insert-options.priority=Priorité
+jsite.preferences.insert-options.manifest-putter=Manifest Putter
jsite.insert.heading=Projet d'insertion
jsite.insert.description=Veuillez attendre durant l'insertion du projet.
import de.todesbaum.jsite.application.Node;
import de.todesbaum.jsite.application.Project;
import de.todesbaum.jsite.main.ConfigurationLocator.ConfigurationLocation;
+import de.todesbaum.util.freenet.fcp2.ClientPutDir.ManifestPutter;
import de.todesbaum.util.freenet.fcp2.PriorityClass;
import de.todesbaum.util.io.Closer;
import de.todesbaum.util.io.StreamCopier;
String filename = fileNode.getNode("filename").getValue();
String lastInsertHash = fileNode.getNode("last-insert-hash").getValue();
int lastInsertEdition = Integer.valueOf(fileNode.getNode("last-insert-edition").getValue());
+ String lastInsertFilename = filename;
+ if (fileNode.getNode("last-insert-filename") != null) {
+ lastInsertFilename = fileNode.getNode("last-insert-filename").getValue();
+ }
FileOption fileOption = project.getFileOption(filename);
- fileOption.setLastInsertHash(lastInsertHash).setLastInsertEdition(lastInsertEdition);
+ fileOption.setLastInsertHash(lastInsertHash).setLastInsertEdition(lastInsertEdition).setLastInsertFilename(lastInsertFilename);
fileOptions.put(filename, fileOption);
}
}
fileNode.append("filename", fileOption.getKey());
fileNode.append("last-insert-hash", fileOption.getValue().getLastInsertHash());
fileNode.append("last-insert-edition", String.valueOf(fileOption.getValue().getLastInsertEdition()));
+ fileNode.append("last-insert-filename", fileOption.getValue().getLastInsertFilename());
}
SimpleXML fileOptionsNode = projectNode.append("file-options");
return this;
}
+ /**
+ * Returns the manifest putter.
+ *
+ * @return The manifest putter
+ */
+ public ManifestPutter getManifestPutter() {
+ return ManifestPutter.valueOf(getNodeValue(new String[] { "manifest-putter" }, "simple").toUpperCase());
+ }
+
+ /**
+ * Sets the manifest putter.
+ *
+ * @param manifestPutter
+ * The manifest putter
+ * @return This configuration
+ */
+ public Configuration setManifestPutter(ManifestPutter manifestPutter) {
+ rootNode.replace("manifest-putter", manifestPutter.name().toLowerCase());
+ return this;
+ }
+
}
/** Mapping from page type to page. */
private final Map<PageType, TWizardPage> pages = new HashMap<PageType, TWizardPage>();
+ /** The original location of the configuration file. */
+ private ConfigurationLocation originalLocation;
+
/**
* Creates a new core with the default configuration file.
*/
configurationLocator.setCustomLocation(configFilename);
}
- ConfigurationLocation preferredLocation = configurationLocator.findPreferredLocation();
- logger.log(Level.CONFIG, "Using configuration from " + preferredLocation + ".");
- configuration = new Configuration(configurationLocator, preferredLocation);
+ originalLocation = configurationLocator.findPreferredLocation();
+ logger.log(Level.CONFIG, "Using configuration from " + originalLocation + ".");
+ configuration = new Configuration(configurationLocator, originalLocation);
Locale.setDefault(configuration.getLocale());
I18n.setLocale(configuration.getLocale());
((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setHasCustomConfiguration(configuration.getConfigurationLocator().isValidLocation(ConfigurationLocation.CUSTOM));
((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setUseEarlyEncode(configuration.useEarlyEncode());
((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setPriority(configuration.getPriority());
+ ((PreferencesPage) pages.get(PageType.PAGE_PREFERENCES)).setManifestPutter(configuration.getManifestPutter());
showPage(PageType.PAGE_PREFERENCES);
optionsPreferencesAction.setEnabled(false);
wizard.setNextEnabled(true);
projectInsertPage.setTempDirectory(tempDirectory);
projectInsertPage.setUseEarlyEncode(configuration.useEarlyEncode());
projectInsertPage.setPriority(configuration.getPriority());
+ projectInsertPage.setManifestPutter(configuration.getManifestPutter());
projectInsertPage.startInsert();
nodeMenu.setEnabled(false);
optionsPreferencesAction.setEnabled(false);
optionsPreferencesAction.setEnabled(true);
configuration.setUseEarlyEncode(preferencesPage.useEarlyEncode());
configuration.setPriority(preferencesPage.getPriority());
+ configuration.setManifestPutter(preferencesPage.getManifestPutter());
configuration.setConfigurationLocation(preferencesPage.getConfigurationLocation());
}
}
JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project.warning.use-clipboard-now"));
}
if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.quit.question"), I18n.getMessage("jsite.quit.question.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
- if (isOverwritingConfiguration()) {
+ if (isOverwritingConfiguration() && !originalLocation.equals(configuration.getConfigurationDirectory())) {
int overwriteConfigurationAnswer = JOptionPane.showConfirmDialog(wizard, MessageFormat.format(I18n.getMessage("jsite.quit.overwrite-configuration"), configuration.getConfigurationLocator().getFile(configuration.getConfigurationDirectory())), I18n.getMessage("jsite.quit.overwrite-configuration.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (overwriteConfigurationAnswer == JOptionPane.YES_OPTION) {
if (saveConfiguration()) {
return name;
}
+ //
+ // OBJECT METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return name.substring(0, 1).toUpperCase() + name.substring(1);
+ }
+
}
/** The default file of the directory. */