001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: import org.wings.io.Device;
016: import org.wings.template.CmsTemplateParseContext;
017: import org.wings.template.parser.ParseContext;
018: import org.wings.template.parser.PositionReader;
019: import org.wings.template.parser.SGMLTag;
020: import org.wings.template.parser.SpecialTagHandler;
021: import org.wingx.XDivision;
022:
023: import java.io.IOException;
024: import java.io.InputStream;
025: import java.util.Map;
026:
027: /**
028: * <code>DebugTagHandler<code>.
029: * <p/>
030: * User: raedler
031: * Date: 03.12.2007
032: * Time: 14:35:57
033: *
034: * @author raedler
035: * @version $Id
036: */
037: public class DebugTagHandler implements SpecialTagHandler {
038: boolean close_is_missing = false;
039:
040: long startPos;
041: long endPos;
042: Map properties;
043: String name;
044:
045: public long getTagStart() {
046: return startPos;
047: }
048:
049: public long getTagLength() {
050: return endPos - startPos;
051: }
052:
053: public void executeTag(ParseContext context, InputStream input)
054: throws Exception {
055: CmsTemplateParseContext tcontext = (CmsTemplateParseContext) context;
056: Device sink = tcontext.getDevice();
057:
058: /*
059: * get the component that is associtated with this name. This has
060: * been set as Layout Manager Constraint.
061: */
062: SComponent[] components = tcontext.getComponents();
063:
064: StringBuilder sb = new StringBuilder();
065: for (long i = getTagLength(); i > 0; i--) {
066: sb.append((char) input.read());
067: }
068:
069: SPanel container = new SPanel(new SFlowDownLayout());
070: XDivision division;
071: for (SComponent c : components) {
072: division = new XDivision();
073: division.add(c);
074: container.add(division);
075: }
076: container.write(sink);
077: }
078:
079: public SGMLTag parseTag(ParseContext context, PositionReader input,
080: long startPosition, SGMLTag startTag) throws IOException {
081:
082: final String startTagName = startTag.getName();
083: final String endTagName = "/" + startTagName;
084:
085: /*
086: * parse the full tag to get all parameters
087: * (i.e. an optional 'format'-parameter)
088: * and to place the Reader at the position
089: * after the closing '>'
090: */
091: startTag.parse(input);
092:
093: /*
094: * The Offset is the space the reader skipped
095: * before it reached the opening '<'
096: * <!-- a comment --> some garbage <DATE>
097: * ^----- offset --------------------^
098: */
099: startPos = startPosition + startTag.getOffset();
100:
101: /*
102: * get properties
103: */
104: properties = startTag.getAttributes();
105:
106: name = startTag.value("NAME", null);
107: if (name == null)
108: return null;
109:
110: endPos = input.getPosition(); // in case </component> is missing
111:
112: while (!startTag.finished()) {
113: startTag = new SGMLTag(input, true);
114: if (startTag.isNamed(endTagName)
115: || startTag.isNamed(startTagName))
116: break;
117: }
118:
119: // Either EOF or newly opened COMPONENT (unexpectedly)
120: if (startTag.finished() || startTag.isNamed(startTagName)) {
121: close_is_missing = true;
122: } else {
123: // The current Position is after the closing '>'
124: endPos = input.getPosition();
125: }
126:
127: // remove properties, which are not necessary for the PropertyManager
128: properties.remove("NAME");
129: properties.remove("TYPE");
130:
131: return startTag;
132: }
133: }
|