001: /*
002: * Created on Jul 27, 2005
003: */
004: package uk.org.ponder.rsf.template;
005:
006: import java.util.HashMap;
007: import java.util.Map;
008:
009: import uk.org.ponder.arrayutil.ArrayUtil;
010:
011: /**
012: * A primitive "lump" of an XML document, representing a "significant"
013: * character span. The basic function is to hold indexes start, length into
014: * the character array for the document, as well as various housekeeping
015: * information to aid navigation and debugging.
016: *
017: * @author Antranig Basman (antranig@caret.cam.ac.uk)
018: */
019: public class XMLLump {
020: public int lumpindex;
021: public int line, column;
022: public int nestingdepth;
023:
024: public XMLViewTemplate parent;
025:
026: public int start, length;
027: public String rsfID;
028: public XMLLump open_end; // lump containing " >"
029: public XMLLump close_tag; // lump containing "</close">
030: public XMLLump uplump;
031: // open and close will be the same for empty tag case " />"
032: // headlump has standard text of |<tagname | to allow easy identification.
033: public XMLLumpMMap downmap;
034:
035: // potentially present on *every* tag - maps branch names to their final close lump
036: private Map endmap;
037: // map from attribute name to lump where value occurs.
038: // this may be reformed to map to text if we collapse attribute lumps?
039: // this is a HashMap so that the fast clone method is easily accessible
040: public HashMap attributemap;
041: // the (XHTML) attribute appearing in the template file designating a
042: // template component.
043: public static final String ID_ATTRIBUTE = "rsf:id";
044: /** The prefix indicating an rsf:id for a
045: * {@link uk.org.ponder.rsf.renderer.scr.StaticComponentRenderer}
046: */
047: public static final String SCR_PREFIX = "scr=";
048: /** The prefix indicating an rsf:id for a simple internationalised message **/
049: public static final String MSG_PREFIX = "msg=";
050: /** Value for rsf:id that represents a CollectingSCR */
051: public static final String SCR_CONTRIBUTE_PREFIX = "scr=contribute-";
052: // A value for the rsf:id attribute indicating that the actual (leaf) component
053: // to be targetted by component rendering is somewhere inside the component
054: // holding the ID. NEVER issue a component with this ID! In this case, the
055: // component holding the ID will be either a div or a span.
056: public static final String PAYLOAD_COMPONENT = "payload-component";
057: // this occurs in the SAME CONTAINER scope as the target???
058: public static final String FORID_PREFIX = "message-for:";// + SplitID.SEPARATOR;
059: public static final String FORID_SUFFIX = "*";
060: /** This prefix for an rsf:id will elide the surrounding tag when rendered. This
061: * cannot be combined with an empty body*/
062: public static final String ELISION_PREFIX = "~";
063:
064: public XMLLump() {
065: }
066:
067: public XMLLump(int lumpindex, int nestingdepth) {
068: this .lumpindex = lumpindex;
069: this .nestingdepth = nestingdepth;
070: }
071:
072: public XMLLump getDownHolder() {
073: XMLLump move = this ;
074: while (move != null && move.downmap == null)
075: move = move.uplump;
076: return move;
077: }
078:
079: public XMLLump getFinal(String id) {
080: return (XMLLump) (endmap == null ? null : endmap.get(id));
081: }
082:
083: public void setFinal(String ID, XMLLump lump) {
084: if (endmap == null) {
085: endmap = new HashMap(8);
086: }
087: endmap.put(ID, lump);
088: }
089:
090: public boolean textEquals(String tocheck) {
091: return ArrayUtil.equals(tocheck, parent.buffer, start, length);
092: }
093:
094: public static String tagToText(String tagname) {
095: return "<" + tagname + " ";
096: }
097:
098: public static String textToTag(String text) {
099: return text.substring(1, text.length() - 1);
100: }
101:
102: public String getTag() {
103: return new String(parent.buffer, start + 1, length - 2);
104: }
105:
106: public String toDebugString() {
107: return "lump line " + line + " column " + column + " index "
108: + lumpindex;
109: }
110:
111: public String toString() {
112: return new String(parent.buffer, start, length)
113: + " at "
114: + toDebugString()
115: + (parent.fullpath == null ? "" : " in file "
116: + parent.fullpath);
117: }
118: }
|