001: /*
002: * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/publishing/markups/TKXmlMarkupParser.java,v 1.6 2000/06/01 15:02:56 alex Exp $
003: *
004: */
005: package com.teamkonzept.publishing.markups;
006:
007: import com.teamkonzept.lib.*;
008:
009: public class TKXmlMarkupParser extends TKMarkupParser {
010:
011: public TKXmlTree tree;
012:
013: // Bitte nicht ˆffentlich machen !
014: protected String closeMarkup;
015: protected boolean isAtom;
016:
017: public TKXmlMarkupParser(TKVector diagnostics, TKXmlTree tree) {
018:
019: super (diagnostics, tree);
020:
021: this .tree = tree;
022: this .closeMarkup = null;
023: this .isAtom = false;
024: }
025:
026: public TKXmlMarkupParser(TKVector diagnostics) {
027:
028: this (diagnostics, new TKXmlTree());
029: }
030:
031: public void initMarkupParsing() {
032:
033: this .isAtom = false;
034: }
035:
036: public void cleanup(TKMarkupItemList itemList, int pos) {
037:
038: if (closeLevel(itemList)) {
039:
040: addDiagnostic((pos < 0 ? "" : "Position " + pos + ": ")
041: + "Syntax-Fehler in /" + compoundName()
042: + ": Markupanfang nicht gefunden");
043:
044: } else
045: super .cleanup(itemList, pos);
046:
047: cleanupCloseLevel();
048: }
049:
050: public TKMarkup createMarkup(String name, TKHashtable params,
051: int pos) {
052:
053: try {
054: return new TKXmlMarkup(name, isAtom, params, pos);
055: } catch (Exception ex) {
056:
057: addDiagnostic(TKMarkupParserException.demandMsg(ex));
058: return super .createMarkup(name, params, pos);
059: }
060: }
061:
062: public void registerCompound(String markupName) {
063:
064: registerMarkup(markupName);
065: closeMarkup = markupName;
066: }
067:
068: public String compoundName() {
069:
070: return closeMarkup == null ? "" : closeMarkup;
071: }
072:
073: public boolean closeLevel(TKMarkupItemList itemList) {
074:
075: return super .closeLevel(itemList) || (closeMarkup != null);
076: }
077:
078: public void cleanupCloseLevel() {
079:
080: super .cleanupCloseLevel();
081: closeMarkup = null;
082: }
083:
084: public int tieMarkup(String text, int pos, TKMarkup markup,
085: TKMarkupItemList itemList) {
086:
087: if (!(markup instanceof TKXmlMarkup)) {
088:
089: itemList.addElement(markup);
090:
091: if ((closeMarkup != null)
092: && closeMarkup.equalsIgnoreCase(markup.name))
093: closeMarkup = null;
094:
095: return pos;
096: }
097:
098: TKXmlMarkup xmlMarkup = (TKXmlMarkup) markup;
099:
100: if (xmlMarkup.isAtom) {
101:
102: itemList.addElement(xmlMarkup);
103: return pos;
104: }
105:
106: TKXmlTree subTree = new TKXmlTree();
107:
108: // rekursiver Abstieg
109: pos = parse(text, pos, subTree);
110:
111: if (itemList instanceof TKXmlTree)
112: itemList.addElement(new TKMarkupNode(xmlMarkup, subTree));
113: else
114: itemList.concat(subTree);
115:
116: if ((closeMarkup != null)
117: && closeMarkup.equalsIgnoreCase(markup.name))
118: closeMarkup = null;
119:
120: return pos;
121: }
122:
123: public int parseAliens(String text, int pos)
124: throws TKMarkupParserException {
125:
126: StringBuffer name = new StringBuffer();
127:
128: int startPos = pos;
129: pos = parsePattern(text, pos, null, "/");
130:
131: if (pos > startPos) {
132:
133: try {
134: pos = forceIdentifier(text, pos, name);
135: pos = parseWhitespace(text, pos, null);
136: pos = forcePattern(text, pos, null, ">");
137:
138: String markupName = new String(name).toUpperCase();
139:
140: registerCompound(markupName);
141:
142: return pos;
143:
144: } catch (TKMarkupParserException ex) {
145:
146: ex.throwAgain(pos);
147:
148: } catch (Exception ex) {
149:
150: TKMarkupParserException.throwAgain(ex, pos);
151: }
152: }
153:
154: return pos;
155: }
156:
157: public int parseAlienTrailer(String text, int pos)
158: throws TKMarkupParserException {
159:
160: int startPos = pos;
161: pos = parsePattern(text, pos, null, "/");
162:
163: if (pos > startPos)
164: isAtom = true;
165:
166: return pos;
167: }
168: //{{DECLARE_CONTROLS
169: //}}
170: }
|