[jbossws-commits] JBossWS SVN: r2296 - trunk/jbossws-docs.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Feb 7 11:27:03 EST 2007


Author: heiko.braun at jboss.com
Date: 2007-02-07 11:27:03 -0500 (Wed, 07 Feb 2007)
New Revision: 2296

Added:
   trunk/jbossws-docs/db2wiki.py
Log:
import

Added: trunk/jbossws-docs/db2wiki.py
===================================================================
--- trunk/jbossws-docs/db2wiki.py	                        (rev 0)
+++ trunk/jbossws-docs/db2wiki.py	2007-02-07 16:27:03 UTC (rev 2296)
@@ -0,0 +1,214 @@
+#!/usr/bin/python
+
+###################################################################
+#                                                                  #
+#         Script: DOCBOOK TO WIKI                                  #
+#         Author: Pep Ribal - pepribal at pepribal.com                #
+#         Version: 1.0                                             #
+#                                                                  #
+####################################################################
+#                                                                  #
+#         IMPORTANT                                                #
+#         =========                                                #
+#         LOOK FOR '%%%%%' INDICATIONS IN THE OUTPUT FILE          #
+#         Set titleNote as desired (translation of "Note")         #
+#         Double quotes assumed in tags (atrib="val" style)        #
+#                                                                  #
+####################################################################
+
+#
+# Recognized tags so far:
+#
+# chapter, section, bridgehead, orderedlist, itemizedlist,
+# emphasis, literal, xref, figure, informalequation, link,
+# inlinegraphic, command, tip, note, para, keycap
+#
+
+import sys
+
+# set titleNote to the desired value in doble quotes (in English, "Note")
+titleNote="Text"
+
+# Advances until next '<' char; 0 - No output, 1- Output; returns tag name
+def nextag(out):
+	global buffer,lastChar,fout
+	while len(buffer)>0 and buffer[0]!="<":
+		if out==1:
+			# No TABS, NLs or CRs will be written:
+			if buffer[0]=="\t" or buffer[0]=="\n" or buffer[0]=="\r":
+				presentChar=" "
+			else:
+				presentChar=buffer[0]
+			if (lastChar==" " or lastChar=="\n" or lastChar=="(") and presentChar==" ":
+				presentChar=""		# Avoid these combinations
+			fout.write(presentChar)
+			if presentChar!="":
+				lastChar=presentChar
+		buffer=buffer[1:]
+	if buffer=="":
+		return		# EOF
+	tag=""
+	while buffer[0]!=" " and buffer[0]!="\t" and buffer[0]!="\n" and buffer[0]!="\r" and buffer[0]!=">":
+		tag=tag+buffer[0]
+		buffer=buffer[1:]
+	buffer=buffer[1:]
+	return tag[1:]
+		
+# Returns string until string found (removes all from buffer)
+def contentUntil(until):
+	global buffer
+	straux=""
+	lastChar="*"		# This is not the global variable; just an internal control var
+	
+	while buffer[:len(until)]!=until:
+		
+		# No TABS, NLs or CRs will be written:
+		#if buffer[0]=="\t" or buffer[0]=="\n" or buffer[0]=="\r":			
+		#	presentChar=" "						
+		#else:
+		#	presentChar=buffer[0]		
+		
+		presentChar=buffer[0]
+		
+		# replace tabs with spaces			
+		if (lastChar=="\t" and presentChar=="\t"):
+			straux=straux+"  "
+		elif(presentChar=="\t"):
+			straux=straux+""
+		else:
+			straux=straux+presentChar				
+		
+		buffer=buffer[1:]
+		if presentChar!="":
+			lastChar=presentChar
+	buffer=buffer[len(until):]
+	return straux
+
+def fileSel(filename):
+	xml2wiki(filename)
+
+def xml2wiki(fname):
+	global buffer,lastChar,fout,escape
+	listType="?"
+	lastChar="*"
+	fin=open(fname,"r")
+	fout=open(fname[:len(fname)-4]+".txt","w")
+	buffer=fin.read()
+	outp=0
+	while len(buffer)>0:
+		aux=nextag(outp)
+		if aux=="chapter":
+			contentUntil("<title>")
+			fout.write("\n='''"+contentUntil("</title>")+"'''=\n")
+			lastChar="\n"
+		elif aux=="section":
+			contentUntil("<title>")
+			fout.write("\n="+contentUntil("</title>")+"=\n")
+			lastChar="\n"
+		elif aux=="bridgehead":
+			contentUntil(">")
+			fout.write("\n==="+contentUntil("</bridgehead>")+"===\n")
+			lastChar="\n"
+		elif aux=="para":
+			fout.write("\n")
+			lastChar="\n"
+			outp=1
+		elif aux=="emphasis":
+			fout.write("'''")
+			contentUntil('>') # this only works when a role attribute is set
+			fout.write(contentUntil('</emphasis>'))				
+			fout.write("'''")
+		elif aux=="/para":
+			fout.write("\n")
+			lastChar="\n"
+			outp=0
+		elif aux=="itemizedlist":
+			fout.write("\n")
+			lastChar="\n"
+			listType="* "
+		elif aux=="orderedlist":
+			fout.write("\n")
+			lastChar="\n"
+			listType="# "
+		elif aux=="listitem":			
+			contentUntil("<para>")
+			outp=1
+			fout.write(listType)
+			lastChar=" "
+		elif aux=="keycap":
+			fout.write("{{KEY|"+contentUntil("</keycap>")+"}}")
+			lastChar="}"
+		elif aux=="literal":
+			fout.write("{{Literal|"+contentUntil("</literal>")+"}}")
+			lastChar="}"
+		elif aux=="xref":
+			contentUntil('="')
+			fout.write("''%%%%%XREF:"+contentUntil('"/>')+"''")
+			lastChar="'"
+		elif aux=="figure":
+			contentUntil("<title>")
+			aux=contentUntil("</title>")
+			contentUntil('fileref="')
+			fout.write("\n[[Image:"+contentUntil('"')+"|frame|none|"+aux+"]]\n")
+			lastChar="\n"
+			contentUntil("</figure>")
+		elif aux=="inlinegraphic":
+			contentUntil('="')
+			fout.write("[[Image:"+contentUntil('"')+"]]")
+			lastChar="]"
+			contentUntil(">")		
+		elif aux=="command":
+			fout.write("====")			
+			fout.write(contentUntil('</command>'))				
+			fout.write("====")
+		elif aux=="programlisting":			
+			contentUntil("<![CDATA[")
+			fout.write("<pre>")
+			code=contentUntil("]]>")
+			fout.write(code)
+			fout.write("</pre>")		
+		elif aux=="tip" or aux=="note":
+			while buffer[0]!="<":		# We might want to keep the '<' char in buffer
+				buffer=buffer[1:]
+			if buffer[:7]=="<title>":
+				buffer=buffer[7:]
+				fout.write("\n{{Tip|"+contentUntil("</title>")+"|")
+			else:
+				fout.write("\n{{Tip|"+titleNote+"=")
+			lastChar="|"
+		elif aux=="/tip" or aux=="/note":
+			fout.write("}}\n")
+			lastChar="\n"
+		elif aux=="informalequation":
+			fout.write("\n%%%%%INFORMALEQUATION:")
+			fout.write(contentUntil("</informalequation>"))
+			fout.write(":INFORMALEQUATION%%%%%\n")
+			lastChar="\n"
+		elif aux=="link":
+			contentUntil('="')
+			fout.write("%%%%%LINK:"+contentUntil('">')+"==>"+contentUntil("</link>")+":LINK%%%%%")
+			lastChar="%"
+		elif aux=="ulink":
+			contentUntil('url="')
+			href=contentUntil('">')
+			name=contentUntil('</ulink>')
+			fout.write("["+href+" "+name+"]")
+		elif aux=="table":			
+			fout.write('{| border="1" cellpadding="5" cellspacing="0"\n')
+			outp=0
+		elif aux=="entry":
+			lastChar=('>')
+			entry=contentUntil('</entry>')
+			fout.write("|"+entry+"\n")	
+		elif aux=="/row":
+			fout.write("|-"+"\n")					
+		elif aux=="/table":
+			fout.write("|}\n")	
+			outp=1
+		
+												
+	fout.close
+	fin.close
+	
+fname = raw_input("Filename: ")
+xml2wiki(fname)


Property changes on: trunk/jbossws-docs/db2wiki.py
___________________________________________________________________
Name: svn:executable
   + *




More information about the jbossws-commits mailing list