* Implement macro comments as <% // ..... %>

* Display an error message for unhandled global macros
This commit is contained in:
hns 2005-01-25 16:43:08 +00:00
parent b3e46bd821
commit 771c13d82d

View file

@ -197,6 +197,8 @@ public final class Skin {
String defaultValue; String defaultValue;
int encoding = ENCODE_NONE; int encoding = ENCODE_NONE;
Map parameters = null; Map parameters = null;
// comment macros are silently dropped during rendering
boolean isCommentMacro = false;
public Macro(int start, int end) { public Macro(int start, int end) {
this.start = start; this.start = start;
@ -210,6 +212,19 @@ public final class Skin {
for (int i = start + 2; i < (end - 2); i++) { for (int i = start + 2; i < (end - 2); i++) {
switch (source[i]) { switch (source[i]) {
case '/':
b.append(source[i]);
escape = false;
if (state == HANDLER && "//".equals(b.toString())) {
isCommentMacro = true;
return;
}
break;
case '.': case '.':
if (state == HANDLER) { if (state == HANDLER) {
@ -218,6 +233,7 @@ public final class Skin {
state = MACRO; state = MACRO;
} else { } else {
b.append(source[i]); b.append(source[i]);
escape = false;
} }
break; break;
@ -283,6 +299,7 @@ public final class Skin {
state = PARAMNAME; state = PARAMNAME;
} else if (state == PARAMVALUE) { } else if (state == PARAMVALUE) {
b.append(source[i]); b.append(source[i]);
escape = false;
} else { } else {
b.setLength(0); b.setLength(0);
} }
@ -297,6 +314,7 @@ public final class Skin {
state = PARAMVALUE; state = PARAMVALUE;
} else { } else {
b.append(source[i]); b.append(source[i]);
escape = false;
} }
break; break;
@ -372,9 +390,12 @@ public final class Skin {
public void render(RequestEvaluator reval, Object thisObject, Map paramObject, public void render(RequestEvaluator reval, Object thisObject, Map paramObject,
Map handlerCache) Map handlerCache)
throws RedirectException, UnsupportedEncodingException { throws RedirectException, UnsupportedEncodingException {
if ((sandbox != null) && !sandbox.contains(fullName)) { // immediately return for comment macros
//String h = (handler == null) ? "global" : handler; if (isCommentMacro) {
return;
}
if ((sandbox != null) && !sandbox.contains(fullName)) {
reval.res.write("[Macro " + fullName + " not allowed in sandbox]"); reval.res.write("[Macro " + fullName + " not allowed in sandbox]");
return; return;
@ -518,16 +539,24 @@ public final class Skin {
writeResponse(value, buffer, false); writeResponse(value, buffer, false);
} }
} else { } else {
// System.err.println ("Getting macro from property"); // for unhandled global macros display error message,
Object value = reval.scriptingEngine.get(handlerObject, name); // otherwise try property lookup
if (handlerObject == null) {
String msg = "[Macro unhandled: " + fullName + "]";
reval.res.write(" " + msg + " ");
app.logEvent(msg);
writeResponse(value, reval.res.getBuffer(), true); } else {
Object value = reval.scriptingEngine.get(handlerObject, name);
writeResponse(value, reval.res.getBuffer(), true);
}
} }
} else {
String msg = "[HopMacro unhandled: " + fullName + "]";
} else {
String msg = "[Macro unhandled: " + fullName + "]";
reval.res.write(" " + msg + " "); reval.res.write(" " + msg + " ");
app.logEvent(msg); app.logEvent(msg);
} }
} catch (RedirectException redir) { } catch (RedirectException redir) {
throw redir; throw redir;