View Javadoc

1   package org.apache.continuum.web.util;
2   
3   import org.apache.commons.lang.StringEscapeUtils;
4   import org.apache.maven.continuum.model.project.ProjectNotifier;
5   import org.apache.maven.continuum.notification.AbstractContinuumNotifier;
6   import org.codehaus.plexus.util.StringUtils;
7   
8   import java.util.Map;
9   
10  /*
11   * Licensed to the Apache Software Foundation (ASF) under one
12   * or more contributor license agreements.  See the NOTICE file
13   * distributed with this work for additional information
14   * regarding copyright ownership.  The ASF licenses this file
15   * to you under the Apache License, Version 2.0 (the
16   * "License"); you may not use this file except in compliance
17   * with the License.  You may obtain a copy of the License at
18   *
19   *   http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing,
22   * software distributed under the License is distributed on an
23   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24   * KIND, either express or implied.  See the License for the
25   * specific language governing permissions and limitations
26   * under the License.
27   */
28  
29  /**
30   * @author José Morales Martínez
31   * @version $Id: GenerateRecipentNotifier.java 1372260 2012-08-13 04:29:09Z brett $
32   */
33  public final class GenerateRecipentNotifier
34  {
35      private GenerateRecipentNotifier()
36      {
37  
38      }
39  
40      @SuppressWarnings( "unchecked" )
41      public static String generate( ProjectNotifier notifier )
42      {
43          Map<String, String> configuration = notifier.getConfiguration();
44          String recipent = "unknown";
45          if ( ( "mail".equals( notifier.getType() ) ) || ( "msn".equals( notifier.getType() ) ) ||
46              ( "jabber".equals( notifier.getType() ) ) )
47          {
48              if ( StringUtils.isNotEmpty( configuration.get( AbstractContinuumNotifier.ADDRESS_FIELD ) ) )
49              {
50                  recipent = configuration.get( AbstractContinuumNotifier.ADDRESS_FIELD );
51              }
52              if ( StringUtils.isNotEmpty( configuration.get( AbstractContinuumNotifier.COMMITTER_FIELD ) ) )
53              {
54                  if ( Boolean.parseBoolean( configuration.get( AbstractContinuumNotifier.COMMITTER_FIELD ) ) )
55                  {
56                      if ( "unknown".equals( recipent ) )
57                      {
58                          recipent = "latest committers";
59                      }
60                      else
61                      {
62                          recipent += ", " + "latest committers";
63                      }
64                  }
65              }
66              if ( StringUtils.isNotEmpty( configuration.get( AbstractContinuumNotifier.DEVELOPER_FIELD ) ) )
67              {
68                  if ( Boolean.parseBoolean( configuration.get( AbstractContinuumNotifier.DEVELOPER_FIELD ) ) )
69                  {
70                      if ( "unknown".equals( recipent ) )
71                      {
72                          recipent = "project developers";
73                      }
74                      else
75                      {
76                          recipent += ", " + "project developers";
77                      }
78                  }
79              }
80          }
81          if ( "irc".equals( notifier.getType() ) )
82          {
83              recipent = configuration.get( "host" );
84              if ( configuration.get( "port" ) != null )
85              {
86                  recipent = recipent + ":" + configuration.get( "port" );
87              }
88              recipent = recipent + ":" + configuration.get( "channel" );
89          }
90          if ( "wagon".equals( notifier.getType() ) )
91          {
92              recipent = configuration.get( "url" );
93          }
94          // escape the characters, it may contain characters possible for an XSS attack
95          return StringEscapeUtils.escapeXml( recipent );
96      }
97  }