Tue, 14 May 2013 10:14:52 -0700
8011642: Remove LinkOutput in favor of direct use of Content
Reviewed-by: bpatel, darcy
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@1736 | 43 | if (content.isEmpty()) |
jjg@1736 | 44 | return; |
jjg@1736 | 45 | ensureMutableContents(); |
jjg@1736 | 46 | if (content instanceof ContentBuilder) { |
jjg@1736 | 47 | contents.addAll(((ContentBuilder) content).contents); |
jjg@1736 | 48 | } else |
jjg@1736 | 49 | contents.add(content); |
jjg@1736 | 50 | } |
jjg@1736 | 51 | |
jjg@1736 | 52 | @Override |
jjg@1736 | 53 | public void addContent(String text) { |
jjg@1736 | 54 | if (text.isEmpty()) |
jjg@1736 | 55 | return; |
jjg@1736 | 56 | ensureMutableContents(); |
jjg@1736 | 57 | Content c = contents.isEmpty() ? null : contents.get(contents.size() - 1); |
jjg@1736 | 58 | StringContent sc; |
jjg@1736 | 59 | if (c != null && c instanceof StringContent) { |
jjg@1736 | 60 | sc = (StringContent) c; |
jjg@1736 | 61 | } else { |
jjg@1736 | 62 | contents.add(sc = new StringContent()); |
jjg@1736 | 63 | } |
jjg@1736 | 64 | sc.addContent(text); |
jjg@1736 | 65 | } |
jjg@1736 | 66 | |
jjg@1736 | 67 | @Override |
jjg@1736 | 68 | public boolean write(Writer writer, boolean atNewline) throws IOException { |
jjg@1736 | 69 | for (Content content: contents) { |
jjg@1736 | 70 | atNewline = content.write(writer, atNewline); |
jjg@1736 | 71 | } |
jjg@1736 | 72 | return atNewline; |
jjg@1736 | 73 | } |
jjg@1736 | 74 | |
jjg@1736 | 75 | @Override |
jjg@1736 | 76 | public boolean isEmpty() { |
jjg@1736 | 77 | for (Content content: contents) { |
jjg@1736 | 78 | if (!content.isEmpty()) |
jjg@1736 | 79 | return false; |
jjg@1736 | 80 | } |
jjg@1736 | 81 | return true; |
jjg@1736 | 82 | } |
jjg@1736 | 83 | |
jjg@1736 | 84 | private void ensureMutableContents() { |
jjg@1736 | 85 | if (contents.isEmpty()) |
jjg@1736 | 86 | contents = new ArrayList<Content>(); |
jjg@1736 | 87 | } |
jjg@1736 | 88 | } |