1 5 package com.teamkonzept.publishing.markups; 6 7 import com.teamkonzept.lib.*; 8 9 public class TKXmlMarkupParser extends TKMarkupParser { 10 11 public TKXmlTree tree; 12 13 protected String closeMarkup; 15 protected boolean isAtom; 16 17 public TKXmlMarkupParser (TKVector diagnostics, TKXmlTree tree) { 18 19 super (diagnostics,tree); 20 21 this.tree = tree; 22 this.closeMarkup = null; 23 this.isAtom = false; 24 } 25 26 public TKXmlMarkupParser (TKVector diagnostics) { 27 28 this (diagnostics, new TKXmlTree()); 29 } 30 31 public void initMarkupParsing () { 32 33 this.isAtom = false; 34 } 35 36 public void cleanup (TKMarkupItemList itemList, int pos) { 37 38 if (closeLevel(itemList)) { 39 40 addDiagnostic ((pos < 0 ? "" : "Position "+ pos+": ")+ 41 "Syntax-Fehler in /"+ compoundName()+ 42 ": Markupanfang nicht gefunden"); 43 44 } else super.cleanup(itemList,pos); 45 46 cleanupCloseLevel(); 47 } 48 49 public TKMarkup createMarkup (String name, TKHashtable params, int pos) { 50 51 try { return new TKXmlMarkup (name,isAtom,params,pos); } 52 catch (Exception ex) { 53 54 addDiagnostic (TKMarkupParserException.demandMsg (ex)); 55 return super.createMarkup (name,params,pos); 56 } 57 } 58 59 public void registerCompound (String markupName) { 60 61 registerMarkup (markupName); 62 closeMarkup = markupName; 63 } 64 65 public String compoundName() { 66 67 return closeMarkup == null ? "" : closeMarkup; 68 } 69 70 public boolean closeLevel (TKMarkupItemList itemList) { 71 72 return super.closeLevel(itemList) || (closeMarkup != null); 73 } 74 75 public void cleanupCloseLevel () { 76 77 super.cleanupCloseLevel(); 78 closeMarkup = null; 79 } 80 81 public int tieMarkup (String text, int pos, TKMarkup markup, TKMarkupItemList itemList) { 82 83 if (!(markup instanceof TKXmlMarkup)) { 84 85 itemList.addElement (markup); 86 87 if ((closeMarkup != null) && closeMarkup.equalsIgnoreCase(markup.name)) 88 closeMarkup = null; 89 90 return pos; 91 } 92 93 TKXmlMarkup xmlMarkup = (TKXmlMarkup) markup; 94 95 if (xmlMarkup.isAtom) { 96 97 itemList.addElement (xmlMarkup); 98 return pos; 99 } 100 101 TKXmlTree subTree = new TKXmlTree(); 102 103 pos = parse (text,pos,subTree); 105 106 if (itemList instanceof TKXmlTree) 107 itemList.addElement (new TKMarkupNode(xmlMarkup,subTree)); 108 else itemList.concat (subTree); 109 110 if ((closeMarkup != null) && closeMarkup.equalsIgnoreCase(markup.name)) closeMarkup = null; 111 112 return pos; 113 } 114 115 public int parseAliens (String text, int pos) throws TKMarkupParserException { 116 117 StringBuffer name = new StringBuffer (); 118 119 int startPos = pos; 120 pos = parsePattern (text,pos,null,"/"); 121 122 if (pos > startPos) { 123 124 try { 125 pos = forceIdentifier (text,pos,name); 126 pos = parseWhitespace (text,pos,null); 127 pos = forcePattern (text,pos,null,">"); 128 129 String markupName = new String (name).toUpperCase(); 130 131 registerCompound(markupName); 132 133 return pos; 134 135 } catch (TKMarkupParserException ex) { 136 137 ex.throwAgain(pos); 138 139 } catch (Exception ex) { 140 141 TKMarkupParserException.throwAgain(ex,pos); 142 } 143 } 144 145 return pos; 146 } 147 148 public int parseAlienTrailer (String text, int pos) throws TKMarkupParserException { 149 150 int startPos = pos; 151 pos = parsePattern (text,pos,null,"/"); 152 153 if (pos > startPos) isAtom = true; 154 155 return pos; 156 } 157 } 160 161 | Popular Tags |