This project has retired. For details please refer to its Attic page.
Printers xref
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.webconsole.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.webconsole.hub.UddiHub;
23  import org.apache.juddi.webconsole.resources.ResourceLoader;
24  import org.uddi.api_v3.*;
25  
26  /**
27   * Provides very basic UDDI spec to String formats, mostly used for debugging
28   *
29   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
30   */
31  public class Printers {
32  
33          private static String TModelInfoToString(TModelInstanceDetails info) {
34                  StringBuilder sb = new StringBuilder();
35                  for (int i = 0; i < info.getTModelInstanceInfo().size(); i++) {
36                          sb.append(info.getTModelInstanceInfo().get(i).getTModelKey());
37                  }
38                  return StringEscapeUtils.escapeHtml(sb.toString());
39          }
40  
41          /**
42           * Converts category bags of tmodels to a readable string used from hub
43           *
44           * @param categoryBag
45           * @return string
46           */
47          public static String CatBagToString(CategoryBag categoryBag, String locale) {
48                  StringBuilder sb = new StringBuilder();
49                  if (categoryBag == null) {
50                          return ResourceLoader.GetResource(locale, "errors.nodatareturned");
51                  }
52                  for (int i = 0; i < categoryBag.getKeyedReference().size(); i++) {
53                          sb.append(KeyedReferenceToString(categoryBag.getKeyedReference().get(i), locale));
54                  }
55                  for (int i = 0; i < categoryBag.getKeyedReferenceGroup().size(); i++) {
56                          sb.append(ResourceLoader.GetResource(locale, "items.keyrefgroup")).
57                                  append(" " + ": ").append(ResourceLoader.GetResource(locale, "items.tmodel.key")).
58                                  append("=").
59                                  append(categoryBag.getKeyedReferenceGroup().get(i).getTModelKey());
60                          for (int k = 0; k < categoryBag.getKeyedReferenceGroup().get(i).getKeyedReference().size(); k++) {
61                                  sb.append(KeyedReferenceToString(categoryBag.getKeyedReferenceGroup().get(i).getKeyedReference().get(k), locale));
62                          }
63                  }
64                  return StringEscapeUtils.escapeHtml(sb.toString());
65          }
66  
67          private static String KeyedReferenceToString(KeyedReference item, String locale) {
68                  StringBuilder sb = new StringBuilder();
69                  sb.append(ResourceLoader.GetResource(locale, "items.keyrefgroup")).
70                          append(": ").
71                          append(ResourceLoader.GetResource(locale, "items.name")).
72                          append("=").
73                          append(item.getKeyName()).
74                          append(" ").
75                          append(ResourceLoader.GetResource(locale, "items.value")).
76                          append("=").
77                          append(item.getKeyValue()).
78                          append(" ").
79                          append(ResourceLoader.GetResource(locale, "items.tmodel")).
80                          append("=").
81                          append(item.getTModelKey()).
82                          append(System.getProperty("<br>"));
83                  return StringEscapeUtils.escapeHtml(sb.toString());
84          }
85  
86          /**
87           * This function is useful for translating UDDI's somewhat complex data
88           * format to something that is more useful. used from hub
89           *
90           * @param bindingTemplates
91           * @param locale
92           * @return string
93           */
94          public static String PrintBindingTemplates(BindingTemplates bindingTemplates, String locale) {
95                  if (bindingTemplates == null) {
96                          return ResourceLoader.GetResource(locale, "errors.nobindingtemplates");
97                  }
98                  StringBuilder sb = new StringBuilder();
99                  for (int i = 0; i < bindingTemplates.getBindingTemplate().size(); i++) {
100                         sb.append(ResourceLoader.GetResource(locale, "items.bindingtemplate.key")).
101                                 append(": ").
102                                 append(StringEscapeUtils.escapeHtml(bindingTemplates.getBindingTemplate().get(i).getBindingKey())).
103                                 append("<Br>");
104                         sb.append(ResourceLoader.GetResource(locale, "items.description")).
105                                 append(": ").
106                                 append(trunc(ListToDescString(bindingTemplates.getBindingTemplate().get(i).getDescription()))).
107                                 append("<Br>");
108                         sb.append(ResourceLoader.GetResource(locale, "pages.editor.tabnav.categories")).
109                                 append(": ").append(CatBagToString(bindingTemplates.getBindingTemplate().get(i).getCategoryBag(), locale)).
110                                 append("<Br>");
111                         sb.append(ResourceLoader.GetResource(locale, "items.tmodel")).
112                                 append(": ").append(TModelInfoToString(bindingTemplates.getBindingTemplate().get(i).getTModelInstanceDetails())).
113                                 append("<Br>");
114                         if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint() != null) {
115                                 sb.append(ResourceLoader.GetResource(locale, "items.accesspoint")).
116                                         append(": ").
117                                         append(StringEscapeUtils.escapeHtml(bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getValue())).
118                                         append(" ").
119                                         append(ResourceLoader.GetResource(locale, "items.type")).
120                                         append(" ").
121                                         append(StringEscapeUtils.escapeHtml(bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getUseType())).
122                                         append("<Br>");
123                         }
124                         if (bindingTemplates.getBindingTemplate().get(i).getHostingRedirector() != null) {
125                                 sb.append(ResourceLoader.GetResource(locale, "items.hostingredirector")).
126                                         append(": ").
127                                         append(bindingTemplates.getBindingTemplate().get(i).getHostingRedirector().getBindingKey()).
128                                         append("<br>");
129                         }
130                 }
131                 return (sb.toString());
132         }
133 
134         /**
135          * Description to space separated string
136          *
137          * @param name
138          * @return string
139          */
140         public static String ListToDescString(List<Description> name) {
141                 StringBuilder sb = new StringBuilder();
142                 for (int i = 0; i < name.size(); i++) {
143                         sb.append(name.get(i).getValue()).append(" ");
144                 }
145                 return StringEscapeUtils.escapeHtml(sb.toString());
146         }
147 
148         /**
149          * Name to space separated string
150          *
151          * @param name
152          * @return string
153          */
154         public static String ListNamesToString(List<Name> name) {
155                 StringBuilder sb = new StringBuilder();
156                 for (int i = 0; i < name.size(); i++) {
157                         sb.append(name.get(i).getValue()).append(" ");
158                 }
159                 return StringEscapeUtils.escapeHtml(sb.toString());
160         }
161 
162         /**
163          * used from Hub at tModelListAsHtml(..)
164          *
165          * @param findTModel
166          * @param session
167          * @param isChooser
168          * @return string
169          */
170         public static String PrintTModelListAsHtml(TModelList findTModel, HttpSession session, boolean isChooser) {
171 
172                 StringBuilder sb = new StringBuilder();
173 
174                 sb.append("<table class=\"table table-hover\"><tr><th>");
175                 if (isChooser) {
176                         //for the input checkbox
177                         sb.append("</th><th>");
178                 }
179                 sb.append(ResourceLoader.GetResource(session, "items.key"))
180                         .append("</th><th>")
181                         .append(ResourceLoader.GetResource(session, "items.name"))
182                         .append("</th><th>")
183                         .append(ResourceLoader.GetResource(session, "items.description"))
184                         .append("</th></tr>");
185                 for (int i = 0; i < findTModel.getTModelInfos().getTModelInfo().size(); i++) {
186                         sb.append("<tr><td>");
187                         if (isChooser) {
188                                 sb.append("<input class=\"modalableTmodel\" type=checkbox id=\"")
189                                         .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getTModelKey()))
190                                         .append("\"   value=\"" + 
191                                                 StringEscapeUtils.escapeHtml(trunc(findTModel.getTModelInfos().getTModelInfo().get(i).getName().getValue()))
192                                                 +
193                                                 "\"></td><td>");
194                         }
195                         if (!isChooser) {
196                                 sb.append("<a href=\"tmodelEditor.jsp?id=")
197                                         .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getTModelKey()))
198                                         .append("\" >");
199                         }
200                         sb.append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getTModelKey()));
201                         if (!isChooser) {
202                                 sb.append("</a>");
203                         }
204                         sb.append("</td><td>")
205                                 .append(StringEscapeUtils.escapeHtml(trunc(findTModel.getTModelInfos().getTModelInfo().get(i).getName().getValue())));
206                         if (findTModel.getTModelInfos().getTModelInfo().get(i).getName().getLang() != null) {
207                                 sb.append(", ")
208                                         .append(StringEscapeUtils.escapeHtml(findTModel.getTModelInfos().getTModelInfo().get(i).getName().getLang()));
209                         }
210                         sb.append("</td><td>")
211                                 .append(StringEscapeUtils.escapeHtml(trunc(Printers.ListToDescString(findTModel.getTModelInfos().getTModelInfo().get(i).getDescription()))))
212                                 .append("</td></tr>");
213                 }
214                 
215                 sb.append("</table>");
216                 return sb.toString();
217         }
218         
219         private static String trunc(String input){
220            if (input==null) return "";
221            if (input.length() > 60)
222             return input.substring(0, 60) + "...";
223            return input;
224         }
225 
226         /**
227          * used from hub
228          *
229          * @param findBusiness
230          * @param session
231          * @param isChooser if it's a chooser/modal the format is different and adds check boxes
232          * @return string
233          */
234         public static String BusinessListAsTable(BusinessList findBusiness, HttpSession session, boolean isChooser) {
235                 StringBuilder sb = new StringBuilder();
236                 sb.append("<table class=\"table table-hover\"<tr><th>");
237                 if (isChooser) {
238                         sb.append("</th><th>");
239                 }
240                 sb.append(ResourceLoader.GetResource(session, "items.name")).
241                         append("</th><th>").
242                         append(ResourceLoader.GetResource(session, "items.service")).
243                         append("</th></tr>");
244                 for (int i = 0; i < findBusiness.getBusinessInfos().getBusinessInfo().size(); i++) {
245                         sb.append("<tr><td>");
246                         if (isChooser) {
247                                 sb.append("<input type=\"checkbox\" class=\"modalableBusinessChooser\" id=\"").
248                                         append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
249                                         append("\"></td><td>");
250                         }
251                         sb.append("<a title=\"").
252                                 append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
253                                 append("\"  href=\"businessEditor2.jsp?id=").
254                                 append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
255                                 append("\">").
256                                 append(StringEscapeUtils.escapeHtml(trunc(Printers.ListNamesToString(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getName())))).
257                                 append(" <i class=\"icon-edit\"></i>").
258                                 append("</a></td><td>").
259                                 append("<a class=\"btn\" href=\"javascript:ShowServicesByBusinessKey('").
260                                 append(StringEscapeUtils.escapeJavaScript(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
261                                 append("');\">");
262 
263                         if (findBusiness.getBusinessInfos().getBusinessInfo().get(i).getServiceInfos() == null) {
264                                 sb.append("0");
265                         } else {
266                                 sb.append(ResourceLoader.GetResource(session, "actions.show")).append(" ").append(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getServiceInfos().getServiceInfo().size());
267                         }
268                         sb.append("</a>");
269                         if (!isChooser) {
270                                 sb.append(" <a class=\"btn btn-primary\" href=\"serviceEditor.jsp?bizid=").
271                                         append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
272                                         append("\"><i class=\"icon-plus-sign icon-white  icon-large\"></i> ").
273                                         append(ResourceLoader.GetResource(session, "actions.add")).append("</a>");
274                         }
275                         sb.append("</td></tr>");
276 
277                         sb.append("<tr><td colspan=3><div id=\"").
278                                 append(StringEscapeUtils.escapeHtml(findBusiness.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())).
279                                 append("\"></div></td></tr>");
280                 }
281                 sb.append("</table>");
282                 return sb.toString();
283         }
284 
285         /**
286          * service list as html, used
287          *
288          * @param findService
289          * @param chooser adds checkboxes for a modal
290          * @param session
291          * @return string
292          */
293         public static String ServiceListAsHtml(ServiceList findService, boolean chooser, HttpSession session) {
294                 StringBuilder sb = new StringBuilder();
295                 sb.append("<table class=\"table\"><tr><th>");
296                 if (chooser) {
297                         sb.append("</th><th>");
298                 }
299                 sb.append(ResourceLoader.GetResource(session, "items.name")).
300                         append("</th><th>").
301                         append(ResourceLoader.GetResource(session, "items.key")).
302                         append("</th><th>").
303                         append(ResourceLoader.GetResource(session, "items.business")).
304                         append("</th></tr>");
305                 for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) {
306                         sb.append("<tr><td>");
307                         if (chooser) {
308                                 sb.append("<input class=\"modalableServiceChooser\" type=\"checkbox\" id=\"").
309                                         append(StringEscapeUtils.escapeHtml(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey())).
310                                         append("\">");
311                                 sb.append("</td><td>");
312                         }
313                         sb.append("<a href=\"serviceEditor.jsp?id=").
314                                 append(StringEscapeUtils.escapeHtml(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey())).
315                                 append("\" title=\"").
316                                 append(StringEscapeUtils.escapeHtml(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey()))
317                                 .append("\">");
318                         sb.append(trunc(Printers.ListNamesToString(findService.getServiceInfos().getServiceInfo().get(i).getName()))).append("<i class=\"icon-edit icon-large\"></i<</a></td><td>");
319 
320                         sb.append((findService.getServiceInfos().getServiceInfo().get(i).getServiceKey())).append("</td><td>");
321                         sb.append("<a href=\"businessEditor2.jsp?id=")
322                                 .append(StringEscapeUtils.escapeHtml((findService.getServiceInfos().getServiceInfo().get(i).getBusinessKey())))
323                                 .append("\">");
324                         sb.append(StringEscapeUtils.escapeHtml((findService.getServiceInfos().getServiceInfo().get(i).getBusinessKey())))
325                                 .append("<i class=\"icon-edit icon-large\"></i<</a></td></tr>");
326                 }
327                 sb.append("</table>");
328                 return sb.toString();
329         }
330 
331         public static String PrintPublisherAssertion(List<SharedRelationships> sharedRelationships, String locale) {
332                 if (sharedRelationships == null || sharedRelationships.isEmpty()) {
333                         return "";
334                 }
335 
336                 StringBuilder sb = new StringBuilder();
337                 for (int i = 0; i < sharedRelationships.size(); i++) {
338                         sb.append(ResourceLoader.GetResource(locale, "items.publisherassertion.direction")).append(": ").append(sharedRelationships.get(i).getDirection().value()).append("<br>");
339                         for (int x = 0; x < sharedRelationships.get(i).getKeyedReference().size(); x++) {
340                                 sb.append(KeyedReferenceToString(sharedRelationships.get(i).getKeyedReference().get(x), locale));
341                         }
342                         for (int k = 0; k < sharedRelationships.get(i).getPublisherAssertion().size(); k++) {
343                                 sb.append(ResourceLoader.GetResource("items.publisherassertion.add.fromkey", locale)).append(sharedRelationships.get(i).getPublisherAssertion().get(k).getFromKey()).append("<br>");
344                                 sb.append(ResourceLoader.GetResource("items.publisherassertion.add.tokey", locale)).append(sharedRelationships.get(i).getPublisherAssertion().get(k).getToKey()).append("<br>");
345                                 sb.append(KeyedReferenceToString(sharedRelationships.get(i).getPublisherAssertion().get(k).getKeyedReference(), locale)).append("<br>");
346                                 for (int y = 0; y < sharedRelationships.get(i).getPublisherAssertion().get(k).getSignature().size(); y++) {
347                                         sb.append(UddiHub.SignatureToReadable(sharedRelationships.get(i).getPublisherAssertion().get(k).getSignature().get(y))).append("<br>");
348                                 }
349 
350                         }
351                 }
352                 return sb.toString();
353         }
354 }