Return-Path: X-Original-To: apmail-creadur-commits-archive@www.apache.org Delivered-To: apmail-creadur-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6728D1040A for ; Sat, 7 Dec 2013 11:35:50 +0000 (UTC) Received: (qmail 22458 invoked by uid 500); 7 Dec 2013 11:34:59 -0000 Delivered-To: apmail-creadur-commits-archive@creadur.apache.org Received: (qmail 22305 invoked by uid 500); 7 Dec 2013 11:34:58 -0000 Mailing-List: contact commits-help@creadur.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@creadur.apache.org Delivered-To: mailing list commits@creadur.apache.org Received: (qmail 22205 invoked by uid 99); 7 Dec 2013 11:34:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Dec 2013 11:34:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Dec 2013 11:34:49 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CE519238883D; Sat, 7 Dec 2013 11:34:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1548891 - /creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/report/xml/writer/impl/base/XmlWriter.java Date: Sat, 07 Dec 2013 11:34:27 -0000 To: commits@creadur.apache.org From: rdonkin@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131207113427.CE519238883D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rdonkin Date: Sat Dec 7 11:34:27 2013 New Revision: 1548891 URL: http://svn.apache.org/r1548891 Log: Add java doc. 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=1548891&r1=1548890&r2=1548891&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:34:27 2013 @@ -25,7 +25,6 @@ import java.util.HashSet; import java.util.Set; import org.apache.commons.collections.ArrayStack; - import org.apache.rat.report.xml.writer.IXmlWriter; import org.apache.rat.report.xml.writer.InvalidXmlException; import org.apache.rat.report.xml.writer.OperationNotAllowedException; @@ -43,12 +42,20 @@ import org.apache.rat.report.xml.writer. */ public final class XmlWriter implements IXmlWriter { + /** The Constant NAME_START_MASK. */ private static final byte NAME_START_MASK = 1 << 1; + + /** The Constant NAME_MASK. */ private static final byte NAME_MASK = 1 << 2; + + /** The Constant NAME_BODY_CHAR. */ private static final byte NAME_BODY_CHAR = NAME_MASK; + + /** The Constant NAME_START_OR_BODY_CHAR. */ private static final byte NAME_START_OR_BODY_CHAR = NAME_MASK | NAME_START_MASK; + /** The Constant ALLOWED_CHARACTERS. */ private final static boolean[] ALLOWED_CHARACTERS = new boolean[1 << 16]; static { @@ -60,6 +67,7 @@ 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 { @@ -405,14 +413,30 @@ public final class XmlWriter implements } + /** The writer. */ private final Writer writer; + + /** The element names. */ private final ArrayStack elementNames; + + /** The current attributes. */ private final Set currentAttributes = new HashSet(); + /** The elements written. */ boolean elementsWritten = false; + + /** The in element. */ boolean inElement = false; + + /** The prolog written. */ boolean prologWritten = false; + /** + * Instantiates a new xml writer. + * + * @param writer + * the writer + */ public XmlWriter(final Writer writer) { this.writer = writer; this.elementNames = new ArrayStack(); @@ -423,9 +447,8 @@ public final class XmlWriter implements * When writing a document fragment, it should not be called. * * @return this object - * @throws OperationNotAllowedException - * if called after the first element has been written or once a - * prolog has already been written + * @throws IOException + * Signals that an I/O exception has occurred. */ public IXmlWriter startDocument() throws IOException { if (elementsWritten) { @@ -445,10 +468,8 @@ public final class XmlWriter implements * @param elementName * the name of the element, not null * @return this object - * @throws InvalidXmlException - * if the name is not valid for an xml element - * @throws OperationNotAllowedException - * if called after the first element has been closed + * @throws IOException + * Signals that an I/O exception has occurred. */ public IXmlWriter openElement(final CharSequence elementName) throws IOException { @@ -481,11 +502,8 @@ public final class XmlWriter implements * @param value * the attribute value, not null * @return this object - * @throws InvalidXmlException - * if the name is not valid for an xml attribute or if a value - * for the attribute has already been written - * @throws OperationNotAllowedException - * if called after {@link #content(CharSequence)} or + * @throws IOException + * Signals that an I/O exception has occurred. * {@link #closeElement()} or before any call to * {@link #openElement(CharSequence)} */ @@ -522,6 +540,14 @@ public final class XmlWriter implements return this; } + /** + * Write attribute content. + * + * @param content + * the content + * @throws IOException + * Signals that an I/O exception has occurred. + */ private void writeAttributeContent(CharSequence content) throws IOException { writeEscaped(content, true); } @@ -533,9 +559,8 @@ public final class XmlWriter implements * @param content * the content to write * @return this object - * @throws OperationNotAllowedException - * if called before any call to {@link #openElement} or after - * the first element has been closed + * @throws IOException + * Signals that an I/O exception has occurred. */ public IXmlWriter content(CharSequence content) throws IOException { if (elementNames.isEmpty()) { @@ -555,11 +580,29 @@ public final class XmlWriter implements return this; } + /** + * Write body content. + * + * @param content + * the content + * @throws IOException + * Signals that an I/O exception has occurred. + */ private void writeBodyContent(final CharSequence content) throws IOException { writeEscaped(content, false); } + /** + * Write escaped. + * + * @param content + * the content + * @param isAttributeContent + * the is attribute content + * @throws IOException + * Signals that an I/O exception has occurred. + */ private void writeEscaped(final CharSequence content, boolean isAttributeContent) throws IOException { final int length = content.length(); @@ -583,6 +626,13 @@ public final class XmlWriter implements } } + /** + * Checks if is out of range. + * + * @param character + * the character + * @return true, if is out of range + */ private boolean isOutOfRange(final char character) { final boolean result = !ALLOWED_CHARACTERS[character]; return result; @@ -592,9 +642,8 @@ public final class XmlWriter implements * Closes the last element written. * * @return this object - * @throws OperationNotAllowedException - * if called before any call to {@link #openElement} or after - * the first element has been closed + * @throws IOException + * Signals that an I/O exception has occurred. */ public IXmlWriter closeElement() throws IOException { if (elementNames.isEmpty()) { @@ -627,8 +676,8 @@ public final class XmlWriter implements * element has already been closed. * * @return this object - * @throws OperationNotAllowedException - * if called before any call to {@link #openElement} + * @throws IOException + * Signals that an I/O exception has occurred. */ public IXmlWriter closeDocument() throws IOException { if (elementNames.isEmpty()) { @@ -644,6 +693,14 @@ public final class XmlWriter implements return this; } + /** + * Raw write. + * + * @param sequence + * the sequence + * @throws IOException + * Signals that an I/O exception has occurred. + */ private void rawWrite(final CharSequence sequence) throws IOException { for (int i = 0; i < sequence.length(); i++) { final char charAt = sequence.charAt(i); @@ -651,6 +708,13 @@ public final class XmlWriter implements } } + /** + * Checks if is valid name. + * + * @param sequence + * the sequence + * @return true, if is valid name + */ private boolean isValidName(final CharSequence sequence) { boolean result = true; final int length = sequence.length(); @@ -671,12 +735,26 @@ public final class XmlWriter implements return result; } + /** + * Checks if is valid name start. + * + * @param character + * the character + * @return true, if is valid name start + */ private boolean isValidNameStart(final char character) { final byte code = CHARACTER_CODES[character]; final boolean result = (code & NAME_START_MASK) > 0; return result; } + /** + * Checks if is valid name body. + * + * @param character + * the character + * @return true, if is valid name body + */ private boolean isValidNameBody(final char character) { final byte code = CHARACTER_CODES[character]; final boolean result = (code & NAME_MASK) > 0;