Skip to content

Create view #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,6 +4,7 @@ import com.lmco.spectrum.systemnavigation3d.domain.catia.DocumentSMG;
import com.lmco.spectrum.systemnavigation3d.dto.TransformerOptions;
import org.springframework.stereotype.Service;
import org.w3c.dom.Element;
import org.w3c.dom.Document;

import javax.annotation.Nullable;
import javax.xml.bind.JAXBContext;
Expand All @@ -15,6 +16,8 @@ import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

import java.text.SimpleDateFormat;

@Service
public class TransformationService {

Expand All @@ -29,6 +32,10 @@ public class TransformationService {
private static final String ATTR_NAME = "Name";
private static final String ATTR_VALUE = "Value";

// view tags
private static final String TAG_VIEW = "CLitView";
private static final String ATTR_IDENT = "Ident";

// TODO make functional
// TODO consider types of transformations we need to make
// accept list of transformation options?
Expand All @@ -51,10 +58,33 @@ public class TransformationService {
if(options.getSetFocusedView() != null) {
ensureViewMode(doc);
setFocusedView(doc, options.getSetFocusedView());
createView(doc, "test");
}
return doc;
}

private void createView(DocumentSMG doc, String viewName) {

for(Element el : doc.getNodes()){
if(el.getTagName().equals(TAG_SERVER)
&& el.hasAttribute(ATTR_TYPE)
&& el.getAttribute(ATTR_TYPE).equals(SERVER_TYPE_CLitList)
) {
Document smgDoc = el.getOwnerDocument();
Element newView = smgDoc.createElement(TAG_VIEW);
el.appendChild(newView);

newView.setAttribute(ATTR_IDENT, new SimpleDateFormat("HH.mm.ss").format(new java.util.Date()));

newView.setAttribute(ATTR_NAME, viewName);

newView.setAttribute(ATTR_TYPE, "1");

break;
}
}
}

private void ensureViewMode(DocumentSMG doc) {
for(Element el : doc.getNodes()) {
if(el.getTagName().equals(TAG_SERVER)
Expand Down