You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2006/02/10 19:14:09 UTC
svn commit: r376784 - in
/struts/el/trunk/src/test/org/apache/strutsel/taglib/utils: DOMHelper.java
HashMapMessageResources.java JspTagTestCase.java TestFormBean.java
TestHelper.java
Author: husted
Date: Fri Feb 10 10:14:06 2006
New Revision: 376784
URL: http://svn.apache.org/viewcvs?rev=376784&view=rev
Log:
Checkstyle Roundup
* EL package reformatted with latest Jalopy settings. Stylistic changes only.
Modified:
struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/DOMHelper.java
struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/HashMapMessageResources.java
struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/JspTagTestCase.java
struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestFormBean.java
struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestHelper.java
Modified: struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/DOMHelper.java
URL: http://svn.apache.org/viewcvs/struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/DOMHelper.java?rev=376784&r1=376783&r2=376784&view=diff
==============================================================================
--- struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/DOMHelper.java (original)
+++ struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/DOMHelper.java Fri Feb 10 10:14:06 2006
@@ -1,28 +1,22 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.strutsel.taglib.utils;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.xml.transform.TransformerException;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xpath.CachedXPathAPI;
@@ -32,23 +26,24 @@
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
+import javax.xml.transform.TransformerException;
-public class DOMHelper {
-
- protected static final String spaces = " ";
+import java.util.Iterator;
+import java.util.Map;
+public class DOMHelper {
+ protected static final String spaces =
+ " ";
private static Log log = LogFactory.getLog(DOMHelper.class);
- public static String getNodeText(org.w3c.dom.Document document,
- String xpath)
- throws TransformerException {
-
+ public static String getNodeText(org.w3c.dom.Document document, String xpath)
+ throws TransformerException {
String result = null;
if (!xpath.endsWith("text()")) {
-
- if (!xpath.endsWith("/"))
+ if (!xpath.endsWith("/")) {
xpath += "/";
+ }
xpath += "text()";
}
@@ -56,66 +51,58 @@
CachedXPathAPI xpathAPI = new CachedXPathAPI();
Node foundNode = xpathAPI.selectSingleNode(document, xpath);
- if (foundNode == null)
+ if (foundNode == null) {
result = "";
- else if (foundNode.getNodeType() == Node.TEXT_NODE)
- result = ((Text)foundNode).getData();
+ } else if (foundNode.getNodeType() == Node.TEXT_NODE) {
+ result = ((Text) foundNode).getData();
+ }
return (result);
}
- public static void recordFoundAttributes(org.w3c.dom.Document document,
- String xpath, Map map)
- throws TransformerException {
-
+ public static void recordFoundAttributes(org.w3c.dom.Document document,
+ String xpath, Map map)
+ throws TransformerException {
CachedXPathAPI xpathAPI = new CachedXPathAPI();
- Node foundNode = xpathAPI.selectSingleNode(document.getDocumentElement(),
- xpath);
+ Node foundNode =
+ xpathAPI.selectSingleNode(document.getDocumentElement(), xpath);
if (foundNode != null) {
-
NamedNodeMap attrMap = foundNode.getAttributes();
for (int ctr = 0; ctr < attrMap.getLength(); ++ctr) {
+ Attr attrNode = (Attr) attrMap.item(ctr);
- Attr attrNode = (Attr)attrMap.item(ctr);
map.put(attrNode.getName(), attrNode.getValue());
}
}
}
- public static boolean verifyAttributesPresent(Map attrMap,
- String[] attrNames,
- boolean allowOthers)
- throws Exception {
-
+ public static boolean verifyAttributesPresent(Map attrMap,
+ String[] attrNames, boolean allowOthers)
+ throws Exception {
boolean result = true;
if (attrNames != null) {
-
// First see if all of the expected attributes were actually found.
for (int ctr = 0; ctr < attrNames.length; ++ctr) {
-
if (attrMap.get(attrNames[ctr]) == null) {
result = false;
- throw new Exception("Expected attribute \"" +
- attrNames[ctr] +
- "\" was not found in the generated tag.");
+ throw new Exception("Expected attribute \""
+ + attrNames[ctr]
+ + "\" was not found in the generated tag.");
}
}
// Now, if no "extra" attributes are allowed, verify that all the
// attributes that were found were expected.
if (!allowOthers) {
-
for (Iterator iter = attrMap.keySet().iterator();
- iter.hasNext();) {
-
- String key = (String)iter.next();
+ iter.hasNext();) {
+ String key = (String) iter.next();
boolean found = false;
for (int ctr = 0; ctr < attrNames.length; ++ctr) {
-
if (key.equals(attrNames[ctr])) {
found = true;
@@ -124,10 +111,9 @@
}
if (!found) {
- throw new Exception("Attribute \"" + key +
- "\" was not " +
- "an expected attribute in the " +
- "generated tag.");
+ throw new Exception("Attribute \"" + key
+ + "\" was not " + "an expected attribute in the "
+ + "generated tag.");
}
}
}
@@ -136,16 +122,12 @@
return (result);
}
- public static boolean verifyAttributesNotPresent(Map attrMap,
- String[] attrNames)
- throws Exception {
-
+ public static boolean verifyAttributesNotPresent(Map attrMap,
+ String[] attrNames) throws Exception {
boolean result = true;
if (attrNames != null) {
-
for (int ctr = 0; ctr < attrNames.length; ++ctr) {
-
if (attrMap.get(attrNames[ctr]) != null) {
result = false;
@@ -165,53 +147,55 @@
}
public static void printNode(Node node, int level) {
-
- if (node == null)
+ if (node == null) {
return;
+ }
String nodeName = node.getNodeName();
NodeList children = node.getChildNodes();
if (children != null) {
-
short nodeType = node.getNodeType();
if (nodeType == Node.TEXT_NODE) {
+ String text = ((Text) node).getData();
- String text = ((Text)node).getData();
System.out.print(text);
} else {
System.out.print(spaces.substring(0, level) + "<" + nodeName);
- NamedNodeMap nodeMap = node.getAttributes();
+ NamedNodeMap nodeMap = node.getAttributes();
+
if (nodeMap.getLength() > 0) {
StringBuffer sb = new StringBuffer();
- for (int ctr = 0; ctr < nodeMap.getLength(); ++ ctr) {
- Attr attrnode = (Attr) nodeMap.item(ctr);
- String name = attrnode.getName();
- String value = attrnode.getValue();
+ for (int ctr = 0; ctr < nodeMap.getLength(); ++ctr) {
+ Attr attrnode = (Attr) nodeMap.item(ctr);
+ String name = attrnode.getName();
+ String value = attrnode.getValue();
sb.append(" " + name + "=\"" + value + "\"");
}
System.out.print(sb.toString());
}
-
+
System.out.println(">");
}
-
- for (int ctr = 0; ctr < children.getLength(); ++ctr) {
+ for (int ctr = 0; ctr < children.getLength(); ++ctr) {
Node child = children.item(ctr);
+
printNode(child, level + 1);
}
- if (nodeType != Node.TEXT_NODE)
- System.out.println(
- spaces.substring(0, level) + "</" + nodeName + ">");
- } else
- System.out.println(
- spaces.substring(0, level) + "<" + nodeName + "/>");
+ if (nodeType != Node.TEXT_NODE) {
+ System.out.println(spaces.substring(0, level) + "</" + nodeName
+ + ">");
+ }
+ } else {
+ System.out.println(spaces.substring(0, level) + "<" + nodeName
+ + "/>");
+ }
}
}
Modified: struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/HashMapMessageResources.java
URL: http://svn.apache.org/viewcvs/struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/HashMapMessageResources.java?rev=376784&r1=376783&r2=376784&view=diff
==============================================================================
--- struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/HashMapMessageResources.java (original)
+++ struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/HashMapMessageResources.java Fri Feb 10 10:14:06 2006
@@ -1,47 +1,43 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.strutsel.taglib.utils;
-import java.util.HashMap;
-import java.util.Locale;
-
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.MessageResourcesFactory;
+import java.util.HashMap;
+import java.util.Locale;
/**
* This is a simple derived class of <code>MessageResources</code> which is
- * just used for testing custom tags which use the
- * <code>MessageResources</code> class.
+ * just used for testing custom tags which use the <code>MessageResources</code>
+ * class.
*/
-public class HashMapMessageResources
- extends MessageResources {
-
+public class HashMapMessageResources extends MessageResources {
private HashMap messages = new HashMap();
- public HashMapMessageResources(MessageResourcesFactory factory,
- String config) {
+ public HashMapMessageResources(MessageResourcesFactory factory,
+ String config) {
super(factory, config);
}
- public HashMapMessageResources(MessageResourcesFactory factory,
- String config, boolean returnNull) {
+ public HashMapMessageResources(MessageResourcesFactory factory,
+ String config, boolean returnNull) {
super(factory, config, returnNull);
}
@@ -54,18 +50,17 @@
}
/**
- * Returns a text message for the specified key, for the specified locale.
- * If no result is found for the given locale, the locale is "trimmed" off
- * the end of more specific locale modifiers to check for a match. If no
- * match is found with the trimmed locale, the current "default" locale is
- * checked, if it is different from the given locale. If still no match is
- * found, an empty locale specifier is used.
- *
- * This method is copied directly from the
- * <code>PropertyMessageResources</code> class.
- */
+ * Returns a text message for the specified key, for the specified locale.
+ * If no result is found for the given locale, the locale is "trimmed" off
+ * the end of more specific locale modifiers to check for a match. If no
+ * match is found with the trimmed locale, the current "default" locale is
+ * checked, if it is different from the given locale. If still no match
+ * is found, an empty locale specifier is used.
+ *
+ * This method is copied directly from the <code>PropertyMessageResources</code>
+ * class.
+ */
public String getMessage(Locale locale, String key) {
-
// Initialize variables we will require
String localeKey = localeKey(locale);
String originalKey = messageKey(localeKey, key);
@@ -76,7 +71,6 @@
// Loop from specific to general Locales looking for this message
while (true) {
-
// Load this Locale's messages if we have not done so yet
loadLocale(localeKey);
@@ -84,10 +78,13 @@
messageKey = messageKey(localeKey, key);
synchronized (messages) {
- message = (String)messages.get(messageKey);
+ message = (String) messages.get(messageKey);
+
if (message != null) {
- if (addIt)
+ if (addIt) {
messages.put(originalKey, message);
+ }
+
return (message);
}
}
@@ -96,9 +93,9 @@
addIt = true;
underscore = localeKey.lastIndexOf("_");
- if (underscore < 0)
-
+ if (underscore < 0) {
break;
+ }
localeKey = localeKey.substring(0, underscore);
}
@@ -110,10 +107,13 @@
loadLocale(localeKey);
synchronized (messages) {
- message = (String)messages.get(messageKey);
+ message = (String) messages.get(messageKey);
+
if (message != null) {
- if (addIt)
+ if (addIt) {
messages.put(originalKey, message);
+ }
+
return (message);
}
}
@@ -125,20 +125,23 @@
loadLocale(localeKey);
synchronized (messages) {
- message = (String)messages.get(messageKey);
+ message = (String) messages.get(messageKey);
if (message != null) {
- if (addIt)
+ if (addIt) {
messages.put(originalKey, message);
+ }
+
return (message);
}
}
// Return an appropriate error indication
- if (returnNull)
+ if (returnNull) {
return (null);
- else
+ } else {
return ("???" + messageKey(locale, key) + "???");
+ }
}
protected void loadLocale(String localeKey) {
Modified: struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/JspTagTestCase.java
URL: http://svn.apache.org/viewcvs/struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/JspTagTestCase.java?rev=376784&r1=376783&r2=376784&view=diff
==============================================================================
--- struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/JspTagTestCase.java (original)
+++ struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/JspTagTestCase.java Fri Feb 10 10:14:06 2006
@@ -1,46 +1,41 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.strutsel.taglib.utils;
-import java.util.HashMap;
import org.apache.cactus.JspTestCase;
-public class JspTagTestCase extends JspTestCase
-{
+import java.util.HashMap;
+
+public class JspTagTestCase extends JspTestCase {
public JspTagTestCase(String theName) {
super(theName);
}
- protected void
- checkAttrValue(HashMap attrMap,
- com.meterware.httpunit.WebResponse testResponse,
- String headerKey,
- String tagName,
- String attrName)
- {
- String attrValue = (String)attrMap.get(attrName);
+ protected void checkAttrValue(HashMap attrMap,
+ com.meterware.httpunit.WebResponse testResponse, String headerKey,
+ String tagName, String attrName) {
+ String attrValue = (String) attrMap.get(attrName);
String requiredAttrValue =
- (String)testResponse.getHeaderField(headerKey);
+ (String) testResponse.getHeaderField(headerKey);
if (!attrValue.equals(requiredAttrValue)) {
fail(TestHelper.getAttrErrMess(tagName, attrName,
- requiredAttrValue, attrValue));
+ requiredAttrValue, attrValue));
}
}
}
Modified: struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestFormBean.java
URL: http://svn.apache.org/viewcvs/struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestFormBean.java?rev=376784&r1=376783&r2=376784&view=diff
==============================================================================
--- struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestFormBean.java (original)
+++ struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestFormBean.java Fri Feb 10 10:14:06 2006
@@ -1,35 +1,41 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.strutsel.taglib.utils;
import org.apache.struts.action.ActionForm;
-public class TestFormBean extends ActionForm
-{
- private String stringProperty;
+public class TestFormBean extends ActionForm {
+ private String stringProperty;
private Object[] arrayProperty;
- public String getStringProperty() { return (stringProperty); }
- public void setStringProperty(String stringProperty)
- { this.stringProperty = stringProperty; }
-
- public Object[] getArrayProperty() { return (arrayProperty); }
- public void setArrayProperty(Object[] arrayProperty)
- { this.arrayProperty = arrayProperty; }
+ public String getStringProperty() {
+ return (stringProperty);
+ }
+
+ public void setStringProperty(String stringProperty) {
+ this.stringProperty = stringProperty;
+ }
+
+ public Object[] getArrayProperty() {
+ return (arrayProperty);
+ }
+
+ public void setArrayProperty(Object[] arrayProperty) {
+ this.arrayProperty = arrayProperty;
+ }
}
Modified: struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestHelper.java
URL: http://svn.apache.org/viewcvs/struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestHelper.java?rev=376784&r1=376783&r2=376784&view=diff
==============================================================================
--- struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestHelper.java (original)
+++ struts/el/trunk/src/test/org/apache/strutsel/taglib/utils/TestHelper.java Fri Feb 10 10:14:06 2006
@@ -1,44 +1,40 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.strutsel.taglib.utils;
-import java.io.IOException;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.io.IOException;
public class TestHelper {
private static Log log = LogFactory.getLog(TestHelper.class);
- public static void printResponse(com.meterware.httpunit.WebResponse testResponse)
- throws IOException {
+ public static void printResponse(
+ com.meterware.httpunit.WebResponse testResponse)
+ throws IOException {
log.debug("response text[" + testResponse.getText() + "]");
}
- public static String getAttrErrMess(String tagName,
- String attrName,
- String requiredValue,
- String actualValue)
- {
- return ("The <" + tagName + "> \"" + attrName + "\" attribute " +
- "should have had value \"" + requiredValue + "\", but it " +
- "instead had value \"" + actualValue + "\".");
+ public static String getAttrErrMess(String tagName, String attrName,
+ String requiredValue, String actualValue) {
+ return ("The <" + tagName + "> \"" + attrName + "\" attribute "
+ + "should have had value \"" + requiredValue + "\", but it "
+ + "instead had value \"" + actualValue + "\".");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org