source: osm/applications/editors/josm/plugins/opendata/includes/org/jopendocument/dom/StyledNode.java

Last change on this file was 36483, checked in by stoecker, 9 days ago

set eol-style, fix checkstyle issues, add ignores

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
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
16package org.jopendocument.dom;
17
18import org.jdom2.Element;
19
20/**
21 * A node with a style.
22 *
23 * @author Sylvain CUAZ
24 *
25 * @param <S> type of style.
26 * @param <D> type of document.
27 */
28public abstract class StyledNode<S extends StyleStyle, D extends ODDocument> extends ODNode {
29
30 private final StyleDesc<S> styleClass;
31
32 /**
33 * Create a new instance. We used to find the {@link StyleStyle} class with reflection but this
34 * was slow.
35 *
36 * @param local our XML model.
37 * @param styleClass our class of style, cannot be <code>null</code>.
38 */
39 public StyledNode(Element local, final Class<S> styleClass) {
40 super(local);
41 if (styleClass == null)
42 throw new NullPointerException("null style class");
43 this.styleClass = StyleStyle.getStyleDesc(styleClass, XMLVersion.getVersion(getElement()));
44 assert this.styleClass.getRefElements().contains(this.getElement().getQualifiedName()) : this.getElement().getQualifiedName() + " not in " + this.styleClass;
45 }
46
47 // can be null if this node wasn't created from a document (eg new Paragraph())
48 public abstract D getODDocument();
49
50 // some nodes have more complicated ways of finding their style (eg Cell)
51 protected String getStyleName() {
52 return this.getElement().getAttributeValue("style-name", this.getElement().getNamespace());
53 }
54}
Note: See TracBrowser for help on using the repository browser.