All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.openshift.launchpad.ui.input.ProjectName Maven / Gradle / Ivy

There is a newer version: 18
Show newest version
/*
 * Copyright 2017 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package io.openshift.launchpad.ui.input;

import java.util.regex.Pattern;

import javax.inject.Inject;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.valuehandling.UnwrapValidatedValue;
import org.jboss.forge.addon.ui.input.AbstractUIInputDecorator;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.metadata.WithAttributes;

/**
 * The project name input
 * 
 * @author George Gastaldi
 */
public class ProjectName extends AbstractUIInputDecorator
{
   private static final Pattern SPECIAL_CHARS = Pattern.compile("[-a-z0-9]|[a-z0-9][-a-z0-9]*[a-z0-9]");

   @Inject
   @WithAttributes(label = "Project name", required = true, defaultValue = "demo", note = "Downloadable project zip and application jar are based on the project name")
   @UnwrapValidatedValue
   @Length(min = 1, max = 24)
   private UIInput named;

   @Override
   protected UIInput createDelegate()
   {
      named.addValidator(context -> {
         if (named.getValue() != null
                 && !SPECIAL_CHARS.matcher(named.getValue()).matches())
            context.addValidationError(named,
                     "Project name must not contain spaces or special characters.");
      }).setDescription("The following characters are accepted: -a-z0-9 and the name cannot start or end with a dash");
      return named;
   }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy