1 13 package info.magnolia.cms.gui.controlx.version; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.gui.controlx.list.AbstractListModel; 17 import info.magnolia.cms.gui.query.SearchQuery; 18 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 import java.util.List ; 22 23 import javax.jcr.RepositoryException; 24 import javax.jcr.version.Version; 25 import javax.jcr.version.VersionHistory; 26 import javax.jcr.version.VersionIterator; 27 28 29 32 public class VersionListModel extends AbstractListModel { 33 34 37 private Content content; 38 39 42 private int max = -1; 43 44 47 protected SearchQuery query; 48 49 53 public VersionListModel(Content content, int max) { 54 this.content = content; 55 this.max = max; 56 } 57 58 61 public VersionListModel(Content content) { 62 this.content = content; 63 } 64 65 69 protected Collection getResult() throws RepositoryException { 70 List allVersions = new ArrayList (); 71 72 VersionHistory versionHistory = this.content.getVersionHistory(); 73 if (versionHistory == null) { 74 return allVersions; 75 } 76 77 VersionIterator iterator = versionHistory.getAllVersions(); 78 iterator.nextVersion(); 81 while (iterator.hasNext()) { 82 Version version = iterator.nextVersion(); 83 allVersions.add(this.content.getVersionedContent(version)); 84 } 85 if (max != -1) { 86 while(allVersions.size() > max){ 87 allVersions.remove(0); 88 } 89 } 90 return allVersions; 91 } 92 93 96 public int getMax() { 97 return this.max; 98 } 99 100 103 public void setMax(int max) { 104 this.max = max; 105 } 106 107 110 public Content getContent() { 111 return this.content; 112 } 113 114 117 public void setContent(Content content) { 118 this.content = content; 119 } 120 } 121 | Popular Tags |