⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linkparser.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return link;    }    private String require( StringTokenizer tok, String required )            throws ParseException, NoSuchElementException    {        String s = tok.nextToken(required);        if( !s.equals(required) )        {            throw new ParseException("expected '"+required+"' not '"+s+"'"); // I18N        }        return s;    }    /**      *  Returns true if the String <tt>s</tt> is completely     *  composed of whitespace.     *      *  @param s The string to check     *  @return True, if "s" is all XML whitespace.     */    public static final boolean isSpace( String s )    {        for( int i = 0 ; i < s.length() ; i++ )        {            if( !isSpace( s.charAt(i)) ) return false;        }        return true;    }    /**      *  Returns true if char <tt>c</tt> is a member of     *  <tt>S</tt> (space) [XML 1.1 production 3].     *       *  @param c Character to check.     *  @return True, if the character is an XML space.     */    public static final boolean isSpace( char c )    {        return           0x20 == c    // SPACE        || 0x0A == c    // LF        || 0x0D == c    // CR        || 0x09 == c    // TAB        || 0x85 == c    // NEL        || 0x2028 == c; // LS (line separator)    }    // .........................................................................    /**     *  Inner class serving as a struct containing the parsed     *  components of a link.     */    public static class Link    {        private String            m_text;        private String            m_ref = null;        private int               m_interwikiPoint = -1;        private List<Attribute>   m_attribs = null;        /**         *  Create a new Link with text but no reference.         *  @param text The link text.         *  @throws ParseException If the link text is illegal.         */        protected Link( String text ) throws ParseException        {            setText(text);        }        /**         *  Create a new link with a given text and hyperlink (reference).         *           *  @param text The link text.         *  @param ref  The hypertext reference.         *  @throws ParseException If the link text or reference are illegal.         */        protected Link( String text, String ref ) throws ParseException        {            setText(text);            setReference(ref);        }        /**         *  Sets the link text.         *           *  @param text The link text.         *  @throws ParseException If the text is illegal (e.g. null).         */        protected void setText( String text ) throws ParseException        {            if( text == null )            {                throw new ParseException("null link text");            }            m_text = text;        }        /**         *  Returns the link text.         *           *  @return Link text.         */        public String getText()        {            return m_text;        }        /**         *  Sets the hypertext reference.  Typically, this is an URI or an interwiki link,         *  or a wikilink.         *           *  @param ref The reference.         *  @throws ParseException If the reference is illegal.         */        protected void setReference( String ref ) throws ParseException        {            if( ref == null )            {                throw new ParseException("null link reference value");            }            m_ref = ref;        }        /**         *  Returns true, if there is a reference.         *           *  @return True, if there's a reference; false otherwise.         */        public boolean hasReference()        {            return m_ref != null;        }        /**          *  Returns the link reference, or the link text if null.          *           *  @return A link reference.         */        public String getReference()        {            return m_ref != null                    ? m_ref                    : m_text ;        }        /**         *  Returns true, if this Link represents an InterWiki link (of the form wiki:page).         *          *  @return True, if this Link represents an InterWiki link.         */        public boolean isInterwikiLink()        {            if( !hasReference() ) m_ref = m_text;            m_interwikiPoint = m_ref.indexOf(':');            return m_interwikiPoint != -1;        }        /**         *  Returns the name of the wiki if this is an interwiki link.          *  <pre>         *    Link link = new Link("Foo","Wikipedia:Foobar");         *    assert( link.getExternalWikiPage(), "Wikipedia" );         *  </pre>          *           *  @return Name of the wiki, or null, if this is not an interwiki link.         */        public String getExternalWiki()        {            if( isInterwikiLink() )            {                return m_ref.substring( 0, m_interwikiPoint );            }                        return null;        }        /**          *  Returns the wikiname part of an interwiki link. Used only with interwiki links.         *  <pre>         *    Link link = new Link("Foo","Wikipedia:Foobar");         *    assert( link.getExternalWikiPage(), "Foobar" );         *  </pre>          *           *  @return Wikiname part, or null, if this is not an interwiki link.         */        public String getExternalWikiPage()        {            if( isInterwikiLink() )            {                return m_ref.substring( m_interwikiPoint+1 );            }                        return null;        }        /**         *  Returns the number of attributes on this link.         *           *  @return The number of attributes.         */        public int attributeCount()        {            return m_attribs != null                    ? m_attribs.size()                    : 0 ;        }        /**         *  Adds another attribute to the link.         *           *  @param attr A JDOM Attribute.         */        public void addAttribute( Attribute attr )        {            if( m_attribs == null )            {                m_attribs = new ArrayList<Attribute>();            }            m_attribs.add(attr);        }        /**          *  Returns an Iterator over the list of JDOM Attributes.         *           *  @return Iterator over the attributes.         */        public Iterator getAttributes()        {            return m_attribs != null                    ? m_attribs.iterator()                    : m_EMPTY.iterator() ;        }        /**          *  Returns a wikitext string representation of this Link.          *  @return WikiText.         */        public String toString()        {            StringBuffer sb = new StringBuffer();            sb.append( '[' );            sb.append( m_text );            if( m_ref != null )            {                sb.append( ' ' );                sb.append( '|' );                sb.append( ' ' );                sb.append( m_ref );            }            if( m_attribs != null )            {                sb.append( ' ' );                sb.append( '|' );                Iterator it = getAttributes();                while ( it.hasNext() )                {                    Attribute a = (Attribute)it.next();                    sb.append( ' ' );                    sb.append( a.getName() );                    sb.append( '=' );                    sb.append( '\'' );                    sb.append( a.getValue() );                    sb.append( '\'' );                }            }            sb.append( ']' );            return sb.toString();        }    } // end inner class}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -