📄 rcsfileprovider.java
字号:
if( version == 1 ) { System.out.println("Migrating, fetching super."); result = super.getPageText( page, WikiProvider.LATEST_VERSION ); } else { throw new NoSuchVersionException( "Page: "+page+", version="+version); } } else { // // Check which version we actually got out! // if( checkedOutVersion != version ) { throw new NoSuchVersionException( "Page: "+page+", version="+version); } } } catch( MalformedPatternException e ) { throw new InternalWikiException("Malformed pattern in RCSFileProvider!"); } catch( InterruptedException e ) { // This is fine, we'll just log it. log.info("RCS process was interrupted, we'll just return whatever we found."); } catch( IOException e ) { log.error("RCS checkout failed",e); } finally { try { if( stdout != null ) stdout.close(); } catch( Exception e ) {} } return result; } /** * Puts the page into RCS and makes sure there is a fresh copy in * the directory as well. */ public void putPageText( WikiPage page, String text ) throws ProviderException { String pagename = page.getName(); // Writes it in the dir. super.putPageText( page, text ); log.debug( "Checking in text..." ); try { String cmd = m_checkinCommand; String author = page.getAuthor(); if( author == null ) author = "unknown"; cmd = TextUtil.replaceString( cmd, "%s", mangleName(pagename)+FILE_EXT ); cmd = TextUtil.replaceString( cmd, "%u", TextUtil.urlEncodeUTF8(author) ); log.debug("Command = '"+cmd+"'"); Process process = Runtime.getRuntime().exec( cmd, null, new File(getPageDirectory()) ); process.waitFor(); log.debug("Done, returned = "+process.exitValue()); // we must close all by exec(..) opened streams: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4784692 process.getInputStream().close(); process.getOutputStream().close(); process.getErrorStream().close(); } catch( Exception e ) { log.error("RCS checkin failed",e); } } // FIXME: Put the rcs date formats into properties as well. public List getVersionHistory( String page ) { PatternMatcher matcher = new Perl5Matcher(); PatternCompiler compiler = new Perl5Compiler(); PatternMatcherInput input; BufferedReader stdout = null; log.debug("Getting RCS version history"); ArrayList list = new ArrayList(); try { Pattern revpattern = compiler.compile( PATTERN_REVISION ); Pattern datepattern = compiler.compile( PATTERN_DATE ); // This complicated pattern is required, since on Linux RCS adds // quotation marks, but on Windows, it does not. Pattern userpattern = compiler.compile( PATTERN_AUTHOR ); String cmd = TextUtil.replaceString( m_fullLogCommand, "%s", mangleName(page)+FILE_EXT ); Process process = Runtime.getRuntime().exec( cmd, null, new File(getPageDirectory()) ); // FIXME: Should this use encoding as well? stdout = new BufferedReader( new InputStreamReader(process.getInputStream()) ); String line; WikiPage info = null; while( (line = stdout.readLine()) != null ) { if( matcher.contains( line, revpattern ) ) { info = new WikiPage( page ); MatchResult result = matcher.getMatch(); int vernum = Integer.parseInt( result.group(1) ); info.setVersion( vernum ); list.add( info ); } if( matcher.contains( line, datepattern ) ) { MatchResult result = matcher.getMatch(); Date d = parseDate( result.group(1) ); info.setLastModified( d ); } if( matcher.contains( line, userpattern ) ) { MatchResult result = matcher.getMatch(); info.setAuthor( TextUtil.urlDecodeUTF8(result.group(1)) ); } } process.waitFor(); // we must close all by exec(..) opened streams: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4784692 process.getInputStream().close(); process.getOutputStream().close(); process.getErrorStream().close(); // // FIXME: This is very slow // for( Iterator i = list.iterator(); i.hasNext(); ) { WikiPage p = (WikiPage) i.next(); String content = getPageText( p.getName(), p.getVersion() ); p.setSize( content.length() ); } } catch( Exception e ) { log.error( "RCS log failed", e ); } finally { try { if( stdout != null ) stdout.close(); } catch( IOException e ) {} } return list; } /** * Removes the page file and the RCS archive from the repository. * This method assumes that the page archive ends with ",v". */ public void deletePage( String page ) throws ProviderException { log.debug( "Deleting page "+page ); super.deletePage( page ); File rcsdir = new File( getPageDirectory(), "RCS" ); if( rcsdir.exists() && rcsdir.isDirectory() ) { File rcsfile = new File( rcsdir, mangleName(page)+FILE_EXT+",v" ); if( rcsfile.exists() ) { if( rcsfile.delete() == false ) { log.warn( "Deletion of RCS file "+rcsfile.getAbsolutePath()+" failed!" ); } } else { log.info( "RCS file does not exist for page: "+page ); } } else { log.info( "No RCS directory at "+rcsdir.getAbsolutePath() ); } } public void deleteVersion( String page, int version ) { String line = "<rcs not run>"; BufferedReader stderr; boolean success = false; String cmd = m_deleteVersionCommand; log.debug("Deleting version "+version+" of page "+page); cmd = TextUtil.replaceString( cmd, "%s", mangleName(page)+FILE_EXT ); cmd = TextUtil.replaceString( cmd, "%v", Integer.toString( version ) ); log.debug("Running command "+cmd); try { Process process = Runtime.getRuntime().exec( cmd, null, new File(getPageDirectory()) ); // // 'rcs' command outputs to stderr methinks. // // FIXME: Should this use encoding as well? stderr = new BufferedReader( new InputStreamReader(process.getErrorStream() ) ); while( (line = stderr.readLine()) != null ) { log.debug( "LINE="+line ); if( line.equals("done") ) { success = true; } } } catch( IOException e ) { log.error("Page deletion failed: ",e); } if( !success ) { log.error("Version deletion failed. Last info from RCS is: "+line); } } /** * util method to parse a date string in Local and UTC formats */ private Date parseDate( String str ) { Date d = null; try { d = m_rcsdatefmt.parse( str ); return d; } catch ( ParseException pe ) { } try { d = m_rcsdatefmt_utc.parse( str ); return d; } catch ( ParseException pe ) { } return d; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -