1 22 23 package org.meshcms.core; 24 25 import org.meshcms.util.*; 26 27 31 public final class PageInfo { 32 private Path path; 33 private String title; 34 private int[] stats; 35 private int statSum; 36 private int lastStatsIndex; 37 private WebSite webSite; 38 private long lastModified; 39 private String charset; 40 41 45 public PageInfo(WebSite webSite, Path path) { 46 this.webSite = webSite; 47 this.path = path; 48 stats = new int[webSite.getStatsLength()]; 49 } 50 51 54 public Path getPath() { 55 return path; 56 } 57 58 61 public void setTitle(String title) { 62 this.title = title; 63 } 64 65 68 public String getTitle() { 69 return title; 70 } 71 72 75 public String getName() { 76 return path.getLastElement(); 77 } 78 79 82 public synchronized void addHit() { 83 stats[getIndex()]++; 84 statSum++; 85 } 86 87 90 public synchronized int getHits() { 91 return stats[getIndex()]; 92 } 93 94 97 public synchronized int getHits(int daysBefore) { 98 int index = getIndex() - daysBefore; 99 return stats[index < 0 ? index + stats.length : index]; 100 } 101 102 105 public synchronized int getTotalHits() { 106 getIndex(); return statSum; 108 } 109 110 protected synchronized int[] getStats() { 111 return stats; 112 } 113 114 protected synchronized int getLastStatsIndex() { 115 return lastStatsIndex; 116 } 117 118 protected synchronized void copyStatsFrom(PageInfo other) { 119 getIndex(); statSum = other.getTotalHits(); stats = other.getStats(); 122 lastStatsIndex = other.getLastStatsIndex(); 123 } 124 125 private synchronized int getIndex() { 126 int index = webSite.getStatsIndex(); 127 128 if (index != lastStatsIndex) { 129 lastStatsIndex = index; 130 statSum -= stats[index]; 131 stats[index] = 0; 132 } 133 134 return index; 135 } 136 137 140 public int getLevel() { 141 return path.getElementCount(); 142 } 143 144 147 public String toString() { 148 return title; 149 } 150 151 154 public long getLastModified() { 155 return lastModified; 156 } 157 158 162 public void setLastModified(long lastModified) { 163 this.lastModified = lastModified; 164 } 165 166 public String getCharset() { 167 return charset; 168 } 169 170 public void setCharset(String charset) { 171 this.charset = charset; 172 } 173 } 174 | Popular Tags |