1 18 19 package sync4j.syncclient.spds.engine.recovery; 20 21 import java.io.*; 22 23 import java.util.Date ; 24 25 import java.security.Principal ; 26 27 import sync4j.syncclient.spds.SyncException; 28 import sync4j.syncclient.spds.engine.SyncItem; 29 import sync4j.syncclient.spds.engine.SyncItemImpl; 30 import sync4j.syncclient.spds.engine.SyncItemState; 31 import sync4j.syncclient.spds.engine.SyncSource; 32 33 48 49 public abstract class AbstractRecovery implements SyncSource { 50 51 52 54 private static final String PROP_RECOVERY_DETAILS = "recovery-details" ; 55 56 private static final String PROP_SOURCE_LIST = "source-list" ; 57 private static final String PROP_LAST = "last" ; 58 private static final String PROP_URI = "uri" ; 59 60 62 protected String sourceList = null; 63 protected String last = null; 64 protected String uri = null; 65 66 68 71 public String getSourceList() { 72 return this.sourceList; 73 } 74 75 78 public void setSourceList(String sourceList) { 79 this.sourceList=sourceList; 80 } 81 82 85 public String getLast() { 86 return this.last; 87 } 88 89 92 public void setLast(String last) { 93 this.last=last; 94 } 95 96 99 public String getUri() { 100 return this.uri; 101 } 102 103 106 public void setUri(String uri) { 107 this.uri=uri; 108 } 109 110 115 public abstract void recovery (Principal p); 116 117 118 130 public SyncItem[] getAllSyncItems(Principal principal) throws SyncException { 131 132 SyncItem[] syncItems = new SyncItem[0]; 133 134 return syncItems; 135 } 136 137 153 public SyncItem[] getDeletedSyncItems(Principal principal, 154 Date since ) throws SyncException { 155 SyncItem[] syncItems = new SyncItem[0]; 156 157 return syncItems; 158 159 } 160 161 176 public SyncItem[] getNewSyncItems(Principal principal, 177 Date since ) throws SyncException { 178 SyncItem[] syncItems = new SyncItem[0]; 179 180 return syncItems; 181 } 182 183 196 public SyncItem[] getUpdatedSyncItems(Principal principal, 197 Date since ) throws SyncException { 198 SyncItem[] syncItems = new SyncItem[0]; 199 200 return syncItems; 201 202 } 203 204 213 public void removeSyncItem(Principal principal, SyncItem syncItem) throws SyncException { 214 215 } 216 217 220 public void beginSync(int syncMode) throws SyncException { 221 222 } 223 224 227 public void commitSync() throws SyncException { 228 229 } 230 231 240 public SyncItem setSyncItem(Principal principal, SyncItem syncItem) 241 throws SyncException { 242 243 String xmlValue = null; 244 String xmlRecoveryDetails = null; 245 246 xmlValue = new String ((byte[])syncItem.getPropertyValue(SyncItem.PROPERTY_BINARY_CONTENT)); 247 248 try { 249 xmlRecoveryDetails = getXMLTagValue(xmlValue, PROP_RECOVERY_DETAILS); 250 } catch (Exception e) { 251 throw new SyncException("Tag not found: " + PROP_RECOVERY_DETAILS); 252 } 253 254 try { 255 this.sourceList = getXMLTagValue(xmlRecoveryDetails, PROP_SOURCE_LIST); 256 } catch (Exception e) { 257 throw new SyncException("Tag not found: " + PROP_SOURCE_LIST); 258 } 259 260 try { 261 this.last = getXMLTagValue(xmlRecoveryDetails, PROP_LAST); 262 } catch (Exception e) { 263 throw new SyncException("Tag not found: " + PROP_LAST); 264 } 265 266 try { 267 this.uri = getXMLTagValue(xmlRecoveryDetails, PROP_URI); 268 } catch (Exception e) { 269 throw new SyncException("Tag not found: " + PROP_URI); 270 } 271 272 recovery(principal); 273 274 SyncItem newSyncItem = 275 new SyncItemImpl(this, syncItem.getKey().getKeyAsString(), SyncItemState.NEW); 276 277 newSyncItem.setProperties(syncItem.getProperties()); 278 279 return newSyncItem; 280 281 } 282 283 285 292 private String getXMLTagValue(String xml, String tag) { 293 294 String startTag = null; 295 String endTag = null; 296 297 String value = null; 298 299 startTag = "(" + tag + ")"; 300 endTag = "(/" + tag + ")"; 301 302 value = xml.substring(xml.indexOf(startTag) + startTag.length(), xml.indexOf(endTag)); 303 304 return value; 305 } 306 307 } 308 | Popular Tags |