Changeset 4722
- Timestamp:
- 11/03/08 04:45:17 (2 months ago)
- Files:
-
- eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/Activator.java (modified) (3 diffs)
- eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/editors/WikiEditorStorage.java (modified) (4 diffs)
- eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/models/TracServer.java (modified) (1 diff)
- eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/models/WikiPage.java (copied) (copied from eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/models/WikiPage.java) (10 diffs, 1 prop)
- eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/wiki/NewWikiPage.java (modified) (1 diff)
- eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/WikiPageCache.java (added)
- eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/xmlrpc/Trac.java (modified) (1 diff)
- eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/xmlrpc/WikiExt.java (modified) (1 diff)
- eclipsetracplugin/tracrpcext/0.10/tracrpcext/wiki.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/Activator.java
r2016 r4722 5 5 import java.net.URL; 6 6 import java.util.ResourceBundle; 7 7 8 8 9 import org.eclipse.jface.resource.ImageDescriptor; … … 31 32 private ContributionTemplateStore templateStore; 32 33 private ContributionContextTypeRegistry contextTypeRegistry; 34 35 private static WikiPageCache wikiPageCache = new WikiPageCache(); 33 36 34 37 /** … … 71 74 { 72 75 return plugin; 76 } 77 78 public static WikiPageCache wikiPageCache() 79 { 80 return wikiPageCache; 73 81 } 74 82 eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/editors/WikiEditorStorage.java
r2003 r4722 1 1 package mm.eclipse.trac.editors; 2 2 3 import java.io.ByteArrayInputStream;4 import java.io.ByteArrayOutputStream;5 import java.io.IOException;6 3 import java.io.InputStream; 7 import java.io.OutputStreamWriter;8 import java.io.Reader;9 import java.io.StringReader;10 import java.io.Writer;11 4 12 5 import mm.eclipse.trac.Log; … … 28 21 } 29 22 30 private class StreamAdapter extends InputStream31 {32 private ByteArrayInputStream istream;33 34 public StreamAdapter( Reader reader )35 {36 ByteArrayOutputStream ostream = new ByteArrayOutputStream();37 try38 {39 Writer writer = new OutputStreamWriter( ostream, Encoding );40 while ( true )41 {42 int c = reader.read();43 if ( c == -1 )44 break;45 writer.write( c );46 }47 48 writer.close();49 } catch ( Exception e )50 {51 Log.error( "Conversion error.", e );52 }53 54 Log.info( "Size: " + ostream.size() );55 56 istream = new ByteArrayInputStream( ostream.toByteArray() );57 }58 59 @Override60 public int read() throws IOException61 {62 return istream.read();63 }64 }65 66 23 public String getCharset() throws CoreException 67 24 { … … 71 28 public InputStream getContents() throws CoreException 72 29 { 73 StringReader reader = new StringReader( page.getContent() ); 74 return new StreamAdapter( reader ); 30 return page.getContent(); 75 31 } 76 32 … … 91 47 } 92 48 49 @SuppressWarnings("unchecked") 93 50 public Object getAdapter( Class adapter ) 94 51 { eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/models/TracServer.java
r2579 r4722 46 46 problems = false; 47 47 48 rootWikiPage = new WikiPage( this, "", true, true );48 rootWikiPage = new WikiPage( this, "", 0, true, true ); 49 49 rootWikiPage.setRoot( true ); 50 50 } eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/models/WikiPage.java
- Property svn:mergeinfo set
r2016 r4722 1 1 package mm.eclipse.trac.models; 2 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.io.InputStreamReader; 6 import java.io.Reader; 3 7 import java.util.ArrayList; 4 8 import java.util.Collection; … … 10 14 import java.util.TreeSet; 11 15 16 import mm.eclipse.trac.Activator; 17 import mm.eclipse.trac.Log; 12 18 import mm.eclipse.trac.xmlrpc.WikiExt; 13 19 … … 16 22 public class WikiPage extends ModelBase implements IAdaptable 17 23 { 18 private TracServer server; 19 20 private String fullName; 21 private boolean exists = false; 22 private boolean hasChildren = false; 23 private List<WikiPage> children = null; 24 private WikiPage parent = null; 25 private boolean root = false; 26 private boolean dirty = false; 27 private String content = null; 28 29 private List<WikiPageVersion> versions = null; 30 31 public WikiPage( TracServer server, String fullName, boolean exists ) 32 { 33 this( server, fullName, exists, server.getWikiExt().hasChildren( fullName ) ); 34 } 35 36 public WikiPage( TracServer server, String fullName, boolean exists, 37 boolean hasChildren ) 24 private final TracServer server; 25 26 private final String fullName; 27 private int version; 28 private boolean exists = false; 29 private boolean hasChildren = false; 30 private List<WikiPage> children = null; 31 private WikiPage parent = null; 32 private boolean root = false; 33 private boolean dirty = false; 34 35 private List<WikiPageVersion> versions = null; 36 37 public WikiPage( TracServer server, String fullName, int version, 38 boolean exists ) 39 { 40 this( server, fullName, version, exists, server.getWikiExt() 41 .hasChildren( fullName ) ); 42 } 43 44 public WikiPage( TracServer server, String fullName, int version, 45 boolean exists, boolean hasChildren ) 38 46 { 39 47 this.server = server; 40 48 this.fullName = fullName; 49 this.version = version; 41 50 this.exists = exists; 42 51 this.hasChildren = hasChildren; 43 } 44 52 Activator.wikiPageCache().checkPage( this ); 53 } 54 45 55 public WikiPage( TracServer server, String fullName ) 46 56 { 47 this( server, fullName, true ); 48 } 49 57 this( server, fullName, 0, true ); 58 Activator.wikiPageCache().checkPage( this ); 59 } 60 50 61 /** 51 62 * @return the server … … 55 66 return server; 56 67 } 57 68 58 69 /** 59 70 * @return the fullName of the page … … 64 75 return path[path.length - 1]; 65 76 } 66 77 67 78 /** 68 79 * @return wheter the page exists in Trac or if is only a tree node. … … 72 83 return exists; 73 84 } 74 85 75 86 /** 76 87 * @return the fullName of the page … … 80 91 return fullName; 81 92 } 82 93 94 public int getVersion() 95 { 96 return version; 97 } 98 83 99 public void addChild( WikiPage child ) 84 100 { 85 if ( children == null ) children = new ArrayList<WikiPage>(); 86 101 if ( children == null ) 102 children = new ArrayList<WikiPage>(); 103 87 104 children.add( child ); 88 105 child.parent = this; 89 106 notifyChanged(); 90 107 } 91 108 92 109 public boolean hasChildren() 93 110 { 94 111 return hasChildren; 95 112 } 96 113 97 114 public Collection<WikiPage> getChildren() 98 115 { 99 if ( children != null ) return children; 100 116 if ( children != null ) 117 return children; 118 101 119 children = new ArrayList<WikiPage>(); 102 120 WikiExt wikiExt = server.getWikiExt(); 103 104 Map<String, Map<String, Boolean>> childrenMap = wikiExt.getChildren( fullName ); 121 122 Map<String, Map<String, Object>> childrenMap = wikiExt 123 .getChildren( fullName ); 105 124 SortedSet<String> names = new TreeSet<String>( childrenMap.keySet() ); 106 125 107 126 for ( String name : names ) 108 127 { 109 Map<String, Boolean> attrs = childrenMap.get( name ); 110 boolean exists = attrs.get( "exists" ); 111 boolean hasChildren = attrs.get( "hasChildren" ); 112 children.add( new WikiPage( server, name, exists, hasChildren ) ); 113 } 114 128 Map<String, Object> attrs = childrenMap.get( name ); 129 int version = (Integer) attrs.get( "version" ); 130 boolean exists = (Boolean) attrs.get( "exists" ); 131 boolean hasChildren = (Boolean) attrs.get( "hasChildren" ); 132 children.add( new WikiPage( server, name, version, exists, 133 hasChildren ) ); 134 } 135 115 136 return children; 116 137 } 117 138 118 139 public WikiPage getParent() 119 140 { 120 141 return parent; 121 142 } 122 143 123 144 public String toString() 124 145 { 125 146 return getFullName(); 126 147 } 127 128 public String getContent() 129 { 130 if ( content == null ) content = server.getWiki().getPage( fullName ); 131 return content; 132 } 133 148 149 public InputStream getContent() 150 { 151 return Activator.wikiPageCache().getPage( this ); 152 } 153 154 public String getStringContent() 155 { 156 InputStream is = getContent(); 157 158 StringBuilder sb = new StringBuilder(); 159 try 160 { 161 while (true) 162 { 163 char c = (char) is.read(); 164 if ( c == (char)-1 ) 165 break; 166 else 167 sb.append( c ); 168 } 169 } 170 catch ( IOException e ) 171 { 172 Log.error( "Error reading content", e ); 173 } 174 175 return sb.toString(); 176 } 177 134 178 public void putContent( String content ) 135 179 { 136 this.content = content;137 180 setDirty( true ); 138 // TODO: Should cache the content on local disk139 } 140 181 Activator.wikiPageCache().putPage( this, content ); 182 } 183 141 184 /** 142 185 * Save the page in the Trac database … … 149 192 Map<String, String> attributes = new HashMap<String, String>(); 150 193 attributes.put( "comment", comment ); 194 195 String content = getStringContent(); 151 196 server.getWiki().putPage( fullName, content, attributes ); 197 198 // Should refresh with newly created version 199 version += 1; 200 versions = null; 201 setDirty( false ); 152 202 153 // Should refresh with newly created version 154 versions = null; 155 156 setDirty( false ); 157 } 158 203 Activator.wikiPageCache().putPage( this, content ); 204 } 205 159 206 public List<WikiPageVersion> getVersions() 160 207 { 161 if ( versions != null ) return versions; 162 208 if ( versions != null ) 209 return versions; 210 163 211 versions = new ArrayList<WikiPageVersion>(); 164 Object[] remoteVersions = server.getWikiExt().getPageVersions( fullName ); 165 212 Object[] remoteVersions = server.getWikiExt() 213 .getPageVersions( fullName ); 214 166 215 for ( Object o : remoteVersions ) 167 216 { 168 217 Map a = (Map) o; 169 218 WikiPageVersion version; 170 version = new WikiPageVersion( this, (Integer) a.get( "version" ), (String) a171 .get( "author" ), (String) a.get( "comment" ), (Date) a172 .get( "lastModified" ) );219 version = new WikiPageVersion( this, (Integer) a.get( "version" ), 220 (String) a.get( "author" ), (String) a.get( "comment" ), 221 (Date) a.get( "lastModified" ) ); 173 222 versions.add( version ); 174 223 } 175 224 176 225 return versions; 177 226 } 178 227 179 228 public Object getAdapter( Class adapter ) 180 229 { … … 182 231 return null; 183 232 } 184 233 185 234 public void setRoot( boolean root ) 186 235 { 187 236 this.root = root; 188 237 } 189 238 190 239 public boolean isRoot() 191 240 { 192 241 return root; 193 242 } 194 243 195 244 public boolean isDirty() 196 245 { 197 246 return dirty; 198 247 } 199 248 200 249 public void setDirty( boolean dirty ) 201 250 { … … 203 252 notifyChanged(); 204 253 } 205 254 206 255 } eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/wiki/NewWikiPage.java
r2161 r4722 50 50 51 51 TracServer server = TracServerList.getInstance().getServerByName( serverName ); 52 WikiPage wikiPage = new WikiPage( server, pageName, true, false );52 WikiPage wikiPage = new WikiPage( server, pageName, 0, true, false ); 53 53 wikiPage.setDirty( true ); 54 54 eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/xmlrpc/Trac.java
r2579 r4722 16 16 import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; 17 17 import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory; 18 import org.apache.xmlrpc.client.XmlRpcSunHttpTransportFactory;19 18 20 19 public class Trac eclipsetracplugin/eclipse/trunk/mm.eclipse.trac/src/mm/eclipse/trac/xmlrpc/WikiExt.java
r2003 r4722 16 16 boolean hasChildren( String pagename ); 17 17 18 Map<String, Map<String, Boolean>> getChildren( String pagename );18 Map<String, Map<String,Object>> getChildren( String pagename ); 19 19 20 20 /** eclipsetracplugin/tracrpcext/0.10/tracrpcext/wiki.py
r4694 r4722 11 11 12 12 implements(IXMLRPCHandler) 13 14 VERSION = '1.0' 13 15 14 16 def __init__(self): … … 23 25 yield ('WIKI_VIEW', ((list, str), ), self.getChildren) 24 26 yield ('WIKI_VIEW', ((dict,), ), self.getMacros) 27 yield ('WIKI_VIEW', ((dict,), ), self.getVersion) 25 28 26 29 def _page_info(self, name, time, author, version, comment=''): … … 64 67 def getChildren(self, req, pagename): 65 68 """ Returns a list of all pages. The result is an array of utf8 pagenames. """ 69 70 cond = '' 71 # params = () 72 66 73 if pagename: 67 74 pagename += '/' 68 pages = list( self.wiki.get_pages( pagename ) ) 69 pages.sort() 75 cond = "WHERE name LIKE '%s%%'" % pagename 76 # params = (pagename,) 77 78 db = self.env.get_db_cnx() 79 cursor = db.cursor() 80 cursor.execute("SELECT name, MAX(version) FROM wiki %s GROUP BY name" % cond ) 81 82 pages = [] 83 for name, version in cursor: 84 pages.append( (name, version) ) 85 70 86 children = {} 71 for page in pages: 72 # print 'Complete name: "%s"' % page 87 for page, version in pages: 73 88 relname = page.replace( pagename, '' ) 74 # print 'RELNAME: "%s"' % relname 75 89 76 90 if relname.find( '/' ) == -1: 77 91 # We only look for direct children 78 92 children[ page ] = { 'exists' : True, 79 'hasChildren' : False } 93 'hasChildren' : False, 94 'version' : version } 80 95 else: 81 96 # The page does not really exists, but it does have … … 84 99 if not children.has_key( name ): 85 100 children[ name ] = { 'exists' : False, 86 'hasChildren' : True } 101 'hasChildren' : True, 102 'version' : version } 87 103 else: 88 104 children[ name ][ 'hasChildren' ] = True 89 105 90 return children 106 return children 91 107 92 108 def getMacros(self, req): … … 100 116 macros[ macro ] = desc 101 117 return macros 118 119 def getVersion( self, req ): 120 '''Return the module version''' 121 return { 'version' : self.VERSION } 102 122
