Example usage for org.apache.commons.lang StringUtils StringUtils

List of usage examples for org.apache.commons.lang StringUtils StringUtils

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils StringUtils.

Prototype

public StringUtils() 

Source Link

Document

StringUtils instances should NOT be constructed in standard programming.

Usage

From source file:com.atlassian.jira.plugin.navigation.FooterModuleDescriptorImpl.java

protected Map<String, Object> createVelocityParams(HttpServletRequest request, Map startingParams) {
    final Map<String, Object> params = (startingParams != null) ? new HashMap<String, Object>(startingParams)
            : new HashMap<String, Object>();

    String licenseMessageClass = null;

    final LicenseDetails licenseDetails = jiraLicenseService.getLicense();
    if (!licenseDetails.isLicenseSet() || licenseDetails.isEvaluation() || !licenseDetails.isCommercial()
            || licenseDetails.hasLicenseTooOldForBuildConfirmationBeenDone()) {
        params.put("notfull", Boolean.TRUE);

        if (!licenseDetails.isLicenseSet()) // unlicensed
        {//from  w w  w .  ja  v  a2 s  . co m
            params.put("unlicensed", Boolean.TRUE);
            licenseMessageClass = "licensemessagered";
        } else if (licenseDetails.isEvaluation()) {
            params.put("evaluation", Boolean.TRUE);
            licenseMessageClass = "licensemessagered";
        } else if (licenseDetails.hasLicenseTooOldForBuildConfirmationBeenDone()) {
            params.put("confirmedWithOldLicense", Boolean.TRUE);
            licenseMessageClass = "licensemessagered";
        } else if (licenseDetails.isCommunity()) {
            params.put("community", Boolean.TRUE);
            licenseMessageClass = "licensemessage";
        } else if (licenseDetails.isOpenSource()) {
            params.put("opensource", Boolean.TRUE);
            licenseMessageClass = "licensemessage";
        } else if (licenseDetails.isNonProfit()) {
            params.put("nonprofit", Boolean.TRUE);
            licenseMessageClass = "licensemessage";
        } else if (licenseDetails.isDemonstration()) {
            params.put("demonstration", Boolean.TRUE);
            licenseMessageClass = "licensemessage";
        } else if (licenseDetails.isDeveloper()) {
            params.put("developer", Boolean.TRUE);
            licenseMessageClass = "licensemessage";
        } else if (licenseDetails.isPersonalLicense()) {
            licenseMessageClass = "licensemessage";
            params.put("personal", licenseDetails.isPersonalLicense());
        }
    }

    if (licenseMessageClass != null) {
        params.put("licenseMessageClass", licenseMessageClass);
    }
    params.put("organisation", licenseDetails.getOrganisation());
    params.put("serverid", jiraLicenseService.getServerId());
    params.put("externalLinkUtil", ExternalLinkUtilImpl.getInstance());
    params.put("utilTimerStack", new UtilTimerStack());
    params.put("version", buildUtilsInfo.getVersion());
    params.put("buildNumber", buildUtilsInfo.getCurrentBuildNumber());
    params.put("req", request);
    params.put("build", buildUtilsInfo);
    params.put("string", new StringUtils());
    params.put("isSysAdmin",
            permissionManager.hasPermission(SYSTEM_ADMIN, getAuthenticationContext().getUser()));
    params.put("showContactAdminForm", applicationProperties.getOption(JIRA_SHOW_CONTACT_ADMINISTRATORS_FORM));

    if (clusterManager.isClustered()) {
        params.put("nodeId", clusterManager.getNodeId());
    }

    return params;
}

From source file:org.anon.smart.generator.code.Codegen.java

/**
 * Generate a java source file for the specified interface description.
 * /*from   w w  w.  j a va2  s . com*/
 * @param id
 *            interface description, must not be null
 */
