incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r797880 - /incubator/kato/trunk/org.apache.kato/kato.anttasks/src/main/java/org/apache/kato/anttasks/xmlgen/XMLWriter.java
Date Sun, 26 Jul 2009 09:09:40 GMT
Author: spoole
Date: Sun Jul 26 09:09:40 2009
New Revision: 797880

URL: http://svn.apache.org/viewvc?rev=797880&view=rev
Log:
updated xml writer to convert some links to docbook

Modified:
    incubator/kato/trunk/org.apache.kato/kato.anttasks/src/main/java/org/apache/kato/anttasks/xmlgen/XMLWriter.java

Modified: incubator/kato/trunk/org.apache.kato/kato.anttasks/src/main/java/org/apache/kato/anttasks/xmlgen/XMLWriter.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.anttasks/src/main/java/org/apache/kato/anttasks/xmlgen/XMLWriter.java?rev=797880&r1=797879&r2=797880&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.anttasks/src/main/java/org/apache/kato/anttasks/xmlgen/XMLWriter.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.anttasks/src/main/java/org/apache/kato/anttasks/xmlgen/XMLWriter.java
Sun Jul 26 09:09:40 2009
@@ -28,6 +28,7 @@
 
 public class XMLWriter {
 
+	private static String url="http://java.sun.com/javase/6/docs/api";
 	private Writer model=null;
 	private PrintWriter out=null;
 	public XMLWriter(Writer model) {
@@ -233,6 +234,8 @@
 		if(commentText.startsWith("<p>")==false) {
 			commentText="<p>"+commentText;
 		}
+		
+		commentText=replaceLinks(commentText);
 		DOMFragmentParser parser = new DOMFragmentParser();
 		
 		HTMLDocument document = new HTMLDocumentImpl();
@@ -249,6 +252,45 @@
 		
         write(fragment);
 	}
+	
+	/**
+	 * Replaces @links with doc references
+	 * 
+	 * @param commentText
+	 * @return
+	 */
+	private String replaceLinks(String commentText) {
+		
+		while(true) {
+			int start=commentText.indexOf("{@link ");
+			if(start<0) break;
+			int end=commentText.indexOf('}',start);
+			if(end<0) break;
+			String left=commentText.substring(0,start);
+			String right=commentText.substring(end+1);
+			String middle=commentText.substring(start+7,end).trim();
+			if(middle.startsWith("#")) {
+				// local ref
+				commentText=left+"<link  linkend=\""+middle+".html\">"+middle+"</link>"+right;
+			}
+			else {
+				// long ref.
+				// same package?
+				if(middle.startsWith("java.")) {
+					
+					commentText=left+"<ulink  url=\""+url+middle.replace('.','/')+".html\">"+middle+"</ulink>"+right;
+					
+				}
+				else {
+					commentText=left+middle+right;
+				}
+			}
+			System.out.println("middle="+middle);
+			
+		}
+		
+		return commentText;
+	}
 	private void write(DocumentFragment fragment) {
 		
 		NodeList list=fragment.getChildNodes();
@@ -311,6 +353,8 @@
 		if(name.equals("DD")) name="db:listitem";
 		if(name.equals("DT")) name="db:listitem";
 		if(name.equals("A")) name="db:link";
+		if(name.equals("LINK")) name="db:link";
+		if(name.equals("ULINK")) name="db:ulink";
 		if(name.equals("PRE")) name="db:programlisting";
 		if(name.equals("CODE")) name="db:programlisting";
 		if(name.equals("BR")) name="db:para";



Mime
View raw message