f34eaf2ee603c72912f196949bd804a07d1c18c2
[clamp.git] / src / main / java / org / onap / clamp / clds / util / drawing / DocumentBuilder.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights
6  *                             reserved.
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.util.drawing;
25
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;
30
31 public class DocumentBuilder {
32     private final Document groupingDocument;
33     private final Document documentFactory;
34
35     static final String DATA_ELEMENT_ID_ATTRIBUTE = "data-element-id";
36
37     DocumentBuilder(Document groupingDocument, Document documentFactory) {
38         this.groupingDocument = groupingDocument;
39         this.documentFactory = documentFactory;
40     }
41
42     void pushChangestoDocument(SVGGraphics2D g2d, String dataElementId) {
43         Element element =
44             this.documentFactory.createElementNS(SVGGraphics2D.SVG_NAMESPACE_URI,
45                 SVGGraphics2D.SVG_G_TAG);
46         element.setAttribute(DATA_ELEMENT_ID_ATTRIBUTE, dataElementId);
47         g2d.getRoot(element);
48         Node node = this.groupingDocument.importNode(element, true);
49         this.groupingDocument.getDocumentElement().appendChild(node);
50     }
51
52     Document getGroupingDocument() {
53         return groupingDocument;
54     }
55 }