public static void generateSource(final InterfaceDescription id) {
    if (id == null) {
        throw new IllegalArgumentException("id must not be null");
    }

    FileWriter fw = null;
    try {
        System.out.println("The function was called");
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        Velocity.init(p);

        fw = new FileWriter(id.getUpper() + ".java");

        VelocityContext context = new VelocityContext();
        context.put("id", id);
        context.put("CodegenUtils", new CodegenUtils());
        context.put("StringUtils", new StringUtils());

        Template template = Velocity.getTemplate("org/dishevelled/codegen/Interface.wm");
        template.merge(context, fw);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            fw.close();
        } catch (Exception e) {
            // empty
        }
    }
}

From source file:org.anon.smart.generator.code.Codegen.java

/**
 * Generate an abstract unit test java source file for the specified
 * interface description.// w  ww.j a va2s.co m
 * 
 * @param id
 *            interface description, must not be null
 */
public static void generateAbstractUnitTest(final InterfaceDescription id) {
    if (id == null) {
        throw new IllegalArgumentException("id must not be null");
    }

    FileWriter fw = null;
    try {
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        Velocity.init(p);

        fw = new FileWriter("Abstract" + id.getUpper() + "Test.java");

        VelocityContext context = new VelocityContext();
        context.put("id", id);
        context.put("CodegenUtils", new CodegenUtils());
        context.put("StringUtils", new StringUtils());

        Template template = Velocity.getTemplate("org/anon/smart/generator/templates/AbstractInterfaceTest.wm");
        template.merge(context, fw);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            fw.close();
        } catch (Exception e) {
            // empty
        }
    }
}

From source file:org.anon.smart.generator.code.Codegen.java

/**
 * Generate a java source file for the specified class description and
 * style./*  w  w w  . j a  va2  s  .c  o m*/
 * 
 * @param cd
 *            class description, must not be null
 * @param style
 *            style, must not be null
 */
public static void generateSource(final ClassDescription cd, String targetPath, final Style style) {
    if (cd == null) {
        throw new IllegalArgumentException("cd must not be null");
    }
    if (style == null) {
        throw new IllegalArgumentException("style must not be null");
    }

    FileWriter fw = null;
    try {
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        Velocity.init(p);

        File targetFile = new File(targetPath + cd.getUpper() + ".java");
        File parent = targetFile.getParentFile();

        // clear target directory:
        if (parent.exists()) {
            parent.delete();
        }
        // create new target directory:
        parent.mkdirs();

        fw = new FileWriter(targetFile);

        VelocityContext context = new VelocityContext();
        context.put("cd", cd);
        context.put("CodegenUtils", new CodegenUtils());
        context.put("StringUtils", new StringUtils());

        Template template = Velocity.getTemplate("org/anon/smart/generator/templates/" + style + ".wm");
        template.merge(context, fw);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            fw.close();
        } catch (Exception e) {
            // empty
        }
    }
}

From source file:org.anon.smart.generator.code.Codegen.java

/**
 * Generate a java source file for a fluent builder API for the specified
 * class description and style.//  ww  w. jav a  2  s .  co m
 * 
 * @param cd
 *            class description, must not be null
 * @param style
 *            style, must not be null
 */
public static void generateBuilderSource(final ClassDescription cd, final Style style) {
    // TODO: perhaps style doesn't matter here, if all the templates are the
    // same
    if (cd == null) {
        throw new IllegalArgumentException("cd must not be null");
    }
    if (style == null) {
        throw new IllegalArgumentException("style must not be null");
    }

    FileWriter fw = null;
    try {
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        Velocity.init(p);

        fw = new FileWriter(cd.getUpper() + "Builder.java");

        VelocityContext context = new VelocityContext();
        context.put("cd", cd);
        context.put("CodegenUtils", new CodegenUtils());
        context.put("StringUtils", new StringUtils());

        Template template = Velocity.getTemplate("org/anon/smart/generator/templates/" + style + "Builder.wm");
        template.merge(context, fw);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            fw.close();
        } catch (Exception e) {
            // empty
        }
    }
}

From source file:org.anon.smart.generator.code.Codegen.java

/**
 * Generate a unit test source file for the specified class description and
 * style.//from   w w w  . ja  va  2  s .com
 * 
 * @param cd
 *            class description, must not be null
 * @param style
 *            style, must not be null
 */
