View Javadoc

1   package org.apache.continuum.web.util;
2   
3   import java.util.Map;
4   
5   import org.apache.commons.lang.StringEscapeUtils;
6   import org.apache.maven.continuum.model.project.ProjectNotifier;
7   import org.apache.maven.continuum.notification.AbstractContinuumNotifier;
8   import org.codehaus.plexus.util.StringUtils;
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 1101669 2011-05-10 22:46:21Z ctan $
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          }
67          if ( "irc".equals( notifier.getType() ) )
68          {
69              recipent = configuration.get( "host" );
70              if ( configuration.get( "port" ) != null )
71              {
72                  recipent = recipent + ":" + configuration.get( "port" );
73              }
74              recipent = recipent + ":" + configuration.get( "channel" );
75          }
76          if ( "wagon".equals( notifier.getType() ) )
77          {
78              recipent = configuration.get( "url" );
79          }
80          // escape the characters, it may contain characters possible for an XSS attack
81          return StringEscapeUtils.escapeXml( recipent );
82      }
83  }