Author: dieppe
Date: 2008-02-10 03:51:06 +0000 (Sun, 10 Feb 2008)
New Revision: 17770
Modified:
trunk/apps/thingamablog/src/net/sf/thingamablog/blog/TBWeblog.java
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBGeneralPanel.java
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWizardDialog.java
trunk/apps/thingamablog/src/net/sf/thingamablog/xml/TBPersistFactory.java
Log:
Update : same as the first patch, but clean.
Modified: trunk/apps/thingamablog/src/net/sf/thingamablog/blog/TBWeblog.java
===================================================================
--- trunk/apps/thingamablog/src/net/sf/thingamablog/blog/TBWeblog.java
2008-02-09 20:27:58 UTC (rev 17769)
+++ trunk/apps/thingamablog/src/net/sf/thingamablog/blog/TBWeblog.java
2008-02-10 03:51:06 UTC (rev 17770)
@@ -89,6 +89,9 @@
private String archivePath = basePath;
private String mediaPath = basePath;
+ // Should be internet or freenet
+ private String type;
+
//private Vector outdatedTopLevelPages = new Vector();
private Vector outdatedCategoryPages = new Vector();
private Vector outdatedArchivePages = new Vector();
@@ -114,9 +117,6 @@
private File homeDir;
private File tmplDir;
private File outputDir;
-
- // Should be internet or freenet
- private String type;
/**
@@ -1398,7 +1398,7 @@
}
public void setType(String type) {
- this.type=type;
+ this.type = type;
}
public String getType() {
Modified:
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBGeneralPanel.java
===================================================================
---
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBGeneralPanel.java
2008-02-09 20:27:58 UTC (rev 17769)
+++
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBGeneralPanel.java
2008-02-10 03:51:06 UTC (rev 17770)
@@ -30,277 +30,295 @@
/**
* @author Bob Tantlinger
*
- *
- *
+ *
+ *
*/
-public class TBGeneralPanel extends PropertyPanel {
+public class TBGeneralPanel extends PropertyPanel
+{
/**
- *
+ *
*/
private static final long serialVersionUID = 1L;
-
+
private static final I18n i18n =
I18n.getInstance("net.sf.thingamablog.gui.properties");
private TBWeblog weblog;
+
+ private JTextField titleField;
+ private JTextArea descrArea;
+ private JTextField basePathField;
+ private JTextField urlField;
+ private JTextField arcUrlField;
+ private JTextField mediaUrlField;
+
+ private JComboBox localeCombo;
+ private JComboBox dateFormatCombo;
+ private JComboBox timeFormatCombo;
+ private JComboBox typeCombo;
+
+ private static Locale LOCS[] = DateFormat.getAvailableLocales();
+ private static String TYPE[] = {"internet","freenet"};
+
+ private String[] getDateFormats(Locale locale) {
+ String s = i18n.str("DateFormatOptions",locale);
+ return tokenize(s);
+ }
+ private String[] getTimeFormats(Locale locale) {
+ String s = i18n.str("TimeFormatOptions",locale);
+ return tokenize(s);
+ }
+ private String[] tokenize(String s) {
+ StringTokenizer st = new StringTokenizer(s,"|");
+ String[] formats = new String[st.countTokens()];
+ for (int i = 0; i < formats.length; i++) {
+ formats[i] = st.nextToken();
+ }
+ return formats;
+ }
+ /*
+ private static final String DATE_FORMATS[] =
+ {
+ "EEEE, MMMM dd, yyyy", //$NON-NLS-1$
+ "EEE, MMM dd, yyyy", //$NON-NLS-1$
+ "EEEE, dd MMMM, yyyy", //$NON-NLS-1$
+ "EEEE dd MMMM yyyy", //$NON-NLS-1$
+ "EEEE",
+ "MMMM dd, yyyy", //$NON-NLS-1$
+ "MMMM dd yyyy", //$NON-NLS-1$
+
+ "MM/dd/yyyy", //$NON-NLS-1$
+ "MM/dd/yy", //$NON-NLS-1$
+ "dd/MM/yyyy", //$NON-NLS-1$
+ "dd/MM/yy", //$NON-NLS-1$
+
+ "dd MMMM yyyy", //$NON-NLS-1$
+ "dd MMMM", //$NON-NLS-1$
+
+ "yyyy-MM-dd", //$NON-NLS-1$
+ "yy-MM-dd", //$NON-NLS-1$
+ "yy.MM.dd", //$NON-NLS-1$
+ "yyyy.MM.dd", //$NON-NLS-1$
+ "EEEE, MM/dd/yyyy", //$NON-NLS-1$
+ "EEE, MM/dd/yyyy" //$NON-NLS-1$
+ };
- private JTextField titleField;
- private JTextArea descrArea;
- private JTextField basePathField;
- private JTextField urlField;
- private JTextField arcUrlField;
- private JTextField mediaUrlField;
-
- private JComboBox localeCombo;
- private JComboBox dateFormatCombo;
- private JComboBox timeFormatCombo;
- private JComboBox typeCombo;
-
- private static Locale LOCS[] = DateFormat.getAvailableLocales();
- private static String TYPE[] = {"internet","freenet"};
-
- private String[] getDateFormats(Locale locale) {
- String s = i18n.str("DateFormatOptions",locale);
- return tokenize(s);
+ private static final SimpleDateFormat GMT_TIME_FORMAT =
+ new SimpleDateFormat("k:mm.ss z"); //$NON-NLS-1$
+ private static final String TIME_FORMATS[] =
+ {
+ "h:mm a", //$NON-NLS-1$
+ "h:mm.ss a", //$NON-NLS-1$
+ "h:mm a z", //$NON-NLS-1$
+ "h:mm.ss a z", //$NON-NLS-1$
+ "h:mm a zzzz", //$NON-NLS-1$
+ "h:mm.ss a zzzz", //$NON-NLS-1$
+ "k:mm", //$NON-NLS-1$
+ "k:mm.ss", //$NON-NLS-1$
+ //GMT_TIME_FORMAT
+ };
+ */
+
+ public TBGeneralPanel(TBWeblog blog)
+ {
+ weblog = blog;
+
+ TextEditPopupManager popupMan = TextEditPopupManager.getInstance();
+ titleField = new JTextField();
+ titleField.setText(weblog.getTitle());
+ popupMan.registerJTextComponent(titleField);
+
+ descrArea = new JTextArea(3, 2);
+ //descrArea.setMinimumSize(descrArea.getPreferredSize());
+ descrArea.setLineWrap(true);
+ descrArea.setWrapStyleWord(true);
+ descrArea.setText(weblog.getDescription());
+ popupMan.registerJTextComponent(descrArea);
+
+
+ //DateFormat.getAvailableLocales()
+ localeCombo = new JComboBox(LOCS);
+ //localeCombo = new JComboBox();
+ localeCombo.setSelectedItem(weblog.getLocale());
+ localeCombo.setRenderer(new ComboRenderer());
+ localeCombo.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ String[] dateFormats =
getDateFormats((Locale)localeCombo.getSelectedItem());
+ replaceComboItem(dateFormatCombo,dateFormats);
+ String[] timeFormats =
getTimeFormats((Locale)localeCombo.getSelectedItem());
+ replaceComboItem(timeFormatCombo,timeFormats);
+ }
+ });
+
+ dateFormatCombo = new
JComboBox(getDateFormats(weblog.getLocale()));
+
dateFormatCombo.setSelectedItem(weblog.getPageGenerator().getDateFormat());
+ dateFormatCombo.setRenderer(new ComboRenderer());
+
+ timeFormatCombo = new
JComboBox(getTimeFormats(weblog.getLocale()));
+
timeFormatCombo.setSelectedItem(weblog.getPageGenerator().getTimeFormat());
+ timeFormatCombo.setRenderer(new ComboRenderer());
+
+ typeCombo = new JComboBox(TYPE);
+ typeCombo.setSelectedItem(weblog.getType());
+
+ basePathField = new JTextField();
+ basePathField.setText(weblog.getBasePath());
+ popupMan.registerJTextComponent(basePathField);
+
+ urlField = new JTextField();
+ urlField.setText(weblog.getBaseUrl());
+ popupMan.registerJTextComponent(urlField);
+
+ arcUrlField = new JTextField();
+ arcUrlField.setText(weblog.getArchiveUrl());
+ popupMan.registerJTextComponent(arcUrlField);
+
+ mediaUrlField = new JTextField();
+ mediaUrlField.setText(weblog.getMediaUrl());
+ popupMan.registerJTextComponent(mediaUrlField);
+
+ setLayout(new BorderLayout(5, 5));
+ setBorder(new EmptyBorder(5, 5, 5, 5));
+ LabelledItemPanel lip1 = new LabelledItemPanel();
+ lip1.setBorder(new TitledBorder(i18n.str("weblog")));
//$NON-NLS-1$
+ lip1.addItem(i18n.str("site_title"), titleField); //$NON-NLS-1$
+ //JPanel descPanel = new JPanel(new BorderLayout());
+ //descPanel.add(new JScrollPane(descrArea),
BorderLayout.CENTER);
+ //lip1.addItem("Description", descPanel);
+ lip1.addItem(i18n.str("description"), new
JScrollPane(descrArea)); //$NON-NLS-1$
+ lip1.addItem(i18n.str("language"), localeCombo); //$NON-NLS-1$
+ lip1.addItem(i18n.str("date_format"), dateFormatCombo);
//$NON-NLS-1$
+ lip1.addItem(i18n.str("time_format"), timeFormatCombo);
//$NON-NLS-1$
+ lip1.addItem(i18n.str("type"), typeCombo);
+
+ LabelledItemPanel lip2 = new LabelledItemPanel();
+ lip2.setBorder(new TitledBorder(i18n.str("location")));
//$NON-NLS-1$
+ lip2.addItem(i18n.str("base_path"), basePathField);
//$NON-NLS-1$
+ lip2.addItem(i18n.str("base_url"), urlField); //$NON-NLS-1$
+ lip2.addItem(i18n.str("archive_url"), arcUrlField);
//$NON-NLS-1$
+ lip2.addItem(i18n.str("media_url"), mediaUrlField);
//$NON-NLS-1$
+
+ add(lip1, BorderLayout.CENTER);
+ add(lip2, BorderLayout.SOUTH);
+
}
- private String[] getTimeFormats(Locale locale) {
- String s = i18n.str("TimeFormatOptions",locale);
- return tokenize(s);
- }
- private String[] tokenize(String s) {
- StringTokenizer st = new StringTokenizer(s,"|");
- String[] formats = new String[st.countTokens()];
- for (int i = 0; i < formats.length; i++) {
- formats[i] = st.nextToken();
- }
- return formats;
- }
- /*
- private static final String DATE_FORMATS[] =
- {
- "EEEE, MMMM dd, yyyy", //$NON-NLS-1$
- "EEE, MMM dd, yyyy", //$NON-NLS-1$
- "EEEE, dd MMMM, yyyy", //$NON-NLS-1$
- "EEEE dd MMMM yyyy", //$NON-NLS-1$
- "EEEE",
- "MMMM dd, yyyy", //$NON-NLS-1$
- "MMMM dd yyyy", //$NON-NLS-1$
-
- "MM/dd/yyyy", //$NON-NLS-1$
- "MM/dd/yy", //$NON-NLS-1$
- "dd/MM/yyyy", //$NON-NLS-1$
- "dd/MM/yy", //$NON-NLS-1$
-
- "dd MMMM yyyy", //$NON-NLS-1$
- "dd MMMM", //$NON-NLS-1$
-
- "yyyy-MM-dd", //$NON-NLS-1$
- "yy-MM-dd", //$NON-NLS-1$
- "yy.MM.dd", //$NON-NLS-1$
- "yyyy.MM.dd", //$NON-NLS-1$
- "EEEE, MM/dd/yyyy", //$NON-NLS-1$
- "EEE, MM/dd/yyyy" //$NON-NLS-1$
- };
-
- private static final SimpleDateFormat GMT_TIME_FORMAT =
- new SimpleDateFormat("k:mm.ss z"); //$NON-NLS-1$
- private static final String TIME_FORMATS[] =
- {
- "h:mm a", //$NON-NLS-1$
- "h:mm.ss a", //$NON-NLS-1$
- "h:mm a z", //$NON-NLS-1$
- "h:mm.ss a z", //$NON-NLS-1$
- "h:mm a zzzz", //$NON-NLS-1$
- "h:mm.ss a zzzz", //$NON-NLS-1$
- "k:mm", //$NON-NLS-1$
- "k:mm.ss", //$NON-NLS-1$
- //GMT_TIME_FORMAT
- };
- */
-
- public TBGeneralPanel(TBWeblog blog) {
- weblog = blog;
-
- TextEditPopupManager popupMan = TextEditPopupManager.getInstance();
- titleField = new JTextField();
- titleField.setText(weblog.getTitle());
- popupMan.registerJTextComponent(titleField);
-
- descrArea = new JTextArea(3, 2);
- //descrArea.setMinimumSize(descrArea.getPreferredSize());
- descrArea.setLineWrap(true);
- descrArea.setWrapStyleWord(true);
- descrArea.setText(weblog.getDescription());
- popupMan.registerJTextComponent(descrArea);
-
-
- //DateFormat.getAvailableLocales()
- localeCombo = new JComboBox(LOCS);
- //localeCombo = new JComboBox();
- localeCombo.setSelectedItem(weblog.getLocale());
- localeCombo.setRenderer(new ComboRenderer());
- localeCombo.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String[] dateFormats =
getDateFormats((Locale)localeCombo.getSelectedItem());
- replaceComboItem(dateFormatCombo,dateFormats);
- String[] timeFormats =
getTimeFormats((Locale)localeCombo.getSelectedItem());
- replaceComboItem(timeFormatCombo,timeFormats);
- }
- });
-
- dateFormatCombo = new JComboBox(getDateFormats(weblog.getLocale()));
-
dateFormatCombo.setSelectedItem(weblog.getPageGenerator().getDateFormat());
- dateFormatCombo.setRenderer(new ComboRenderer());
-
- timeFormatCombo = new JComboBox(getTimeFormats(weblog.getLocale()));
-
timeFormatCombo.setSelectedItem(weblog.getPageGenerator().getTimeFormat());
- timeFormatCombo.setRenderer(new ComboRenderer());
-
- typeCombo = new JComboBox(TYPE);
- typeCombo.setSelectedItem(weblog.getType());
-
- basePathField = new JTextField();
- basePathField.setText(weblog.getBasePath());
- popupMan.registerJTextComponent(basePathField);
-
- urlField = new JTextField();
- urlField.setText(weblog.getBaseUrl());
- popupMan.registerJTextComponent(urlField);
-
- arcUrlField = new JTextField();
- arcUrlField.setText(weblog.getArchiveUrl());
- popupMan.registerJTextComponent(arcUrlField);
-
- mediaUrlField = new JTextField();
- mediaUrlField.setText(weblog.getMediaUrl());
- popupMan.registerJTextComponent(mediaUrlField);
-
- setLayout(new BorderLayout(5, 5));
- setBorder(new EmptyBorder(5, 5, 5, 5));
- LabelledItemPanel lip1 = new LabelledItemPanel();
- lip1.setBorder(new TitledBorder(i18n.str("weblog"))); //$NON-NLS-1$
- lip1.addItem(i18n.str("site_title"), titleField); //$NON-NLS-1$
- //JPanel descPanel = new JPanel(new BorderLayout());
- //descPanel.add(new JScrollPane(descrArea), BorderLayout.CENTER);
- //lip1.addItem("Description", descPanel);
- lip1.addItem(i18n.str("description"), new JScrollPane(descrArea));
//$NON-NLS-1$
- lip1.addItem(i18n.str("language"), localeCombo); //$NON-NLS-1$
- lip1.addItem(i18n.str("date_format"), dateFormatCombo); //$NON-NLS-1$
- lip1.addItem(i18n.str("time_format"), timeFormatCombo); //$NON-NLS-1$
- lip1.addItem(i18n.str("type"), typeCombo);
-
- LabelledItemPanel lip2 = new LabelledItemPanel();
- lip2.setBorder(new TitledBorder(i18n.str("location"))); //$NON-NLS-1$
- lip2.addItem(i18n.str("base_path"), basePathField); //$NON-NLS-1$
- lip2.addItem(i18n.str("base_url"), urlField); //$NON-NLS-1$
- lip2.addItem(i18n.str("archive_url"), arcUrlField); //$NON-NLS-1$
- lip2.addItem(i18n.str("media_url"), mediaUrlField); //$NON-NLS-1$
-
- add(lip1, BorderLayout.CENTER);
- add(lip2, BorderLayout.SOUTH);
-
- }
private void replaceComboItem(JComboBox combo, String[] items) {
- combo.removeAllItems();
- for (int i = 0; i < items.length; i++) {
- combo.addItem(items[i]);
- }
- }
+ combo.removeAllItems();
+ for (int i = 0; i < items.length; i++) {
+ combo.addItem(items[i]);
+ }
+ }
/* (non-Javadoc)
* @see
net.sf.thingamablog.gui.properties.PropertyPanel#savePropertiesToWeblog()
*/
- public void saveProperties() {
- weblog.setPublishAll(true);
+ public void saveProperties()
+ {
+ weblog.setPublishAll(true);
weblog.setBlogUrls(
- basePathField.getText(), urlField.getText(),
- arcUrlField.getText(), mediaUrlField.getText());
+ basePathField.getText(), urlField.getText(),
+ arcUrlField.getText(), mediaUrlField.getText());
weblog.setLocale((Locale)localeCombo.getSelectedItem());
weblog.setTitle(titleField.getText());
weblog.setDescription(descrArea.getText());
weblog.getPageGenerator().setDateFormat(dateFormatCombo.getSelectedItem().toString());
-
weblog.getPageGenerator().setTimeFormat(timeFormatCombo.getSelectedItem().toString());
- weblog.setType(typeCombo.getSelectedItem().toString());
+
weblog.getPageGenerator().setTimeFormat(timeFormatCombo.getSelectedItem().toString());
+ weblog.setType(typeCombo.getSelectedItem().toString());
}
+
-
- public boolean isValidData() {
- String base = urlField.getText();
- String arc = arcUrlField.getText();
- String media = mediaUrlField.getText();
-
- if(basePathField.getText() == null ||
basePathField.getText().equals("")) //$NON-NLS-1$
- {
- JOptionPane.showMessageDialog(this,
- i18n.str("no_base_path_prompt"), //$NON-NLS-1$
- i18n.str("warning"), JOptionPane.WARNING_MESSAGE);
//$NON-NLS-1$
- return false;
- }
-
- if(typeCombo.getSelectedItem().equals("internet") &&
(!isValidUrl(base) || !isValidUrl(arc) || !isValidUrl(media)))
- return false;
-
- if(typeCombo.getSelectedItem().equals("freenet") && (!isValidKey(base)
|| !isValidKey(arc) || !isValidKey(media)))
- return false;
-
- if(!arc.startsWith(base)) {
- JOptionPane.showMessageDialog(this,
- i18n.str("bad_arc_url_prompt"), //$NON-NLS-1$
- i18n.str("warning"), JOptionPane.WARNING_MESSAGE);
//$NON-NLS-1$
-
- return false;
- }
-
- if(!media.startsWith(base)) {
- JOptionPane.showMessageDialog(this,
- i18n.str("bad_media_url_prompt"), //$NON-NLS-1$
- i18n.str("warning"), JOptionPane.WARNING_MESSAGE);
//$NON-NLS-1$
-
- return false;
- }
-
- return true;
+ public boolean isValidData()
+ {
+ String base = urlField.getText();
+ String arc = arcUrlField.getText();
+ String media = mediaUrlField.getText();
+
+ if(basePathField.getText() == null ||
basePathField.getText().equals("")) //$NON-NLS-1$
+ {
+ JOptionPane.showMessageDialog(this,
+ i18n.str("no_base_path_prompt"), //$NON-NLS-1$
+ i18n.str("warning"),
JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
+ return false;
+ }
+
+ if(typeCombo.getSelectedItem().toString().equals("internet") &&
(!isValidUrl(base) || !isValidUrl(arc) || !isValidUrl(media)))
+ return false;
+
+ if(typeCombo.getSelectedItem().toString().equals("freenet") &&
(!isValidSSK(base)) || !isValidSSK(arc) || !isValidSSK(media))
+ return false;
+
+ if(!arc.startsWith(base))
+ {
+ JOptionPane.showMessageDialog(this,
+ i18n.str("bad_arc_url_prompt"), //$NON-NLS-1$
+ i18n.str("warning"),
JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
+
+ return false;
+ }
+
+ if(!media.startsWith(base))
+ {
+ JOptionPane.showMessageDialog(this,
+ i18n.str("bad_media_url_prompt"), //$NON-NLS-1$
+ i18n.str("warning"),
JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
+
+ return false;
+ }
+
+ return true;
}
- private boolean isValidUrl(String u) {
- try {
- new URL(u);
- } catch(Exception ex)//malformed url
- {
- JOptionPane.showMessageDialog(this,
- u + i18n.str("invalid_url_prompt"), //$NON-NLS-1$
- i18n.str("warning"), JOptionPane.WARNING_MESSAGE);
//$NON-NLS-1$
- return false;
- }
- return true;
+ private boolean isValidUrl(String u)
+ {
+ try
+ {
+ new URL(u);
+ }
+ catch(Exception ex)//malformed url
+ {
+ JOptionPane.showMessageDialog(this,
+ u + i18n.str("invalid_url_prompt"),
//$NON-NLS-1$
+ i18n.str("warning"),
JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
+ return false;
+ }
+ return true;
}
- private boolean isValidKey(String key) {
- // TODO : Check if the key match a USK key
+ private boolean isValidSSK(String u)
+ {
+ // TODO : Check if u match a SSK key
return true;
}
+
- private class ComboRenderer extends DefaultListCellRenderer {
- /**
- *
+ private class ComboRenderer extends DefaultListCellRenderer
+ {
+ /**
+ *
*/
private static final long serialVersionUID = 1L;
private Date date = new Date();
-
- public Component getListCellRendererComponent(JList list,
- Object value, int index, boolean isSelected, boolean
cellHasFocus) {
- if(value instanceof Locale) {
- Locale loc = (Locale)value;
- value = loc.getDisplayName();
- } else {
- Locale loc = (Locale)localeCombo.getSelectedItem();
- SimpleDateFormat df = new
SimpleDateFormat(value.toString(),loc);
- value = df.format(date);
- }
-
- return super.getListCellRendererComponent(
- list, value, index, isSelected, cellHasFocus);
- }
- }
-
+
+ public Component getListCellRendererComponent(JList list,
+ Object value, int index, boolean isSelected, boolean
cellHasFocus)
+ {
+ if(value instanceof Locale)
+ {
+ Locale loc = (Locale)value;
+ value = loc.getDisplayName();
+ }
+ else
+ {
+ Locale loc =
(Locale)localeCombo.getSelectedItem();
+ SimpleDateFormat df = new
SimpleDateFormat(value.toString(),loc);
+ value = df.format(date);
+ }
+
+ return super.getListCellRendererComponent(
+ list, value, index, isSelected, cellHasFocus);
+ }
+ }
+
}
Modified:
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWizardDialog.java
===================================================================
---
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWizardDialog.java
2008-02-09 20:27:58 UTC (rev 17769)
+++
trunk/apps/thingamablog/src/net/sf/thingamablog/gui/properties/TBWizardDialog.java
2008-02-10 03:51:06 UTC (rev 17770)
@@ -52,200 +52,216 @@
/**
* @author Bob Tantlinger
*
- *
- *
+ *
+ *
*/
-public class TBWizardDialog extends JDialog {
+public class TBWizardDialog extends JDialog
+{
/**
- *
+ *
*/
private static final long serialVersionUID = 1L;
-
+
private static final I18n i18n =
I18n.getInstance("net.sf.thingamablog.gui.properties"); //$NON-NLS-1$
private static final String CANCEL = i18n.str("cancel"); //$NON-NLS-1$
- private static final String FINISH = i18n.str("finish"); //$NON-NLS-1$
-
- private CardLayout wizLayout;
- private JPanel wizPanel;
-
- private PropertyPanel starterPanel;
- private TitleDescrPanel titlePanel;
- private CategoriesPanel catPanel;
- private AuthorsPanel authPanel;
+ private static final String FINISH = i18n.str("finish");
//$NON-NLS-1$
+
+ private CardLayout wizLayout;
+ private JPanel wizPanel;
+
+ private PropertyPanel starterPanel;
+ private TitleDescrPanel titlePanel;
+ private CategoriesPanel catPanel;
+ private AuthorsPanel authPanel;
private PropertyPanel emailPanel;
- private PropertyPanel templPanel;
- private PropertyPanel transportPanel;
- private PropertyPanel donePanel;
- private Vector panels = new Vector();
+ private PropertyPanel templPanel;
+ private PropertyPanel transportPanel;
+ private PropertyPanel donePanel;
+ private Vector panels = new Vector();
+
+ private JButton nextButton, backButton, doneButton;
+
+ private boolean isCancelled;
+
+ private TBWeblog weblog;
- private JButton nextButton, backButton, doneButton;
+ private TextEditPopupManager popupManager =
TextEditPopupManager.getInstance();
- private boolean isCancelled;
-
- private TBWeblog weblog;
-
- private TextEditPopupManager popupManager =
TextEditPopupManager.getInstance();
-
private TemplatePack selectedPack;
-
- public TBWizardDialog(Frame f, File dir, WeblogBackend backend) {
- super(f, true);
- setTitle(i18n.str("new_weblog")); //$NON-NLS-1$
+
+ public TBWizardDialog(Frame f, File dir, WeblogBackend backend)
+ {
+ super(f, true);
+ setTitle(i18n.str("new_weblog")); //$NON-NLS-1$
+
+ WindowAdapter windowAdapter = new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent windowEvent)
+ {
+ cancelDialog();
+ }
+ };
+ addWindowListener(windowAdapter);
+
+ weblog = new TBWeblog(dir);
+ weblog.setBackend(backend);
+ weblog.setPublishTransport(new
net.sf.thingamablog.transport.FTPTransport());
+ //weblog.setAuthorStore(authStore);
+ //weblog.setCategoryStore(catStore);
+
+ wizLayout = new CardLayout();
+ wizPanel = new JPanel(wizLayout);
+
+ starterPanel = new StarterPanel();
+ starterPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+ panels.add(starterPanel);
+
+ titlePanel = new TitleDescrPanel();
+ titlePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+ panels.add(titlePanel);
+
+ catPanel = new CategoriesPanel();
+ catPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+ panels.add(catPanel);
+
+ authPanel = new AuthorsPanel();
+ authPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+ panels.add(authPanel);
- WindowAdapter windowAdapter = new WindowAdapter() {
- public void windowClosing(WindowEvent windowEvent) {
- cancelDialog();
- }
- };
- addWindowListener(windowAdapter);
-
- weblog = new TBWeblog(dir);
- weblog.setBackend(backend);
- weblog.setPublishTransport(new
net.sf.thingamablog.transport.FTPTransport());
- //weblog.setAuthorStore(authStore);
- //weblog.setCategoryStore(catStore);
-
- wizLayout = new CardLayout();
- wizPanel = new JPanel(wizLayout);
-
- starterPanel = new StarterPanel();
- starterPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
- panels.add(starterPanel);
-
- titlePanel = new TitleDescrPanel();
- titlePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
- panels.add(titlePanel);
-
- catPanel = new CategoriesPanel();
- catPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
- panels.add(catPanel);
-
- authPanel = new AuthorsPanel();
- authPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
- panels.add(authPanel);
-
emailPanel = new EmailPanel();
emailPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
panels.add(emailPanel);
-
- templPanel = new TemplatePanel();
- templPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
- panels.add(templPanel);
-
- transportPanel = new TransportPanel();
- transportPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
- panels.add(transportPanel);
-
- donePanel = new DonePanel();
- donePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
- panels.add(donePanel);
-
- wizPanel.add(starterPanel, "1"); //$NON-NLS-1$
- wizPanel.add(titlePanel, "2"); //$NON-NLS-1$
- wizPanel.add(catPanel, "3"); //$NON-NLS-1$
- wizPanel.add(authPanel, "4"); //$NON-NLS-1$
+
+ templPanel = new TemplatePanel();
+ templPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+ panels.add(templPanel);
+
+ transportPanel = new TransportPanel();
+ transportPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+ panels.add(transportPanel);
+
+ donePanel = new DonePanel();
+ donePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+ panels.add(donePanel);
+
+ wizPanel.add(starterPanel, "1"); //$NON-NLS-1$
+ wizPanel.add(titlePanel, "2"); //$NON-NLS-1$
+ wizPanel.add(catPanel, "3"); //$NON-NLS-1$
+ wizPanel.add(authPanel, "4"); //$NON-NLS-1$
wizPanel.add(emailPanel, "5"); //$NON-NLS-1$
- wizPanel.add(templPanel, "6"); //$NON-NLS-1$
- wizPanel.add(transportPanel, "7"); //$NON-NLS-1$
- wizPanel.add(donePanel, "8"); //$NON-NLS-1$
-
- ActionListener listener = new ButtonHandler();
- nextButton = new JButton(i18n.str("next-")); //$NON-NLS-1$
- nextButton.addActionListener(listener);
- backButton = new JButton(i18n.str("-back")); //$NON-NLS-1$
- backButton.setEnabled(false);
- backButton.addActionListener(listener);
- doneButton = new JButton(CANCEL);
- doneButton.addActionListener(listener);
-
- JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
- controlPanel.setBorder(new EtchedBorder());
- JPanel buttonPanel = new JPanel(new GridLayout(1, 3, 5, 5));
- buttonPanel.add(backButton);
- buttonPanel.add(nextButton);
- buttonPanel.add(doneButton);
- controlPanel.add(buttonPanel);
-
- JLabel img = new JLabel();
- img.setVerticalAlignment(SwingConstants.TOP);
- img.setOpaque(true);
- img.setBackground(Color.WHITE);
- img.setIcon(UIUtils.getIcon(UIUtils.MISC, "wizard.jpg")); //$NON-NLS-1$
-
- getContentPane().add(wizPanel, BorderLayout.CENTER);
- getContentPane().add(controlPanel, BorderLayout.SOUTH);
- getContentPane().add(img, BorderLayout.WEST);
-
- pack();
+ wizPanel.add(templPanel, "6"); //$NON-NLS-1$
+ wizPanel.add(transportPanel, "7"); //$NON-NLS-1$
+ wizPanel.add(donePanel, "8"); //$NON-NLS-1$
+
+ ActionListener listener = new ButtonHandler();
+ nextButton = new JButton(i18n.str("next-")); //$NON-NLS-1$
+ nextButton.addActionListener(listener);
+ backButton = new JButton(i18n.str("-back")); //$NON-NLS-1$
+ backButton.setEnabled(false);
+ backButton.addActionListener(listener);
+ doneButton = new JButton(CANCEL);
+ doneButton.addActionListener(listener);
+
+ JPanel controlPanel = new JPanel(new
FlowLayout(FlowLayout.RIGHT));
+ controlPanel.setBorder(new EtchedBorder());
+ JPanel buttonPanel = new JPanel(new GridLayout(1, 3, 5, 5));
+ buttonPanel.add(backButton);
+ buttonPanel.add(nextButton);
+ buttonPanel.add(doneButton);
+ controlPanel.add(buttonPanel);
+
+ JLabel img = new JLabel();
+ img.setVerticalAlignment(SwingConstants.TOP);
+ img.setOpaque(true);
+ img.setBackground(Color.WHITE);
+ img.setIcon(UIUtils.getIcon(UIUtils.MISC, "wizard.jpg"));
//$NON-NLS-1$
+
+ getContentPane().add(wizPanel, BorderLayout.CENTER);
+ getContentPane().add(controlPanel, BorderLayout.SOUTH);
+ getContentPane().add(img, BorderLayout.WEST);
+
+ pack();
setSize(560, getHeight());
- setResizable(false);
- }
-
- public TBWeblog getWeblog() {
- return weblog;
- }
-
- public boolean hasUserCancelled() {
- return isCancelled;
- }
-
- private void doFinish() {
- /*for(int i = 0; i < panels.size(); i++)
- {
- PropertyPanel p = (PropertyPanel)panels.elementAt(i);
- p.saveProperties();
- }*/
+ setResizable(false);
+ }
+
+ public TBWeblog getWeblog()
+ {
+ return weblog;
+ }
+
+ public boolean hasUserCancelled()
+ {
+ return isCancelled;
+ }
+
+ private void doFinish()
+ {
+ /*for(int i = 0; i < panels.size(); i++)
+ {
+ PropertyPanel p = (PropertyPanel)panels.elementAt(i);
+ p.saveProperties();
+ }*/
- try {
+ try
+ {
selectedPack.installPack(weblog.getHomeDirectory());
- } catch(Exception ex) {
+ }
+ catch(Exception ex)
+ {
UIUtils.showError(this, ex);
}
+
+ //add a couple ping services
+ WeblogsDotComPing ping = new WeblogsDotComPing();
- //add a couple ping services
- WeblogsDotComPing ping = new WeblogsDotComPing();
-
//removed because the TAMB ping server has been shutdown...
- /*ping.setServiceName("Updated Thingamablogs");
-
ping.setServiceUrl("http://thingamablog.sourceforge.net/rpc.php");
- ping.setEnabled(true);
- weblog.addPingService(ping);*/
-
- ping = new WeblogsDotComPing();
- ping.setServiceName("weblogs.com"); //$NON-NLS-1$
- ping.setServiceUrl("http://rpc.weblogs.com/RPC2"); //$NON-NLS-1$
- ping.setEnabled(false);
- weblog.addPingService(ping);
-
- dispose();
- }
+ /*ping.setServiceName("Updated Thingamablogs");
+
ping.setServiceUrl("http://thingamablog.sourceforge.net/rpc.php");
+ ping.setEnabled(true);
+ weblog.addPingService(ping);*/
+
+ ping = new WeblogsDotComPing();
+ ping.setServiceName("weblogs.com"); //$NON-NLS-1$
+ ping.setServiceUrl("http://rpc.weblogs.com/RPC2"); //$NON-NLS-1$
+ ping.setEnabled(false);
+ weblog.addPingService(ping);
+
+ dispose();
+ }
+
+ private void cancelDialog()
+ {
+ isCancelled = true;
+ try{
+ weblog.deleteAll();
+ }catch(BackendException ex){}
+ dispose();
+ }
- private void cancelDialog() {
- isCancelled = true;
- try{
- weblog.deleteAll();
- }catch(BackendException ex){}
- dispose();
- }
-
- public void dispose() {
- WeblogPreviewer.getInstance().clearPreviewData();
+ public void dispose()
+ {
+ WeblogPreviewer.getInstance().clearPreviewData();
super.dispose();
}
+
+ private JLabel createHeaderLabel(String text)
+ {
+ JLabel label = new JLabel("<html><h2>" + text +
"</h2></html>"); //$NON-NLS-1$ //$NON-NLS-2$
+ return label;
+ }
- private JLabel createHeaderLabel(String text) {
- JLabel label = new JLabel("<html><h2>" + text + "</h2></html>");
//$NON-NLS-1$ //$NON-NLS-2$
- return label;
- }
+
-
-
- private PropertyPanel getCurrentPanel() {
- for(int i = 0; i < panels.size(); i++) {
+ private PropertyPanel getCurrentPanel()
+ {
+ for(int i = 0; i < panels.size(); i++)
+ {
PropertyPanel p = (PropertyPanel)panels.elementAt(i);
- if(p.isVisible()) {
+ if(p.isVisible())
+ {
//return p.isValidData();
return p;
}
@@ -253,224 +269,260 @@
return null;
}
-
- private class ButtonHandler implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == nextButton) {
- if(!donePanel.isVisible()) {
- //if(isCurrentPanelValid())
+
+ private class ButtonHandler implements ActionListener
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ if(e.getSource() == nextButton)
+ {
+ if(!donePanel.isVisible())
+ {
+ //if(isCurrentPanelValid())
PropertyPanel p = getCurrentPanel();
- if(p != null && p.isValidData()) {
- p.saveProperties();
+ if(p != null && p.isValidData())
+ {
+ p.saveProperties();
wizLayout.next(wizPanel);
}
- }
-
- if(donePanel.isVisible()) {
- doneButton.setText(FINISH);
- nextButton.setEnabled(false);
- }
- backButton.setEnabled(true);
- } else if(e.getSource() == backButton) {
- if(!starterPanel.isVisible())
- wizLayout.previous(wizPanel);
- if(starterPanel.isVisible())
- backButton.setEnabled(false);
- if(doneButton.getText().equals(FINISH))
- doneButton.setText(CANCEL);
- nextButton.setEnabled(true);
- } else if(e.getSource() == doneButton) {
- //the new Weblog was canceled, so delete the
- //directory structure that was created when
- //the Weblog was instantiated
- if(doneButton.getText().equals(FINISH)) {
- doFinish();
- } else {
- cancelDialog();
- }
- }
- }
- }
-
-
-
-
- private class StarterPanel extends PropertyPanel {
- /**
- *
+ }
+
+ if(donePanel.isVisible())
+ {
+ doneButton.setText(FINISH);
+ nextButton.setEnabled(false);
+ }
+ backButton.setEnabled(true);
+ }
+ else if(e.getSource() == backButton)
+ {
+ if(!starterPanel.isVisible())
+ wizLayout.previous(wizPanel);
+ if(starterPanel.isVisible())
+ backButton.setEnabled(false);
+ if(doneButton.getText().equals(FINISH))
+ doneButton.setText(CANCEL);
+ nextButton.setEnabled(true);
+ }
+ else if(e.getSource() == doneButton)
+ {
+ //the new Weblog was canceled, so delete the
+ //directory structure that was created when
+ //the Weblog was instantiated
+ if(doneButton.getText().equals(FINISH))
+ {
+ doFinish();
+ }
+ else
+ {
+ cancelDialog();
+ }
+ }
+ }
+ }
+
+
+
+
+ private class StarterPanel extends PropertyPanel
+ {
+ /**
+ *
*/
private static final long serialVersionUID = 1L;
private JTextField pathField = new JTextField(20);
- private JTextField urlField = new JTextField(20);
- private String TYPE[] = {"internet","freenet"};
- private JComboBox typeCombo = new JComboBox(TYPE);
-
- public StarterPanel() {
- JLabel header = createHeaderLabel(i18n.str("weblog_wizard"));
//$NON-NLS-1$
- String text =
- i18n.str("welcome_panel_text"); //$NON-NLS-1$
-
-
- LabelledItemPanel lip = new LabelledItemPanel();
- lip.addItem(i18n.str("base_path"), pathField); //$NON-NLS-1$
- lip.addItem(i18n.str("base_url"), urlField); //$NON-NLS-1$
- lip.addItem(i18n.str("type"), typeCombo);
-
- popupManager.registerJTextComponent(pathField);
- popupManager.registerJTextComponent(urlField);
-
- setLayout(new BorderLayout());
- add(header, BorderLayout.NORTH);
- add(new MultilineText(text), BorderLayout.CENTER);
- add(lip, BorderLayout.SOUTH);
- }
-
- public boolean isValidData() {
+ private JTextField urlField = new JTextField(20);
+ private String TYPE[]={"internet","freenet"};
+ private JComboBox typeCombo = new JComboBox(TYPE);
+
+ public StarterPanel()
+ {
+ JLabel header =
createHeaderLabel(i18n.str("weblog_wizard")); //$NON-NLS-1$
+ String text =
+ i18n.str("welcome_panel_text"); //$NON-NLS-1$
+
+
+ LabelledItemPanel lip = new LabelledItemPanel();
+ lip.addItem(i18n.str("base_path"), pathField);
//$NON-NLS-1$
+ lip.addItem(i18n.str("base_url"), urlField);
//$NON-NLS-1$
+ lip.addItem(i18n.str("type"), typeCombo);
+
+ popupManager.registerJTextComponent(pathField);
+ popupManager.registerJTextComponent(urlField);
+
+ setLayout(new BorderLayout());
+ add(header, BorderLayout.NORTH);
+ add(new MultilineText(text), BorderLayout.CENTER);
+ add(lip, BorderLayout.SOUTH);
+ }
+
+ public boolean isValidData()
+ {
if(pathField.getText().equals("")) //$NON-NLS-1$
{
JOptionPane.showMessageDialog(TBWizardDialog.this,
- i18n.str("invalid_path_prompt"),
i18n.str("invalid_path"), //$NON-NLS-1$ //$NON-NLS-2$
- JOptionPane.WARNING_MESSAGE);
+ i18n.str("invalid_path_prompt"), i18n.str("invalid_path"),
//$NON-NLS-1$ //$NON-NLS-2$
+ JOptionPane.WARNING_MESSAGE);
return false;
}
if(urlField.getText().equals("")) //$NON-NLS-1$
{
JOptionPane.showMessageDialog(TBWizardDialog.this,
- i18n.str("invalid_url_prompt"),
i18n.str("invalid_url"), //$NON-NLS-1$ //$NON-NLS-2$
- JOptionPane.WARNING_MESSAGE);
+ i18n.str("invalid_url_prompt"), i18n.str("invalid_url"),
//$NON-NLS-1$ //$NON-NLS-2$
+ JOptionPane.WARNING_MESSAGE);
return false;
}
-
- if(typeCombo.getSelectedItem().toString().equals("internet")) {
- try {
- new URL(urlField.getText());
- } catch(MalformedURLException ex) //invalid url
+ if (typeCombo.getSelectedItem().toString().equals("internet")) {
+ try
+ {
+ new URL(urlField.getText());
+ }
+ catch(MalformedURLException ex) //invalid url
+ {
+
+ // Display a warning message instead of just
put http:// at the beginning of the url, in case the user enter a USK key and
didn't use the type combobox
+ urlField.setText("http://" +
urlField.getText()); //$NON-NLS-1$
+
JOptionPane.showMessageDialog(TBWizardDialog.this,
+ i18n.str("invalid_url_prompt"),
i18n.str("invalid_url"), //$NON-NLS-1$ //$NON-NLS-2$
+ JOptionPane.WARNING_MESSAGE);
+ return false;
+ }
+ }
+ if (typeCombo.getSelectedItem().toString().equals("freenet"))
+ return isValidSSK(urlField.getText());
+
+ return true;
+ }
+ private boolean isValidSSK(String u)
{
- urlField.setText("http://" + urlField.getText());
//$NON-NLS-1$
+ // TODO : Check if u match a SSK key
+ return true;
}
- } else {
- return isValidKey(urlField.getText());
- }
-
- return true;
- }
-
- public Boolean isValidKey(String key){
- // TODO : Check if the key match a USK key
- return true;
- }
-
- public void saveProperties() {
- String path = pathField.getText();
- String url = urlField.getText();
- if(!url.endsWith("/")) //$NON-NLS-1$
- url += "/";; //$NON-NLS-1$
-
- String arcUrl = url + "archives"; //$NON-NLS-1$
- String mediaUrl = url + "media"; //$NON-NLS-1$
-
- weblog.setBlogUrls(path, url, arcUrl, mediaUrl);
- weblog.setType(typeCombo.getSelectedItem().toString());
- }
- }
-
- private class TitleDescrPanel extends PropertyPanel {
- /**
- *
+ public void saveProperties()
+ {
+ String path = pathField.getText();
+ String url = urlField.getText();
+ if(!url.endsWith("/")) //$NON-NLS-1$
+ url += "/";; //$NON-NLS-1$
+ String arcUrl = url + "archives"; //$NON-NLS-1$
+ String mediaUrl = url + "media"; //$NON-NLS-1$
+
+ weblog.setBlogUrls(path, url, arcUrl, mediaUrl);
+ weblog.setType(typeCombo.getSelectedItem().toString());
+ }
+ }
+
+ private class TitleDescrPanel extends PropertyPanel
+ {
+ /**
+ *
*/
private static final long serialVersionUID = 1L;
private JTextField titleField = new JTextField();
- private JTextArea textArea = new JTextArea(4, 4);
+ private JTextArea textArea = new JTextArea(4, 4);
+
+ public TitleDescrPanel()
+ {
+ setLayout(new BorderLayout());
+
+ JPanel instrPanel = new JPanel(new BorderLayout());
+ JLabel header =
createHeaderLabel(i18n.str("title_and_description")); //$NON-NLS-1$
+ String text =
+ i18n.str("title_panel_text"); //$NON-NLS-1$
+ instrPanel.add(header, BorderLayout.NORTH);
+ instrPanel.add(new MultilineText(text),
BorderLayout.CENTER);
+
+ popupManager.registerJTextComponent(titleField);
+ popupManager.registerJTextComponent(textArea);
+
+ LabelledItemPanel lip = new LabelledItemPanel();
+ lip.addItem(i18n.str("site_title"), titleField);
//$NON-NLS-1$
+ lip.addItem(i18n.str("description"), new
JScrollPane(textArea)); //$NON-NLS-1$
+
+ add(instrPanel, BorderLayout.NORTH);
+ add(lip, BorderLayout.CENTER);
+ }
+
+ public boolean isValidData()
+ {
+ if(titleField.getText().equals("")) //$NON-NLS-1$
+ {
+
JOptionPane.showMessageDialog(TBWizardDialog.this,
+ i18n.str("invalid_title_prompt"),
i18n.str("title"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
+ return false;
+ }
+ return true;
+ }
+
+ public void saveProperties()
+ {
+ weblog.setTitle(titleField.getText());
+ weblog.setDescription(textArea.getText());
+ }
- public TitleDescrPanel() {
- setLayout(new BorderLayout());
-
- JPanel instrPanel = new JPanel(new BorderLayout());
- JLabel header =
createHeaderLabel(i18n.str("title_and_description")); //$NON-NLS-1$
- String text =
- i18n.str("title_panel_text"); //$NON-NLS-1$
- instrPanel.add(header, BorderLayout.NORTH);
- instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
-
- popupManager.registerJTextComponent(titleField);
- popupManager.registerJTextComponent(textArea);
-
- LabelledItemPanel lip = new LabelledItemPanel();
- lip.addItem(i18n.str("site_title"), titleField); //$NON-NLS-1$
- lip.addItem(i18n.str("description"), new JScrollPane(textArea));
//$NON-NLS-1$
-
- add(instrPanel, BorderLayout.NORTH);
- add(lip, BorderLayout.CENTER);
- }
-
- public boolean isValidData() {
- if(titleField.getText().equals("")) //$NON-NLS-1$
- {
- JOptionPane.showMessageDialog(TBWizardDialog.this,
- i18n.str("invalid_title_prompt"), i18n.str("title"),
JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
- return false;
- }
- return true;
- }
-
- public void saveProperties() {
- weblog.setTitle(titleField.getText());
- weblog.setDescription(textArea.getText());
- }
-
- public String getTitle() {
+ public String getTitle()
+ {
return titleField.getText();
}
- public String getDescription() {
+ public String getDescription()
+ {
return textArea.getText();
}
- }
-
- private class CategoriesPanel extends PropertyPanel {
- /**
- *
+ }
+
+ private class CategoriesPanel extends PropertyPanel
+ {
+ /**
+ *
*/
private static final long serialVersionUID = 1L;
private EditableList list;
- private WeblogEditableListModel model;
-
- public CategoriesPanel() {
- setLayout(new BorderLayout(5, 5));
+ private WeblogEditableListModel model;
+
+ public CategoriesPanel()
+ {
+ setLayout(new BorderLayout(5, 5));
+
+ JPanel instrPanel = new JPanel(new BorderLayout());
+ JLabel header =
createHeaderLabel(i18n.str("categories")); //$NON-NLS-1$
+ String text =
+ i18n.str("categories_panel_text"); //$NON-NLS-1$
+ instrPanel.add(header, BorderLayout.NORTH);
+ instrPanel.add(new MultilineText(text),
BorderLayout.CENTER);
+
+ model = new
WeblogEditableListModel(WeblogEditableListModel.CATEGORIES);
+ list = new EditableList(model);
+ setBorder(BorderFactory.createEmptyBorder(12, 12, 12,
12));
+
+ add(instrPanel, BorderLayout.NORTH);
+ add(list, BorderLayout.CENTER);
- JPanel instrPanel = new JPanel(new BorderLayout());
- JLabel header = createHeaderLabel(i18n.str("categories"));
//$NON-NLS-1$
- String text =
- i18n.str("categories_panel_text"); //$NON-NLS-1$
- instrPanel.add(header, BorderLayout.NORTH);
- instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
- model = new
WeblogEditableListModel(WeblogEditableListModel.CATEGORIES);
- list = new EditableList(model);
- setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
-
- add(instrPanel, BorderLayout.NORTH);
- add(list, BorderLayout.CENTER);
-
-
- }
+ }
+
+ public boolean isValidData()
+ {
+ return true;
+ }
+
+ public void saveProperties()
+ {
+ //ListModel lm = catList.getModel();
+ try
+ {
+ model.syncListWithWeblog(weblog);
+ }
+ catch(Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
- public boolean isValidData() {
- return true;
- }
-
- public void saveProperties() {
- //ListModel lm = catList.getModel();
- try {
- model.syncListWithWeblog(weblog);
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- }
-
- public String[] getCategories() {
+ public String[] getCategories()
+ {
List data = list.getListData();
String[] cats = new String[data.size()];
for(int i = 0; i < cats.length; i++)
@@ -478,50 +530,59 @@
return cats;
}
- public WeblogEditableListModel getModel() {
+ public WeblogEditableListModel getModel()
+ {
return model;
}
- }
-
- private class AuthorsPanel extends PropertyPanel {
- /**
- *
+ }
+
+ private class AuthorsPanel extends PropertyPanel
+ {
+ /**
+ *
*/
private static final long serialVersionUID = 1L;
private EditableList list;
- private WeblogEditableListModel model;
+ private WeblogEditableListModel model;
+
+ public AuthorsPanel()
+ {
+ setLayout(new BorderLayout(5, 5));
+
+ JPanel instrPanel = new JPanel(new BorderLayout());
+ JLabel header = createHeaderLabel(i18n.str("authors"));
//$NON-NLS-1$
+ String text =
+ i18n.str("authors_panel_text"); //$NON-NLS-1$
+ instrPanel.add(header, BorderLayout.NORTH);
+ instrPanel.add(new MultilineText(text),
BorderLayout.CENTER);
+
+ model = new
WeblogEditableListModel(WeblogEditableListModel.AUTHORS);
+ list = new EditableList(model);
+ setBorder(BorderFactory.createEmptyBorder(12, 12, 12,
12));
+
+ add(instrPanel, BorderLayout.NORTH);
+ add(list, BorderLayout.CENTER);
+ }
+
+ public boolean isValidData()
+ {
+ return true;
+ }
+
+ public void saveProperties()
+ {
+ try
+ {
+ model.syncListWithWeblog(weblog);
+ }
+ catch(Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
- public AuthorsPanel() {
- setLayout(new BorderLayout(5, 5));
-
- JPanel instrPanel = new JPanel(new BorderLayout());
- JLabel header = createHeaderLabel(i18n.str("authors"));
//$NON-NLS-1$
- String text =
- i18n.str("authors_panel_text"); //$NON-NLS-1$
- instrPanel.add(header, BorderLayout.NORTH);
- instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
-
- model = new
WeblogEditableListModel(WeblogEditableListModel.AUTHORS);
- list = new EditableList(model);
- setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
-
- add(instrPanel, BorderLayout.NORTH);
- add(list, BorderLayout.CENTER);
- }
-
- public boolean isValidData() {
- return true;
- }
-
- public void saveProperties() {
- try {
- model.syncListWithWeblog(weblog);
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- }
-
- public Author[] getAuthors() {
+ public Author[] getAuthors()
+ {
List data = list.getListData();
Author[] a = new Author[data.size()];
for(int i = 0; i < a.length; i++)
@@ -529,27 +590,30 @@
return a;
}
- public WeblogEditableListModel getModel() {
+ public WeblogEditableListModel getModel()
+ {
return model;
}
- }
+ }
- private class EmailPanel extends PropertyPanel {
-
+ private class EmailPanel extends PropertyPanel
+ {
+
/**
- *
+ *
*/
private static final long serialVersionUID = 1L;
TBEmailPanel emailPanel;
- public EmailPanel() {
+ public EmailPanel()
+ {
setLayout(new BorderLayout(5, 5));
JPanel instrPanel = new JPanel(new BorderLayout());
JLabel header = createHeaderLabel("Email"); //$NON-NLS-1$
String text =
- i18n.str("specify_mail_server_prompt"); //$NON-NLS-1$
-
+ i18n.str("specify_mail_server_prompt"); //$NON-NLS-1$
+
instrPanel.add(header, BorderLayout.NORTH);
instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
@@ -561,106 +625,120 @@
/* (non-Javadoc)
* @see net.sf.thingamablog.gui.properties.PropertyPanel#isValidData()
*/
- public boolean isValidData() {
+ public boolean isValidData()
+ {
return emailPanel.isValidData();
}
-
+
/* (non-Javadoc)
* @see
net.sf.thingamablog.gui.properties.PropertyPanel#saveProperties()
*/
- public void saveProperties() {
- emailPanel.saveProperties();
+ public void saveProperties()
+ {
+ emailPanel.saveProperties();
}
}
-
- private class TransportPanel extends PropertyPanel {
- /**
- *
+
+ private class TransportPanel extends PropertyPanel
+ {
+ /**
+ *
*/
private static final long serialVersionUID = 1L;
TBPublishTransportPanel pubPanel;
-
- public TransportPanel() {
- setLayout(new BorderLayout());
-
- JPanel instrPanel = new JPanel(new BorderLayout());
- JLabel header = createHeaderLabel(i18n.str("publishing"));
//$NON-NLS-1$
- String text =
- i18n.str("publishing_panel_text"); //$NON-NLS-1$
- instrPanel.add(header, BorderLayout.NORTH);
- instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
-
- pubPanel = new TBPublishTransportPanel(weblog);
- add(instrPanel, BorderLayout.NORTH);
- add(pubPanel, BorderLayout.CENTER);
- }
-
- public boolean isValidData() {
- return pubPanel.isValidData();
- }
-
- public void saveProperties() {
- pubPanel.saveProperties();
- }
- }
-
- private class TemplatePanel extends PropertyPanel {
- /**
- *
+
+ public TransportPanel()
+ {
+ setLayout(new BorderLayout());
+
+ JPanel instrPanel = new JPanel(new BorderLayout());
+ JLabel header =
createHeaderLabel(i18n.str("publishing")); //$NON-NLS-1$
+ String text =
+ i18n.str("publishing_panel_text"); //$NON-NLS-1$
+ instrPanel.add(header, BorderLayout.NORTH);
+ instrPanel.add(new MultilineText(text),
BorderLayout.CENTER);
+
+ pubPanel = new TBPublishTransportPanel(weblog);
+ add(instrPanel, BorderLayout.NORTH);
+ add(pubPanel, BorderLayout.CENTER);
+ }
+
+ public boolean isValidData()
+ {
+ return pubPanel.isValidData();
+ }
+
+ public void saveProperties()
+ {
+ pubPanel.saveProperties();
+ }
+ }
+
+ private class TemplatePanel extends PropertyPanel
+ {
+ /**
+ *
*/
private static final long serialVersionUID = 1L;
- //private JComboBox tmplCombo;
+ //private JComboBox tmplCombo;
//private TemplatePropertiesPanel propertyPanel;
private TemplateSelectionPanel selPanel;
-
- public TemplatePanel() {
- JPanel instrPanel = new JPanel(new BorderLayout());
- JLabel header = createHeaderLabel(i18n.str("templates"));
//$NON-NLS-1$
- String text =
- i18n.str("templates_panel_text"); //$NON-NLS-1$
- instrPanel.add(header, BorderLayout.NORTH);
- instrPanel.add(new MultilineText(text), BorderLayout.CENTER);
-
- selPanel = new TemplateSelectionPanel(weblog);
-
+
+ public TemplatePanel()
+ {
+ JPanel instrPanel = new JPanel(new BorderLayout());
+ JLabel header =
createHeaderLabel(i18n.str("templates")); //$NON-NLS-1$
+ String text =
+ i18n.str("templates_panel_text"); //$NON-NLS-1$
+ instrPanel.add(header, BorderLayout.NORTH);
+ instrPanel.add(new MultilineText(text),
BorderLayout.CENTER);
+
+ selPanel = new TemplateSelectionPanel(weblog);
+
setLayout(new BorderLayout(5, 5));
- add(instrPanel, BorderLayout.NORTH);
- add(selPanel, BorderLayout.CENTER);
- }
-
- public boolean isValidData() {
- if(selPanel.getSelectedPack() == null)
+ add(instrPanel, BorderLayout.NORTH);
+ add(selPanel, BorderLayout.CENTER);
+ }
+
+ public boolean isValidData()
+ {
+ if(selPanel.getSelectedPack() == null)
return false;
return true;
- }
-
- public void saveProperties() {
+ }
+
+ public void saveProperties()
+ {
selectedPack = selPanel.getSelectedPack();
}
- }
-
- private class DonePanel extends PropertyPanel {
- /**
- *
+ }
+
+ private class DonePanel extends PropertyPanel
+ {
+ /**
+ *
*/
private static final long serialVersionUID = 1L;
-
- public DonePanel() {
- JLabel header = createHeaderLabel(i18n.str("done")); //$NON-NLS-1$
- String text =
- i18n.str("finished_panel_text"); //$NON-NLS-1$
-
- setLayout(new BorderLayout());
- add(header, BorderLayout.NORTH);
- add(new MultilineText(text), BorderLayout.CENTER);
- }
-
- public boolean isValidData() {
- return true;
- }
-
- public void saveProperties() {
- }
- }
+
+ public DonePanel()
+ {
+ JLabel header = createHeaderLabel(i18n.str("done"));
//$NON-NLS-1$
+ String text =
+ i18n.str("finished_panel_text"); //$NON-NLS-1$
+
+ setLayout(new BorderLayout());
+ add(header, BorderLayout.NORTH);
+ add(new MultilineText(text), BorderLayout.CENTER);
+ }
+
+ public boolean isValidData()
+ {
+ return true;
+ }
+
+ public void saveProperties()
+ {
+ }
+ }
}
Modified:
trunk/apps/thingamablog/src/net/sf/thingamablog/xml/TBPersistFactory.java
===================================================================
--- trunk/apps/thingamablog/src/net/sf/thingamablog/xml/TBPersistFactory.java
2008-02-09 20:27:58 UTC (rev 17769)
+++ trunk/apps/thingamablog/src/net/sf/thingamablog/xml/TBPersistFactory.java
2008-02-10 03:51:06 UTC (rev 17770)
@@ -14,7 +14,7 @@
* 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,
@@ -62,328 +62,362 @@
/**
- *
+ *
* Factory for persisting a Thingamablog XML "database"
- *
+ *
* @author Bob Tantlinger
*
*/
-public class TBPersistFactory {
+public class TBPersistFactory
+{
//private static final Logger logger =
Logger.getLogger("net.sf.thingamablog.xml");
/**
- * Saves the current data to an XML file
- *
- * @param blogList The list of weblogs
- * @param feedRootFolder The root FeedFolder
- * @param path The path to save the file to
- * @throws IOException If an IO error occurs
- * @throws JDOMException If a JDOM error occurs
- */
- public synchronized static void save(WeblogList blogList, FeedFolder
feedRootFolder, String path)
- throws IOException, JDOMException {
- String mainRoot = "Thingamablog";
- //Document document = XMLUtils.initDocument(mainRoot, mainRoot, new
File(path));
- Document document = new Document(new Element(mainRoot));
- Comment comment =
- new Comment("Generated by Thingamablog. DO NOT EDIT THIS
FILE!!!");
- document.getContent().add(0, comment);
-
- Element weblogsRoot = new Element("Weblogs");
- Element feedsRoot = new Element("Feeds");
- saveWeblogsToXML(blogList, weblogsRoot);
- saveFeedFolder(feedRootFolder, feedsRoot);
-
- Element root = document.getRootElement();
- root.addContent(weblogsRoot);
- root.addContent(feedsRoot);
-
- XMLUtils.writeXML(document, path, true);
- }
-
- public static void loadData(String path, WeblogList list, FeedFolder
rootFolder, WeblogBackend b1, FeedBackend b2)
- throws IOException, JDOMException {
- File f = new File(path);
- Document doc = createDocument(f);
- loadWeblogList(doc, f, list, b1);
- loadFeedTree(doc, rootFolder, b2);
- }
-
- private static Document createDocument(File file)
- throws IOException, JDOMException {
- SAXBuilder builder = new SAXBuilder(false);
- builder.setEntityResolver(new TBEntityResolver());
- Document document = builder.build(file);
- return document;
- }
-
-
-
- private static void saveFeedFolder(FeedFolder folder, Element element) {
- FeedFolder sub[] = folder.getFolders();
- for(int i = 0; i < sub.length; i++) {
- Element category = new Element("Folder");
- category.setAttribute("name", sub[i].getName());
- element.addContent(category);
- saveFeedFolder(sub[i], category);
- }
-
- Feed feeds[] = folder.getFeeds();
- for(int j = 0; j < feeds.length; j++) {
- Element link = new Element("Feed");
- link.setText(feeds[j].getURL());
-
- String title = feeds[j].getTitle();
- if(title != null)
- link.setAttribute("title", title);
- else
- link.setAttribute("title", "Untitled");
-
- link.setAttribute("archive", feeds[j].isLimitItems() + "");
- link.setAttribute("limit", feeds[j].getItemLimit() + "");
-
- Date updateDate = feeds[j].getLastUpdated();
- if(updateDate != null)
- link.setAttribute("update_date", updateDate.getTime() + "");
- //link.setAttribute("update_failed", feeds[j].isLastUpdateFailed()
+ "");
- if(feeds[j].isLastUpdateFailed())
- link.setAttribute("update_failed",
feeds[j].getLastUpdateFailedReason());
-
- element.addContent(link);
- }
- }
-
- /**
- * Loads the FeedFolder heirarchy from an XML file
- *
- * @param rootFolder The root FeedFolder
- * @param path The path to the XML file
- * @param backend The backend for the feeds
- * @throws IOException If an IO error occurs
- * @throws JDOMException If a JDOM error occurs
- */
- public static void loadFeedTree(FeedFolder rootFolder, String path,
FeedBackend backend)
- throws IOException, JDOMException {
- Document document = createDocument(new File(path));
- if(document == null)
- return;
-
- loadFeedTree(document, rootFolder, backend);
- }
-
- private static void loadFeedTree(Document document, FeedFolder rootFolder,
FeedBackend backend) {
- Element root = document.getRootElement();
- Element feedRoot = root.getChild("Feeds");
-
- if(feedRoot != null) {
- loadFeeds(rootFolder, feedRoot, backend);
- }
- }
-
- private static void loadFeeds(FeedFolder folder, Element element,
FeedBackend backend) {
- List contents = element.getChildren();
- Iterator contentsIt = contents.iterator();
-
- while(contentsIt.hasNext()) {
- Element ele = (Element) contentsIt.next();
-
- /** The element is a category */
- if(ele.getName().equals("Folder")) {
- FeedFolder subFolder = loadFeedFolder(ele);
- folder.addFolder(subFolder);
- loadFeeds(subFolder, ele, backend);
- }
- /** The element is a favorite */
- else if (ele.getName().equals("Feed")) {
- folder.addFeed(loadFeed(ele, backend));
- }
- }
- }
-
- private static FeedFolder loadFeedFolder(Element element) {
-
- /** Name of the category */
- String folderName = element.getAttributeValue("name");
-
- /** Create a new category */
- FeedFolder sub = new FeedFolder(folderName);
- return sub;
- }
-
- private static Feed loadFeed(Element element, FeedBackend backend) {
- String url = "";
- String title = "";
- Date updated = null;
- boolean /*lastUpdateFailed = false,*/ archive = true;
- String failReason = null;
- int limit = 50;
-
- // Url of the feed
- if (element.getText() != null)
- url = element.getText();
-
- // Title of the feed
- if (element.getAttributeValue("title") != null)
- title = element.getAttributeValue("title");
-
- if(element.getAttributeValue("update_date") != null) {
- try {
- long epoch =
Long.parseLong(element.getAttributeValue("update_date"));
- updated = new Date(epoch);
- } catch(Exception ex){}
- }
-
- try {
- limit = Integer.parseInt(element.getAttributeValue("limit", "50"));
- }catch(Exception ex){}
-
- archive = element.getAttributeValue("archive", "true").equals("true");
-
- if(element.getAttributeValue("update_failed") != null) {
- failReason = element.getAttributeValue("update_failed");
- }
-
- Feed f = new Feed(url);
- f.setTitle(title);
- f.setBackend(backend);
- f.setLastUpdated(updated);
- f.setLastUpdateFailed(failReason != null);
- f.setLimitItems(archive);
- f.setItemLimit(limit);
- if(failReason != null)
- f.setLastUpdateFailedReason(failReason);
- return f;
- }
-
-
- private static void saveWeblogsToXML(WeblogList blogList, Element root)
- throws IOException, JDOMException {
- for(int i = 0; i < blogList.getWeblogCount(); i++) {
- Weblog blog = blogList.getWeblogAt(i);
- Element bElement = createWeblogElement(blog);
- root.addContent(bElement);
- }
- }
-
- private static Element createWeblogElement(Weblog blog) {
- Element element = new Element("Weblog");
- element.setAttribute("title", blog.getTitle());
- element.setAttribute("key", blog.getKey());
- element.setAttribute("last_publish",
blog.getLastPublishDate().getTime() + "");
+ * Saves the current data to an XML file
+ *
+ * @param blogList The list of weblogs
+ * @param feedRootFolder The root FeedFolder
+ * @param path The path to save the file to
+ * @throws IOException If an IO error occurs
+ * @throws JDOMException If a JDOM error occurs
+ */
+ public synchronized static void save(WeblogList blogList, FeedFolder
feedRootFolder, String path)
+ throws IOException, JDOMException
+ {
+ String mainRoot = "Thingamablog";
+ //Document document = XMLUtils.initDocument(mainRoot, mainRoot,
new File(path));
+ Document document = new Document(new Element(mainRoot));
+ Comment comment =
+ new Comment("Generated by Thingamablog. DO NOT EDIT
THIS FILE!!!");
+ document.getContent().add(0, comment);
+
+ Element weblogsRoot = new Element("Weblogs");
+ Element feedsRoot = new Element("Feeds");
+ saveWeblogsToXML(blogList, weblogsRoot);
+ saveFeedFolder(feedRootFolder, feedsRoot);
+
+ Element root = document.getRootElement();
+ root.addContent(weblogsRoot);
+ root.addContent(feedsRoot);
+
+ XMLUtils.writeXML(document, path, true);
+ }
+
+ public static void loadData(String path, WeblogList list, FeedFolder
rootFolder, WeblogBackend b1, FeedBackend b2)
+ throws IOException, JDOMException
+ {
+ File f = new File(path);
+ Document doc = createDocument(f);
+ loadWeblogList(doc, f, list, b1);
+ loadFeedTree(doc, rootFolder, b2);
+ }
+
+ private static Document createDocument(File file)
+ throws IOException, JDOMException
+ {
+ SAXBuilder builder = new SAXBuilder(false);
+ builder.setEntityResolver(new TBEntityResolver());
+ Document document = builder.build(file);
+ return document;
+ }
+
+
+
+ private static void saveFeedFolder(FeedFolder folder, Element element)
+ {
+ FeedFolder sub[] = folder.getFolders();
+ for(int i = 0; i < sub.length; i++)
+ {
+ Element category = new Element("Folder");
+ category.setAttribute("name", sub[i].getName());
+ element.addContent(category);
+ saveFeedFolder(sub[i], category);
+ }
+
+ Feed feeds[] = folder.getFeeds();
+ for(int j = 0; j < feeds.length; j++)
+ {
+ Element link = new Element("Feed");
+ link.setText(feeds[j].getURL());
+
+ String title = feeds[j].getTitle();
+ if(title != null)
+ link.setAttribute("title", title);
+ else
+ link.setAttribute("title", "Untitled");
+
+ link.setAttribute("archive", feeds[j].isLimitItems() +
"");
+ link.setAttribute("limit", feeds[j].getItemLimit() +
"");
+
+ Date updateDate = feeds[j].getLastUpdated();
+ if(updateDate != null)
+ link.setAttribute("update_date",
updateDate.getTime() + "");
+ //link.setAttribute("update_failed",
feeds[j].isLastUpdateFailed() + "");
+ if(feeds[j].isLastUpdateFailed())
+ link.setAttribute("update_failed",
feeds[j].getLastUpdateFailedReason());
+
+ element.addContent(link);
+ }
+ }
+
+ /**
+ * Loads the FeedFolder heirarchy from an XML file
+ *
+ * @param rootFolder The root FeedFolder
+ * @param path The path to the XML file
+ * @param backend The backend for the feeds
+ * @throws IOException If an IO error occurs
+ * @throws JDOMException If a JDOM error occurs
+ */
+ public static void loadFeedTree(FeedFolder rootFolder, String path,
FeedBackend backend)
+ throws IOException, JDOMException
+ {
+ Document document = createDocument(new File(path));
+ if(document == null)
+ return;
+
+ loadFeedTree(document, rootFolder, backend);
+ }
+
+ private static void loadFeedTree(Document document, FeedFolder
rootFolder, FeedBackend backend)
+ {
+ Element root = document.getRootElement();
+ Element feedRoot = root.getChild("Feeds");
+
+ if(feedRoot != null)
+ {
+ loadFeeds(rootFolder, feedRoot, backend);
+ }
+ }
+
+ private static void loadFeeds(FeedFolder folder, Element element,
FeedBackend backend)
+ {
+ List contents = element.getChildren();
+ Iterator contentsIt = contents.iterator();
+
+ while(contentsIt.hasNext())
+ {
+ Element ele = (Element) contentsIt.next();
+
+ /** The element is a category */
+ if(ele.getName().equals("Folder"))
+ {
+ FeedFolder subFolder = loadFeedFolder(ele);
+ folder.addFolder(subFolder);
+ loadFeeds(subFolder, ele, backend);
+ }
+ /** The element is a favorite */
+ else if (ele.getName().equals("Feed"))
+ {
+ folder.addFeed(loadFeed(ele, backend));
+ }
+ }
+ }
+
+ private static FeedFolder loadFeedFolder(Element element)
+ {
+
+ /** Name of the category */
+ String folderName = element.getAttributeValue("name");
+
+ /** Create a new category */
+ FeedFolder sub = new FeedFolder(folderName);
+ return sub;
+ }
+
+ private static Feed loadFeed(Element element, FeedBackend backend)
+ {
+ String url = "";
+ String title = "";
+ Date updated = null;
+ boolean /*lastUpdateFailed = false,*/ archive = true;
+ String failReason = null;
+ int limit = 50;
+
+ // Url of the feed
+ if (element.getText() != null)
+ url = element.getText();
+
+ // Title of the feed
+ if (element.getAttributeValue("title") != null)
+ title = element.getAttributeValue("title");
+
+ if(element.getAttributeValue("update_date") != null)
+ {
+ try
+ {
+ long epoch =
Long.parseLong(element.getAttributeValue("update_date"));
+ updated = new Date(epoch);
+ }
+ catch(Exception ex){}
+ }
+
+ try
+ {
+ limit =
Integer.parseInt(element.getAttributeValue("limit", "50"));
+ }catch(Exception ex){}
+
+ archive = element.getAttributeValue("archive",
"true").equals("true");
+
+ if(element.getAttributeValue("update_failed") != null)
+ {
+ failReason = element.getAttributeValue("update_failed");
+ }
+
+ Feed f = new Feed(url);
+ f.setTitle(title);
+ f.setBackend(backend);
+ f.setLastUpdated(updated);
+ f.setLastUpdateFailed(failReason != null);
+ f.setLimitItems(archive);
+ f.setItemLimit(limit);
+ if(failReason != null)
+ f.setLastUpdateFailedReason(failReason);
+ return f;
+ }
+
+
+ private static void saveWeblogsToXML(WeblogList blogList, Element root)
+ throws IOException, JDOMException
+ {
+ for(int i = 0; i < blogList.getWeblogCount(); i++)
+ {
+ Weblog blog = blogList.getWeblogAt(i);
+ Element bElement = createWeblogElement(blog);
+ root.addContent(bElement);
+ }
+ }
+
+ private static Element createWeblogElement(Weblog blog)
+ {
+ Element element = new Element("Weblog");
+ element.setAttribute("title", blog.getTitle());
+ element.setAttribute("key", blog.getKey());
+ element.setAttribute("last_publish",
blog.getLastPublishDate().getTime() + "");
element.setAttribute("publish_failed", blog.isPublishFailed() + "");
- Element descr = new Element("Description");
- descr.addContent(blog.getDescription());
- element.addContent(descr);
- element.addContent(createPingServicesElement(blog));
- element.addContent(createPublishTransportElement(blog));
+ Element descr = new Element("Description");
+ descr.addContent(blog.getDescription());
+ element.addContent(descr);
+ element.addContent(createPingServicesElement(blog));
+ element.addContent(createPublishTransportElement(blog));
element.addContent(createMailSettingsElement(blog));
-
- if(blog instanceof TBWeblog) {
- TBWeblog tbBlog = (TBWeblog)blog;
- return createTBWeblogElement(tbBlog, element);
- }
- return element;
- }
-
- private static Element createPingServicesElement(Weblog blog) {
- Element element = new Element("PingServices");
- PingService ps[] = blog.getPingServices();
- for(int i = 0; i < ps.length; i++) {
- if(ps[i] instanceof WeblogsDotComPing) {
- Element ping = new Element("WeblogsDotComPing");
- ping.setAttribute("name", ps[i].getServiceName());
- ping.setAttribute("url", ps[i].getServiceUrl());
- ping.setAttribute("enabled", ps[i].isEnabled() + "");
- element.addContent(ping);
- }
- }
- return element;
- }
-
- private static Element createTBWeblogElement(TBWeblog blog, Element
element) {
- element.setName("TBWeblog");
- element.setAttribute("url", blog.getBaseUrl());
- element.setAttribute("arc_url", blog.getArchiveUrl());
- element.setAttribute("media_url", blog.getMediaUrl());
- element.setAttribute("base_path", blog.getBasePath());
- element.setAttribute("base_date", blog.getArchiveBaseDate().getTime()
+ "");
- element.setAttribute("arc_policy", blog.getArchivePolicy() + "");
- element.setAttribute("day_interval", blog.getArchiveByDayInterval() +
"");
- element.setAttribute("arc_ext", blog.getArchivesExtension());
- element.setAttribute("cat_ext", blog.getCategoriesExtension());
+
+ if(blog instanceof TBWeblog)
+ {
+ TBWeblog tbBlog = (TBWeblog)blog;
+ return createTBWeblogElement(tbBlog, element);
+ }
+ return element;
+ }
+
+ private static Element createPingServicesElement(Weblog blog)
+ {
+ Element element = new Element("PingServices");
+ PingService ps[] = blog.getPingServices();
+ for(int i = 0; i < ps.length; i++)
+ {
+ if(ps[i] instanceof WeblogsDotComPing)
+ {
+ Element ping = new Element("WeblogsDotComPing");
+ ping.setAttribute("name",
ps[i].getServiceName());
+ ping.setAttribute("url", ps[i].getServiceUrl());
+ ping.setAttribute("enabled", ps[i].isEnabled()
+ "");
+ element.addContent(ping);
+ }
+ }
+ return element;
+ }
+
+ private static Element createTBWeblogElement(TBWeblog blog, Element
element)
+ {
+ element.setName("TBWeblog");
+ element.setAttribute("url", blog.getBaseUrl());
+ element.setAttribute("arc_url", blog.getArchiveUrl());
+ element.setAttribute("media_url", blog.getMediaUrl());
+ element.setAttribute("base_path", blog.getBasePath());
+ element.setAttribute("base_date",
blog.getArchiveBaseDate().getTime() + "");
+ element.setAttribute("arc_policy", blog.getArchivePolicy() +
"");
+ element.setAttribute("day_interval",
blog.getArchiveByDayInterval() + "");
+ element.setAttribute("arc_ext", blog.getArchivesExtension());
+ element.setAttribute("cat_ext", blog.getCategoriesExtension());
element.setAttribute("gen_cat_feed", blog.isGenerateCategoryFeeds() +
"");
element.setAttribute("cat_feed_ext",
blog.getCategoriesFeedExtension());
- element.setAttribute("entry_ext", blog.getEntryPageExtension());
- element.setAttribute("gen_rss", blog.isGenerateRssFeed() + "");
- element.setAttribute("gen_arc_index", blog.isGenerateArchiveIndex() +
"");
- element.setAttribute("gen_entries", blog.isGenerateEntryPages() + "");
- element.setAttribute("fp_filename", blog.getFrontPageFileName());
- element.setAttribute("rss_filename", blog.getRssFileName());
- element.setAttribute("arc_index_filename",
blog.getArchiveIndexFileName());
- element.setAttribute("locale", blog.getLocale().toString());
- element.setAttribute("publish_all", blog.isPublishAll() + "");
- element.setAttribute("type", blog.getType());
-
- Element outdatedArcs = new Element("OutdatedArchives");
- ArchiveRange ar[] = blog.getOutdatedArchives();
- for(int i = 0; i < ar.length; i++) {
- Element arcRange = new Element("Archive");
- arcRange.setAttribute("start", ar[i].getStartDate().getTime() +
"");
- arcRange.setAttribute("end", ar[i].getExpirationDate().getTime() +
"");
- outdatedArcs.addContent(arcRange);
- }
- element.addContent(outdatedArcs);
-
- Element outdatedCats = new Element("OutdatedCategories");
- String cats[] = blog.getOutdatedCategories();
- for(int i = 0; i < cats.length; i++) {
- Element category = new Element("Category");
- category.setText(cats[i]);
- outdatedCats.addContent(category);
- }
- element.addContent(outdatedCats);
-
- Element outdatedEntries = new Element("OutdatedEntries");
- long ids[] = blog.getOutdatedEntryIDs();
- for(int i = 0; i < ids.length; i++) {
- Element ent = new Element("Entry");
- ent.setText(ids[i] + "");
- outdatedEntries.addContent(ent);
- }
- element.addContent(outdatedEntries);
-
- Element genElement = new Element("Generator");
- PageGenerator gen = blog.getPageGenerator();
- genElement.setAttribute("charset", gen.getCharset());
- genElement.setAttribute("range_format", gen.getArchiveRangeFormat());
- genElement.setAttribute("span_range", gen.isSpanArcRange() + "");
- genElement.setAttribute("date_format", gen.getDateFormat());
- genElement.setAttribute("time_format", gen.getTimeFormat());
- genElement.setAttribute("front_asc", gen.isFrontPageAscending() + "");
- genElement.setAttribute("cat_asc", gen.isCategoryPageAscending() + "");
- genElement.setAttribute("arc_asc", gen.isArchivePageAscending() + "");
- genElement.setAttribute("limit_front", gen.isLimitFrontPage() + "");
- genElement.setAttribute("front_page_limit", gen.getFrontPageLimit() +
"");
- genElement.setAttribute("limit_cat", gen.isLimitCategoryPage() + "");
- genElement.setAttribute("cat_page_limit", gen.getCategoryPageLimit() +
"");
- genElement.setAttribute("limit_rss_body", gen.isLimitRssEntry() + "");
-
-
- Element customTagsElement = new Element("CustomTags");
- CustomTag tags[] = gen.getCustomTags();
- for(int i = 0; i < tags.length; i++) {
- Element tag = new Element("Tag");
- tag.setAttribute("name", tags[i].getName());
- tag.setText(tags[i].getValue());
- customTagsElement.addContent(tag);
- }
-
- genElement.addContent(customTagsElement);
- element.addContent(genElement);
- return element;
- }
+ element.setAttribute("entry_ext", blog.getEntryPageExtension());
+ element.setAttribute("gen_rss", blog.isGenerateRssFeed() + "");
+ element.setAttribute("gen_arc_index",
blog.isGenerateArchiveIndex() + "");
+ element.setAttribute("gen_entries", blog.isGenerateEntryPages()
+ "");
+ element.setAttribute("fp_filename",
blog.getFrontPageFileName());
+ element.setAttribute("rss_filename", blog.getRssFileName());
+ element.setAttribute("arc_index_filename",
blog.getArchiveIndexFileName());
+ element.setAttribute("locale", blog.getLocale().toString());
+ element.setAttribute("publish_all", blog.isPublishAll() + "");
+ element.setAttribute("type", blog.getType());
+
+ Element outdatedArcs = new Element("OutdatedArchives");
+ ArchiveRange ar[] = blog.getOutdatedArchives();
+ for(int i = 0; i < ar.length; i++)
+ {
+ Element arcRange = new Element("Archive");
+ arcRange.setAttribute("start",
ar[i].getStartDate().getTime() + "");
+ arcRange.setAttribute("end",
ar[i].getExpirationDate().getTime() + "");
+ outdatedArcs.addContent(arcRange);
+ }
+ element.addContent(outdatedArcs);
+
+ Element outdatedCats = new Element("OutdatedCategories");
+ String cats[] = blog.getOutdatedCategories();
+ for(int i = 0; i < cats.length; i++)
+ {
+ Element category = new Element("Category");
+ category.setText(cats[i]);
+ outdatedCats.addContent(category);
+ }
+ element.addContent(outdatedCats);
+
+ Element outdatedEntries = new Element("OutdatedEntries");
+ long ids[] = blog.getOutdatedEntryIDs();
+ for(int i = 0; i < ids.length; i++)
+ {
+ Element ent = new Element("Entry");
+ ent.setText(ids[i] + "");
+ outdatedEntries.addContent(ent);
+ }
+ element.addContent(outdatedEntries);
+
+ Element genElement = new Element("Generator");
+ PageGenerator gen = blog.getPageGenerator();
+ genElement.setAttribute("charset", gen.getCharset());
+ genElement.setAttribute("range_format",
gen.getArchiveRangeFormat());
+ genElement.setAttribute("span_range", gen.isSpanArcRange() +
"");
+ genElement.setAttribute("date_format", gen.getDateFormat());
+ genElement.setAttribute("time_format", gen.getTimeFormat());
+ genElement.setAttribute("front_asc", gen.isFrontPageAscending()
+ "");
+ genElement.setAttribute("cat_asc",
gen.isCategoryPageAscending() + "");
+ genElement.setAttribute("arc_asc", gen.isArchivePageAscending()
+ "");
+ genElement.setAttribute("limit_front", gen.isLimitFrontPage() +
"");
+ genElement.setAttribute("front_page_limit",
gen.getFrontPageLimit() + "");
+ genElement.setAttribute("limit_cat", gen.isLimitCategoryPage()
+ "");
+ genElement.setAttribute("cat_page_limit",
gen.getCategoryPageLimit() + "");
+ genElement.setAttribute("limit_rss_body", gen.isLimitRssEntry()
+ "");
+
+
+ Element customTagsElement = new Element("CustomTags");
+ CustomTag tags[] = gen.getCustomTags();
+ for(int i = 0; i < tags.length; i++)
+ {
+ Element tag = new Element("Tag");
+ tag.setAttribute("name", tags[i].getName());
+ tag.setText(tags[i].getValue());
+ customTagsElement.addContent(tag);
+ }
+
+ genElement.addContent(customTagsElement);
+ element.addContent(genElement);
+ return element;
+ }
- private static Element createMailSettingsElement(Weblog blog) {
+ private static Element createMailSettingsElement(Weblog blog)
+ {
Element mailSettings = new Element("MailSettings");
mailSettings.setAttribute("enabled", blog.isImportFromEmailEnabled() +
"");
if(blog.getLastEmailCheck() != null)
@@ -399,32 +433,36 @@
transport.setAttribute("port", rpt.getPort() + "");
transport.setAttribute("user", rpt.getUserName());
if(rpt.isSavePassword())
- transport.setAttribute("password",
- PasswordUtil.encrypt(rpt.getPassword(), PasswordUtil.KEY));
+ transport.setAttribute("password",
+ PasswordUtil.encrypt(rpt.getPassword(), PasswordUtil.KEY));
mailSettings.addContent(transport);
return mailSettings;
}
-
- private static Element createPublishTransportElement(Weblog blog) {
- Element transport = new Element("Transport");
- PublishTransport pt = blog.getPublishTransport();
- if(pt instanceof RemoteTransport) {
- RemoteTransport rpt = (RemoteTransport)pt;
- transport.setAttribute("type", "sftp");
- transport.setAttribute("server", rpt.getAddress());
- transport.setAttribute("port", rpt.getPort() + "");
- transport.setAttribute("user", rpt.getUserName());
- if(rpt.isSavePassword())
- transport.setAttribute("password",
- PasswordUtil.encrypt(rpt.getPassword(),
PasswordUtil.KEY));
- if(rpt instanceof FTPTransport) {
- FTPTransport ftp = (FTPTransport)rpt;
- transport.setAttribute("type", "ftp");
- transport.setAttribute("passive", ftp.isPassiveMode()+"");
+
+ private static Element createPublishTransportElement(Weblog blog)
+ {
+ Element transport = new Element("Transport");
+ PublishTransport pt = blog.getPublishTransport();
+ if(pt instanceof RemoteTransport)
+ {
+ RemoteTransport rpt = (RemoteTransport)pt;
+ transport.setAttribute("type", "sftp");
+ transport.setAttribute("server", rpt.getAddress());
+ transport.setAttribute("port", rpt.getPort() + "");
+ transport.setAttribute("user", rpt.getUserName());
+ if(rpt.isSavePassword())
+ transport.setAttribute("password",
+ PasswordUtil.encrypt(rpt.getPassword(),
PasswordUtil.KEY));
+ if(rpt instanceof FTPTransport)
+ {
+ FTPTransport ftp = (FTPTransport)rpt;
+ transport.setAttribute("type", "ftp");
+ transport.setAttribute("passive",
ftp.isPassiveMode()+"");
Element e = new Element("ASCIITypes");
List exts = ftp.getASCIIExtensions();
- for(Iterator it = exts.iterator(); it.hasNext();) {
+ for(Iterator it = exts.iterator(); it.hasNext();)
+ {
String ex = it.next().toString();
Element c = new Element("ext");
c.setText(ex);
@@ -432,252 +470,284 @@
}
transport.addContent(e);
- }
- } else {
- transport.setAttribute("type", "local");
- }
-
- return transport;
- }
-
-
- /**
- * Creates a WeblogList from an XML file
- *
- * @param path The path to the XML file
- * @param backend The backend to connect the weblogs to
- * @param authStore The author store for the weblogs
- * @param catStore The category store for the weblogs
- * @return A list of weblogs
- * @throws IOException If an IO error occurs
- * @throws JDOMException If a JDOM error occurs
- */
- public static WeblogList loadWeblogsFromXML(String path, WeblogBackend
backend)
- throws IOException, JDOMException {
- WeblogList list = new WeblogList();
- File f = new File(path);
- Document document = createDocument(f);
- loadWeblogList(document, f, list, backend);
-
- return list;
- }
-
- private static void loadWeblogList(Document document, File path,
WeblogList list, WeblogBackend backend) {
- if(document == null)//couldn't load xml file
- return;//return empty WeblogList
-
- Element root = document.getRootElement();
- List weblogs = root.getChild("Weblogs").getChildren();
- Iterator weblogsIt = weblogs.iterator();
- //children should all be weblogs
- while(weblogsIt.hasNext()) {
- Element blogElement = (Element)weblogsIt.next();
- Weblog w = createWeblogFromElement(blogElement,path);
- if(w != null) {
- w.setBackend(backend);
- list.addWeblog(w);
- }
- }
- list.sortList();
- }
-
- private static Weblog createWeblogFromElement(Element blogEle, File path) {
- Weblog weblog = null;
- //different weblog types might be added later
- //for now we're only dealing with TBWeblogs
- if(blogEle.getName().equals("TBWeblog"))
- weblog = createTBWeblogFromElement(blogEle, path);
-
- if(weblog == null)
- return null;
-
- weblog.setPublishTransport(loadPublishTransportFromXML(blogEle));
- loadPingServicesFromXML(blogEle, weblog);
+ }
+ }
+ else
+ {
+ transport.setAttribute("type", "local");
+ }
+
+ return transport;
+ }
+
+
+ /**
+ * Creates a WeblogList from an XML file
+ *
+ * @param path The path to the XML file
+ * @param backend The backend to connect the weblogs to
+ * @param authStore The author store for the weblogs
+ * @param catStore The category store for the weblogs
+ * @return A list of weblogs
+ * @throws IOException If an IO error occurs
+ * @throws JDOMException If a JDOM error occurs
+ */
+ public static WeblogList loadWeblogsFromXML(String path, WeblogBackend
backend)
+ throws IOException, JDOMException
+ {
+ WeblogList list = new WeblogList();
+ File f = new File(path);
+ Document document = createDocument(f);
+ loadWeblogList(document, f, list, backend);
+
+ return list;
+ }
+
+ private static void loadWeblogList(Document document, File path,
WeblogList list, WeblogBackend backend)
+ {
+ if(document == null)//couldn't load xml file
+ return;//return empty WeblogList
+
+ Element root = document.getRootElement();
+ List weblogs = root.getChild("Weblogs").getChildren();
+ Iterator weblogsIt = weblogs.iterator();
+ //children should all be weblogs
+ while(weblogsIt.hasNext())
+ {
+ Element blogElement = (Element)weblogsIt.next();
+ Weblog w = createWeblogFromElement(blogElement,path);
+ if(w != null)
+ {
+ w.setBackend(backend);
+ list.addWeblog(w);
+ }
+ }
+ list.sortList();
+ }
+
+ private static Weblog createWeblogFromElement(Element blogEle, File
path)
+ {
+ Weblog weblog = null;
+ //different weblog types might be added later
+ //for now we're only dealing with TBWeblogs
+ if(blogEle.getName().equals("TBWeblog"))
+ weblog = createTBWeblogFromElement(blogEle, path);
+
+ if(weblog == null)
+ return null;
+
+
weblog.setPublishTransport(loadPublishTransportFromXML(blogEle));
+ loadPingServicesFromXML(blogEle, weblog);
loadEmailSettingsFromXML(blogEle, weblog);
- weblog.setTitle(blogEle.getAttributeValue("title", "Untitled"));
- String description = "";
- Element desc = blogEle.getChild("Description");
- if(desc != null)
- description = desc.getText();
- weblog.setDescription(description);
- try {
- long time = Long.parseLong(
- blogEle.getAttributeValue("last_publish",
- System.currentTimeMillis() + ""));
- weblog.setLastPublishDate(new Date(time));
- } catch(Exception ex){}
+ weblog.setTitle(blogEle.getAttributeValue("title", "Untitled"));
+ String description = "";
+ Element desc = blogEle.getChild("Description");
+ if(desc != null)
+ description = desc.getText();
+ weblog.setDescription(description);
+ try
+ {
+ long time = Long.parseLong(
+ blogEle.getAttributeValue("last_publish",
+ System.currentTimeMillis() + ""));
+ weblog.setLastPublishDate(new Date(time));
+ }
+ catch(Exception ex){}
weblog.setPublishFailed(Boolean.parseBoolean(blogEle.getAttributeValue("publish_failed",
"false")));
-
+
return weblog; //element wasn't a known type
- }
-
- private static TBWeblog createTBWeblogFromElement(Element element, File
path) {
- String key = element.getAttributeValue("key");
- if(key == null)
- return null; //can't continue if this weblog doesnt have a unique
key
-
- TBWeblog tb = new TBWeblog(path.getParentFile(), key);
- String genericUrl = "http://www.mysite.com";
- String basePath = element.getAttributeValue("base_path", "/");
- String url = element.getAttributeValue("url", genericUrl);
- String arcUrl = element.getAttributeValue("arc_url", genericUrl);
- String mediaUrl = element.getAttributeValue("media_url", genericUrl);
- tb.setBlogUrls(basePath, url, arcUrl, mediaUrl);
-
- tb.setCategoriesExtension(element.getAttributeValue("cat_ext",
".html"));
- tb.setArchivesExtension(element.getAttributeValue("arc_ext", ".html"));
- tb.setEntryPageExtension(element.getAttributeValue("entry_ext",
".html"));
- tb.setFrontPageFileName(element.getAttributeValue("fp_filename",
"blog.html"));
- tb.setRssFileName(element.getAttributeValue("rss_filename",
"rss.xml"));
-
tb.setArchiveIndexFileName(element.getAttributeValue("arc_index_filename",
"list.html"));
-
+ }
+
+ private static TBWeblog createTBWeblogFromElement(Element element, File
path)
+ {
+ String key = element.getAttributeValue("key");
+ if(key == null)
+ return null; //can't continue if this weblog doesnt
have a unique key
+
+ TBWeblog tb = new TBWeblog(path.getParentFile(), key);
+ String genericUrl = "http://www.mysite.com";
+ String basePath = element.getAttributeValue("base_path", "/");
+ String url = element.getAttributeValue("url", genericUrl);
+ String arcUrl = element.getAttributeValue("arc_url",
genericUrl);
+ String mediaUrl = element.getAttributeValue("media_url",
genericUrl);
+ tb.setBlogUrls(basePath, url, arcUrl, mediaUrl);
+
+ tb.setCategoriesExtension(element.getAttributeValue("cat_ext",
".html"));
+ tb.setArchivesExtension(element.getAttributeValue("arc_ext",
".html"));
+ tb.setEntryPageExtension(element.getAttributeValue("entry_ext",
".html"));
+
tb.setFrontPageFileName(element.getAttributeValue("fp_filename", "blog.html"));
+ tb.setRssFileName(element.getAttributeValue("rss_filename",
"rss.xml"));
+
tb.setArchiveIndexFileName(element.getAttributeValue("arc_index_filename",
"list.html"));
+
tb.setGenerateCategoryFeeds(element.getAttributeValue("gen_cat_feed",
"false").equals("true"));
tb.setCategoriesFeedExtension(element.getAttributeValue("cat_feed_ext",
".rss"));
- tb.setGenerateRssFeed(element.getAttributeValue("gen_rss",
"true").equals("true"));
- tb.setGenerateArchiveIndex(element.getAttributeValue("gen_arc_index",
"true").equals("true"));
- tb.setGenerateEntryPages(element.getAttributeValue("gen_entries",
"false").equals("true"));
-
- tb.setLocale(createLocale(element.getAttributeValue("locale",
Locale.getDefault().toString())));
- tb.setPublishAll(element.getAttributeValue("publish_all",
"true").equals("true"));
- tb.setType(element.getAttributeValue("type").toString());
-
- int arcPolicy = TBWeblog.ARCHIVE_MONTHLY;
- int dayInterval = 5;
- Date arcBaseDate = new Date(0);
- try {
- arcPolicy = Integer.parseInt(
- element.getAttributeValue("arc_policy",
Integer.toString(TBWeblog.ARCHIVE_MONTHLY)));
- dayInterval =
Integer.parseInt(element.getAttributeValue("day_interval", "5"));
- long time = Long.parseLong(element.getAttributeValue("base_date"));
- arcBaseDate = new Date(time);
- } catch(Exception ex){}
- tb.setArchivePolicy(arcPolicy);
- tb.setArchiveByDayInterval(dayInterval);
- tb.setArchiveBaseDate(arcBaseDate);
-
- //load outdated archives from xml
- Element outdatedArcs = element.getChild("OutdatedArchives");
- if(outdatedArcs != null) {
- Iterator itr = (outdatedArcs.getChildren()).iterator();
- while(itr.hasNext()) {
- Date start = new Date();
- Date exp = new Date();
- Element e = (Element)itr.next();
- if(e.getName().equals("Archive")) {
- try {
- long d1 = Long.parseLong(e.getAttributeValue("start"));
- long d2 = Long.parseLong(e.getAttributeValue("end"));
- start.setTime(d1);
- exp.setTime(d2);
- tb.addOutdatedArchive(new ArchiveRange(start, exp));
- } catch(Exception ex){}
- }
- }
- }
-
- //load outdated cats from xml
- Element outdatedCats = element.getChild("OutdatedCategories");
- if(outdatedCats != null) {
- Iterator itr = (outdatedCats.getChildren()).iterator();
- while(itr.hasNext()) {
- Element e = (Element)itr.next();
- if(e.getName().equals("Category")) {
- tb.addOutdatedCategory(e.getText());
- }
- }
- }
-
- //load outdated entries from xml
- Element outdatedEnts = element.getChild("OutdatedEntries");
- if(outdatedEnts != null) {
- Iterator itr = (outdatedEnts.getChildren()).iterator();
- while(itr.hasNext()) {
- Element e = (Element)itr.next();
- if(e.getName().equals("Entry")) {
- try{
- long id = Long.parseLong(e.getText());
- tb.addOutdatedEntryID(new Long(id));
- }catch(Exception ex){}
- }
- }
- }
-
- loadGeneratorSettingsFromXML(tb, element);
- return tb;
- }
+ tb.setGenerateRssFeed(element.getAttributeValue("gen_rss",
"true").equals("true"));
+
tb.setGenerateArchiveIndex(element.getAttributeValue("gen_arc_index",
"true").equals("true"));
+
tb.setGenerateEntryPages(element.getAttributeValue("gen_entries",
"false").equals("true"));
+
+ tb.setLocale(createLocale(element.getAttributeValue("locale",
Locale.getDefault().toString())));
+ tb.setPublishAll(element.getAttributeValue("publish_all",
"true").equals("true"));
+ tb.setType(element.getAttributeValue("type").toString());
+
+ int arcPolicy = TBWeblog.ARCHIVE_MONTHLY;
+ int dayInterval = 5;
+ Date arcBaseDate = new Date(0);
+ try
+ {
+ arcPolicy = Integer.parseInt(
+ element.getAttributeValue("arc_policy",
Integer.toString(TBWeblog.ARCHIVE_MONTHLY)));
+ dayInterval =
Integer.parseInt(element.getAttributeValue("day_interval", "5"));
+ long time =
Long.parseLong(element.getAttributeValue("base_date"));
+ arcBaseDate = new Date(time);
+ }
+ catch(Exception ex){}
+ tb.setArchivePolicy(arcPolicy);
+ tb.setArchiveByDayInterval(dayInterval);
+ tb.setArchiveBaseDate(arcBaseDate);
+
+ //load outdated archives from xml
+ Element outdatedArcs = element.getChild("OutdatedArchives");
+ if(outdatedArcs != null)
+ {
+ Iterator itr = (outdatedArcs.getChildren()).iterator();
+ while(itr.hasNext())
+ {
+ Date start = new Date();
+ Date exp = new Date();
+ Element e = (Element)itr.next();
+ if(e.getName().equals("Archive"))
+ {
+ try
+ {
+ long d1 =
Long.parseLong(e.getAttributeValue("start"));
+ long d2 =
Long.parseLong(e.getAttributeValue("end"));
+ start.setTime(d1);
+ exp.setTime(d2);
+ tb.addOutdatedArchive(new
ArchiveRange(start, exp));
+ }
+ catch(Exception ex){}
+ }
+ }
+ }
+
+ //load outdated cats from xml
+ Element outdatedCats = element.getChild("OutdatedCategories");
+ if(outdatedCats != null)
+ {
+ Iterator itr = (outdatedCats.getChildren()).iterator();
+ while(itr.hasNext())
+ {
+ Element e = (Element)itr.next();
+ if(e.getName().equals("Category"))
+ {
+ tb.addOutdatedCategory(e.getText());
+ }
+ }
+ }
+
+ //load outdated entries from xml
+ Element outdatedEnts = element.getChild("OutdatedEntries");
+ if(outdatedEnts != null)
+ {
+ Iterator itr = (outdatedEnts.getChildren()).iterator();
+ while(itr.hasNext())
+ {
+ Element e = (Element)itr.next();
+ if(e.getName().equals("Entry"))
+ {
+ try{
+ long id =
Long.parseLong(e.getText());
+ tb.addOutdatedEntryID(new Long(id));
+ }catch(Exception ex){}
+ }
+ }
+ }
+
+ loadGeneratorSettingsFromXML(tb, element);
+ return tb;
+ }
+
+ private static void loadGeneratorSettingsFromXML(TBWeblog tbw, Element
element)
+ {
+ //set up the page generator defaults
+ PageGenerator gen = tbw.getPageGenerator();
+ Element genElement = element.getChild("Generator");
+ if(genElement == null)
+ return;
+
+ gen.setCharset(genElement.getAttributeValue("charset",
"UTF-8"));
+ gen.setDateFormat(genElement.getAttributeValue("date_format"));
+ gen.setTimeFormat(genElement.getAttributeValue("time_format"));
+ String s = genElement.getAttributeValue("span_range");
+ boolean span = s != null && s.equals("true");
+
gen.setArchiveRangeFormat(genElement.getAttributeValue("range_format"), span);
+ s = genElement.getAttributeValue("front_asc");
+ gen.setFrontPageAscending(s != null && s.equals("true"));
+ s = genElement.getAttributeValue("arc_asc");
+ gen.setArchivePageAscending(s != null && s.equals("true"));
+ s = genElement.getAttributeValue("cat_asc");
+ gen.setCategoryPageAscending(s != null && s.equals("true"));
+
+ int fpLimit = 10;
+ int catLimit = 20;
+ try
+ {
+ fpLimit =
Integer.parseInt(genElement.getAttributeValue("front_page_limit"));
+ catLimit =
Integer.parseInt(genElement.getAttributeValue("cat_page_limit"));
+ }
+ catch(Exception ex){}
+
+
gen.setLimitFrontPage(genElement.getAttributeValue("limit_front",
"true").equals("true"));
+ gen.setFrontPageLimit(fpLimit);
+
gen.setLimitCategoryPage(genElement.getAttributeValue("limit_cat",
"true").equals("true"));
+ gen.setCategoryPageLimit(catLimit);
+ s = genElement.getAttributeValue("limit_rss_body");
+ gen.setLimitRssEntry(s != null && s.equals("true"));
+
+ Element custTags = genElement.getChild("CustomTags");
+ if(custTags == null)return;
+ Iterator itr = custTags.getChildren().iterator();
+ while(itr.hasNext())
+ {
+ Element e = (Element)itr.next();
+ if(e.getName().equals("Tag"))
+ {
+ String name = e.getAttributeValue("name");
+ if(name == null)
+ continue;
+ String value = e.getText();
+ CustomTag tag = new CustomTag(name, value);
+ gen.addCustomTag(tag);
+ }
+ }
+ }
+
+
+
+ private static void loadPingServicesFromXML(Element parent, Weblog blog)
+ {
+ Element services = parent.getChild("PingServices");
+ if(services == null)
+ services = new Element("PingServices");
+
+ Iterator itr = (services.getChildren()).iterator();
+ while(itr.hasNext())
+ {
+ Element service = (Element)itr.next();
+ if(service.getName().equals("WeblogsDotComPing"))
+ {
+ WeblogsDotComPing ping = new
WeblogsDotComPing();
+
ping.setServiceUrl(service.getAttributeValue("url"));
+
ping.setServiceName(service.getAttributeValue("name"));
+
ping.setEnabled(service.getAttributeValue("enabled", "true").equals("true"));
+ blog.addPingService(ping);
+ }
+ }
+ }
- private static void loadGeneratorSettingsFromXML(TBWeblog tbw, Element
element) {
- //set up the page generator defaults
- PageGenerator gen = tbw.getPageGenerator();
- Element genElement = element.getChild("Generator");
- if(genElement == null)
- return;
-
- gen.setCharset(genElement.getAttributeValue("charset", "UTF-8"));
- gen.setDateFormat(genElement.getAttributeValue("date_format"));
- gen.setTimeFormat(genElement.getAttributeValue("time_format"));
- String s = genElement.getAttributeValue("span_range");
- boolean span = s != null && s.equals("true");
-
gen.setArchiveRangeFormat(genElement.getAttributeValue("range_format"), span);
- s = genElement.getAttributeValue("front_asc");
- gen.setFrontPageAscending(s != null && s.equals("true"));
- s = genElement.getAttributeValue("arc_asc");
- gen.setArchivePageAscending(s != null && s.equals("true"));
- s = genElement.getAttributeValue("cat_asc");
- gen.setCategoryPageAscending(s != null && s.equals("true"));
-
- int fpLimit = 10;
- int catLimit = 20;
- try {
- fpLimit =
Integer.parseInt(genElement.getAttributeValue("front_page_limit"));
- catLimit =
Integer.parseInt(genElement.getAttributeValue("cat_page_limit"));
- } catch(Exception ex){}
-
- gen.setLimitFrontPage(genElement.getAttributeValue("limit_front",
"true").equals("true"));
- gen.setFrontPageLimit(fpLimit);
- gen.setLimitCategoryPage(genElement.getAttributeValue("limit_cat",
"true").equals("true"));
- gen.setCategoryPageLimit(catLimit);
- s = genElement.getAttributeValue("limit_rss_body");
- gen.setLimitRssEntry(s != null && s.equals("true"));
-
- Element custTags = genElement.getChild("CustomTags");
- if(custTags == null)return;
- Iterator itr = custTags.getChildren().iterator();
- while(itr.hasNext()) {
- Element e = (Element)itr.next();
- if(e.getName().equals("Tag")) {
- String name = e.getAttributeValue("name");
- if(name == null)
- continue;
- String value = e.getText();
- CustomTag tag = new CustomTag(name, value);
- gen.addCustomTag(tag);
- }
- }
- }
-
-
-
- private static void loadPingServicesFromXML(Element parent, Weblog blog) {
- Element services = parent.getChild("PingServices");
- if(services == null)
- services = new Element("PingServices");
-
- Iterator itr = (services.getChildren()).iterator();
- while(itr.hasNext()) {
- Element service = (Element)itr.next();
- if(service.getName().equals("WeblogsDotComPing")) {
- WeblogsDotComPing ping = new WeblogsDotComPing();
- ping.setServiceUrl(service.getAttributeValue("url"));
- ping.setServiceName(service.getAttributeValue("name"));
- ping.setEnabled(service.getAttributeValue("enabled",
"true").equals("true"));
- blog.addPingService(ping);
- }
- }
- }
-
- private static void loadEmailSettingsFromXML(Element parent, Weblog blog) {
+ private static void loadEmailSettingsFromXML(Element parent, Weblog blog)
+ {
Element mailSettings = parent.getChild("MailSettings");
if(mailSettings == null)
return;
@@ -694,102 +764,126 @@
configureRemoteTransport(blog.getMailTransport(), transport, 110);
}
- private static int parseInt(String intStr, int defaultVal) {
- try {
+ private static int parseInt(String intStr, int defaultVal)
+ {
+ try
+ {
defaultVal = Integer.parseInt(intStr);
- } catch(Exception ex){}
+ }
+ catch(Exception ex){}
return defaultVal;
}
- private static Date parseDate(String epocString) {
+ private static Date parseDate(String epocString)
+ {
long d = 0;
- try {
+ try
+ {
d = Long.parseLong(epocString);
- } catch(Exception ex){}
+ }
+ catch(Exception ex){}
return new Date(d);
}
-
- private static Locale createLocale(String str) {
- Vector v = new Vector();
- if(str != null) {
- StringTokenizer st = new StringTokenizer(str, "_");
- while (st.hasMoreTokens()) {
- v.add(st.nextToken());
- }
- }
-
- Locale loc = Locale.getDefault();
- if(v.size() == 3)
- loc = new Locale(v.elementAt(0).toString(),
- v.elementAt(1).toString(), v.elementAt(2).toString());
- else if(v.size() == 2)
- loc = new Locale(v.elementAt(0).toString(),
- v.elementAt(1).toString());
- else if(v.size() == 1)
- loc = new Locale(v.elementAt(0).toString());
-
- return loc;
- }
-
- private static PublishTransport loadPublishTransportFromXML(Element
parent) {
- Element transport = parent.getChild("Transport");
- if(transport == null)
- transport = new Element("Transport");
- PublishTransport pubTransport = null;
- String type = transport.getAttributeValue("type", "local");
-
- if(type.equals("ftp") || type.equals("sftp")) {
- RemotePublishTransport rtp = null;
- int port = 22;
- if(type.equals("ftp")) {
- FTPTransport ftp = new FTPTransport();
- ftp.setPassiveMode(transport.getAttributeValue("passive",
"true").equals("true"));
- Element asciiElem = transport.getChild("ASCIITypes");
+
+ private static Locale createLocale(String str)
+ {
+ Vector v = new Vector();
+ if(str != null)
+ {
+ StringTokenizer st = new StringTokenizer(str, "_");
+ while (st.hasMoreTokens())
+ {
+ v.add(st.nextToken());
+ }
+ }
+
+ Locale loc = Locale.getDefault();
+ if(v.size() == 3)
+ loc = new Locale(v.elementAt(0).toString(),
+ v.elementAt(1).toString(),
v.elementAt(2).toString());
+ else if(v.size() == 2)
+ loc = new Locale(v.elementAt(0).toString(),
+ v.elementAt(1).toString());
+ else if(v.size() == 1)
+ loc = new Locale(v.elementAt(0).toString());
+
+ return loc;
+ }
+
+ private static PublishTransport loadPublishTransportFromXML(Element
parent)
+ {
+ Element transport = parent.getChild("Transport");
+ if(transport == null)
+ transport = new Element("Transport");
+ PublishTransport pubTransport = null;
+ String type = transport.getAttributeValue("type", "local");
+
+ if(type.equals("ftp") || type.equals("sftp"))
+ {
+ RemotePublishTransport rtp = null;
+ int port = 22;
+ if(type.equals("ftp"))
+ {
+ FTPTransport ftp = new FTPTransport();
+
ftp.setPassiveMode(transport.getAttributeValue("passive",
"true").equals("true"));
+ Element asciiElem =
transport.getChild("ASCIITypes");
ArrayList lst = new ArrayList();
- if(asciiElem == null) {
+ if(asciiElem == null)
+ {
lst.add("cgi");
lst.add("pl");
lst.add("php");
- lst.add("asp");
- } else {
+ lst.add("asp");
+ }
+ else
+ {
List ch = asciiElem.getChildren();
- for(int i = 0; i < ch.size(); i++) {
+ for(int i = 0; i < ch.size(); i++)
+ {
Element e = (Element)ch.get(i);
if(e.getName() == "ext");
- lst.add(e.getText());
+ lst.add(e.getText());
}
}
ftp.setASCIIExtentions(lst);
rtp = ftp;
- port = 21;
- } else
- rtp = new SFTPTransport();
-
- configureRemoteTransport(rtp, transport, port);
- pubTransport = rtp;
- } else
- pubTransport = new LocalTransport();
-
- return pubTransport;
- }
+ port = 21;
+ }
+ else
+ rtp = new SFTPTransport();
+
+ configureRemoteTransport(rtp, transport, port);
+ pubTransport = rtp;
+ }
+ else
+ pubTransport = new LocalTransport();
+
+ return pubTransport;
+ }
- private static void configureRemoteTransport(RemoteTransport rtp, Element
transport, int defaultPort) {
- try {
+ private static void configureRemoteTransport(RemoteTransport rtp, Element
transport, int defaultPort)
+ {
+ try
+ {
defaultPort =
Integer.parseInt(transport.getAttributeValue("port"));
}catch(Exception ex){}
- rtp.setPort(defaultPort);
+ rtp.setPort(defaultPort);
rtp.setAddress(transport.getAttributeValue("server"));
rtp.setUserName(transport.getAttributeValue("user"));
- String password = transport.getAttributeValue("password");
+ String password = transport.getAttributeValue("password");
rtp.setSavePassword(password != null);
- if(rtp.isSavePassword()) {
- try {
+ if(rtp.isSavePassword())
+ {
+ try
+ {
password = PasswordUtil.decrypt(password, PasswordUtil.KEY);
- } catch(Exception ex) {
+ }
+ catch(Exception ex)
+ {
password = "";
}
rtp.setPassword(password);