public static void generateUnitTest(final ClassDescription cd, final Style style) {
    if (cd == null) {
        throw new IllegalArgumentException("cd must not be null");
    }
    if (style == null) {
        throw new IllegalArgumentException("style must not be null");
    }

    FileWriter fw = null;
    try {
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        Velocity.init(p);

        fw = new FileWriter(cd.getUpper() + "Test.java");

        VelocityContext context = new VelocityContext();
        context.put("cd", cd);
        context.put("CodegenUtils", new CodegenUtils());
        context.put("StringUtils", new StringUtils());

        Template template = Velocity.getTemplate("org/anon/smart/generator/templates/" + style + "Test.wm");
        template.merge(context, fw);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            fw.close();
        } catch (Exception e) {
            // empty
        }
    }
}

From source file:org.anon.smart.generator.code.Codegen.java

/**
 * Generate an enum source file for the specified class description.
 * /* ww  w.  j  ava 2s  . c  o  m*/
 * @param cd
 *            class description, must not be null
 */
public static void generateEnum(final ClassDescription cd) {
    if (cd == null) {
        throw new IllegalArgumentException("cd must not be null");
    }

    FileWriter fw = null;
    try {
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        Velocity.init(p);

        fw = new FileWriter(cd.getUpper() + ".java");

        VelocityContext context = new VelocityContext();
        context.put("cd", cd);
        context.put("CodegenUtils", new CodegenUtils());
        context.put("StringUtils", new StringUtils());

        Template template = Velocity.getTemplate("org/anon/smart/generator/templates/Enum.wm");
        template.merge(context, fw);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            fw.close();
        } catch (Exception e) {
            // empty
        }
    }
}

From source file:org.anon.smart.generator.code.Codegen.java

/**
 * Generate an enum with lookup source file for the specified class
 * description.//from  w  w  w .  j  a  v  a  2  s.com
 * 
 * @param cd
 *            class description, must not be null
 */
public static void generateEnumWithLookup(final ClassDescription cd) {
    if (cd == null) {
        throw new IllegalArgumentException("cd must not be null");
    }

    FileWriter fw = null;
    try {
        Properties p = new Properties();
        p.setProperty("resource.loader", "class");
        p.setProperty("class.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

        Velocity.init(p);

        fw = new FileWriter(cd.getUpper() + ".java");

        VelocityContext context = new VelocityContext();
        context.put("cd", cd);
        context.put("CodegenUtils", new CodegenUtils());
        context.put("StringUtils", new StringUtils());

        Template template = Velocity.getTemplate("org/anon/smart/generator/templates/EnumWithLookup.wm");
        template.merge(context, fw);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        try {
            fw.close();
        } catch (Exception e) {
            // empty
        }
    }
}

From source file:org.carrot2.util.attribute.metadata.VelocityInitializer.java

/**
 * Create Velocity context and place default tools into it.
 *///from  ww  w. j  a v  a 2s.  c  o m
public static VelocityContext createContext() {
    final VelocityContext context = new VelocityContext();

    context.put("esc", new EscapeTool());
    context.put("stringutils", new StringUtils());
    context.put("methodutils", new MethodUtils());

    return context;
}

From source file:org.carrot2.workbench.velocity.VelocityInitializer.java

/**
 * Create Velocity context and place default tools into it.
 */// ww  w .ja v a  2  s .  c  o m
public static VelocityContext createContext() {
    final VelocityContext context = new VelocityContext();

    context.put("esc", new EscapeTool());
    context.put("stringutils", new StringUtils());
    context.put("annotationutils", new AnnotationUtils());

    final IPreferenceStore store = WorkbenchCorePlugin.getDefault().getPreferenceStore();
    int maxFieldLength = store.getInt(PreferenceConstants.MAX_FIELD_LENGTH);
    if (maxFieldLength == 0)
        maxFieldLength = Integer.MAX_VALUE;
    context.put("maxFieldLength", maxFieldLength);

    return context;
}