| 1 | /*
|
|---|
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright 2008 jOpenDocument, by ILM Informatique. All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * The contents of this file are subject to the terms of the GNU
|
|---|
| 7 | * General Public License Version 3 only ("GPL").
|
|---|
| 8 | * You may not use this file except in compliance with the License.
|
|---|
| 9 | * You can obtain a copy of the License at http://www.gnu.org/licenses/gpl-3.0.html
|
|---|
| 10 | * See the License for the specific language governing permissions and limitations under the License.
|
|---|
| 11 | *
|
|---|
| 12 | * When distributing the software, include this License Header Notice in each file.
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | package org.jopendocument.dom;
|
|---|
| 17 |
|
|---|
| 18 | import java.util.HashSet;
|
|---|
| 19 | import java.util.Set;
|
|---|
| 20 |
|
|---|
| 21 | import org.jdom2.Document;
|
|---|
| 22 | import org.jdom2.Element;
|
|---|
| 23 |
|
|---|
| 24 | public class ImmutableDocStyledNode<S extends StyleStyle, D extends ODDocument> extends StyledNode<S, D> {
|
|---|
| 25 |
|
|---|
| 26 | private static final Set<Document> getDocuments(final ODPackage pkg) {
|
|---|
| 27 | final Set<Document> res = new HashSet<>();
|
|---|
| 28 | for (final String entry : pkg.getEntries()) {
|
|---|
| 29 | final ODPackageEntry e = pkg.getEntry(entry);
|
|---|
| 30 | if (e.getData() instanceof ODXMLDocument)
|
|---|
| 31 | res.add(pkg.getDocument(entry));
|
|---|
| 32 | }
|
|---|
| 33 | return res;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | private final D parent;
|
|---|
| 37 |
|
|---|
| 38 | /**
|
|---|
| 39 | * Create a new instance. We used to find the {@link StyleStyle} class with reflection but this
|
|---|
| 40 | * was slow.
|
|---|
| 41 | *
|
|---|
| 42 | * @param parent the parent document.
|
|---|
| 43 | * @param local our XML model.
|
|---|
| 44 | * @param styleClass our class of style, cannot be <code>null</code>.
|
|---|
| 45 | */
|
|---|
| 46 | public ImmutableDocStyledNode(D parent, Element local, final Class<S> styleClass) {
|
|---|
| 47 | super(local, styleClass);
|
|---|
| 48 | this.parent = parent;
|
|---|
| 49 | assert getDocuments(this.parent.getPackage()).contains(local.getDocument()) : "Local not in parent: " + parent;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | @Override
|
|---|
| 53 | public final D getODDocument() {
|
|---|
| 54 | return this.parent;
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|