Changeset 41 in default


Ignore:
Timestamp:
11/05/10 16:46:19 (13 years ago)
Author:
zeiss
Message:
 
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  
    33               .,\ 
    44               plugin.xml,\ 
    5                lib/commons-lang-2.5.jar 
     5               lib/commons-lang-2.5.jar,\ 
     6               resources/ 
    67 
    78source.. = 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" 
    22xmlns:o="urn:schemas-microsoft-com:office:office" 
    33xmlns: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  
    144144                StringBuffer whiteSpaces = new StringBuffer(); 
    145145                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)) { 
    147151                        whiteSpaces.append(str.charAt(currentPosition)); 
    148152                        currentPosition--; 
     153                        if (currentPosition < 0) 
     154                                break; 
     155                        ch = str.charAt(currentPosition); 
    149156                } 
    150157                return whiteSpaces.toString(); 
  • trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/EbnfHtmlFormatterVisitor.java

    r40 r41  
    88import org.eclipse.emf.ecore.EObject; 
    99import org.eclipse.xtext.parsetree.LeafNode; 
     10import org.eclipse.xtext.parsetree.NodeUtil; 
    1011 
    1112import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf; 
     13import de.ugoe.cs.swe.bnftools.ebnf.Import; 
    1214import de.ugoe.cs.swe.bnftools.ebnf.Rule; 
    1315import de.ugoe.cs.swe.bnftools.ebnf.RuleReference; 
     
    2022        private ArrayList<MetaTextEntry> transformedTexts = new ArrayList<MetaTextEntry>(); 
    2123        private int lastMetaTextBlock = 0; 
     24        private boolean isParagraphOpen = false; 
    2225         
    2326        public EbnfHtmlFormatterVisitor(EObject rootNode, FormatterConfig config) { 
     
    111114                                } 
    112115                        } else { 
    113                                 if (lastMetaTextBlock == 0 && (currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces == currentMetaText.getOffset())) { 
     116                                while (lastMetaTextBlock == 0 && (currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces >= currentMetaText.getOffset())) { 
    114117                                        result.append(currentMetaText.getText()); 
    115118                                        metaTexts.remove(currentMetaText); 
     
    118121                                        else 
    119122                                                currentMetaText = null; 
    120                                         lastMetaTextBlock = 1; 
     123                                         
     124                                        if ((currentMetaText == null) && (bufferPositionFormattedTextNoWhitespaces != currentMetaText.getOffset())) 
     125                                                lastMetaTextBlock = 1; 
    121126                                } 
    122127 
     
    139144                                } 
    140145 
    141                                 if (lastMetaTextBlock == 1 && (currentMetaText != null) && (bufferPositionFormattedTextNoWhitespaces == currentMetaText.getOffset())) { 
     146                                while ( lastMetaTextBlock == 1 && currentMetaText != null && bufferPositionFormattedTextNoWhitespaces >= currentMetaText.getOffset()) { 
    142147                                        result.append(currentMetaText.getText()); 
    143148                                        metaTexts.remove(currentMetaText); 
    144                                         if (metaTexts.iterator().hasNext()) 
     149                                        if (metaTexts.iterator().hasNext()) { 
    145150                                                currentMetaText = metaTexts.iterator().next(); 
    146                                         else 
     151                                        } else { 
    147152                                                currentMetaText = null; 
    148                                         lastMetaTextBlock = 0; 
     153                                        } 
     154                                         
     155                                        if ((currentMetaText == null) || (bufferPositionFormattedTextNoWhitespaces != currentMetaText.getOffset())) 
     156                                                lastMetaTextBlock = 0; 
    149157                                } 
    150158                        } 
    151159                } 
     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                 
    152171                buf = result; 
    153172        } 
     
    164183                newLineOffsetCounter += original.length(); 
    165184        } 
    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         
    167203        // ----------------------------------------------------------------------------- 
    168204         
     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         
    169222        protected void visitAfter(EtsiBnf node) { 
     223                metaText("</div>\n"); 
     224                metaText("</body>\n"); 
     225                metaText("</html>\n"); 
    170226                weaveComments(); 
    171227        } 
    172228 
     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         
    173242        protected void visitBefore(SectionHeading node) { 
    174243                if (!lastWasSectionHeading && !buf.substring(buf.length()-2).equals("\n\n")) 
     
    177246                lastWasSectionHeading=true; 
    178247                 
    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"); 
    182253        } 
    183254 
     
    188259                wrap(); 
    189260                 
    190                 metaText("<a href=\"#" + node.getRuleref().getName() + "\">"); 
     261                metaText("<u><span style='color:blue'><a href=\"#T" + node.getRuleref().getName() + "\">"); 
    191262                text(node.getRuleref().getName()); 
    192                 metaText("</a>"); 
     263                metaText("</a></span></u>"); 
    193264        } 
    194265 
     
    197268 
    198269        protected void visitBefore(Rule node) { 
    199                 if (lastWasSectionHeading) 
     270//              if (lastWasSectionHeading) 
    200271                        newLine(); 
    201272                 
     
    206277                if (node.getRulenumber() > 0) 
    207278                        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]", "")); 
    211282                metaText("</a>"); 
    212283                text(" ::= "); 
     
    217288         
    218289        protected void visitAfter(Rule node) { 
    219                 metaText("<br/>"); 
     290                metaText("<o:p></o:p>\n</span>"); 
    220291                text(";"); 
    221292                newLine(); 
     293                text("\n"); 
    222294                ruleSpacingStack.pop(); 
    223295        } 
     
    227299                if (node.getLiteral() != null) { 
    228300//                      text("\"" + node.getLiteral() + "\""); 
    229                         textTransformed("\"" + node.getLiteral() + "\"", StringEscapeUtils.escapeHtml("\"" + node.getLiteral() + "\"")); 
     301                        textTransformed("\"" + node.getLiteral() + "\"", StringEscapeUtils.escapeHtml("\"" + node.getLiteral() + "\"").replaceAll("[ \t\n\r]", "")); 
    230302//                      textTransformed("\"" + node.getLiteral() + "\"", "gnabar"); 
    231303                } else if (node.getColon() != null) { 
    232304//                      text("\"\"\""); 
    233                         textTransformed("\"\"\"", StringEscapeUtils.escapeHtml("\"\"\"")); 
     305                        textTransformed("\"\"\"", StringEscapeUtils.escapeHtml("\"\"\"").replaceAll("[ \t\n\r]", "")); 
    234306//                      textTransformed("\"\"\"", "gnabar"); 
    235307                } 
  • trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/formatter/HtmlFormatterHandler.java

    r35 r41  
    11package de.ugoe.cs.swe.bnftools.ui.formatter; 
    22 
     3import java.io.BufferedInputStream; 
     4import java.io.BufferedReader; 
    35import java.io.BufferedWriter; 
    46import java.io.File; 
     7import java.io.FileInputStream; 
    58import java.io.FileWriter; 
     9import java.io.IOException; 
     10import java.net.URISyntaxException; 
     11import java.net.URL; 
    612 
    713import org.eclipse.core.commands.AbstractHandler; 
     
    2026import org.eclipse.xtext.ui.editor.XtextEditor; 
    2127import org.eclipse.xtext.ui.editor.model.XtextDocument; 
     28import org.osgi.framework.Bundle; 
    2229 
    2330import de.ugoe.cs.swe.bnftools.utils.RootEObjectFinder; 
     
    4653                visitor.accept(); 
    4754 
    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                 
    4965                System.out.println(visitor.getBuf()); 
     66                 
     67                writeFile(result, editor.getResource().getLocation().toPortableString().toString() + ".html"); 
    5068                 
    5169                return null; 
    5270        } 
    5371 
     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         
    5479        private void writeFile(String str, String filename) { 
    5580                try { 
Note: See TracChangeset for help on using the changeset viewer.