Skip to main content
summaryrefslogtreecommitdiffstats
blob: a837c04f82d7494273975d8021e1cc34d07cec17 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
 * Copyright (c) 2010 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.core.dsl.ui.integration.internal;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.dsl.integration.util.OseeDslSegmentParser;
import org.eclipse.osee.framework.core.dsl.ui.integration.AbstractDslRenderer;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.core.operation.IOperation;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.skynet.render.DefaultArtifactRenderer;
import org.eclipse.osee.framework.ui.skynet.render.FileToAttributeUpdateOperation;
import org.eclipse.osee.framework.ui.skynet.render.PresentationType;

/**
 * @author Roberto E. Escobar
 */
public final class OseeDslRenderer extends AbstractDslRenderer {
   private static final IArtifactType[] MATCHING_ARTIFACT_TYPES = {
      CoreArtifactTypes.AccessControlModel,
      CoreArtifactTypes.OseeTypeDefinition};

   private static final OseeDslSegmentParser parser = new OseeDslSegmentParser();

   @Override
   public String getName() {
      return "OseeDsl Editor";
   }

   @Override
   public DefaultArtifactRenderer newInstance() {
      return new OseeDslRenderer();
   }

   @SuppressWarnings("unused")
   @Override
   public String getAssociatedExtension(Artifact artifact) throws OseeCoreException {
      return "osee";
   }

   @Override
   public InputStream getRenderInputStream(PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException {
      Artifact artifact = artifacts.iterator().next();

      String data;
      if (artifact.isOfType(CoreArtifactTypes.OseeTypeDefinition)) {
         data = artifact.getSoleAttributeValueAsString(CoreAttributeTypes.UriGeneralStringData, "");
      } else {
         StringBuilder builder = new StringBuilder();
         builder.append(parser.getStartTag(artifact));
         builder.append("\n");
         builder.append(artifact.getSoleAttributeValueAsString(CoreAttributeTypes.GeneralStringData, ""));
         builder.append("\n");
         builder.append(parser.getEndTag(artifact));
         data = builder.toString();
      }

      InputStream inputStream = null;
      try {
         inputStream = new ByteArrayInputStream(data.getBytes("UTF-8"));
      } catch (UnsupportedEncodingException ex) {
         OseeExceptions.wrapAndThrow(ex);
      }
      return inputStream;
   }

   @Override
   protected IOperation getUpdateOperation(File file, List<Artifact> artifacts, IOseeBranch branch, PresentationType presentationType) {
      IOperation op;
      Artifact artifact = artifacts.iterator().next();
      if (artifact.isOfType(CoreArtifactTypes.OseeTypeDefinition)) {
         OseeTypeModifier modifier = new OseeTypeModifier();
         op =
            new FileToAttributeUpdateOperation(file, artifacts.get(0), CoreAttributeTypes.UriGeneralStringData,
               modifier);
      } else {
         op = new OseeDslArtifactUpdateOperation(parser, file);
      }
      return op;
   }

   @Override
   public int minimumRanking() {
      return GENERAL_MATCH;
   }

   @Override
   protected IArtifactType[] getArtifactTypeMatches() {
      return MATCHING_ARTIFACT_TYPES;
   }
}

Back to the top