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.
 package com.sonyericsson.hudson.plugins.gerrit.trigger.utils;
Various string making utility methods.

Robert Sandell <>
 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) {
         } else if (number.length() == 2) {
         } else {
             str.append(number.substring(number.length() - 2));
         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.

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

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

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

Escape quotes in String value.

value the name of String object having quotes.
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