📄 translatorreader.java
字号:
return ""; } /** * Gobbles up all hyperlinks that are encased in square brackets. */ private String handleHyperlinks( String link ) { StringBuffer sb = new StringBuffer(); String reallink; int cutpoint; if( isAccessRule( link ) ) { return handleAccessRule( link ); } if( isMetadata( link ) ) { return handleMetadata( link ); } if( PluginManager.isPluginLink( link ) ) { String included = ""; try { if( m_enablePlugins ) { included = m_engine.getPluginManager().execute( m_context, link ); } } catch( PluginException e ) { log.info( "Failed to insert plugin", e ); log.info( "Root cause:",e.getRootThrowable() ); included = m_renderer.makeError("Plugin insertion failed: "+e.getMessage()); } sb.append( included ); return sb.toString(); } link = TextUtil.replaceEntities( link ); if( (cutpoint = link.indexOf('|')) != -1 ) { reallink = link.substring( cutpoint+1 ).trim(); link = link.substring( 0, cutpoint ); } else { reallink = link.trim(); } int interwikipoint = -1; // // Yes, we now have the components separated. // link = the text the link should have // reallink = the url or page name. // // In many cases these are the same. [link|reallink]. // if( VariableManager.isVariableLink( link ) ) { String value; try { value = m_engine.getVariableManager().parseAndGetValue( m_context, link ); } catch( NoSuchVariableException e ) { value = m_renderer.makeError(e.getMessage()); } catch( IllegalArgumentException e ) { value = m_renderer.makeError(e.getMessage()); } sb.append( value ); } else if( isExternalLink( reallink ) ) { // It's an external link, out of this Wiki callMutatorChain( m_externalLinkMutatorChain, reallink ); if( isImageLink( reallink ) ) { sb.append( handleImageLink( reallink, link, (cutpoint != -1) ) ); } else { sb.append( makeLink( EXTERNAL, reallink, link ) ); sb.append( m_renderer.outlinkImage() ); } } else if( (interwikipoint = reallink.indexOf(":")) != -1 ) { // It's an interwiki link // InterWiki links also get added to external link chain // after the links have been resolved. // FIXME: There is an interesting issue here: We probably should // URLEncode the wikiPage, but we can't since some of the // Wikis use slashes (/), which won't survive URLEncoding. // Besides, we don't know which character set the other Wiki // is using, so you'll have to write the entire name as it appears // in the URL. Bugger. String extWiki = reallink.substring( 0, interwikipoint ); String wikiPage = reallink.substring( interwikipoint+1 ); String urlReference = m_engine.getInterWikiURL( extWiki ); if( urlReference != null ) { urlReference = TextUtil.replaceString( urlReference, "%s", wikiPage ); callMutatorChain( m_externalLinkMutatorChain, urlReference ); sb.append( makeLink( INTERWIKI, urlReference, link ) ); if( isExternalLink(urlReference) ) { sb.append( m_renderer.outlinkImage() ); } } else { sb.append( link+" "+m_renderer.makeError("No InterWiki reference defined in properties for Wiki called '"+extWiki+"'!)") ); } } else if( reallink.startsWith("#") ) { // It defines a local footnote sb.append( makeLink( LOCAL, reallink, link ) ); } else if( isNumber( reallink ) ) { // It defines a reference to a local footnote sb.append( makeLink( LOCALREF, reallink, link ) ); } else { int hashMark = -1; // // Internal wiki link, but is it an attachment link? // String attachment = findAttachment( reallink ); if( attachment != null ) { callMutatorChain( m_attachmentLinkMutatorChain, attachment ); if( isImageLink( reallink ) ) { attachment = m_context.getURL( WikiContext.ATTACH, attachment ); sb.append( handleImageLink( attachment, link, (cutpoint != -1) ) ); } else { sb.append( makeLink( ATTACHMENT, attachment, link ) ); } } else if( (hashMark = reallink.indexOf('#')) != -1 ) { // It's an internal Wiki link, but to a named section String namedSection = reallink.substring( hashMark+1 ); reallink = reallink.substring( 0, hashMark ); reallink = cleanLink( reallink ); callMutatorChain( m_localLinkMutatorChain, reallink ); String matchedLink; if( (matchedLink = linkExists( reallink )) != null ) { String sectref = "section-"+m_engine.encodeName(matchedLink)+"-"+namedSection; sectref = sectref.replace('%', '_'); sb.append( makeLink( READ, matchedLink, link, sectref ) ); } else { sb.append( makeLink( EDIT, reallink, link ) ); } } else { // It's an internal Wiki link reallink = cleanLink( reallink ); callMutatorChain( m_localLinkMutatorChain, reallink ); String matchedLink = linkExists( reallink ); if( matchedLink != null ) { sb.append( makeLink( READ, matchedLink, link ) ); } else { sb.append( makeLink( EDIT, reallink, link ) ); } } } return sb.toString(); } private String findAttachment( String link ) { AttachmentManager mgr = m_engine.getAttachmentManager(); WikiPage currentPage = m_context.getPage(); Attachment att = null; /* System.out.println("Finding attachment of page "+currentPage.getName()); System.out.println("With name "+link); */ try { att = mgr.getAttachmentInfo( m_context, link ); } catch( ProviderException e ) { log.warn("Finding attachments failed: ",e); return null; } if( att != null ) { return att.getName(); } else if( link.indexOf('/') != -1 ) { return link; } return null; } /** * Closes all annoying lists and things that the user might've * left open. */ private String closeAll() { StringBuffer buf = new StringBuffer(); if( m_isbold ) { buf.append(m_renderer.closeTextEffect(BOLD)); m_isbold = false; } if( m_isitalic ) { buf.append(m_renderer.closeTextEffect(ITALIC)); m_isitalic = false; } if( m_isTypedText ) { buf.append(m_renderer.closeTextEffect(TYPED)); m_isTypedText = false; } /* for( ; m_listlevel > 0; m_listlevel-- ) { buf.append( "</ul>\n" ); } for( ; m_numlistlevel > 0; m_numlistlevel-- ) { buf.append( "</ol>\n" ); } */ // cleanup OL and UL lists buf.append(unwindGeneralList()); if( m_isPre ) { buf.append(m_renderer.closePreformatted()); m_isEscaping = false; m_isPre = false; } if( m_istable ) { buf.append( m_renderer.closeTable() ); m_istable = false; } if( m_isOpenParagraph ) { buf.append( m_renderer.closeParagraph() ); m_isOpenParagraph = false; } return buf.toString(); } // FIXME: should remove countChar() as it is unused /** * Counts how many consecutive characters of a certain type exists on the line. * @param line String of chars to check. * @param startPos Position to start reading from. * @param char Character to check for. */ private int countChar( String line, int startPos, char c ) { int count; for( count = 0; (startPos+count < line.length()) && (line.charAt(count+startPos) == c); count++ ); return count; } /** * Returns a new String that has char c n times. */ private String repeatChar( char c, int n ) { StringBuffer sb = new StringBuffer(); for( int i = 0; i < n; i++ ) sb.append(c); return sb.toString(); } private int nextToken() throws IOException { if( m_in == null ) return -1; return m_in.read(); } /** * Push back any character to the current input. Does not * push back a read EOF, though. */ private void pushBack( int c ) throws IOException { if( c != -1 && m_in != null ) { m_in.unread( c ); } } /** * Pushes back any string that has been read. It will obviously * be pushed back in a reverse order. * * @since 2.1.77 */ private void pushBack( String s ) throws IOException { for( int i = s.length()-1; i >= 0; i-- ) { pushBack( s.charAt(i) ); } } private String handleBackslash() throws IOException { int ch = nextToken(); if( ch == '\\' ) { int ch2 = nextToken(); if( ch2 == '\\' ) { return m_renderer.lineBreak(true); } pushBack( ch2 ); return m_renderer.lineBreak(false); } pushBack( ch ); return "\\"; } private String handleUnderscore() throws IOException { int ch = nextToken(); String res = "_"; if( ch == '_' ) { res = m_isbold ? m_renderer.closeTextEffect(BOLD) : m_renderer.openTextEffect(BOLD); m_isbold = !m_isbold; } else { pushBack( ch ); } return res; } /** * For example: italics. */ private String handleApostrophe() throws IOException { int ch = nextToken(); String res = "'"; if( ch == '\'' ) { res = m_isitalic ? m_renderer.closeTextEffect(ITALIC) : m_renderer.openTextEffect(ITALIC); m_isitalic = !m_isitalic; } else { pushBack( ch ); } return res; } private String handleOpenbrace( boolean isBlock ) throws IOException { int ch = nextToken();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -