2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.util.drawing;
26 import org.apache.batik.svggen.SVGGraphics2D;
27 import org.w3c.dom.Document;
28 import org.w3c.dom.Element;
29 import org.w3c.dom.Node;
31 public class DocumentBuilder {
32 private final Document groupingDocument;
33 private final Document documentFactory;
35 static final String DATA_ELEMENT_ID_ATTRIBUTE = "data-element-id";
36 static final String DATA_ELEMENT_GROUPING_ATTRIBUTE = "data-grouping-id";
37 static final String DATA_FOR_UI_ATTRIBUTE = "data-for-ui";
39 DocumentBuilder(Document groupingDocument, Document documentFactory) {
40 this.groupingDocument = groupingDocument;
41 this.documentFactory = documentFactory;
44 void pushChangestoDocument(SVGGraphics2D g2d, String dataElementId) {
45 pushChangestoDocument(g2d, dataElementId,null,null);
48 void pushChangestoDocument(SVGGraphics2D g2d, String dataElementId, String dataGroupingId, String dataForUI) {
50 this.documentFactory.createElementNS(SVGGraphics2D.SVG_NAMESPACE_URI,
51 SVGGraphics2D.SVG_G_TAG);
52 element.setAttribute(DATA_ELEMENT_ID_ATTRIBUTE, dataElementId);
53 if (dataGroupingId != null) {
54 element.setAttribute(DATA_ELEMENT_GROUPING_ATTRIBUTE, dataGroupingId);
56 if (dataForUI != null) {
57 element.setAttribute(DATA_FOR_UI_ATTRIBUTE, dataForUI);
60 Node node = this.groupingDocument.importNode(element, true);
61 this.groupingDocument.getDocumentElement().appendChild(node);
64 Document getGroupingDocument() {
65 return groupingDocument;