protected void onSubmit() { super.onSubmit(); if (section.equals("template")) { user.getSite().publish(user); } else { user.getSite().publishTheme(); } // Here we need to redirect back to this page to refresh the models - not sure why... setResponsePage(EditTemplate.class, getPageParameters()); }
public TemplateForm(String id, final String section, boolean custom, UserData u) { super(id); this.user = u; this.section = section; final com.rectang.xsm.site.Site site = user.getSite(); Button create = new Button("create") { public void onSubmit() { InputStream in = null; OutputStream out = null; try { in = getDefault(section, user.getSite()); out = new FileOutputStream(getCustomFile(section)); IOUtil.copyStream(in, out); if (section.equals("layout")) { site.setLayout("custom"); site.save(); } else if (section.equals("style")) { site.setStylesheet("custom"); site.save(); } // Here we need to redirect back to this page to refresh the models - not sure // why... setResponsePage(EditTemplate.class, getPageParameters()); } catch (IOException e) { error("Unable to create custom copy of template " + section); } finally { if (in != null) { IOUtil.close(in); } if (out != null) { IOUtil.close(out); } } } }; create.setDefaultFormProcessing(false); add(create); Button save = new Button("save"); add(save); Button revert = new Button("revert"); add(revert); Button delete = new Button("delete") { public void onSubmit() { if (getCustomFile(section).delete()) { if (section.equals("layout")) { site.setLayout("menu-left"); site.save(); } else if (section.equals("style")) { site.setStylesheet("grey"); site.getPublishedDoc("style.css").delete(); site.save(); } if (section.equals("template")) { site.publish(user); } else { site.publishTheme(); } // Here we need to redirect back to this page to refresh the models - not sure // why... setResponsePage(EditTemplate.class, getPageParameters()); } else { error("Unable to delete custom template " + section); } } }; delete.setDefaultFormProcessing(false); add(delete); if (custom) { add(new TextArea("customise", new StringFileModel(getCustomFile(section)))); create.setVisible(false); } else { StringBuffer content = new StringBuffer(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(getDefault(section, site))); String line = reader.readLine(); while (line != null) { content.append(line); content.append('\n'); line = reader.readLine(); } } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { IOUtil.close(reader); } } TextArea area = new TextArea("customise", new Model(content.toString())); area.setEnabled(false); add(area); save.setVisible(false); revert.setVisible(false); delete.setVisible(false); } BookmarkablePageLink back; back = new BookmarkablePageLink("back", Theme.class); back.add(new Label("back-label", "Back to Theme page")); add(back); }