Update of
/var/cvs/contributions/CMSContainer_Modules/glossary/src/java/com/finalist/cmsc/module/glossary
In directory
james.mmbase.org:/tmp/cvs-serv20672/glossary/src/java/com/finalist/cmsc/module/glossary
Modified Files:
Tag: b1_6
Glossary.java
Log Message:
CMSC-1304 add <span class="noGlossary"> around stuff to skip
See also:
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/glossary/src/java/com/finalist/cmsc/module/glossary
See also: http://www.mmbase.org/jira/browse/CMSC-1304
Index: Glossary.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/glossary/src/java/com/finalist/cmsc/module/glossary/Glossary.java,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -u -b -r1.9 -r1.9.2.1
--- Glossary.java 20 Feb 2009 14:22:57 -0000 1.9
+++ Glossary.java 1 Apr 2009 14:29:25 -0000 1.9.2.1
@@ -7,7 +7,7 @@
import java.util.regex.Pattern;
public class Glossary {
- public static final String LINKPATTERN = "<span class=\"glossaryWord\"
title=\"%s\" id=\"_glossary_%s\">%s</span>";
+ public static final String LINKPATTERN = "<dfn class=\"glossaryWord\"
title=\"%2$s - %s\" id=\"_glossary_%2$s\">%2$s</dfn>";
public static final String GLOSSARY = "glossary";
private final Map<String, String> terms = new HashMap<String, String>();
private static Glossary glossary = null;
@@ -34,7 +34,7 @@
int end = matcher.end();
String found = material.substring(start, end);
if (!isInFormatedFragment(material, word, start)) {
- String highlight = String.format(LINKPATTERN, terms.get(word),
found, found);
+ String highlight = String.format(LINKPATTERN, terms.get(word),
found);
material = (new StringBuilder()).append(material.substring(0,
start)).append(highlight).append(
material.substring(end, material.length())).toString();
break;
@@ -46,17 +46,35 @@
}
- private boolean isInFormatedFragment(String material, String keywords, int
keywordStartPosition) {
- Pattern pattern = Pattern.compile(String.format("<[abh][^</]*%s[^>]*>",
keywords));
- Matcher matcher = pattern.matcher(material);
+ private boolean isInFormatedFragment(String material, String keyword, int
keywordStartPosition) {
+ String materialBefore = material.substring(0, keywordStartPosition);
- while (matcher.find()) {
- int start = matcher.start();
- int end = matcher.end();
+ int openA = materialBefore.lastIndexOf("<a");
+ int closeA = materialBefore.lastIndexOf("/a>");
+ if(openA > closeA) {
+ return true;
+ }
+
+ int openInput = materialBefore.lastIndexOf("<input");
+ int closeInput = materialBefore.lastIndexOf(">");
+ if(openInput > closeInput) {
+ return true;
+ }
- if (keywordStartPosition + keywords.length() < end &&
keywordStartPosition > start)
+ int openSpan = materialBefore.lastIndexOf("<span class=\"noGlossary\">");
+ int closeSpan = materialBefore.lastIndexOf("</span>");
+ if(openSpan > closeSpan) {
return true;
}
+
+ for(int h = 1; h <= 6; h++) {
+ int openH = materialBefore.lastIndexOf("<h"+h);
+ int closeH = materialBefore.lastIndexOf("/h"+h+">");
+ if(openH > closeH) {
+ return true;
+ }
+ }
+
return false;
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs