- Timestamp:
- 11/05/10 16:46:19 (14 years ago)
- Location:
- trunk/de.ugoe.cs.swe.bnftools.ebnf.ui
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/build.properties
r38 r41 3 3 .,\ 4 4 plugin.xml,\ 5 lib/commons-lang-2.5.jar 5 lib/commons-lang-2.5.jar,\ 6 resources/ 6 7 7 8 source.. = src/,\ -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/resources/html-header.html
r36 r41 1 html xmlns:v="urn:schemas-microsoft-com:vml"1 <html xmlns:v="urn:schemas-microsoft-com:vml" 2 2 xmlns:o="urn:schemas-microsoft-com:office:office" 3 3 xmlns:w="urn:schemas-microsoft-com:office:word" -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfFormatterVisitor.java
r37 r41 144 144 StringBuffer whiteSpaces = new StringBuffer(); 145 145 int currentPosition = position; 146 while (isWhitespace(str.charAt(currentPosition))) { 146 if (currentPosition >= str.length() || currentPosition < 0) 147 return ""; 148 char ch; 149 ch = str.charAt(currentPosition); 150 while (isWhitespace(ch)) { 147 151 whiteSpaces.append(str.charAt(currentPosition)); 148 152 currentPosition--; 153 if (currentPosition < 0) 154 break; 155 ch = str.charAt(currentPosition); 149 156 } 150 157 return whiteSpaces.toString(); -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfHtmlFormatterVisitor.java
r40 r41 8 8 import org.eclipse.emf.ecore.EObject; 9 9 import org.eclipse.xtext.parsetree.LeafNode; 10 import org.eclipse.xtext.parsetree.NodeUtil; 10 11 11 12 import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf; 13 import de.ugoe.cs.swe.bnftools.ebnf.Import; 12 14 import de.ugoe.cs.swe.bnftools.ebnf.Rule; 13 15 import de.ugoe.cs.swe.bnftools.ebnf.RuleReference; … … 20 22 private ArrayList<MetaTextEntry> transformedTexts = new ArrayList<MetaTextEntry>(); 21 23 private int lastMetaTextBlock = 0; 24 private boolean isParagraphOpen = false; 22 25 23 26 public EbnfHtmlFormatterVisitor(EObject rootNode, FormatterConfig config) { … … 111 114 } 112 115 } else { 113 if (lastMetaTextBlock == 0 && (currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces == currentMetaText.getOffset())) {116 while (lastMetaTextBlock == 0 && (currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces >= currentMetaText.getOffset())) { 114 117 result.append(currentMetaText.getText()); 115 118 metaTexts.remove(currentMetaText); … … 118 121 else 119 122 currentMetaText = null; 120 lastMetaTextBlock = 1; 123 124 if ((currentMetaText == null) && (bufferPositionFormattedTextNoWhitespaces != currentMetaText.getOffset())) 125 lastMetaTextBlock = 1; 121 126 } 122 127 … … 139 144 } 140 145 141 if (lastMetaTextBlock == 1 && (currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces == currentMetaText.getOffset())) {146 while ( lastMetaTextBlock == 1 && currentMetaText != null && bufferPositionFormattedTextNoWhitespaces >= currentMetaText.getOffset()) { 142 147 result.append(currentMetaText.getText()); 143 148 metaTexts.remove(currentMetaText); 144 if (metaTexts.iterator().hasNext()) 149 if (metaTexts.iterator().hasNext()) { 145 150 currentMetaText = metaTexts.iterator().next(); 146 else151 } else { 147 152 currentMetaText = null; 148 lastMetaTextBlock = 0; 153 } 154 155 if ((currentMetaText == null) || (bufferPositionFormattedTextNoWhitespaces != currentMetaText.getOffset())) 156 lastMetaTextBlock = 0; 149 157 } 150 158 } 151 159 } 160 while ( bufferPositionFormattedTextNoWhitespaces >= formattedTextNoWhitespaces.length()-1 && currentMetaText != null) { 161 result.append(currentMetaText.getText()); 162 metaTexts.remove(currentMetaText); 163 if (metaTexts.iterator().hasNext()) { 164 currentMetaText = metaTexts.iterator().next(); 165 } else { 166 currentMetaText = null; 167 } 168 } 169 170 152 171 buf = result; 153 172 } … … 164 183 newLineOffsetCounter += original.length(); 165 184 } 166 185 186 protected void newLine() { 187 buf.append("\n"); 188 if (!isParagraphOpen) { 189 metaText("\n<p class=PL style='mso-pagination:widow-orphan lines-together;page-break-after: avoid'>\n"); 190 isParagraphOpen = true; 191 } else { 192 metaText("\n</p>\n"); 193 isParagraphOpen = false; 194 } 195 196 if ((ruleSpacingStack != null) && (!ruleSpacingStack.empty())) { 197 newLineOffsetCounter = ruleSpacingStack.peek(); 198 } else { 199 newLineOffsetCounter = 0; 200 } 201 } 202 167 203 // ----------------------------------------------------------------------------- 168 204 205 protected void visitBefore(EtsiBnf node) { 206 parserEtsiBnfNode = NodeUtil.getNodeAdapter(node).getParserNode(); 207 collectAllComments(parserEtsiBnfNode); 208 originalText = NodeUtil.getNodeAdapter(node).getParserNode().serialize(); 209 originalTextNoWhitespaces = originalText.replaceAll("[ \t\n\r]", ""); 210 211 textTransformed("grammar " + node.getName(),""); 212 if (node.getType() != null) 213 textTransformed(node.getType(),""); 214 textTransformed(";",""); 215 metaText("<body lang=EN-US link=blue vlink=purple style='tab-interval:14.15pt'>\n"); 216 metaText("<div class=WordSection1>\n"); 217 218 // newLine(); 219 // newLine(); 220 } 221 169 222 protected void visitAfter(EtsiBnf node) { 223 metaText("</div>\n"); 224 metaText("</body>\n"); 225 metaText("</html>\n"); 170 226 weaveComments(); 171 227 } 172 228 229 protected void visitBefore(Import node) { 230 textTransformed("import \"" + node.getImportURI() + "\"",""); 231 if (node.getGrammarType() != null) { 232 textTransformed("/" + node.getGrammarType(), ""); 233 } 234 if (node.getLabel() != null) { 235 space(); 236 textTransformed("label: " + node.getLabel(), ""); 237 } 238 textTransformed(";", ""); 239 // text("\n"); 240 } 241 173 242 protected void visitBefore(SectionHeading node) { 174 243 if (!lastWasSectionHeading && !buf.substring(buf.length()-2).equals("\n\n")) … … 177 246 lastWasSectionHeading=true; 178 247 179 metaText("<h1>"); 180 text(node.getSectionHeader().replaceAll("[\n\r]", "")); 181 metaText("</h1>"); 248 metaText("<h3><span lang=EN-GB>\n"); 249 String text = node.getSectionHeader().replaceAll("[\n\r]", ""); 250 textTransformed(text, StringEscapeUtils.escapeHtml(text).replaceAll("[\n\r]", "")); 251 // textTransformed(text, text.replaceAll("[\t]", "\\<span style='mso-tab-count:1'\\>")); 252 metaText("\n</span></h3>\n"); 182 253 } 183 254 … … 188 259 wrap(); 189 260 190 metaText("< a href=\"#" + node.getRuleref().getName() + "\">");261 metaText("<u><span style='color:blue'><a href=\"#T" + node.getRuleref().getName() + "\">"); 191 262 text(node.getRuleref().getName()); 192 metaText("</a> ");263 metaText("</a></span></u>"); 193 264 } 194 265 … … 197 268 198 269 protected void visitBefore(Rule node) { 199 if (lastWasSectionHeading)270 // if (lastWasSectionHeading) 200 271 newLine(); 201 272 … … 206 277 if (node.getRulenumber() > 0) 207 278 text(node.getRulenumber() + ". "); 208 209 metaText("< a name=\"#" + node.getName() + "\">");210 text (node.getName());279 280 metaText("<span lang=EN-GB style='mso-no-proof:no'>\n<a name=\"#T" + node.getName() + "\">"); 281 textTransformed(node.getName(), node.getName().replaceAll("[ \t\r\n]", "")); 211 282 metaText("</a>"); 212 283 text(" ::= "); … … 217 288 218 289 protected void visitAfter(Rule node) { 219 metaText("< br/>");290 metaText("<o:p></o:p>\n</span>"); 220 291 text(";"); 221 292 newLine(); 293 text("\n"); 222 294 ruleSpacingStack.pop(); 223 295 } … … 227 299 if (node.getLiteral() != null) { 228 300 // text("\"" + node.getLiteral() + "\""); 229 textTransformed("\"" + node.getLiteral() + "\"", StringEscapeUtils.escapeHtml("\"" + node.getLiteral() + "\"") );301 textTransformed("\"" + node.getLiteral() + "\"", StringEscapeUtils.escapeHtml("\"" + node.getLiteral() + "\"").replaceAll("[ \t\n\r]", "")); 230 302 // textTransformed("\"" + node.getLiteral() + "\"", "gnabar"); 231 303 } else if (node.getColon() != null) { 232 304 // text("\"\"\""); 233 textTransformed("\"\"\"", StringEscapeUtils.escapeHtml("\"\"\"") );305 textTransformed("\"\"\"", StringEscapeUtils.escapeHtml("\"\"\"").replaceAll("[ \t\n\r]", "")); 234 306 // textTransformed("\"\"\"", "gnabar"); 235 307 } -
trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/HtmlFormatterHandler.java
r35 r41 1 1 package de.ugoe.cs.swe.bnftools.ui.formatter; 2 2 3 import java.io.BufferedInputStream; 4 import java.io.BufferedReader; 3 5 import java.io.BufferedWriter; 4 6 import java.io.File; 7 import java.io.FileInputStream; 5 8 import java.io.FileWriter; 9 import java.io.IOException; 10 import java.net.URISyntaxException; 11 import java.net.URL; 6 12 7 13 import org.eclipse.core.commands.AbstractHandler; … … 20 26 import org.eclipse.xtext.ui.editor.XtextEditor; 21 27 import org.eclipse.xtext.ui.editor.model.XtextDocument; 28 import org.osgi.framework.Bundle; 22 29 23 30 import de.ugoe.cs.swe.bnftools.utils.RootEObjectFinder; … … 46 53 visitor.accept(); 47 54 48 writeFile(visitor.getBuf().toString(), parent.getLocationURI().getPath() + "/" + editor.getResource().getName() + ".html"); 55 Bundle bundle = Platform.getBundle("de.ugoe.cs.swe.bnftools.ebnf.ui"); 56 String bundlePath = bundle.getLocation().replaceAll("reference:file:",""); 57 String resourcePath = bundle.getResource("resources/html-header.html").getPath(); 58 String result = ""; 59 try { 60 result = readFileAsString(bundlePath + resourcePath); 61 } catch (IOException e) { 62 } 63 result = result + visitor.getBuf(); 64 49 65 System.out.println(visitor.getBuf()); 66 67 writeFile(result, editor.getResource().getLocation().toPortableString().toString() + ".html"); 50 68 51 69 return null; 52 70 } 53 71 72 private String readFileAsString(String filePath) throws java.io.IOException{ 73 byte[] buffer = new byte[(int) new File(filePath).length()]; 74 FileInputStream f = new FileInputStream(filePath); 75 f.read(buffer); 76 return new String(buffer); 77 } 78 54 79 private void writeFile(String str, String filename) { 55 80 try {
Note: See TracChangeset
for help on using the changeset viewer.