Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  The MIT License
   *
   *  Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
   *  Copyright 2012 Sony Mobile Communications AB. All rights reserved.
   *
   *  Permission is hereby granted, free of charge, to any person obtaining a copy
   *  of this software and associated documentation files (the "Software"), to deal
   *  in the Software without restriction, including without limitation the rights
  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  *  copies of the Software, and to permit persons to whom the Software is
  *  furnished to do so, subject to the following conditions:
  *
  *  The above copyright notice and this permission notice shall be included in
  *  all copies or substantial portions of the Software.
  *
  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  *  THE SOFTWARE.
  */
 package com.sonyericsson.hudson.plugins.gerrit.trigger.utils;
 
Various string making utility methods.

Author(s):
Robert Sandell <robert.sandell@sonyericsson.com>
 
 public final class StringUtil {

    
What comes before the change and patch numbers in a refspec.
 
     public static final String REFSPEC_PREFIX = "refs/changes/";

    
The base URL of this plugin.
 
     public static final String PLUGIN_URL = "/plugin/gerrit-trigger/";

    
the field will be used as quote "\""
 
     private static final Pattern QUOTES_PATTERN = Pattern.compile("\"");;

    
The base URL of the plugin images.
 
     public static final String PLUGIN_IMAGES_URL =  + "images/";

    
The base URL of the plugin javascripts.
 
     public static final String PLUGIN_JS_URL =  + "js/";

    
Private Constructor for Utility Class.
 
     private StringUtil() {
     }

    
Creates a refspec string from the data in the event. Unless the patch-set already has a refspec specified. For a change with number 3456 and patchset 1 the refspec would be refs/changes/56/3456/1

 
     public static String makeRefSpec(ChangeBasedEvent event) {
         if (event.getPatchSet() != null && event.getPatchSet().getRef() != null) {
             if (event.getPatchSet().getRef().length() > 0) {
                 return event.getPatchSet().getRef();
             }
         }
         StringBuilder str = new StringBuilder();
         String number = event.getChange().getNumber();
         if (number.length() < 2) {
             str.append("0").append(number);
         } else if (number.length() == 2) {
             str.append(number);
         } else {
             str.append(number.substring(number.length() - 2));
         }
         str.append("/").append(number);
         str.append("/").append(event.getPatchSet().getNumber());
         return str.toString();
     }

    
Gets the path to the provided image inside this plugin. The path returned is "compliant" with what for example hudson.model.Action.getIconFileName() expects.

Parameters:
imageName the fileName of the image.
Returns:
the full path to the image.
See also:
PLUGIN_IMAGES_URL
    public static String getPluginImageUrl(String imageName) {
        return  + imageName;
    }

    
Gets the path to the provided javascript file inside this plugin.

Parameters:
jsName the name if the javascript.
Returns:
the full path to the file.
See also:
PLUGIN_JS_URL
    public static String getPluginJsUrl(String jsName) {
        return  + jsName;
    }

    
Escape quotes in String value.

Parameters:
value the name of String object having quotes.
Returns:
String object as the result of escape quotes in input.
    public static String escapeQuotes(String value) {
        if (value == null) {
            return null;
        } else {
            return .matcher(value).replaceAll("\\\\\"");
        }
    }
New to GrepCode? Check out our FAQ X