Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0a602d25fbc283ff40694cd7b14be37ebc5a4db5 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.ui.skynet.render.word.template;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.osee.framework.core.data.IRelationTypeSide;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.word.WordUtil;
import org.eclipse.osee.framework.ui.skynet.render.word.WordMLProducer;

/**
 * @author Andrew M. Finkbeiner
 */
public class ArtifactProcessing implements ITemplateTask {

   private final List<ITemplateTask> innerTasks;
   private boolean outlining;
   private boolean recurseChildren;
   private IRelationTypeSide outlineRelation;
   private String headingAttributeName;
   private String outlineNumber;
   private String cleanedText;
   private String artifactSetName;

   private static final Matcher outlineElementsMatcher = Pattern.compile("<((\\w+:)?(Outline))>(.*?)</\\1>",
      Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE).matcher("");
   private static final Matcher internalOutlineElementsMatcher =
      Pattern.compile("<((\\w+:)?(HeadingAttribute|RecurseChildren|Number))>(.*?)</\\1>",
         Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE).matcher("");
   private static final Matcher setNameMatcher =
      Pattern.compile("<(\\w+:)?Set_Name>(.*?)</(\\w+:)?Set_Name>", Pattern.DOTALL | Pattern.MULTILINE).matcher("");

   public ArtifactProcessing(List<ITemplateTask> innerTasks, String artifactSection, String elementType) {
      this.innerTasks = innerTasks;
      extractInformation(artifactSection, elementType);
   }

   @Override
   public boolean isTypeNameWildcard() {
      return false;
   }

   @Override
   public void process(WordMLProducer wordMl, Artifact artifact, List<ITemplateAttributeHandler> handlers) {
      // do nothing
   }

   public List<ITemplateTask> getTasks() {
      return innerTasks;
   }

   private void extractInformation(String artifactElement, String type) {
      if (type.equals("Artifact")) {
         setNameMatcher.reset(artifactElement);
         setNameMatcher.find();
         artifactSetName = WordUtil.textOnly(setNameMatcher.group(2));
         artifactElement = setNameMatcher.replaceAll("");
      }
      outlineElementsMatcher.reset(artifactElement);

      if (outlineElementsMatcher.find()) {
         internalOutlineElementsMatcher.reset(outlineElementsMatcher.group(4));
         outlining = true;
         recurseChildren = false;
         outlineRelation = CoreRelationTypes.Default_Hierarchical__Child;

         while (internalOutlineElementsMatcher.find()) {
            String elementType = internalOutlineElementsMatcher.group(3);
            String value = WordUtil.textOnly(internalOutlineElementsMatcher.group(4));

            if (elementType.equals("HeadingAttribute")) {
               headingAttributeName = value;
            } else if (elementType.equals("RecurseChildren")) {
               recurseChildren = Boolean.parseBoolean(value);
            } else if (elementType.equals("Number")) {
               outlineNumber = value;
            }
         }
      } else {
         outlining = false;
         recurseChildren = false;
         outlineRelation = null;
         headingAttributeName = null;
      }
      cleanedText = outlineElementsMatcher.replaceAll("");
   }

   public List<ITemplateTask> getInnerTasks() {
      return innerTasks;
   }

   public boolean isOutlining() {
      return outlining;
   }

   public boolean isRecurseChildren() {
      return recurseChildren;
   }

   public IRelationTypeSide getOutlineRelation() {
      return outlineRelation;
   }

   public String getHeadingAttributeName() {
      return headingAttributeName;
   }

   public String getOutlineNumber() {
      return outlineNumber;
   }

   public String getText() {
      return this.cleanedText;
   }

   /**
    * @return the artifactSetName
    */
   public String getArtifactSetName() {
      return artifactSetName;
   }

}

Back to the top