View Javadoc
1   /*
2    * Copyright 2001-2013 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.adminconsole.hub.builders;
18  
19  import java.util.List;
20  import javax.servlet.http.HttpSession;
21  import org.apache.commons.lang.StringEscapeUtils;
22  import org.apache.juddi.adminconsole.resources.ResourceLoader;
23  import org.uddi.api_v3.*;
24  
25  /**
26   * Provides very basic UDDI spec to String formats, mostly used for debugging
27   *
28   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
29   */
30  public class Printers {
31  
32      public static String TModelInfoToString(TModelInstanceDetails info) {
33          StringBuilder sb = new StringBuilder();
34          for (int i = 0; i < info.getTModelInstanceInfo().size(); i++) {
35              sb.append(info.getTModelInstanceInfo().get(i).getTModelKey());
36          }
37          return sb.toString();
38      }
39  
40      /**
41       * Converts category bags of tmodels to a readable string
42       *
43       * @param categoryBag
44       * @return
45       */
46      public static String CatBagToString(CategoryBag categoryBag, String locale) {
47          StringBuilder sb = new StringBuilder();
48          if (categoryBag == null) {
49              return "no data";
50          }
51          for (int i = 0; i < categoryBag.getKeyedReference().size(); i++) {
52              sb.append(KeyedReferenceToString(categoryBag.getKeyedReference().get(i), locale));
53          }
54          for (int i = 0; i < categoryBag.getKeyedReferenceGroup().size(); i++) {
55              sb.append("Key Ref Grp: TModelKey=");
56              for (int k = 0; k < categoryBag.getKeyedReferenceGroup().get(i).getKeyedReference().size(); k++) {
57                  sb.append(KeyedReferenceToString(categoryBag.getKeyedReferenceGroup().get(i).getKeyedReference().get(k), locale));
58              }
59          }
60          return sb.toString();
61      }
62  
63      public static String KeyedReferenceToString(KeyedReference item, String locale) {
64          StringBuilder sb = new StringBuilder();
65          sb.append("Key Ref: Name=").append(item.getKeyName()).append(" Value=").append(item.getKeyValue()).append(" tModel=").append(item.getTModelKey()).append(System.getProperty("line.separator"));
66          return sb.toString();
67      }
68  
69      /**
70       * This function is useful for translating UDDI's somewhat complex data
71       * format to something that is more useful.
72       *
73       * @param bindingTemplates
74       */
75      public static String PrintBindingTemplates(BindingTemplates bindingTemplates, String locale) {
76          if (bindingTemplates == null) {
77              return "No binding templates";
78          }
79          StringBuilder sb = new StringBuilder();
80          for (int i = 0; i < bindingTemplates.getBindingTemplate().size(); i++) {
81              sb.append("Binding Key: ").append(bindingTemplates.getBindingTemplate().get(i).getBindingKey()).append("<Br>");
82              sb.append("Description: ").append(ListToDescString(bindingTemplates.getBindingTemplate().get(i).getDescription())).append("<Br>");
83              sb.append("CatBag: ").append(CatBagToString(bindingTemplates.getBindingTemplate().get(i).getCategoryBag(), locale)).append("<Br>");
84              sb.append("tModels: ").append(Printers.TModelInfoToString(bindingTemplates.getBindingTemplate().get(i).getTModelInstanceDetails())).append("<Br>");
85              if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint() != null) {
86                  sb.append("Access Point: ").append(bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getValue()).append(" type ").append(bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType()).append("<Br>");
87              }
88              if (bindingTemplates.getBindingTemplate().get(i).getHostingRedirector() != null) {
89                  sb.append("Hosting Director: ").append(bindingTemplates.getBindingTemplate().get(i).getHostingRedirector().getBindingKey()).append("<br>");
90              }
91          }
92          return sb.toString();
93      }
94  
95      public static String ListToDescString(List<Description> name) {
96          StringBuilder sb = new StringBuilder();
97          for (int i = 0; i < name.size(); i++) {
98              sb.append(name.get(i).getValue()).append(" ");
99          }
100         return sb.toString();
101     }
102 
103     public static String ListNamesToString(List<Name> name) {
104         StringBuilder sb = new StringBuilder();
105         for (int i = 0; i < name.size(); i++) {
106             sb.append(name.get(i).getValue()).append(" ");
107         }
108         return sb.toString();
109     }
110 
111     public static String ListDiscoToString(DiscoveryURLs info) {
112         StringBuilder sb = new StringBuilder();
113         if (info == null) {
114             return "";
115         }
116         for (int i = 0; i < info.getDiscoveryURL().size(); i++) {
117             sb.append("Type: ").append(StringEscapeUtils.escapeHtml(info.getDiscoveryURL().get(i).getValue())).append(" ").append(StringEscapeUtils.escapeHtml(info.getDiscoveryURL().get(i).getValue()));
118         }
119         return sb.toString();
120     }
121 
122     /**
123      * converts contacts to a simple string output
124      */
125     public static String PrintContacts(Contacts contacts, String locale) {
126         if (contacts == null) {
127             return "";
128         }
129         StringBuilder sb = new StringBuilder();
130         for (int i = 0; i < contacts.getContact().size(); i++) {
131             sb.append("Contact ").append(i).append(" type:").append(contacts.getContact().get(i).getUseType()).append("<br>");
132             for (int k = 0; k < contacts.getContact().get(i).getPersonName().size(); k++) {
133                 sb.append("Name: ").append(contacts.getContact().get(i).getPersonName().get(k).getValue()).append("<br>");
134             }
135             for (int k = 0; k < contacts.getContact().get(i).getEmail().size(); k++) {
136                 sb.append("Email: ").append(contacts.getContact().get(i).getEmail().get(k).getValue()).append("<br>");
137             }
138             for (int k = 0; k < contacts.getContact().get(i).getAddress().size(); k++) {
139                 sb.append("Address sort code ").append(contacts.getContact().get(i).getAddress().get(k).getSortCode()).append("<br>");
140                 sb.append("Address use type ").append(contacts.getContact().get(i).getAddress().get(k).getUseType()).append("<br>");
141                 sb.append("Address tmodel key ").append(contacts.getContact().get(i).getAddress().get(k).getTModelKey()).append("<br>");
142                 for (int x = 0; x < contacts.getContact().get(i).getAddress().get(k).getAddressLine().size(); x++) {
143                     sb.append("Address line value ").append(contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getValue()).append("<br>");
144                     sb.append("Address line key name ").append(contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getKeyName()).append("<br>");
145                     sb.append("Address line key value ").append(contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getKeyValue()).append("<br>");
146                 }
147             }
148             for (int k = 0; k < contacts.getContact().get(i).getDescription().size(); k++) {
149                 sb.append("Desc: ").append(contacts.getContact().get(i).getDescription().get(k).getValue()).append("<br>");
150             }
151             for (int k = 0; k < contacts.getContact().get(i).getPhone().size(); k++) {
152                 sb.append("Phone: ").append(contacts.getContact().get(i).getPhone().get(k).getValue()).append("<br>");
153             }
154         }
155         return sb.toString();
156     }
157 
158     public static String ListIdentBagToString(IdentifierBag info, String locale) {
159         StringBuilder sb = new StringBuilder();
160         if (info == null) {
161             return "";
162         }
163         for (int i = 0; i < info.getKeyedReference().size(); i++) {
164             sb.append(KeyedReferenceToString(info.getKeyedReference().get(i), locale));
165         }
166         return sb.toString();
167     }
168 
169     public static String PublisherAssertionsToHtml(List<PublisherAssertion> list, String locale) {
170         if (list == null || list.isEmpty()) {
171             return "No input";
172         }
173         StringBuilder sb = new StringBuilder();
174         sb.append("<table class=\"table\">");
175         for (int i = 0; i < list.size(); i++) {
176             sb.append("<tr><td>");
177             sb.append(StringEscapeUtils.escapeHtml(list.get(i).getToKey()));
178             sb.append("</td><td>");
179             sb.append(StringEscapeUtils.escapeHtml(list.get(i).getFromKey()));
180             sb.append("</td><td>");
181             sb.append(list.get(i).getSignature().isEmpty());
182             sb.append("</td><td>");
183             sb.append(StringEscapeUtils.escapeHtml(Printers.KeyedReferenceToString(list.get(i).getKeyedReference(), locale)));
184             sb.append("</td></tr>");
185         }
186         sb.append("</table>");
187         return sb.toString();
188     }
189 
190     public static String PrintTModelListAsHtml(TModelList findTModel, HttpSession session, boolean isChooser) {
191 
192         StringBuilder sb = new StringBuilder();
193 
194         sb.append("<table class=\"table table-hover\"><tr><th>");
195         if (isChooser) {
196             sb.append("</th><th>");
197         }
198         sb.append(ResourceLoader.GetResource(session, "items.key"))
199                 .append("</th><th>")
200                 .append(ResourceLoader.GetResource(session, "items.name"))
201                 .append("</th><th>")
202                 .append(ResourceLoader.GetResource(session, "items.description"))
203                 .append("</th></tr>");
204         for (int i = 0; i < findTModel.getTModelInfos().getTModelInfo().size(); i++) {
205             sb.append("<tr><td>");
206             if (isChooser) {
207                 sb.append("<input class=\"modalableTmodel\" type=checkbox id=\"")
208                         .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getTModelKey()))
209                         .append("\"></td><td>");
210             }
211             if (!isChooser) {
212                 sb.append("<a href=\"tmodelEditor.jsp?id=")
213                         .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getTModelKey()))
214                         .append("\" >");
215             }
216             sb.append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getTModelKey()));
217             if (!isChooser) {
218                 sb.append("</a>");
219             }
220             sb.append("</td><td>")
221                     .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getName().getValue()));
222             if (findTModel.getTModelInfos().getTModelInfo().get(i).getName().getLang() != null) {
223                 sb.append(", ")
224                         .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getName().getLang()));
225             }
226             sb.append("</td><td>")
227                     .append(StringEscapeUtils.escapeHtml(Printers.ListToDescString(findTModel.getTModelInfos().getTModelInfo().get(i).getDescription())))
228                     .append("</td></tr>");
229         }
230         sb.append("</table>");
231         return sb.toString();
232     }
233 
234     @Deprecated
235     private static String PrintTModelListAsHtmlModel(TModelList findTModel, HttpSession session) {
236         StringBuilder sb = new StringBuilder();
237 
238         sb.append("<table class=\"table table-hover\"><tr><th>");
239 
240         sb.append("</th><th>");
241 
242         sb.append(ResourceLoader.GetResource(session, "items.key"))
243                 .append("</th><th>")
244                 .append(ResourceLoader.GetResource(session, "items.name"))
245                 .append("</th><th>")
246                 .append(ResourceLoader.GetResource(session, "items.description"))
247                 .append("</th></tr>");
248         for (int i = 0; i < findTModel.getTModelInfos().getTModelInfo().size(); i++) {
249             sb.append("<tr><td>");
250 
251             sb.append("<input class=\"modalableTmodel\" type=checkbox id=\"")
252                     .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getTModelKey()))
253                     .append("\"></td><td>");
254 
255             sb.append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getTModelKey()));
256             sb.append("</td><td>")
257                     .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getName().getValue()));
258             if (findTModel.getTModelInfos().getTModelInfo().get(i).getName().getLang() != null) {
259                 sb.append(", ")
260                         .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getName().getLang()));
261             }
262             sb.append("</td><td>")
263                     .append(StringEscapeUtils.escapeHtml(Printers.ListToDescString(findTModel.getTModelInfos().getTModelInfo().get(i).getDescription())))
264                     .append("</td></tr>");
265         }
266         sb.append("</table>");
267         return sb.toString();
268     }
269 
270     public static String BusinessListAsTable(BusinessList findBusiness, HttpSession session, boolean isChooser) {
271         StringBuilder sb = new StringBuilder();
272         sb.append("<table class=\"table table-hover\"<tr><th>");
273         if (isChooser) {
274             sb.append("</th><th>");
275         }
276         sb.append(ResourceLoader.GetResource(session, "items.name")).
277                 append("</th><th>").
278                 append(ResourceLoader.GetResource(session, "items.service")).
279                 append("</th></tr>");
280         for (int i = 0; i < findBusiness.getBusinessInfos().getBusinessInfo().size(); i++) {
281             sb.append("<tr><td>");
282             if (isChooser) {
283                 sb.append("<input type=\"checkbox\" class=\"modalableBusinessChooser\" id=\"").
284                         append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
285                         append("\"></td><td>");
286             }
287             sb.append("<a title=\"").
288                     append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
289                     append("\"  href=\"businessEditor2.jsp?id=").
290                     append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
291                     append("\">").
292                     append(StringEscapeUtils.escapeHtml(Printers.ListNamesToString(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getName()))).
293                     append("</a></td><td>").
294                     append("<a class=\"btn btn-primary\" href=\"javascript:ShowServicesByBusinessKey('").
295                     append(StringEscapeUtils.escapeJavaScript(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
296                     append("');\">");
297 
298             if (findBusiness.getBusinessInfos().getBusinessInfo().get(i).getServiceInfos() == null) {
299                 sb.append("0");
300             } else {
301                 sb.append("Show ").append(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getServiceInfos().getServiceInfo().size());
302             }
303             sb.append("</a>");
304             if (!isChooser) {
305                 sb.append("<a class=\"btn btn-primary\" href=\"serviceEditor.jsp?bizid=").
306                         append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
307                         append("\"><i class=\"icon-plus-sign icon-white  icon-large\"></i></a>");
308             }
309             sb.append("</td></tr>");
310 
311             sb.append("<tr><td colspan=3><div id=\"").
312                     append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
313                     append("\"></div></td></tr>");
314         }
315         sb.append("</table>");
316         return sb.toString();
317     }
318 
319     /**
320      * service list as html
321      * @param findService
322      * @param chooser
323      * @param session
324      * @return 
325      */
326     public static String ServiceListAsHtml(ServiceList findService, boolean chooser, HttpSession session) {
327         StringBuilder sb = new StringBuilder();
328         sb.append("<table class=\"table\"><tr><th>");
329         if (chooser) {
330             sb.append("</th><th>");
331         }
332         sb.append(ResourceLoader.GetResource(session, "items.name")).
333                 append("</th><th>").
334                 append(ResourceLoader.GetResource(session, "items.key")).
335                 append("</th><th>").
336                 append(ResourceLoader.GetResource(session, "items.business")).
337                 append("</th></tr>");
338         for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) {
339             sb.append("<tr><td>");
340             if (chooser) {
341                 sb.append("<input class=\"modalableServiceChooser\" type=\"checkbox\" id=\"").
342                         append(StringEscapeUtils.escapeHtml(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey())).
343                         append("\">");
344                 sb.append("</td><td>");
345             }
346             sb.append("<a href=\"serviceEditor.jsp?id=").
347                     append(StringEscapeUtils.escapeHtml(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey())).
348                     append("\" title=\"").
349                     append(StringEscapeUtils.escapeHtml(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey()))
350                     .append("\">");
351             sb.append(Printers.ListNamesToString(findService.getServiceInfos().getServiceInfo().get(i).getName())).append("<i class=\"icon-edit icon-large\"></i<</a></td><td>");
352            
353             sb.append((findService.getServiceInfos().getServiceInfo().get(i).getServiceKey())).append("</td><td>");
354              sb.append("<a href=\"businessEditor2.jsp?id=")
355                     .append(StringEscapeUtils.escapeHtml((findService.getServiceInfos().getServiceInfo().get(i).getBusinessKey())))
356                     .append("\">");
357             sb.append(StringEscapeUtils.escapeHtml((findService.getServiceInfos().getServiceInfo().get(i).getBusinessKey())))
358                     .append("<i class=\"icon-edit icon-large\"></i<</a></td></tr>");
359         }
360         sb.append("</table>");
361         return sb.toString();
362     }
363 }