01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.test.web.framework.actions;
18:
19: import org.w3c.dom.Node;
20:
21: import edu.iu.uis.eden.test.web.framework.Property;
22: import edu.iu.uis.eden.test.web.framework.PropertyScheme;
23: import edu.iu.uis.eden.test.web.framework.Script;
24: import edu.iu.uis.eden.test.web.framework.Util;
25:
26: /**
27: * ScriptAction that echos a property or literal text to console
28: * <pre>
29: * <echo [ value="..." | variable="..." | literal="..." | resource="..." | url="..." ] />
30: * <echo>...</echo>
31: * </pre>
32: * The 'value' attribute is resolved via {@link edu.iu.uis.eden.test.web.framework.Util#getResolvableAttribute(Node, String, PropertyScheme)},
33: * defaulting to literal scheme.
34: * If a value variant is not present, the algorithm proceeds again without a specific prefix (i.e., just looks for variable, literal, etc.).
35: * @author Aaron Hamid (arh14 at cornell dot edu)
36: */
37: public class EchoAction extends BaseScriptAction {
38: private static final String[] NAMES = { "echo" };
39:
40: public String[] getNames() {
41: return NAMES;
42: }
43:
44: public void process(Script script, Node node) {
45: /* first try looking for the attribute "value" */
46: Property property = Util.getResolvableAttribute(node, "value",
47: PropertyScheme.LITERAL_SCHEME);
48: /* if not found, fall back to looking for any of the property scheme types: literal, variable, resource, url, etc. */
49: property = Util.getResolvableAttribute(node, null, null);
50: if (property == null) {
51: String text = Util.getContent(node);
52: if (text == null) {
53: //String message = "echo element has no text content: " + XmlHelper.jotNode(node);
54: //log.error(message);
55: //throw new RuntimeException(message);
56: text = "";
57: }
58: log.info(text);
59: } else {
60: Object o = script.getState().retrieveProperty(property);
61: if (o == null) {
62: String message = "Could not load value property: "
63: + property;
64: log.error(message);
65: throw new RuntimeException(message);
66: } else {
67: if (!PropertyScheme.LITERAL_SCHEME.getName().equals(
68: property.scheme)
69: && !PropertyScheme.LITERAL_SCHEME
70: .getShortName().equals(property.scheme)) {
71: /* if it's not a literal, print out the locator as well */
72: log.info(property.locator + ": " + o);
73: } else {
74: log.info(o);
75: }
76:
77: }
78: }
79: }
80: }
|