Index: TXM/trunk/bundles/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZDefaultPagerStep.groovy
===================================================================
--- TXM/trunk/bundles/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZDefaultPagerStep.groovy	(revision 3714)
+++ TXM/trunk/bundles/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZDefaultPagerStep.groovy	(revision 3715)
@@ -13,80 +13,80 @@
 import org.txm.importer.xtz.*
 
 public class XTZDefaultPagerStep {
-	
+
 	List<String> NoSpaceBefore;
-	
+
 	/** The No space after. */
 	List<String> NoSpaceAfter;
-	
+
 	/** The wordcount. */
 	int wordcount = 0;
-	
+
 	/** The pagecount. */
 	int pagecount = 0;
-	
+
 	/** The wordmax. */
 	int wordmax = 0;
-	
+
 	/** The basename. */
 	String basename = "";
 	String txtname = "";
 	File outdir;
-	
+
 	/** The wordid. */
 	String wordid;
-	
+
 	/** The first word. */
 	boolean firstWord = true;
-	
+
 	boolean enableCollapsibles = false;
-	
+
 	/** The wordvalue. */
 	String wordvalue = "";
-	
+
 	/** The interpvalue. */
 	String interpvalue = "";
-	
+
 	/** The lastword. */
 	String lastword = " ";
-	
+
 	/** The wordtype. */
 	String wordtype;
-	
+
 	/** The flagform. */
 	boolean flagform = false;
-	
+
 	/** The flaginterp. */
 	boolean flaginterp = false;
-	
+
 	/** The url. */
 	private def url;
-	
+
 	/** The input data. */
 	private def inputData;
-	
+
 	/** The factory. */
 	private def factory;
-	
+
 	/** The parser. */
 	private XMLStreamReader parser;
-	
+
 	/** The writer. */
 	OutputStreamWriter writer;
-	
+
 	/** The pagedWriter. */
 	StaxStackWriter pagedWriter = null;
-	
+
 	/** The infile. */
 	File infile;
-	
+
 	/** The outfile. */
 	File outfile;
-	
+
 	/** The pages. */
 	//TODO enhance this to store the page name/id as well
 	ArrayList<File> pages = new ArrayList<File>();
-	
+
 	/** The idxstart. */
 	ArrayList<String> idxstart = new ArrayList<String>();
 	String paginationElement;
@@ -96,7 +96,7 @@
 	def noteElements = new HashSet<String>();
 	def outOfTextElements = new HashSet<String>();
 	XTZPager pager;
-	
+
 	/**
 	 * Instantiates a new pager.
 	 *
@@ -123,20 +123,20 @@
 		this.wordTag= pager.wordTag;
 		outdir.mkdirs()
 		this.enableCollapsibles = pager.getImportModule().getProject().getEditionDefinition("default").getEnableCollapsibleMetadata();
-		
+
 		inputData = new BufferedInputStream(url.openStream());
 		factory = XMLInputFactory.newInstance();
 		parser = factory.createXMLStreamReader(inputData);
-		
+
 		String notesListString = pager.getImportModule().getProject().getTextualPlan("Note")
 		if (notesListString != null) for (def s : notesListString.split(",")) noteElements << s;
-		
+
 		String elems = pager.getImportModule().getProject().getTextualPlan("OutSideTextTagsAndKeepContent")
 		if (elems != null) for (def s : elems.split(",")) outOfTextElements << s;
-		
+
 		//process();
 	}
-	
+
 	public String getAttributeValue(def parser, String ns, String name) {
 		for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
 			if (name == parser.getAttributeLocalName(i)) {
@@ -145,32 +145,32 @@
 		}
 		return null;
 	}
-	
+
 	private def closeMultiWriter() {
 		if (pagedWriter != null) {
 			def tags = []
 			tags.addAll(pagedWriter.getTagStack())
-			
+
 			//println "CLOSING... STACK="+pagedWriter.getTagStack()
 			// def stack = Thread.currentThread().getStackTrace();
 			// int m = Math.min(15, stack.size()-1)
 			// for (def s : stack[1..m]) println s
 			// println "FILE ="+outfile
 			if (firstWord) { // there was no words
-				pagedWriter.writeCharacters("");
+				pagedWriter.writeCharacters("")
 				this.idxstart.add("w_0")
-				pagedWriter.write("<span id=\"w_0\"/>");
+				pagedWriter.write("<span id=\"w_0\"/>")
 			}
-			
-			// write notes before closing all tags 
+
+			// write notes before closing all tags
 			if (notes.size() > 0) {
-				pagedWriter.writeStartElement("hr", ["id":"notes", "width":"20%", "align":"left"]);
+				pagedWriter.writeStartElement("hr", ["id":"notes", "width":"20%", "align":"left"])
 				pagedWriter.writeEndElement() // </hr>
 				//pagedWriter.writeStartElement("ol");
 				int i = 1;
 				for (String note : notes) {
 					//pagedWriter.writeStartElement("li");
-					pagedWriter.writeStartElement("a", ["href":"#noteref_"+i, "name":"note_"+i]);
+					pagedWriter.writeStartElement("a", ["href":"#noteref_"+i, "name":"note_"+i])
 					pagedWriter.writeStartElement("sup")
 					pagedWriter.writeCharacters(""+i)
 					pagedWriter.writeEndElement() // </sub>
@@ -181,11 +181,11 @@
 				}
 				notes.clear()
 			}
-			
+
 			pagedWriter.writeEndElements();
-			
+
 			pagedWriter.close();
-			
+
 			//println "STACK TO REWRITE: $tags"
 			int removedDiv = 0;
 			for (int i = 0 ; i < tags.size() ; i++) {
@@ -203,7 +203,7 @@
 			return [];
 		}
 	}
-	
+
 	/**
 	 * Creates the next output.
 	 *
@@ -213,27 +213,27 @@
 		wordcount = 0;
 		try {
 			def tags = closeMultiWriter()
-			
+
 			outfile = new File(outdir, txtname+"_"+(++pagecount)+".html")
 			pages.add(outfile)
 			firstWord = true; // waiting for next word
-			
+
 			pagedWriter = new StaxStackWriter(outfile, "UTF-8")
-			
+
 			//pagedWriter.writeStartDocument()
 			pagedWriter.writeDTD("<!DOCTYPE html>")
 			pagedWriter.writeCharacters("\n")
 			pagedWriter.writeStartElement("html")
-			
+
 			pagedWriter.writeCharacters("\n\t")
 			pagedWriter.writeEmptyElement("meta", ["http-equiv":"Content-Type", "content":"text/html","charset":"UTF-8"])
-			
-			
+
+
 			for (String css : cssList) {
 				pagedWriter.writeCharacters("\t\n")
 				pagedWriter.writeEmptyElement("link", ["rel":"stylesheet", "type":"text/css","href":"$css"])
-				
 			}
+			
 			pagedWriter.writeCharacters("\t\n")
 			pagedWriter.writeStartElement("head")
 			pagedWriter.writeCharacters("\t\t\n")
@@ -252,9 +252,9 @@
 			pagedWriter.writeCharacters("\t\t\n")
 			pagedWriter.writeStartElement("div", ["class": "txmeditionpage"]) //<div>
 			pagedWriter.writeCharacters("\n")
-			
-//			println "NEW HTML: "+outfile
-//			println "TAGS: "+tags
+
+			//			println "NEW HTML: "+outfile
+			//			println "TAGS: "+tags
 			pagedWriter.writeStartElements(tags)
 			return true;
 		} catch (Exception e) {
@@ -263,7 +263,7 @@
 			return false;
 		}
 	}
-	
+
 	/**
 	 * Creates the output.
 	 *
@@ -278,7 +278,7 @@
 			return false;
 		}
 	}
-	
+
 	/**
 	 * Gets the page files.
 	 *
@@ -287,7 +287,7 @@
 	public ArrayList<File> getPageFiles() {
 		return pages;
 	}
-	
+
 	/**
 	 * Gets the idx.
 	 *
@@ -296,18 +296,21 @@
 	public ArrayList<String> getIdx() {
 		return idxstart;
 	}
-	
+
 	/**
 	 * Go to text.
 	 */
 	private void goToText() {
+		
 		for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
-			if (event == XMLStreamConstants.END_ELEMENT)
-				if (parser.getLocalName().matches("teiHeader"))
+			if (event == XMLStreamConstants.END_ELEMENT) {
+				if (parser.getLocalName().matches("teiHeader")) {
 					return;
+				}
+			}
 		}
 	}
