Eclipseplugins
pABalpxxcdf.java
1 package com.proalpha.pds.templates.jet.trunk;
2 
3 import com.openedge.pdt.core.template.TemplateGenerationException;
4 import com.proalpha.pds.templates.jet.IpaTemplateGenerator;
5 import com.proalpha.pds.templates.data.GeneratorSettingsConstans;
6 
7 import java.util.Map;
8 import java.util.*;
9 import com.proalpha.pds.templates.helper.CodeFormatter;
10 
11 public class pABalpxxcdf implements IpaTemplateGenerator
12 {
13  protected static String nl;
14  public static synchronized pABalpxxcdf create(String lineSeparator)
15  {
16  nl = lineSeparator;
17  pABalpxxcdf result = new pABalpxxcdf();
18  nl = null;
19  return result;
20  }
21 
22  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
23  protected final String TEXT_1 = "";
24  protected final String TEXT_2 = NL;
25  protected final String TEXT_3 = NL + NL + "/* *************************** Main Block *************************** */" + NL + "" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* User-Exits */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "" + NL + "{&{&PA-XINCLBASISNAME}_CX}" + NL + "{&{&PA-XINCLBASISNAME}_UX}" + NL + "{&{&PA-XINCLBASISNAME}_QX}" + NL + "{&{&PA-XINCLBASISNAME}_XX}" + NL + "{&{&PA-XINCLBASISNAME}_YX}" + NL + "" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* Include Code */" + NL + "/*----------------------------------------------------------------------------*/" + NL + NL;
26  protected final String TEXT_4 = NL + NL + "/* _UIB-CODE-BLOCK-END */" + NL + "&ANALYZE-RESUME";
27 
28 /* (non-javadoc)
29  * @see ITemplateGenerator#generate(Object)
30  */
31 public String generate(Map<String, Object> wizardSettings) throws TemplateGenerationException
32  {
33  final StringBuffer stringBuffer = new StringBuffer();
34 
35 
36  String customLevel = (String)wizardSettings.get(GeneratorSettingsConstans.CUSTOM_LEVEL);
37  String parentObject = (String)wizardSettings.get(GeneratorSettingsConstans.PARENT_OBJECT);
38  String fileName = (String)wizardSettings.get(GeneratorSettingsConstans.FILE_NAME);
39  String mainClassName = (String)wizardSettings.get(GeneratorSettingsConstans.MAIN_CLASS);
40  String xbasename = parentObject.replace(".","_");
41  String relativePath = (String)wizardSettings.get(GeneratorSettingsConstans.RELATIVE_PATH);
42  List<String> userExitList = (List<String>)wizardSettings.get("userExitList");
43  List<String> balpTemplateList = (List<String>)wizardSettings.get("baltTemplateList");
44 
45  int iSpace = 80 - 35 - xbasename.length() + "_".length() + customLevel.length() + 1;
46  String sBlanks = CodeFormatter.pad("",iSpace,' ');
47 
48  String newUserExit = "";
49 
50  if (fileName.endsWith(".cls")){
51 
52  xbasename = mainClassName.concat("_CLS");
53 
54  relativePath = relativePath.replace("/",".");
55 
56  iSpace = 80 - 35 - xbasename.length() - 3;
57 
58  if (iSpace <= 0){
59  sBlanks = " ";
60  }else{
61  sBlanks = CodeFormatter.pad("",iSpace,' ');
62  }
63 
64  if (customLevel.equals("X")){
65  newUserExit = "&GLOB " + xbasename + "_INHERITS" + sBlanks + relativePath + "." + fileName.replace(".cls","");
66  } else{
67  newUserExit = "&GLOB " + xbasename + "_" + customLevel +"_INHERITS" + sBlanks + relativePath + "." + fileName.replace(".cls","");
68  }
69 
70  } else if (parentObject.contains(".fld")){
71  String fldSuffix;
72  if (customLevel.equals("X")){
73  fldSuffix = "";
74  } else {
75  fldSuffix = "_" + customLevel;
76  }
77 
78  newUserExit = "&GLOB " + xbasename + fldSuffix + sBlanks + relativePath + "/" + fileName;
79  } else {
80  newUserExit = "&GLOB " + xbasename + "_" + customLevel + "X" + sBlanks + "~{" + relativePath + "/" + fileName + " &" + customLevel + "X}";
81  }
82 
83  // Entfernt die Kommentare
84  Boolean isInList = Boolean.FALSE;
85  for (String userExit : userExitList) {
86  String userExitWithoutComment = userExit.replaceAll("/\\*([^*]|[\\r\\n])*\\*/","");
87  if (userExitWithoutComment.equals(newUserExit)) {
88  isInList = Boolean.TRUE;
89  }
90  }
91 
92  if (!isInList) {
93  userExitList.add(newUserExit.trim());
94  }
95 
96  HashSet<String> hashSet = new HashSet<String>(userExitList);
97  userExitList.clear();
98  userExitList.addAll(hashSet);
99  Collections.sort(userExitList, String.CASE_INSENSITIVE_ORDER);
100 
101  ListIterator<String> contentIterator = balpTemplateList.listIterator();
102 
103  while (contentIterator.hasNext()){
104 
105  stringBuffer.append(TEXT_1);
106  stringBuffer.append(contentIterator.next());
107  stringBuffer.append(TEXT_2);
108  }
109  stringBuffer.append(TEXT_3);
110 
111  for(String userExit : userExitList){
112 
113  stringBuffer.append(userExit);
114  stringBuffer.append(TEXT_2);
115 
116  }
117 
118  stringBuffer.append(TEXT_4);
119  stringBuffer.append(TEXT_2);
120  return stringBuffer.toString();
121  }
122 }