Author: jalkanen
Date: Mon Jun 9 13:01:12 2008
New Revision: 665863
URL: http://svn.apache.org/viewvc?rev=665863&view=rev
Log:
JSPWIKI-228: Added patch from Alexander Chow to fix a problem where multiple
headings with the same text were producing illegal XML through duplicated ID
attributes.
Modified:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java
Modified:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java?rev=665863&r1=665862&r2=665863&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java
(original)
+++
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java
Mon Jun 9 13:01:12 2008
@@ -119,6 +119,9 @@
private Element m_currentElement;
+ /** Keep track of duplicate header names. */
+ private Map<String, Integer> m_titleSectionCounter = new HashMap<String,
Integer>();
+
/**
* This property defines the inline image pattern. It's current value
* is jspwiki.translatorReader.inlinePattern
@@ -1091,18 +1094,34 @@
* Modifies the "hd" parameter to contain proper values. Because
* an "id" tag may only contain [a-zA-Z0-9:_-], we'll replace the
* % after url encoding with '_'.
+ * <p>
+ * Counts also duplicate headings (= headings with similar name), and
+ * attaches a counter.
*/
- // FIXME: This method should probably be public and in an util class
somewhere
private String makeHeadingAnchor( String baseName, String title, Heading
hd )
{
hd.m_titleText = title;
title = MarkupParser.wikifyLink( title );
+
hd.m_titleSection = m_engine.encodeName(title);
+
+ if( m_titleSectionCounter.containsKey( hd.m_titleSection ) )
+ {
+ Integer count = m_titleSectionCounter.get( hd.m_titleSection );
+ count = count + 1;
+ m_titleSectionCounter.put( hd.m_titleSection, count );
+ hd.m_titleSection += "-" + count;
+ }
+ else
+ {
+ m_titleSectionCounter.put( hd.m_titleSection, 1 );
+ }
+
hd.m_titleAnchor = "section-"+m_engine.encodeName(baseName)+
"-"+hd.m_titleSection;
-
hd.m_titleAnchor = hd.m_titleAnchor.replace( '%', '_' );
hd.m_titleAnchor = hd.m_titleAnchor.replace( '/', '_' );
+
return hd.m_titleAnchor;
}