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: import helma.framework.core.Prototype;
021: import helma.util.ResourceProperties;
022:
023: import java.io.*;
024: import java.util.Iterator;
025:
026: /**
027: *
028: */
029: public class DocPrototype extends DocElement {
030:
031: DocPrototype parentPrototype = null;
032: Prototype proto;
033:
034: /**
035: * creates a prototype based on a prototype of the application
036: *
037: * @param proto
038: * @param parent
039: */
040: protected DocPrototype(Prototype proto, DocElement parent) {
041: super (proto.getName(), PROTOTYPE);
042: this .parent = parent;
043: this .proto = proto;
044: }
045:
046: /**
047: * checks the type.properites for _extend values and connected a possible
048: * parent prototype with this prototype. this can't be successfull at construction
049: * time but only -after- all prototypes are parsed and attached to a parent
050: * DocApplication object.
051: */
052: public void checkInheritance() {
053: // hopobject is the top prototype:
054: if (name.equals("hopobject")) {
055: return;
056: }
057:
058: // check for "_extends" in the the type.properties
059: String ext = proto.getTypeProperties().getProperty("_extends");
060:
061: if ((ext != null) && (parent != null)) {
062: // try to get the prototype if available
063: parentPrototype = (DocPrototype) parent
064: .getChildElement("prototype_" + ext);
065: }
066:
067: if ((parentPrototype == null) && (parent != null)
068: && !name.equals("global")) {
069: // if no _extend was set, get the hopobject prototype
070: parentPrototype = (DocPrototype) parent
071: .getChildElement("prototype_hopobject");
072: }
073: }
074:
075: /**
076: * Return this prototype's parent prototype
077: *
078: * @return this prototype's parent prototype
079: */
080: public DocPrototype getParentPrototype() {
081: return parentPrototype;
082: }
083:
084: /**
085: * runs through the prototype directory and parses all helma files
086: */
087: public void readFiles() throws IOException {
088: children.clear();
089:
090: Iterator it = proto.getCodeResources();
091:
092: while (it.hasNext()) {
093: Resource res = (Resource) it.next();
094:
095: String name = res.getShortName();
096: if (getDocApplication().isExcluded(name)) {
097: continue;
098: }
099:
100: try {
101: if (name.endsWith(".hac")) {
102: addChild(DocFunction.newAction(res, this ));
103: } else if (name.endsWith(".js")) {
104: DocElement[] elements = DocFunction.newFunctions(
105: res, this );
106:
107: for (int j = 0; j < elements.length; j++) {
108: addChild(elements[j]);
109: }
110: }
111: } catch (Throwable err) {
112: proto.getApplication().logError(
113: "Couldn't parse file " + res, err);
114: }
115: }
116:
117: it = proto.getSkinResources();
118:
119: while (it.hasNext()) {
120: Resource res = (Resource) it.next();
121:
122: String name = res.getShortName();
123: if (getDocApplication().isExcluded(name)) {
124: continue;
125: }
126:
127: addChild(DocSkin.newInstance(res, this ));
128: }
129:
130: ResourceProperties props = proto.getTypeProperties();
131: it = props.getResources();
132:
133: int index = 0;
134: while (it.hasNext()) {
135: Resource res = (Resource) it.next();
136: if (res.exists()) {
137: addChild(new DocProperties(res, props, index++, this));
138: }
139: }
140: }
141: }
|