src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java

Tue, 20 Aug 2013 14:55:20 -0700

author
jjg
date
Tue, 20 Aug 2013 14:55:20 -0700
changeset 1964
79e341614c50
parent 1751
ca8808c88f94
child 2116
bf6b11347b1a
permissions
-rw-r--r--

8022080: javadoc generates invalid HTML in Turkish locale
Reviewed-by: bpatel

jjg@1736 1 /*
jjg@1736 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
jjg@1736 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@1736 4 *
jjg@1736 5 * This code is free software; you can redistribute it and/or modify it
jjg@1736 6 * under the terms of the GNU General Public License version 2 only, as
jjg@1736 7 * published by the Free Software Foundation. Oracle designates this
jjg@1736 8 * particular file as subject to the "Classpath" exception as provided
jjg@1736 9 * by Oracle in the LICENSE file that accompanied this code.
jjg@1736 10 *
jjg@1736 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@1736 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@1736 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@1736 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@1736 15 * accompanied this code).
jjg@1736 16 *
jjg@1736 17 * You should have received a copy of the GNU General Public License version
jjg@1736 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@1736 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@1736 20 *
jjg@1736 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@1736 22 * or visit www.oracle.com if you need additional information or have any
jjg@1736 23 * questions.
jjg@1736 24 */
jjg@1736 25
jjg@1736 26 package com.sun.tools.doclets.formats.html.markup;
jjg@1736 27
jjg@1736 28 import java.io.IOException;
jjg@1736 29 import java.io.Writer;
jjg@1736 30 import java.util.ArrayList;
jjg@1736 31 import java.util.Collections;
jjg@1736 32 import java.util.List;
jjg@1736 33 import com.sun.tools.doclets.internal.toolkit.Content;
jjg@1736 34
jjg@1736 35 /**
jjg@1736 36 * A sequence of Content nodes.
jjg@1736 37 */
jjg@1736 38 public class ContentBuilder extends Content {
jjg@1736 39 protected List<Content> contents = Collections.<Content>emptyList();
jjg@1736 40
jjg@1736 41 @Override
jjg@1736 42 public void addContent(Content content) {
jjg@1751 43 nullCheck(content);
jjg@1739 44 if ((content instanceof ContentBuilder) && content.isEmpty())
jjg@1736 45 return;
jjg@1736 46 ensureMutableContents();
jjg@1736 47 if (content instanceof ContentBuilder) {
jjg@1736 48 contents.addAll(((ContentBuilder) content).contents);
jjg@1736 49 } else
jjg@1736 50 contents.add(content);
jjg@1736 51 }
jjg@1736 52
jjg@1736 53 @Override
jjg@1736 54 public void addContent(String text) {
jjg@1736 55 if (text.isEmpty())
jjg@1736 56 return;
jjg@1736 57 ensureMutableContents();
jjg@1736 58 Content c = contents.isEmpty() ? null : contents.get(contents.size() - 1);
jjg@1736 59 StringContent sc;
jjg@1736 60 if (c != null && c instanceof StringContent) {
jjg@1736 61 sc = (StringContent) c;
jjg@1736 62 } else {
jjg@1736 63 contents.add(sc = new StringContent());
jjg@1736 64 }
jjg@1736 65 sc.addContent(text);
jjg@1736 66 }
jjg@1736 67
jjg@1736 68 @Override
jjg@1736 69 public boolean write(Writer writer, boolean atNewline) throws IOException {
jjg@1736 70 for (Content content: contents) {
jjg@1736 71 atNewline = content.write(writer, atNewline);
jjg@1736 72 }
jjg@1736 73 return atNewline;
jjg@1736 74 }
jjg@1736 75
jjg@1736 76 @Override
jjg@1736 77 public boolean isEmpty() {
jjg@1736 78 for (Content content: contents) {
jjg@1736 79 if (!content.isEmpty())
jjg@1736 80 return false;
jjg@1736 81 }
jjg@1736 82 return true;
jjg@1736 83 }
jjg@1736 84
jjg@1740 85 @Override
jjg@1737 86 public int charCount() {
jjg@1737 87 int n = 0;
jjg@1737 88 for (Content c : contents)
jjg@1737 89 n += c.charCount();
jjg@1737 90 return n;
jjg@1737 91 }
jjg@1737 92
jjg@1736 93 private void ensureMutableContents() {
jjg@1736 94 if (contents.isEmpty())
jjg@1736 95 contents = new ArrayList<Content>();
jjg@1736 96 }
jjg@1736 97 }

mercurial