-	
+
 	def notes = []
 	def currentOutOfTextElements = [] // stack of element with out of text to edit opened element
 	def writeOutOfTextToEditText = false
@@ -315,16 +318,16 @@
 	 * Process.
 	 */
 	public boolean process() {
-		
+
 		try {
 			def anaValues = [:]
 			def anaType = ""
 			def anaResp = ""
 			def anaValue = new StringBuilder()
-			
+
 			boolean flagNote = false
 			boolean flagW = false
-			
+
 			boolean allTags = true
 			boolean ignoreUnmanagedTags = true
 			// unmanagedElementsPolicyCombo.setItems("ignore", "keep as is", "rename to span");
@@ -342,12 +345,12 @@
 			String noteType = ""
 			String rend = ""
 			goToText();
-			
+
 			String localname = ""
 			if (!createNextOutput()) {
 				return false;
 			}
-			
+
 			for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
 				rend = "";
 				switch (event) {
@@ -359,56 +362,56 @@
 						} else if (currentOutOfTextElements.size() > 0) {
 							currentOutOfTextElements << localname
 						}
-					
+
 						if (localname == paginationElement) {
 							if (paginate) {
 								createNextOutput()
 							}
-							
+
 							wordcount = 0;
 							pagedWriter.write("\n")
 							if (getAttributeValue(parser, null,"n") != null) {
 								pagedWriter.writeElement("p", ["class":"txmeditionpb", "align":"center"], getAttributeValue(parser, null,"n"))
 							}
 						}
-					
+
 						rend = getAttributeValue(parser, null, "rend")
-						//if (rend == null) rend = localname;
-					
+					//if (rend == null) rend = localname;
+
 						switch (localname) {
 							case "text":
 								LinkedHashMap attributes = new LinkedHashMap();
 								for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
 									attributes[parser.getAttributeLocalName(i)] = parser.getAttributeValue(i).toString()
 								}
-							
+
 								pagedWriter.write("\n")
 								pagedWriter.writeStartElement("p")
 								pagedWriter.writeAttribute("class", rend)
 								if (attributes.containsKey("id")) {
 									pagedWriter.writeElement("h3", attributes["id"])
 								}
-							
-							if (enableCollapsibles && parser.getAttributeCount() > 2) {
-								pagedWriter.writeStartElement("button");
-								pagedWriter.writeAttribute("class", "collapsible");
-								pagedWriter.writeAttribute("onclick", "onCollapsibleClicked(this)");
-								pagedWriter.writeCharacters("➕");
-								pagedWriter.writeEndElement()
-								pagedWriter.writeCharacters("\n")
-							}
-							pagedWriter.writeStartElement("table");
-							if (enableCollapsibles && parser.getAttributeCount() > 2) {
-								pagedWriter.writeAttribute("class", "collapsiblecontent")
-								pagedWriter.writeAttribute("style", "display:none;")
-							} else {
-								pagedWriter.writeAttribute("class", "metadata");
-							}
-							
+
+								if (enableCollapsibles && parser.getAttributeCount() > 2) {
+									pagedWriter.writeStartElement("button");
+									pagedWriter.writeAttribute("class", "collapsible");
+									pagedWriter.writeAttribute("onclick", "onCollapsibleClicked(this)");
+									pagedWriter.writeCharacters("➕");
+									pagedWriter.writeEndElement()
+									pagedWriter.writeCharacters("\n")
+								}
+								pagedWriter.writeStartElement("table");
+								if (enableCollapsibles && parser.getAttributeCount() > 2) {
+									pagedWriter.writeAttribute("class", "collapsiblecontent")
+									pagedWriter.writeAttribute("style", "display:none;")
+								} else {
+									pagedWriter.writeAttribute("class", "metadata");
+								}
+
 								for (String k : attributes.keySet()) {
 									if (k == "id") continue;
 									if (k == "rend") continue;
-									
+
 									pagedWriter.writeStartElement("tr")
 									pagedWriter.writeAttribute("class", "metadata-line")
 									pagedWriter.writeElement("td", ["class": "metadata-cell"], k)
@@ -416,7 +419,7 @@
 									pagedWriter.writeEndElement() //tr
 								}
 								pagedWriter.writeEndElement() // table
-								
+
 								pagedWriter.writeEndElement() // p
 								pagedWriter.writeCharacters("\n")
 								break;
@@ -425,7 +428,7 @@
 								pagedWriter.writeAttribute("class", "sync")
 								if (parser.getAttributeValue(null,"time") != null) {
 									pagedWriter.writeCharacters(parser.getAttributeValue(null,"time"))
-									
+
 									writeMediaAccess(parser.getAttributeValue(null,"time"), corpus, txtname)
 								}
 								break;
@@ -438,14 +441,14 @@
 								break;
 							case "sp":
 								pagedWriter.writeStartElement("p", ["class":"turn", "type":localname])
-							
+
 								if (parser.getAttributeValue(null,"speaker") != null) {
 									pagedWriter.writeStartElement("span")
 									pagedWriter.writeAttribute("class", "spk")
 									pagedWriter.writeCharacters(parser.getAttributeValue(null,"speaker")+": ")
 									pagedWriter.writeEndElement() // span@class=spk
 								}
-							
+
 								break;
 							case "cb":
 								pagedWriter.write("\n")
@@ -545,7 +548,7 @@
 								if (paginate && wordcount >= wordmax) {
 									createNextOutput();
 								}
-							
+
 								if (firstWord) {
 									firstWord = false;
 									this.idxstart.add(wordid);
@@ -573,15 +576,15 @@
 						break;
 					case XMLStreamConstants.END_ELEMENT:
 						localname = parser.getLocalName();
-						
+
 						if (currentOutOfTextElements.size() > 0) currentOutOfTextElements.pop()
-						
+
 						writeOutOfTextToEditText = currentOutOfTextElements.size() > 0
-					
+
 						if (localname == paginationElement) {
 							break; // element already processed in the START_ELEMENT event
 						}
-					
+
 						switch (localname) {
 							case "text":
 								break;
@@ -600,7 +603,7 @@
 								break;
 							case "lb":
 								break;
-							
+
 							case "body":
 							case "div":
 							case "div1":
@@ -659,7 +662,7 @@
 								if (l > 0) {
 									endOfLastWord = lastword.subSequence(l-1, l)
 								}
-							
+
 								String interpvalue = null;
 								def tooltipProperties = pager.project.getEditionDefinition("default").get(TBXPreferences.EDITION_DEFINITION_TOOLTIP_PROPERTIES, "*");
 								if (tooltipProperties.equals("*")) {
@@ -671,18 +674,22 @@
 									interpvalue += "- "+wordid
 								}
 								
-								if (NoSpaceBefore.contains(wordvalue) ||
-										NoSpaceAfter.contains(lastword) ||
-										wordvalue.startsWith("-") ||
-										NoSpaceAfter.contains(endOfLastWord)) {
-									pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid])
+								if (!flagNote) { // don't write words of the note elements
+									if (NoSpaceBefore.contains(wordvalue) ||
+											NoSpaceAfter.contains(lastword) ||
+											wordvalue.startsWith("-") ||
+											NoSpaceAfter.contains(endOfLastWord)) {
+										pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid])
+									} else {
+										pagedWriter.writeCharacters("\n")
+										pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid])
+									}
+
+									pagedWriter.writeCharacters(wordvalue)
+									pagedWriter.writeEndElement()
 								} else {
-									pagedWriter.writeCharacters("\n")
-									pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid])
+									
 								}
-							
-								pagedWriter.writeCharacters(wordvalue)
-								pagedWriter.writeEndElement()
 							//pagedWriter.writeComment("\n")
 								lastword=wordvalue;
 								wordvalue="" // reset
@@ -744,9 +751,9 @@
 		}
 		return true;
 	}
-	
+
 	private void writeMediaAccess(def time) {
-		
+
 		pagedWriter.writeCharacters(" ");
 		pagedWriter.writeStartElement("a");
 		pagedWriter.writeAttribute("onclick", "txmcommand('id', 'org.txm.backtomedia.commands.function.BackToMedia', 'corpus', '"+basename+"', 'text', '"+txtname+"', 'time', '"+time+"')");
