Author: rdonkin
Date: Sat Dec 7 11:35:16 2013
New Revision: 1548892
URL: http://svn.apache.org/r1548892
Log:
Apply PMD Rules.
Modified:
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/impl/base/XmlWriter.java
Modified:
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/impl/base/XmlWriter.java
URL:
http://svn.apache.org/viewvc/creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/impl/base/XmlWriter.java?rev=1548892&r1=1548891&r2=1548892&view=diff
==============================================================================
---
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/impl/base/XmlWriter.java
(original)
+++
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/impl/base/XmlWriter.java
Sat Dec 7 11:35:16 2013
@@ -42,6 +42,9 @@ import org.apache.rat.report.xml.writer.
*/
public final class XmlWriter implements IXmlWriter {
+ /** The Constant CHARACTER_CODES. */
+ private final static byte[] CHARACTER_CODES = new byte[1 << 16];
+
/** The Constant NAME_START_MASK. */
private static final byte NAME_START_MASK = 1 << 1;
@@ -58,6 +61,32 @@ public final class XmlWriter implements
/** The Constant ALLOWED_CHARACTERS. */
private final static boolean[] ALLOWED_CHARACTERS = new boolean[1 <<
16];
+ private static final char AMPERSAND = '&';
+
+ private static final char MINOR = '<';
+
+ private static final char MAYOR = '>';
+
+ private static final int ZERO = 0;
+
+ /** The elements written. */
+ private boolean elementsWritten;
+
+ /** The writer. */
+ private final Writer writer;
+
+ /** The element names. */
+ private final ArrayStack elementNames;
+
+ /** The current attributes. */
+ private final Set<CharSequence> currentAttributes = new
HashSet<CharSequence>();
+
+ /** The in element. */
+ private boolean inElement;
+
+ /** The prolog written. */
+ private boolean prologWritten;
+
static {
Arrays.fill(ALLOWED_CHARACTERS, false);
ALLOWED_CHARACTERS[0x9] = true;
@@ -67,9 +96,6 @@ public final class XmlWriter implements
Arrays.fill(ALLOWED_CHARACTERS, 0xE000, 0xFFFD, true);
}
- /** The Constant CHARACTER_CODES. */
- private final static byte[] CHARACTER_CODES = new byte[1 << 16];
-
static {
// Name ::= (Letter | '_' | ':') (NameChar)*
CHARACTER_CODES['_'] = NAME_START_OR_BODY_CHAR;
@@ -413,24 +439,6 @@ public final class XmlWriter implements
}
- /** The writer. */
- private final Writer writer;
-
- /** The element names. */
- private final ArrayStack elementNames;
-
- /** The current attributes. */
- private final Set<CharSequence> currentAttributes = new
HashSet<CharSequence>();
-
- /** The elements written. */
- boolean elementsWritten = false;
-
- /** The in element. */
- boolean inElement = false;
-
- /** The prolog written. */
- boolean prologWritten = false;
-
/**
* Instantiates a new xml writer.
*
@@ -507,7 +515,8 @@ public final class XmlWriter implements
* {@link #closeElement()} or before any call to
* {@link #openElement(CharSequence)}
*/
- public IXmlWriter attribute(CharSequence name, CharSequence value)
+ public IXmlWriter attribute(final CharSequence name,
+ final CharSequence value)
throws IOException {
if (elementNames.isEmpty()) {
if (elementsWritten) {
@@ -548,7 +557,8 @@ public final class XmlWriter implements
* @throws IOException
* Signals that an I/O exception has occurred.
*/
- private void writeAttributeContent(CharSequence content) throws
IOException {
+ private void writeAttributeContent(final CharSequence content)
+ throws IOException {
writeEscaped(content, true);
}
@@ -562,7 +572,7 @@ public final class XmlWriter implements
* @throws IOException
* Signals that an I/O exception has occurred.
*/
- public IXmlWriter content(CharSequence content) throws IOException {
+ public IXmlWriter content(final CharSequence content) throws
IOException {
if (elementNames.isEmpty()) {
if (elementsWritten) {
throw new OperationNotAllowedException(
@@ -604,15 +614,15 @@ public final class XmlWriter implements
* Signals that an I/O exception has occurred.
*/
private void writeEscaped(final CharSequence content,
- boolean isAttributeContent) throws IOException {
+ final boolean isAttributeContent) throws IOException {
final int length = content.length();
for (int i = 0; i < length; i++) {
char character = content.charAt(i);
- if (character == '&') {
+ if (character == AMPERSAND) {
writer.write("&");
- } else if (character == '<') {
+ } else if (character == MINOR) {
writer.write("<");
- } else if (character == '>') {
+ } else if (character == MAYOR) {
writer.write(">");
} else if (isAttributeContent && character == '\'') {
writer.write("'");
@@ -634,8 +644,7 @@ public final class XmlWriter implements
* @return true, if is out of range
*/
private boolean isOutOfRange(final char character) {
- final boolean result = !ALLOWED_CHARACTERS[character];
- return result;
+ return !ALLOWED_CHARACTERS[character];
}
/**
@@ -680,11 +689,9 @@ public final class XmlWriter implements
* Signals that an I/O exception has occurred.
*/
public IXmlWriter closeDocument() throws IOException {
- if (elementNames.isEmpty()) {
- if (!elementsWritten) {
- throw new OperationNotAllowedException(
- "Close called before an element
has been opened.");
- }
+ if (elementNames.isEmpty() && !elementsWritten) {
+ throw new OperationNotAllowedException(
+ "Close called before an element has
been opened.");
}
while (!elementNames.isEmpty()) {
closeElement();
@@ -720,7 +727,7 @@ public final class XmlWriter implements
final int length = sequence.length();
for (int i = 0; i < length; i++) {
char character = sequence.charAt(i);
- if (i == 0) {
+ if (i == ZERO) {
if (!isValidNameStart(character)) {
result = false;
break;
@@ -744,8 +751,7 @@ public final class XmlWriter implements
*/
private boolean isValidNameStart(final char character) {
final byte code = CHARACTER_CODES[character];
- final boolean result = (code & NAME_START_MASK) > 0;
- return result;
+ return (code & NAME_START_MASK) > 0;
}
/**
@@ -757,7 +763,6 @@ public final class XmlWriter implements
*/
private boolean isValidNameBody(final char character) {
final byte code = CHARACTER_CODES[character];
- final boolean result = (code & NAME_MASK) > 0;
- return result;
+ return (code & NAME_MASK) > 0;
}
}