Skip to main content
summaryrefslogtreecommitdiffstats
blob: eb014796952675cf920e990fd7f42cfffe057503 (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
/*******************************************************************************
 * 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.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.attribute.Attribute;
import org.eclipse.osee.framework.skynet.core.attribute.AttributeType;
import org.eclipse.osee.framework.skynet.core.attribute.AttributeTypeManager;
import org.eclipse.osee.framework.skynet.core.attribute.WordAttribute;
import org.eclipse.osee.framework.ui.skynet.render.word.WordMLProducer;

/**
 * @author b1528444
 */
public final class BasicTemplateAttributeHandler implements ITemplateAttributeHandler {

   private final Set<String> ignoreAttributeExtensions;

   public BasicTemplateAttributeHandler() {
      this.ignoreAttributeExtensions = new HashSet<String>();
   }

   /*
    * (non-Javadoc)
    * 
    * @see org.eclipse.osee.framework.ui.skynet.render.word.template.ITemplateAttributeHandler#process(org.eclipse.osee.framework.skynet.core.artifact.Artifact,
    *      org.eclipse.osee.framework.ui.skynet.render.word.template.TemplateAttribute)
    */
   @Override
   public void process(WordMLProducer wordMl, Artifact artifact, TemplateAttribute templateAttribute) throws SQLException, IllegalStateException, IOException {
	   AttributeType attributeType = AttributeTypeManager.getTypeWithWordContentCheck(artifact,templateAttribute.getName());
	   Collection<Attribute<Object>> attributes = artifact.getAttributes(attributeType.getName());
       if (!attributes.isEmpty()) {
         Attribute<Object> attribute = attributes.iterator().next();
         attributeType = attribute.getAttributeType();

         
         
         // check if the attribute descriptor name is in the ignore list.
         if (ignoreAttributeExtensions.contains(attributeType.getName())) {
            return;
         }

         if (templateAttribute.isParagrapthWrap()) {
            wordMl.startParagraph();
         }
         // assumption: the label is of the form <w:r><w:t> text </w:t></w:r>
         //         if (allAttrs) {
         if (templateAttribute.hasLabel()) {
            wordMl.addWordMl("<w:r><w:t> " + templateAttribute.getName() + ": </w:t></w:r>");
         }
         //         } else {
         //            if (templateAttribute.hasLabel()) {
         //               wordMl.addParagraph(templateAttribute.getLabel());
         //            }
         //    
         String valueList;
         if(attributeType.getName().equals(WordAttribute.WORD_TEMPLATE_CONTENT)){
			wordMl.addWordMl((String)attribute.getValue());
         } else {
        	 valueList = Collections.toString(", ", artifact.getAttributes(templateAttribute.getName()));
        	 if (templateAttribute.hasFormatting()) {
                 if (templateAttribute.getFormat().contains(">x<")) {
                    wordMl.addWordMl(templateAttribute.getFormat().replace(">x<", ">" + valueList + "<"));
                 }
              } else {
                 wordMl.addTextInsideParagraph(valueList);
              }
         }
         if (templateAttribute.isParagrapthWrap()) {
            wordMl.endParagraph();
         }

      }
   }

   /*
    * (non-Javadoc)
    * 
    * @see org.eclipse.osee.framework.ui.skynet.render.word.template.ITemplateAttributeNameHandler#canHandle(org.eclipse.osee.framework.skynet.core.artifact.Artifact,
    *      org.eclipse.osee.framework.ui.skynet.render.word.template.TemplateAttribute)
    */
   @Override
   public boolean canHandle(Artifact artifact, TemplateAttribute attribute) {
      return true;
   }

}

Back to the top