001: package fitnesse.responders;
002:
003: import fitnesse.wiki.*;
004: import fitnesse.html.*;
005: import java.util.Date;
006:
007: public class WikiImportProperty extends WikiPageProperty {
008: public static final String PROPERTY_NAME = "WikiImport";
009:
010: private WikiImportProperty() {
011: }
012:
013: public WikiImportProperty(String source) {
014: set("Source", source);
015: }
016:
017: public String getSourceUrl() {
018: return get("Source");
019: }
020:
021: public boolean isRoot() {
022: return has("IsRoot");
023: }
024:
025: public void setRoot(boolean value) {
026: if (value)
027: set("IsRoot");
028: else
029: remove("IsRoot");
030: }
031:
032: public boolean isAutoUpdate() {
033: return has("AutoUpdate");
034: }
035:
036: public void setAutoUpdate(boolean value) {
037: if (value)
038: set("AutoUpdate");
039: else
040: remove("AutoUpdate");
041: }
042:
043: public static WikiImportProperty createFrom(
044: WikiPageProperty property) {
045: if (property.has(PROPERTY_NAME)) {
046: WikiImportProperty importProperty = new WikiImportProperty();
047: WikiPageProperty rawImportProperty = property
048: .getProperty(PROPERTY_NAME);
049: importProperty.set("Source", rawImportProperty
050: .getProperty("Source"));
051: importProperty.set("LastRemoteModification",
052: rawImportProperty
053: .getProperty("LastRemoteModification"));
054: if (rawImportProperty.has("IsRoot"))
055: importProperty.set("IsRoot", rawImportProperty
056: .getProperty("IsRoot"));
057: if (rawImportProperty.has("AutoUpdate"))
058: importProperty.set("AutoUpdate", rawImportProperty
059: .getProperty("AutoUpdate"));
060:
061: return importProperty;
062: } else
063: return null;
064: }
065:
066: public void addTo(WikiPageProperty rootProperty) {
067: rootProperty.set(PROPERTY_NAME, this );
068: }
069:
070: public void setLastRemoteModificationTime(Date date) {
071: set("LastRemoteModification", getTimeFormat().format(date));
072: }
073:
074: public Date getLastRemoteModificationTime() throws Exception {
075: Date date = new Date(0);
076: String strValue = get("LastRemoteModification");
077: if (strValue != null)
078: date = getTimeFormat().parse(strValue);
079:
080: return date;
081: }
082:
083: public static void handleImportProperties(HtmlPage html,
084: WikiPage page, PageData pageData) throws Exception {
085: html.actions.add(HtmlUtil.makeNavBreak());
086: WikiImportProperty importProperty = WikiImportProperty
087: .createFrom(pageData.getProperties());
088: if (importProperty != null && !importProperty.isRoot()) {
089: html.body.addAttribute("class", "imported");
090: WikiPagePath localPagePath = page.getPageCrawler()
091: .getFullPath(page);
092: String localPageName = PathParser.render(localPagePath);
093: html.actions.add(HtmlUtil.makeActionLink(localPageName,
094: "Edit Locally", "edit", "e", false));
095: String remoteInput = "responder=edit&redirectToReferer=true&redirectAction=importAndView";
096: html.actions.add(HtmlUtil.makeActionLink(importProperty
097: .getSourceUrl(), "Edit Remotely", remoteInput, "e",
098: false));
099: } else if (page instanceof ProxyPage)
100: html.body.addAttribute("class", "virtual");
101: }
102: }
|