📄 xhtmlelementtowikitranslator.java
字号:
String src = trimLink( img.getAttributeValue( "src" ) ); if( src == null ) { return; } map.put( "align", base.getAttributeValue( "align" ) ); map.put( "height", img.getAttributeValue( "height" ) ); map.put( "width", img.getAttributeValue( "width" ) ); map.put( "alt", img.getAttributeValue( "alt" ) ); map.put( "caption", emptyToNull( XPath.newInstance( "CAPTION" ).valueOf( base ) ) ); map.put( "link", href ); map.put( "border", img.getAttributeValue( "border" ) ); map.put( "style", base.getAttributeValue( "style" ) ); if( map.size() > 0 ) { m_out.print( "[{Image src='" + src + "'" ); for( Iterator i = map.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry)i.next(); if( !entry.getValue().equals( "" ) ) { m_out.print( " " + entry.getKey() + "='" + entry.getValue() + "'" ); } } m_out.print( "}]" ); } else { m_out.print( "[" + src + "]" ); } } private String emptyToNull( String s ) { return s == null ? null : (s.replaceAll( "\\s", "" ).length() == 0 ? null : s); } private String propsToStyleString( Map styleProps ) { StringBuffer style = new StringBuffer(); for( Iterator i = styleProps.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry)i.next(); style.append( " " ).append( entry.getKey() ).append( ": " ).append( entry.getValue() ).append( ";" ); } return style.toString(); } private boolean isIgnorableWikiMarkupLink( Element a ) { String ref = a.getAttributeValue( "href" ); String clazz = a.getAttributeValue( "class" ); return (ref != null && ref.startsWith( m_config.getPageInfoJsp() )) || (clazz != null && clazz.trim().equalsIgnoreCase( m_config.getOutlink() )); } /** * Checks if the link points to an undefined page. */ private boolean isUndefinedPageLink( Element a) { String classVal = a.getAttributeValue( "class" ); return classVal != null && classVal.equals( "createpage" ); } /** * Returns a Map containing the valid augmented wiki link attributes. */ private Map getAugmentedWikiLinkAttributes( Element a ) { Map<String,String> attributesMap = new HashMap<String,String>(); String id = a.getAttributeValue( "id" ); if( id != null && !id.equals( "" ) ) { attributesMap.put( "id", id.replaceAll( "'", "\"" ) ); } String cssClass = a.getAttributeValue( "class" ); if( cssClass != null && !cssClass.equals( "" ) && !cssClass.matches( "wikipage|createpage|external|interwiki|attachment" ) ) { attributesMap.put( "class", cssClass.replaceAll( "'", "\"" ) ); } String style = a.getAttributeValue( "style" ); if( style != null && !style.equals( "" ) ) { attributesMap.put( "style", style.replaceAll( "'", "\"" ) ); } String title = a.getAttributeValue( "title" ); if( title != null && !title.equals( "" ) ) { attributesMap.put( "title", title.replaceAll( "'", "\"" ) ); } String lang = a.getAttributeValue( "lang" ); if( lang != null && !lang.equals( "" ) ) { attributesMap.put( "lang", lang.replaceAll( "'", "\"" ) ); } String dir = a.getAttributeValue( "dir" ); if( dir != null && !dir.equals( "" ) ) { attributesMap.put( "dir", dir.replaceAll( "'", "\"" ) ); } String charset = a.getAttributeValue( "charset" ); if( charset != null && !charset.equals("") ) { attributesMap.put( "charset", charset.replaceAll( "'", "\"" ) ); } String type = a.getAttributeValue( "type" ); if( type != null && !type.equals( "" ) ) { attributesMap.put( "type", type.replaceAll( "'", "\"" ) ); } String hreflang = a.getAttributeValue( "hreflang" ); if( hreflang != null && !hreflang.equals( "" ) ) { attributesMap.put( "hreflang", hreflang.replaceAll( "'", "\"" ) ); } String rel = a.getAttributeValue( "rel" ); if( rel != null && !rel.equals( "" ) ) { attributesMap.put( "rel", rel.replaceAll( "'", "\"" ) ); } String rev = a.getAttributeValue( "rev" ); if( rev != null && !rev.equals( "" ) ) { attributesMap.put( "rev", rev.replaceAll( "'", "\"" ) ); } String accesskey = a.getAttributeValue( "accesskey" ); if( accesskey != null && !accesskey.equals( "" ) ) { attributesMap.put( "accesskey", accesskey.replaceAll( "'", "\"" ) ); } String tabindex = a.getAttributeValue( "tabindex" ); if( tabindex != null && !tabindex.equals( "" ) ) { attributesMap.put( "tabindex", tabindex.replaceAll( "'", "\"" ) ); } String target = a.getAttributeValue( "target" ); if( target != null && !target.equals( "" ) ) { attributesMap.put( "target", target.replaceAll( "'", "\"" ) ); } return attributesMap; } /** * Converts the entries in the map to a string for use in a wiki link. */ private String augmentedWikiLinkMapToString( Map attributesMap ) { StringBuffer sb = new StringBuffer(); for ( Iterator itr = attributesMap.entrySet().iterator(); itr.hasNext(); ) { Map.Entry entry = (Map.Entry)itr.next(); String attributeName = (String)entry.getKey(); String attributeValue = (String)entry.getValue(); sb.append( " " + attributeName + "='" + attributeValue + "'" ); } return sb.toString().trim(); } private Map getStylePropertiesLowerCase( Element base ) throws IOException { String n = base.getName().toLowerCase(); //"font-weight: bold; font-style: italic;" String style = base.getAttributeValue( "style" ); if( style == null ) { style = ""; } if( n.equals( "p" ) || n.equals( "div" ) ) { String align = base.getAttributeValue( "align" ); if( align != null ) { // only add the value of the align attribute if the text-align style didn't already exist. if( style.indexOf( "text-align" ) == -1 ) { style = style + ";text-align:" + align + ";"; } } } if( n.equals( "font" ) ) { String color = base.getAttributeValue( "color" ); String face = base.getAttributeValue( "face" ); String size = base.getAttributeValue( "size" ); if( color != null ) { style = style + "color:" + color + ";"; } if( face != null ) { style = style + "font-family:" + face + ";"; } if( size != null ) { if( size.equals( "1" ) ) { style = style + "font-size:xx-small;"; } else if( size.equals( "2" ) ) { style = style + "font-size:x-small;"; } else if( size.equals( "3" ) ) { style = style + "font-size:small;"; } else if( size.equals( "4" ) ) { style = style + "font-size:medium;"; } else if( size.equals( "5" ) ) { style = style + "font-size:large;"; } else if( size.equals( "6" ) ) { style = style + "font-size:x-large;"; } else if( size.equals( "7" ) ) { style = style + "font-size:xx-large;"; } } } if( style.equals( "" ) ) { return null; } style = style.replace( ';', '\n' ).toLowerCase(); LinkedHashMap m = new LinkedHashMap(); new PersistentMapDecorator( m ).load( new ByteArrayInputStream( style.getBytes() ) ); return m; } private String trimLink( String ref ) { if( ref == null ) { return null; } try { ref = URLDecoder.decode( ref, UTF8 ); ref = ref.trim(); if( ref.startsWith( m_config.getAttachPage() ) ) { ref = ref.substring( m_config.getAttachPage().length() ); } if( ref.startsWith( m_config.getWikiJspPage() ) ) { ref = ref.substring( m_config.getWikiJspPage().length() ); // Handle links with section anchors. // For example, we need to translate the html string "TargetPage#section-TargetPage-Heading2" // to this wiki string "TargetPage#Heading2". ref = ref.replaceFirst( ".+#section-(.+)-(.+)", "$1#$2" ); } if( ref.startsWith( m_config.getEditJspPage() ) ) { ref = ref.substring( m_config.getEditJspPage().length() ); } if( m_config.getPageName() != null ) { if( ref.startsWith( m_config.getPageName() ) ) { ref = ref.substring( m_config.getPageName().length() ); } } } catch ( UnsupportedEncodingException e ) { // Shouldn't happen... } return ref; } // FIXME: These should probably be better used with java.util.Stack private static class LiStack { private StringBuffer m_li = new StringBuffer(); public void push( String c ) { m_li.append( c ); } public void pop() { m_li = m_li.deleteCharAt( m_li.length()-1 ); // m_li = m_li.substring( 0, m_li.length() - 1 ); } public String toString() { return m_li.toString(); } } private class PreStack { private int m_pre = 0; public boolean isPreMode() { return m_pre > 0; } public void push() { m_pre++; m_outTimmer.setWhitespaceTrimMode( !isPreMode() ); } public void pop() { m_pre--; m_outTimmer.setWhitespaceTrimMode( !isPreMode() ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -