View Javadoc

1   /*
2    * $Id: ApplicationStartupSplashScreen.java 20844 2010-12-29 19:39:23Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.util;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.agent.Agent;
15  import org.mule.config.i18n.CoreMessages;
16  
17  import java.util.Collection;
18  import java.util.StringTokenizer;
19  
20  public class ApplicationStartupSplashScreen extends SplashScreen
21  {
22      @Override
23      protected void doHeader(MuleContext context)
24      {
25          header.add("Application: " + context.getConfiguration().getId());
26          header.add(String.format("OS encoding: %s, Mule encoding: %s",
27                                   System.getProperty("file.encoding"),
28                                   context.getConfiguration().getDefaultEncoding()));
29          header.add(" ");
30      }
31  
32      @Override
33      protected void doFooter(MuleContext context)
34      {
35          // Mule Agents
36          if (!body.isEmpty())
37          {
38              footer.add(" ");
39          }
40          //List agents
41          Collection<Agent> agents = context.getRegistry().lookupObjects(Agent.class);
42          if (agents.size() == 0)
43          {
44              footer.add(CoreMessages.agentsRunning().getMessage() + " "
45                      + CoreMessages.none().getMessage());
46          }
47          else
48          {
49              footer.add(CoreMessages.agentsRunning().getMessage());
50              for (Agent agent : agents)
51              {
52                  String description = agent.getDescription();
53                  if (description.startsWith("'''"))
54                  {
55                      description = description.substring("'''".length());
56                      // handle multiline descriptions better
57                      for (StringTokenizer st = new StringTokenizer(description, String.format("%n")); st.hasMoreTokens();)
58                      {
59                          footer.add("  " + st.nextToken());
60                      }
61                  }
62                  else
63                  {
64                      footer.add("  " + description);
65                  }
66              }
67          }
68      }
69  }