001: /*
002: * Helma License Notice
003: *
004: * The contents of this file are subject to the Helma License
005: * Version 2.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://adele.helma.org/download/helma/license.txt
008: *
009: * Copyright 1998-2003 Helma Software. All Rights Reserved.
010: *
011: * $RCSfile$
012: * $Author: root $
013: * $Revision: 8604 $
014: * $Date: 2007-09-28 15:16:38 +0200 (Fre, 28 Sep 2007) $
015: */
016:
017: package helma.doc;
018:
019: import helma.framework.repository.Resource;
020:
021: import java.util.*;
022: import java.io.IOException;
023:
024: /**
025: *
026: */
027: public class DocSkin extends DocResourceElement {
028:
029: protected DocSkin(String name, Resource res, DocElement parent)
030: throws IOException {
031: super (name, res, SKIN);
032: this .parent = parent;
033: content = res.getContent();
034: parseHandlers();
035: }
036:
037: /**
038: * creates a new independent DocSkin object
039: */
040: public static DocSkin newInstance(Resource res) throws IOException {
041: return newInstance(res, null);
042: }
043:
044: /**
045: * creates a new DocSkin object connected to another DocElement
046: */
047: public static DocSkin newInstance(Resource res, DocElement parent)
048: throws IOException {
049: String skinname = res.getBaseName();
050: return new DocSkin(skinname, res, parent);
051: }
052:
053: /**
054: * parses the source code of the skin and
055: * extracts all included macros. code taken
056: * from helma.framework.core.Skin
057: * @see helma.framework.core.Skin
058: */
059: private void parseHandlers() {
060: ArrayList partBuffer = new ArrayList();
061: char[] source = content.toCharArray();
062: int sourceLength = source.length;
063:
064: for (int i = 0; i < (sourceLength - 1); i++) {
065: if ((source[i] == '<') && (source[i + 1] == '%')) {
066: // found macro start tag
067: int j = i + 2;
068:
069: // search macro end tag
070: while ((j < (sourceLength - 1))
071: && ((source[j] != '%') || (source[j + 1] != '>'))) {
072: j++;
073: }
074:
075: if (j > (i + 2)) {
076: String str = (new String(source, i + 2, j - i))
077: .trim();
078:
079: if (str.endsWith("%>")) {
080: str = str.substring(0, str.length() - 2);
081: }
082:
083: if (str.startsWith("//")) {
084: parseComment(str);
085: } else {
086: if (str.indexOf(" ") > -1) {
087: str = str.substring(0, str.indexOf(" "));
088: }
089:
090: if ((str.indexOf(".") > -1)
091: && (str.startsWith("param.")
092: || str.startsWith("response.")
093: || str.startsWith("request.") || str
094: .startsWith("session."))
095: && !partBuffer.contains(str)) {
096: partBuffer.add(str);
097: }
098: }
099: }
100:
101: i = j + 1;
102: }
103: }
104:
105: String[] strArr = (String[]) partBuffer.toArray(new String[0]);
106:
107: Arrays.sort(strArr);
108:
109: for (int i = 0; i < strArr.length; i++) {
110: addParameter(strArr[i]);
111: }
112: }
113:
114: /**
115: * from helma.framework.IPathElement. Use the same prototype as functions etc.
116: */
117: public java.lang.String getPrototype() {
118: return "docfunction";
119: }
120: }
|