├── addressbook_screenshot.png ├── src ├── test │ ├── resources │ │ └── Dateformat.properties │ └── java │ │ └── com │ │ └── edurekademo │ │ └── utilities │ │ ├── UnitDTO.java │ │ ├── ExceptionThrower.java │ │ ├── TestHexAsciiConversion.java │ │ ├── TestLogger.java │ │ └── TestGenericComparator.java └── main │ ├── java │ └── com │ │ └── edurekademo │ │ ├── helper │ │ └── GenericResourceBundle.java │ │ ├── utilities │ │ ├── PrepareTargetMethod.java │ │ ├── HexAsciiConvertor.java │ │ ├── LoggerStackTraceUtil.java │ │ ├── PropertyHelper.java │ │ ├── PropertyLoader.java │ │ ├── CaseInsensitiveComparator.java │ │ ├── StringUtilities.java │ │ └── GenericComparator.java │ │ └── tutorial │ │ └── addressbook │ │ ├── backend │ │ ├── Contact.java │ │ └── ContactService.java │ │ ├── ContactForm.java │ │ └── AddressbookUI.java │ └── pmd │ ├── ruleset_security.xml │ ├── pmd.xsl │ ├── ruleset_basics.xml │ └── ruleset_j2ee.xml ├── README.md └── pom.xml /addressbook_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edureka-git/devops/HEAD/addressbook_screenshot.png -------------------------------------------------------------------------------- /src/test/resources/Dateformat.properties: -------------------------------------------------------------------------------- 1 | EXPECTED=yyyy-MM-dd 2 | ACTUAL=dd-MM-yyyy 3 | TIME=hh:mm:ss aa 4 | TIMEIN=HH:mm:ss -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/helper/GenericResourceBundle.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.helper; 2 | 3 | import java.util.Enumeration; 4 | import java.util.ResourceBundle; 5 | 6 | public class GenericResourceBundle { 7 | public static String getProperties(String source){ 8 | ResourceBundle rb = ResourceBundle.getBundle("ResourceBundle"); 9 | Enumeration keys = rb.getKeys(); 10 | String value=""; 11 | while (keys.hasMoreElements()) { 12 | 13 | String key = keys.nextElement(); 14 | 15 | if(key.equalsIgnoreCase(source)){ 16 | value = rb.getString(key); 17 | } 18 | } 19 | return value; 20 | } 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/utilities/PrepareTargetMethod.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | public class PrepareTargetMethod { 4 | 5 | private static final String METHOD_GET_PREFIX = "get"; 6 | /** 7 | * preparing target name of getter method for given sort field 8 | * 9 | * @param name a {@link java.lang.String} 10 | * @return methodName a {@link java.lang.String} 11 | */ 12 | public String prepareTargetMethod(String name) { 13 | StringBuffer fieldName = new StringBuffer(METHOD_GET_PREFIX); 14 | fieldName.append(name.substring(0, 1).toUpperCase()).append(name.substring(1)); 15 | return fieldName.toString(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/pmd/ruleset_security.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | These rules check the security guidelines from Sun, published at http://java.sun.com/security/seccodeguide.html#gcg 8 | 9 | 10 | 17 | 3 18 | 3 19 | 20 | -------------------------------------------------------------------------------- /src/test/java/com/edurekademo/utilities/UnitDTO.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | public class UnitDTO { 4 | 5 | private Integer empID; 6 | private String empName; 7 | private Integer deptID; 8 | private String dateofJoining; 9 | private Double spare; 10 | private Object spare2; 11 | 12 | public Integer getEmpID() { 13 | return empID; 14 | } 15 | public void setEmpID(Integer empID) { 16 | this.empID = empID; 17 | } 18 | public String getEmpName() { 19 | return empName; 20 | } 21 | public void setEmpName(String empName) { 22 | this.empName = empName; 23 | } 24 | public Integer getDeptID() { 25 | return deptID; 26 | } 27 | public void setDeptID(Integer deptID) { 28 | this.deptID = deptID; 29 | } 30 | public String getDateofJoining() { 31 | return dateofJoining; 32 | } 33 | public void setDateofJoining(String dateofJoining) { 34 | this.dateofJoining = dateofJoining; 35 | } 36 | public Double getSpare() { 37 | return spare; 38 | } 39 | public void setSpare(Double spare) { 40 | this.spare = spare; 41 | } 42 | public Object getSpare2() { 43 | return spare2; 44 | } 45 | public void setSpare2(Object spare2) { 46 | this.spare2 = spare2; 47 | } 48 | 49 | public UnitDTO() { 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/edurekademo/utilities/ExceptionThrower.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | import java.io.IOException; 4 | 5 | import com.edurekademo.utilities.LoggerStackTraceUtil; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | public class ExceptionThrower { 10 | 11 | private static final Logger LOG=LoggerFactory.getLogger(ExceptionThrower.class); 12 | public void getCounter() { 13 | int i = 1/0; // this will throw the error... 14 | LOG.info(""+i); 15 | } 16 | 17 | public void doNothing() throws IOException { 18 | throw new IOException("TESTIOEXCEPTION"); 19 | } 20 | 21 | private void doXXX() { 22 | try { 23 | doYYY(); 24 | String s = null; 25 | if("sss".equals(s)) { 26 | LOG.info("ssss"); 27 | } 28 | } 29 | catch (Exception e){ 30 | LOG.error(new LoggerStackTraceUtil().getErrorMessage(e)); 31 | } 32 | } 33 | 34 | private void doYYY() { 35 | LOG.error(new LoggerStackTraceUtil().getErrorMessage(new Exception("DEAR"))); 36 | } 37 | public void doCheck() throws Exception { 38 | try { 39 | doXXX(); 40 | doNothing(); 41 | } 42 | catch (Exception e){ 43 | throw new Exception("TEST MESSAGE"); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/utilities/HexAsciiConvertor.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | public class HexAsciiConvertor { 4 | /** 5 | * Method to convert hexadecimal values into ascii 6 | * method is return the ascii value 7 | * @param hexValue 8 | * @return outputAscii 9 | */ 10 | 11 | public static String convertHexToASCII(String hexValue) 12 | { 13 | StringBuilder outputAscii = new StringBuilder(); 14 | String asciiValue = null; 15 | try{ 16 | if(hexValue!=null){ 17 | for (int i = 0; i < hexValue.length(); i += 2) 18 | { 19 | String str = hexValue.substring(i, i + 2); 20 | outputAscii.append((char) Integer.parseInt(str, 16)); 21 | } 22 | asciiValue = outputAscii.toString(); 23 | } 24 | } 25 | catch(Exception ex){ 26 | LoggerStackTraceUtil.printErrorMessage(ex); 27 | } 28 | return asciiValue; 29 | } 30 | 31 | /** 32 | * Method to convert ascii values into hexadecimal 33 | * method is returning the hexadecimal value 34 | * @param asciiValue 35 | * @return hex 36 | */ 37 | 38 | public static String convertAsciiToHex(String asciiValue) 39 | { 40 | String hexvalue = null; 41 | try { 42 | 43 | if(asciiValue!=null) 44 | { 45 | char[] chars = asciiValue.toCharArray(); 46 | StringBuffer hex = new StringBuffer(); 47 | for (int i = 0; i < chars.length; i++) 48 | { 49 | hex.append(Integer.toHexString((int) chars[i])); 50 | } 51 | hexvalue= hex.toString(); 52 | } 53 | } 54 | catch (Exception e) { 55 | LoggerStackTraceUtil.printErrorMessage(e); 56 | } 57 | return hexvalue; 58 | } 59 | } -------------------------------------------------------------------------------- /src/test/java/com/edurekademo/utilities/TestHexAsciiConversion.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import com.edurekademo.utilities.HexAsciiConvertor; 6 | import org.junit.AfterClass; 7 | import org.junit.BeforeClass; 8 | import org.junit.Test; 9 | 10 | 11 | public class TestHexAsciiConversion { 12 | 13 | HexAsciiConvertor conversion=new HexAsciiConvertor(); 14 | String Value="testing ascii convertion into hexadecimal"; 15 | String hexvalue="74657374696e6720617363696920636f6e76657274696f6e20696e746f2068657861646563696d616c"; 16 | @BeforeClass 17 | public static void setUpBeforeClass() throws Exception { 18 | } 19 | 20 | @AfterClass 21 | public static void tearDownAfterClass() throws Exception { 22 | } 23 | 24 | @Test 25 | public void testAsciiToHexValid() { 26 | String hexadecimalValue= conversion.convertAsciiToHex(Value); 27 | assertEquals(" ",hexadecimalValue, "74657374696e6720617363696920636f6e76657274696f6e20696e746f2068657861646563696d616c"); 28 | System.out.println(hexadecimalValue); 29 | } 30 | 31 | @Test 32 | public void testAsciiToHexNull() 33 | { 34 | String hexvalueNull=conversion.convertHexToASCII(null); 35 | assertNull("Result should be null", hexvalueNull); 36 | 37 | } 38 | 39 | @Test 40 | 41 | public void testHexToAsciiValid() 42 | { 43 | String asciiValue=conversion.convertHexToASCII(hexvalue); 44 | 45 | assertEquals(" ",asciiValue,"testing ascii convertion into hexadecimal"); 46 | System.out.println(asciiValue); 47 | } 48 | 49 | @Test 50 | 51 | public void testHextoAsciiNull() 52 | { 53 | String asciiValueNull=conversion.convertAsciiToHex(null); 54 | assertNull("Result should be null", asciiValueNull); 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/utilities/LoggerStackTraceUtil.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | import org.apache.commons.lang3.exception.ExceptionUtils; 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | // Class used to log the print stack trace items 7 | public class LoggerStackTraceUtil { 8 | 9 | private static final Logger LOG =LoggerFactory.getLogger(LoggerStackTraceUtil.class); 10 | private int maxCount=3; 11 | 12 | /** 13 | * @param th - The exception that was thrown and to be logged. 14 | * @return at very least the 1st error, if stacktrace is more than 1, then it also 15 | * returns the immediate cause 16 | * 17 | * Note this function cannot be made static for thread safety.. 18 | */ 19 | public String getErrorMessage(Throwable th){ 20 | if (th==null) return ""; 21 | StringBuilder b = new StringBuilder(""); 22 | String [] aryError = ExceptionUtils.getRootCauseStackTrace(th); 23 | b.append(aryError[0].trim()); 24 | if (aryError.length >= 2){ 25 | b.append(String.format("%nCause:%s",aryError[1].trim())); 26 | } 27 | if (aryError.length >= maxCount){ 28 | b.append(String.format("%nCause:%s",aryError[2].trim())); 29 | } 30 | return b.toString(); 31 | } 32 | 33 | // Static Logger function 34 | public static void printErrorMessage(Throwable th) 35 | { 36 | try{ 37 | // log the error caused by 38 | LOG.error("Error Cause: {}",th.getMessage()); 39 | // Conditional statement to check the length of the array 40 | int count=0; 41 | for(StackTraceElement stackTrace:th.getStackTrace()){ 42 | if(count<=25){ 43 | LOG.error("Error Class: {} and Line Number: {}",stackTrace.getClassName(),stackTrace.getLineNumber()); 44 | }else{ 45 | break; 46 | } 47 | count++; 48 | } 49 | } 50 | catch(Exception e) 51 | { 52 | // log the exception error 53 | LoggerStackTraceUtil.printErrorMessage(e); 54 | } 55 | 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/tutorial/addressbook/backend/Contact.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.tutorial.addressbook.backend; 2 | 3 | import org.apache.commons.beanutils.BeanUtils; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | /** 9 | * A simple DTO for the address book example. 10 | * 11 | * Serializable and cloneable Java Object that are typically persisted 12 | * in the database and can also be easily converted to different formats like JSON. 13 | */ 14 | // Backend DTO class. This is just a typical Java backend implementation 15 | // class and nothing Vaadin specific. 16 | public class Contact implements Serializable, Cloneable { 17 | 18 | private Long id; 19 | 20 | private String firstName = ""; 21 | private String lastName = ""; 22 | private String phone = ""; 23 | private String email = ""; 24 | private Date birthDate; 25 | 26 | public Long getId() { 27 | return id; 28 | } 29 | 30 | public void setId(Long id) { 31 | this.id = id; 32 | } 33 | 34 | public String getFirstName() { 35 | return firstName; 36 | } 37 | 38 | public void setFirstName(String firstName) { 39 | this.firstName = firstName; 40 | } 41 | 42 | public String getLastName() { 43 | return lastName; 44 | } 45 | 46 | public void setLastName(String lastName) { 47 | this.lastName = lastName; 48 | } 49 | 50 | public String getPhone() { 51 | return phone; 52 | } 53 | 54 | public void setPhone(String phone) { 55 | this.phone = phone; 56 | } 57 | 58 | public String getEmail() { 59 | return email; 60 | } 61 | 62 | public void setEmail(String email) { 63 | this.email = email; 64 | } 65 | 66 | public Date getBirthDate() { 67 | return birthDate; 68 | } 69 | 70 | public void setBirthDate(Date birthDate) { 71 | this.birthDate = birthDate; 72 | } 73 | 74 | @Override 75 | public Contact clone() throws CloneNotSupportedException { 76 | try { 77 | return (Contact) BeanUtils.cloneBean(this); 78 | } catch (Exception ex) { 79 | throw new CloneNotSupportedException(); 80 | } 81 | } 82 | 83 | @Override 84 | public String toString() { 85 | return "Contact{" + "id=" + id + ", firstName=" + firstName 86 | + ", lastName=" + lastName + ", phone=" + phone + ", email=" 87 | + email + ", birthDate=" + birthDate + '}'; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/utilities/PropertyHelper.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | import java.util.Enumeration; 4 | import java.util.HashMap; 5 | import java.util.Properties; 6 | @SuppressWarnings("unchecked") 7 | 8 | /** 9 | * Helper Class to load Properties from a property file to be passed to caller for execution. 10 | * Multiple properties can be loaded. 11 | * Note that if same property is specified multiple times in a single file, there is no guaranteed "Winner" 12 | * Also note in the case of loading multiple files and duplicate definition of properties across files, 13 | * the last loaded property file "wins". 14 | * The getProperty()/get() methods also returns "" silently if no such query exists. 15 | * @author Seshagiri Sriram 16 | * @version 1.0 17 | * @see PropertyLoader 18 | */ 19 | 20 | public final class PropertyHelper { 21 | 22 | /** 23 | * hMapProperties contains the hashmap of key/value pairs associated with each property 24 | */ 25 | protected final static HashMap HMAPPROPERTIES = new HashMap(); 26 | 27 | 28 | /** 29 | * @param propertyFile 30 | * @return 31 | */ 32 | public static HashMap loadProperties(String propertyFile) { 33 | Properties properties = PropertyLoader.loadProperties(propertyFile); 34 | Enumeration keys = (Enumeration) properties.propertyNames(); 35 | while (keys.hasMoreElements()) { 36 | String tmpKey = (String) keys.nextElement(); 37 | HMAPPROPERTIES.put(tmpKey,properties.getProperty(tmpKey)); 38 | 39 | } 40 | return HMAPPROPERTIES; 41 | } 42 | 43 | 44 | /** 45 | * @param propertyName 46 | * @return 47 | */ 48 | public static String getProperty(String propertyName){ 49 | String propertyValue = ""; 50 | try { 51 | propertyValue = (String) HMAPPROPERTIES.get(propertyName); 52 | } 53 | catch (Exception e){ 54 | LoggerStackTraceUtil.printErrorMessage(e); 55 | propertyValue = ""; 56 | } 57 | finally { 58 | } 59 | return propertyValue; 60 | } 61 | 62 | /** 63 | * Function used to get the default value if the property is null 64 | * @param propertyName - Name of the property 65 | * @param strDefault - Default value that needs to be returned if the value is null 66 | * @return Property value/Default Value as String 67 | */ 68 | public static String getProperty(String propertyName,String strDefault){ 69 | String propertyValue = ""; 70 | try { 71 | propertyValue = (String) HMAPPROPERTIES.get(propertyName); 72 | // Check the property value is null/not 73 | if(propertyValue == null){ 74 | // Assign the default value to the propertyValue 75 | propertyValue=strDefault; 76 | } 77 | } 78 | catch (Exception e){ 79 | LoggerStackTraceUtil.printErrorMessage(e); 80 | propertyValue = ""; 81 | } 82 | finally { 83 | } 84 | return propertyValue; 85 | } 86 | 87 | /** 88 | * A convenience method (aliasing getProperty) 89 | * @param propertyName property to be retrieved. 90 | * @return 91 | * @see getProperty 92 | */ 93 | public static String get(String propertyName){ 94 | return getProperty(propertyName); 95 | } 96 | } 97 | 98 | -------------------------------------------------------------------------------- /src/test/java/com/edurekademo/utilities/TestLogger.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | import com.edurekademo.utilities.LoggerStackTraceUtil; 3 | import org.junit.Test; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | public class TestLogger { 8 | 9 | private static final Logger LOG = LoggerFactory.getLogger(TestLogger.class); 10 | @Test 11 | public void testGetErrorMessage1() { 12 | String s = "Not Implemented"; 13 | try { 14 | int f = 1/0; 15 | System.out.println(f); 16 | } 17 | catch (Exception e){ 18 | LoggerStackTraceUtil util = new LoggerStackTraceUtil(); 19 | s = util.getErrorMessage(e); 20 | } 21 | LOG.info(s); 22 | assert(s.contains(System.getProperty("line.separator"))); 23 | } 24 | @Test 25 | public void testGetErrorMessage2() { 26 | String s = "Not Implemented"; 27 | LoggerStackTraceUtil util = new LoggerStackTraceUtil(); 28 | 29 | try { 30 | int f = 1/0; 31 | LOG.info(""+f); 32 | } 33 | catch (Exception e){ 34 | s = util.getErrorMessage(e); 35 | } 36 | LOG.info(s); 37 | assert(s.contains("/ by zero")); 38 | } 39 | 40 | @Test 41 | public void testGetErrorMessage3() { 42 | String s = "Not Implemented"; 43 | try { 44 | ExceptionThrower g = new ExceptionThrower(); 45 | g.getCounter(); 46 | } 47 | catch (Exception e){ 48 | LoggerStackTraceUtil util = new LoggerStackTraceUtil(); 49 | s = util.getErrorMessage(e); 50 | } 51 | LOG.info(s); 52 | assert(s.contains("/ by zero")); 53 | } 54 | 55 | @Test 56 | public void testGetErrorMessage4() { 57 | String s = "Not Implemented"; 58 | try { 59 | ExceptionThrower g = new ExceptionThrower(); 60 | g.doNothing(); 61 | } 62 | catch (Exception e){ 63 | LoggerStackTraceUtil util = new LoggerStackTraceUtil(); 64 | s = util.getErrorMessage(e); 65 | } 66 | LOG.info(s); 67 | assert(s.contains("TESTIOEXCEPTION")); 68 | } 69 | 70 | @Test 71 | public void testGetErrorMessage5() { 72 | String s = "Not Implemented"; 73 | try { 74 | ExceptionThrower g = new ExceptionThrower(); 75 | g.doCheck(); 76 | 77 | } 78 | catch (Exception e){ 79 | LoggerStackTraceUtil util = new LoggerStackTraceUtil(); 80 | s = util.getErrorMessage(e); 81 | } 82 | finally { 83 | LOG.info(s); 84 | System.out.println("***** "+s); 85 | assert(s.contains("TEST MESSAGE")); 86 | 87 | } 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Addressbook Tutorial 2 | ==================== 3 | 4 | This tutorial teaches you some of the basic concepts in [Vaadin Framework](https://vaadin.com). It is meant to be 5 | a fast read for learning how to get started - not an example on how application should be 6 | designed. Please note this example uses and requires Java 8 to work. 7 | 8 | ![Addressbook Screenshot](addressbook_screenshot.png "Addressbook Screenshot") 9 | 10 | 11 | Running the example from the command line 12 | ------------------- 13 | ``` 14 | $ mvn jetty:run 15 | ``` 16 | 17 | Open [http://localhost:8080/](http://localhost:8080/) 18 | 19 | 20 | Importing in IntelliJ IDEA 14 21 | -------------------- 22 | These instructions were tested on IntelliJ IDEA 14 CE. You can get it from https://www.jetbrains.com/idea/ 23 | 24 | To get the project up and running in IDEA, do: 25 | - File -> New -> Project from Version Control -> Git 26 | - The URL to use is https://github.com/vaadin/addressbook.git 27 | - If you get a message about "Non-managed pom.xml file found". Choose "Add as Maven Project" 28 | - If you get a message about no JDK or SDK being selected. Choose "Configure" and select your installed JDK. You can also set the JDK using File -> Project Structure 29 | - To start the project, find the "Maven Projects" tab on the right hand side of the screen and navigate to 30 | - Vaadin Web Application -> Plugins -> jetty -> jetty:run 31 | - Click the play button or right click and select Run (Select Debug instead to run in debug mode) 32 | 33 | You should now have a Jetty server running on localhost:8080. Navigate to http://localhost:8080 to play with the application 34 | 35 | Importing in NetBeans 8 36 | -------------------- 37 | These instructions were tested on NetBeans 8.0.2. You can get it from https://www.netbeans.org 38 | 39 | To checkout and run the project in NetBeans, do: 40 | - Team -> Git -> Clone 41 | - Set repository URL to https://github.com/vaadin/addressbook.git 42 | - Finish 43 | - Right click the imported project (Vaadin Addressbook Application) and select Run 44 | - Select GlassFish Server 4.1 -> Remember in Current IDE Session -> OK 45 | 46 | You should now have a GlassFish server running on localhost:8080 and a browser tab should also be automatically opened with this location 47 | 48 | Importing in Eclipse 49 | -------------------- 50 | These instructions were tested on Eclipse IDE for Java EE Developers Luna SR2. You can get it from http://eclipse.org/downloads/ 51 | 52 | To checkout and run the project in Eclipse, do: 53 | - File -> Import... 54 | - Check out Maven Projects from SCM 55 | - Choose Git from SCM menu 56 | - If you do not see "Git" in the SCM menu, click "Find more SCM connectors in the m2e Marketplace" and install "m2e-egit". Restart Eclipse and start over. 57 | - Set the repository URL to https://github.com/vaadin/addressbook.git 58 | - Right click the imported "addressbook" and choose Run As -> Maven Build... 59 | - Set the goal to "jetty:run" and click "Run" 60 | 61 | You should now have a Jetty server running on localhost:8080. Navigate to [http://localhost:8080/](http://localhost:8080/) to play with the application 62 | 63 | To use the built in server adapters of Eclipse, instead of doing "Run As -> Maven Build..." you can do 64 | - Run As -> Run on Server 65 | - Select the server you want to run on, e.g. Apache Tomcat 8 and click ok 66 | - *Do not use the suggested J2EE Preview server* as it is outdated, deprecated and does not support Servlet 3, which is required for this application 67 | 68 | *** End of documentation -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/utilities/PropertyLoader.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | import java.io.InputStream; 4 | import java.util.Enumeration; 5 | import java.util.Locale; 6 | import java.util.Properties; 7 | import java.util.ResourceBundle; 8 | 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | /** 12 | * Looks up a resource named 'name' in the classpath. The resource must map 13 | * to a file with .properties extention. The name is assumed to be absolute 14 | * and can use either "/" or "." for package segment separation with an 15 | * optional leading "/" and optional ".properties" suffix. Thus, the 16 | * following names refer to the same resource: 17 | * 18 | * @author Seshagiri Sriram 19 | * @version 1.0 20 | * @param name classpath resource name [may not be null] 21 | * @param loader classloader through which to load the resource [null 22 | * is equivalent to the application loader] 23 | * @return resource converted to java.util.Properties [may be null if the 24 | * resource was not found and THROW_ON_LOAD_FAILURE is false] 25 | * @throws IllegalArgumentException if the resource was not found and 26 | * THROW_ON_LOAD_FAILURE is true 27 | */ 28 | 29 | public class PropertyLoader 30 | { 31 | 32 | private static final boolean THROW_ON_LOAD_FAILURE = true; 33 | private static final boolean LOAD_AS_RESOURCE_BUNDLE = false; 34 | private static final String SUFFIX = ".properties"; 35 | 36 | /** 37 | * Logger enabled for the current class 38 | */ 39 | private static final Logger LOG =LoggerFactory.getLogger(PropertyLoader.class); 40 | 41 | /** 42 | * A convenience overload of {@link #loadProperties(String, ClassLoader)} 43 | * that uses the current thread's context classloader. 44 | */ 45 | 46 | public static Properties loadProperties (final String name) { 47 | return loadProperties (name, Thread.currentThread ().getContextClassLoader ()); 48 | } 49 | 50 | @SuppressWarnings("rawtypes") 51 | public static Properties loadProperties (String names, ClassLoader loader) 52 | { 53 | String name = null; 54 | ClassLoader loaders; 55 | if (names == null) throw new IllegalArgumentException ("null input: name"); 56 | if (names.startsWith ("/")) name = names.substring (1); 57 | if (names.endsWith (SUFFIX)) name = names.substring (0, names.length () - SUFFIX.length ()); 58 | Properties result = null; 59 | InputStream in = null; 60 | try { 61 | if (loader == null) 62 | loaders = ClassLoader.getSystemClassLoader (); 63 | if (LOAD_AS_RESOURCE_BUNDLE) 64 | { 65 | name = name.replace ('/', '.'); // Throws MissingResourceException on lookup failures: 66 | final ResourceBundle rb = ResourceBundle.getBundle (name, Locale.getDefault (), loaders); 67 | result = new Properties (); 68 | for (Enumeration keys = rb.getKeys (); keys.hasMoreElements ();) 69 | { 70 | final String key = (String) keys.nextElement (); 71 | final String value = rb.getString (key); 72 | result.put (key, value); 73 | } 74 | } 75 | else { 76 | name = name.replace ('.', '/'); 77 | if (! name.endsWith (SUFFIX)) name = name.concat (SUFFIX); // Returns null on lookup failures: 78 | if(loader!=null) 79 | in = loader.getResourceAsStream (name); 80 | if (in != null) { 81 | result = new Properties (); 82 | result.load (in); // Can throw IOException 83 | } 84 | } 85 | } 86 | catch (Exception e) { 87 | result = new Properties (); 88 | LoggerStackTraceUtil.printErrorMessage(e); 89 | } 90 | finally { 91 | if (in != null) 92 | try 93 | { 94 | in.close (); 95 | } 96 | catch (Throwable ignore) {} 97 | } 98 | if (THROW_ON_LOAD_FAILURE && (result == null)) 99 | { 100 | // LOG exception... Do not re-throw this.. as I do not expect users to catch this exception :-) 101 | //throw new IllegalArgumentException ("could not load [" + name + "]"+ " as " + (LOAD_AS_RESOURCE_BUNDLE ? "a resource bundle" : "a classloader resource")); 102 | result = new Properties (); 103 | } 104 | return result; 105 | } 106 | 107 | } -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/tutorial/addressbook/backend/ContactService.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.tutorial.addressbook.backend; 2 | 3 | import org.apache.commons.beanutils.BeanUtils; 4 | 5 | import java.util.*; 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | 9 | /** Separate Java service class. 10 | * Backend implementation for the address book application, with "detached entities" 11 | * simulating real world DAO. Typically these something that the Java EE 12 | * or Spring backend services provide. 13 | */ 14 | // Backend service class. This is just a typical Java backend implementation 15 | // class and nothing Vaadin specific. 16 | public class ContactService { 17 | 18 | // Create dummy data by randomly combining first and last names 19 | static String[] fnames = { "Peter", "Alice", "John", "Mike", "Olivia", 20 | "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene", "Lisa", 21 | "Linda", "Timothy", "Daniel", "Brian", "George", "Scott", 22 | "Jennifer" }; 23 | static String[] lnames = { "Smith", "Johnson", "Williams", "Jones", 24 | "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor", 25 | "Anderson", "Thomas", "Jackson", "White", "Harris", "Martin", 26 | "Thompson", "Young", "King", "Robinson" }; 27 | 28 | private static ContactService instance; 29 | 30 | public static ContactService createDemoService() { 31 | if (instance == null) { 32 | 33 | final ContactService contactService = new ContactService(); 34 | 35 | Random r = new Random(0); 36 | Calendar cal = Calendar.getInstance(); 37 | for (int i = 0; i < 100; i++) { 38 | Contact contact = new Contact(); 39 | contact.setFirstName(fnames[r.nextInt(fnames.length)]); 40 | contact.setLastName(lnames[r.nextInt(fnames.length)]); 41 | contact.setEmail(contact.getFirstName().toLowerCase() + "@" 42 | + contact.getLastName().toLowerCase() + ".com"); 43 | contact.setPhone("+ 358 555 " + (100 + r.nextInt(900))); 44 | cal.set(1930 + r.nextInt(70), 45 | r.nextInt(11), r.nextInt(28)); 46 | contact.setBirthDate(cal.getTime()); 47 | contactService.save(contact); 48 | } 49 | instance = contactService; 50 | } 51 | 52 | return instance; 53 | } 54 | 55 | private HashMap contacts = new HashMap<>(); 56 | private long nextId = 0; 57 | 58 | public synchronized List findAll(String stringFilter) { 59 | ArrayList arrayList = new ArrayList(); 60 | for (Contact contact : contacts.values()) { 61 | try { 62 | boolean passesFilter = (stringFilter == null || stringFilter.isEmpty()) 63 | || contact.toString().toLowerCase() 64 | .contains(stringFilter.toLowerCase()); 65 | if (passesFilter) { 66 | arrayList.add(contact.clone()); 67 | } 68 | } catch (CloneNotSupportedException ex) { 69 | Logger.getLogger(ContactService.class.getName()).log( 70 | Level.SEVERE, null, ex); 71 | } 72 | } 73 | Collections.sort(arrayList, new Comparator() { 74 | 75 | @Override 76 | public int compare(Contact o1, Contact o2) { 77 | return (int) (o2.getId() - o1.getId()); 78 | } 79 | }); 80 | return arrayList; 81 | } 82 | 83 | public synchronized long count() { 84 | return contacts.size(); 85 | } 86 | 87 | public synchronized void delete(Contact value) { 88 | contacts.remove(value.getId()); 89 | } 90 | 91 | public synchronized void save(Contact entry) { 92 | if (entry.getId() == null) { 93 | entry.setId(nextId++); 94 | } 95 | try { 96 | entry = (Contact) BeanUtils.cloneBean(entry); 97 | } catch (Exception ex) { 98 | throw new RuntimeException(ex); 99 | } 100 | contacts.put(entry.getId(), entry); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/tutorial/addressbook/ContactForm.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.tutorial.addressbook; 2 | 3 | import com.vaadin.event.ShortcutAction; 4 | import com.edurekademo.tutorial.addressbook.backend.Contact; 5 | import com.vaadin.ui.Button; 6 | import com.vaadin.ui.FormLayout; 7 | import com.vaadin.ui.HorizontalLayout; 8 | import com.vaadin.ui.Notification; 9 | import com.vaadin.ui.Notification.Type; 10 | import com.vaadin.ui.themes.ValoTheme; 11 | import com.vaadin.v7.data.fieldgroup.BeanFieldGroup; 12 | import com.vaadin.v7.data.fieldgroup.FieldGroup; 13 | import com.vaadin.v7.ui.DateField; 14 | import com.vaadin.v7.ui.TextField; 15 | 16 | /* Create custom UI Components. 17 | * 18 | * Create your own Vaadin components by inheritance and composition. 19 | * This is a form component inherited from VerticalLayout. Use 20 | * Use BeanFieldGroup to bind data fields from DTO to UI fields. 21 | * Similarly named field by naming convention or customized 22 | * with @PropertyId annotation. 23 | */ 24 | public class ContactForm extends FormLayout { 25 | 26 | Button save = new Button("Save", this::save); 27 | Button cancel = new Button("Cancel", this::cancel); 28 | TextField firstName = new TextField("First name"); 29 | TextField lastName = new TextField("Last name"); 30 | TextField phone = new TextField("Phone"); 31 | TextField email = new TextField("Email"); 32 | DateField birthDate = new DateField("Birth date"); 33 | 34 | Contact contact; 35 | 36 | // Easily bind forms to beans and manage validation and buffering 37 | BeanFieldGroup formFieldBindings; 38 | 39 | public ContactForm() { 40 | configureComponents(); 41 | buildLayout(); 42 | } 43 | 44 | private void configureComponents() { 45 | /* 46 | * Highlight primary actions. 47 | * 48 | * With Vaadin built-in styles you can highlight the primary save button 49 | * and give it a keyboard shortcut for a better UX. 50 | */ 51 | save.setStyleName(ValoTheme.BUTTON_PRIMARY); 52 | save.setClickShortcut(ShortcutAction.KeyCode.ENTER); 53 | setVisible(false); 54 | } 55 | 56 | private void buildLayout() { 57 | setSizeUndefined(); 58 | setMargin(true); 59 | 60 | HorizontalLayout actions = new HorizontalLayout(save, cancel); 61 | actions.setSpacing(true); 62 | 63 | addComponents(actions, firstName, lastName, phone, email, birthDate); 64 | } 65 | 66 | /* 67 | * Use any JVM language. 68 | * 69 | * Vaadin supports all languages supported by Java Virtual Machine 1.6+. 70 | * This allows you to program user interface in Java 8, Scala, Groovy or any 71 | * other language you choose. The new languages give you very powerful tools 72 | * for organizing your code as you choose. For example, you can implement 73 | * the listener methods in your compositions or in separate controller 74 | * classes and receive to various Vaadin component events, like button 75 | * clicks. Or keep it simple and compact with Lambda expressions. 76 | */ 77 | public void save(Button.ClickEvent event) { 78 | try { 79 | // Commit the fields from UI to DAO 80 | formFieldBindings.commit(); 81 | 82 | // Save DAO to backend with direct synchronous service API 83 | getUI().service.save(contact); 84 | 85 | String msg = String.format("Saved '%s %s'.", contact.getFirstName(), 86 | contact.getLastName()); 87 | Notification.show(msg, Type.TRAY_NOTIFICATION); 88 | getUI().refreshContacts(); 89 | } catch (FieldGroup.CommitException e) { 90 | // Validation exceptions could be shown here 91 | } 92 | } 93 | 94 | public void cancel(Button.ClickEvent event) { 95 | // Place to call business logic. 96 | Notification.show("Cancelled", Type.TRAY_NOTIFICATION); 97 | getUI().contactList.select(null); 98 | } 99 | 100 | void edit(Contact contact) { 101 | this.contact = contact; 102 | if (contact != null) { 103 | // Bind the properties of the contact POJO to fiels in this form 104 | formFieldBindings = BeanFieldGroup.bindFieldsBuffered(contact, 105 | this); 106 | firstName.focus(); 107 | } 108 | setVisible(contact != null); 109 | } 110 | 111 | @Override 112 | public AddressbookUI getUI() { 113 | return (AddressbookUI) super.getUI(); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/utilities/CaseInsensitiveComparator.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.util.Date; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | public class CaseInsensitiveComparator extends GenericComparator { 10 | 11 | private static final long serialVersionUID = -6836701171640412573L; 12 | private static final Logger LOG =LoggerFactory.getLogger(CaseInsensitiveComparator.class); 13 | 14 | /* 15 | * This function call base GenericComparator(boolean sortAscending) class and set whether sorting is in ascending or descending 16 | * sortAscending = true then ascending 17 | * sortAscending = false then descending 18 | */ 19 | public CaseInsensitiveComparator(boolean sortAscending) { 20 | super(sortAscending); 21 | this.targetMethod = null; 22 | this.sortAscending = sortAscending; 23 | } 24 | /* 25 | * This function call base GenericComparator(boolean sortField) class and set which field we need to sort and sort as asc 26 | */ 27 | public CaseInsensitiveComparator(String sortField) { 28 | super(sortField); 29 | this.targetMethod = prepareTargetMethod(sortField); 30 | this.sortAscending = true; 31 | } 32 | /* 33 | * This function call base GenericComparator(boolean sortField,sortAscending) class and set which field we need to sort and sort based on the boolen value given 34 | * sortAscending = true then ascending 35 | * sortAscending = false then descending 36 | */ 37 | public CaseInsensitiveComparator(String sortField, boolean sortAscending) { 38 | super(sortField, sortAscending); 39 | this.targetMethod = prepareTargetMethod(sortField); 40 | this.sortAscending = sortAscending; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see com.edurekademo.utilities.GenericComparator#compare(java.lang.Object, java.lang.Object) 46 | */ 47 | public int compare(Object o1, Object o2) { 48 | int response = LESSER; 49 | Object v1,v2; 50 | String returnType; 51 | try { 52 | if(this.targetMethod==null){ 53 | v1=o1; 54 | v2=02; 55 | returnType=o1.getClass().getName(); 56 | }else{ 57 | v1=getValue(o1); 58 | v2=getValue(o2); 59 | returnType=getMethod(o1).getReturnType().getName(); 60 | } 61 | 62 | CompareMode cm = findCompareMode(v1, v2); 63 | if (!cm.equals(CompareMode.DEFAULT)) { 64 | return compareAlternate(cm); 65 | } 66 | response = compareActual(v1, v2, returnType); 67 | } 68 | catch (NoSuchMethodException e){LOG.error(new LoggerStackTraceUtil().getErrorMessage(e));} 69 | catch (IllegalAccessException e){LOG.error(new LoggerStackTraceUtil().getErrorMessage(e));} 70 | catch (InvocationTargetException e){LOG.error(new LoggerStackTraceUtil().getErrorMessage(e));} 71 | return response; 72 | } 73 | /* 74 | * This Method is the overridden compareActual of GenericComparator. 75 | * If the data type is String then it convert string to upper case and compare it with other. 76 | */ 77 | protected int compareActual(Object v1, Object v2, String returnType) { 78 | String obj = returnType; 79 | if ("java.lang.Object".equals(obj) && v1!=null) { 80 | obj = v1.getClass().getName(); 81 | } 82 | int acutal = LESSER; 83 | if (obj.equals(DATATYPE_INTEGER)) { 84 | acutal = ((Integer) v1).compareTo((Integer) v2) * determinePosition(); 85 | } else if (obj.equals(DATATYPE_LONG)) { 86 | acutal = ((Long) v1).compareTo((Long) v2) * determinePosition(); 87 | } else if (obj.equals(DATATYPE_STRING)) { 88 | acutal = ((String) v1).toUpperCase().compareTo(((String) v2).toUpperCase()) * determinePosition(); 89 | } else if (obj.equals(DATATYPE_DATE)) { 90 | acutal = ((Date) v1).compareTo((Date) v2) * determinePosition(); 91 | } else if (obj.equals(DATATYPE_FLOAT)) { 92 | acutal = ((Float) v1).compareTo((Float) v2) * determinePosition(); 93 | } else if (obj.equals(DATATYPE_DOUBLE)) { 94 | acutal = ((Double) v1).compareTo((Double) v2) * determinePosition(); 95 | } 96 | return acutal; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/tutorial/addressbook/AddressbookUI.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.tutorial.addressbook; 2 | 3 | import javax.servlet.annotation.WebServlet; 4 | 5 | import com.vaadin.annotations.Theme; 6 | import com.vaadin.annotations.Title; 7 | import com.vaadin.annotations.VaadinServletConfiguration; 8 | import com.vaadin.annotations.Widgetset; 9 | import com.vaadin.server.VaadinRequest; 10 | import com.vaadin.server.VaadinServlet; 11 | import com.edurekademo.tutorial.addressbook.backend.Contact; 12 | import com.edurekademo.tutorial.addressbook.backend.ContactService; 13 | import com.vaadin.ui.Button; 14 | import com.vaadin.ui.HorizontalLayout; 15 | import com.vaadin.ui.UI; 16 | import com.vaadin.ui.VerticalLayout; 17 | import com.vaadin.v7.data.util.BeanItemContainer; 18 | import com.vaadin.v7.ui.Grid; 19 | import com.vaadin.v7.ui.TextField; 20 | 21 | /* User Interface written in Java. 22 | * 23 | * Define the user interface shown on the Vaadin generated web page by extending the UI class. 24 | * By default, a new UI instance is automatically created when the page is loaded. To reuse 25 | * the same instance, add @PreserveOnRefresh. 26 | */ 27 | @Title("Addressbook") 28 | @Theme("valo") 29 | @Widgetset("com.vaadin.v7.Vaadin7WidgetSet") 30 | public class AddressbookUI extends UI { 31 | 32 | /* 33 | * Hundreds of widgets. Vaadin's user interface components are just Java 34 | * objects that encapsulate and handle cross-browser support and 35 | * client-server communication. The default Vaadin components are in the 36 | * com.vaadin.ui package and there are over 500 more in 37 | * vaadin.com/directory. 38 | */ 39 | TextField filter = new TextField(); 40 | Grid contactList = new Grid(); 41 | Button newContact = new Button("New contact"); 42 | 43 | // ContactForm is an example of a custom component class 44 | ContactForm contactForm = new ContactForm(); 45 | 46 | // ContactService is a in-memory mock DAO that mimics 47 | // a real-world datasource. Typically implemented for 48 | // example as EJB or Spring Data based service. 49 | ContactService service = ContactService.createDemoService(); 50 | 51 | /* 52 | * The "Main method". 53 | * 54 | * This is the entry point method executed to initialize and configure the 55 | * visible user interface. Executed on every browser reload because a new 56 | * instance is created for each web page loaded. 57 | */ 58 | @Override 59 | protected void init(VaadinRequest request) { 60 | configureComponents(); 61 | buildLayout(); 62 | } 63 | 64 | private void configureComponents() { 65 | /* 66 | * Synchronous event handling. 67 | * 68 | * Receive user interaction events on the server-side. This allows you 69 | * to synchronously handle those events. Vaadin automatically sends only 70 | * the needed changes to the web page without loading a new page. 71 | */ 72 | newContact.addClickListener(e -> contactForm.edit(new Contact())); 73 | 74 | filter.setInputPrompt("Filter contacts..."); 75 | filter.addTextChangeListener(e -> refreshContacts(e.getText())); 76 | 77 | contactList 78 | .setContainerDataSource(new BeanItemContainer<>(Contact.class)); 79 | contactList.setColumnOrder("firstName", "lastName", "email"); 80 | contactList.removeColumn("id"); 81 | contactList.removeColumn("birthDate"); 82 | contactList.removeColumn("phone"); 83 | contactList.setSelectionMode(Grid.SelectionMode.SINGLE); 84 | contactList.addSelectionListener( 85 | e -> contactForm.edit((Contact) contactList.getSelectedRow())); 86 | refreshContacts(); 87 | } 88 | 89 | /* 90 | * Robust layouts. 91 | * 92 | * Layouts are components that contain other components. HorizontalLayout 93 | * contains TextField and Button. It is wrapped with a Grid into 94 | * VerticalLayout for the left side of the screen. Allow user to resize the 95 | * components with a SplitPanel. 96 | * 97 | * In addition to programmatically building layout in Java, you may also 98 | * choose to setup layout declaratively with Vaadin Designer, CSS and HTML. 99 | */ 100 | private void buildLayout() { 101 | HorizontalLayout actions = new HorizontalLayout(filter, newContact); 102 | actions.setWidth("100%"); 103 | filter.setWidth("100%"); 104 | actions.setExpandRatio(filter, 1); 105 | 106 | VerticalLayout left = new VerticalLayout(actions, contactList); 107 | left.setSizeFull(); 108 | contactList.setSizeFull(); 109 | left.setExpandRatio(contactList, 1); 110 | 111 | HorizontalLayout mainLayout = new HorizontalLayout(left, contactForm); 112 | mainLayout.setSizeFull(); 113 | mainLayout.setExpandRatio(left, 1); 114 | 115 | // Split and allow resizing 116 | setContent(mainLayout); 117 | } 118 | 119 | /* 120 | * Choose the design patterns you like. 121 | * 122 | * It is good practice to have separate data access methods that handle the 123 | * back-end access and/or the user interface updates. You can further split 124 | * your code into classes to easier maintenance. With Vaadin you can follow 125 | * MVC, MVP or any other design pattern you choose. 126 | */ 127 | void refreshContacts() { 128 | refreshContacts(filter.getValue()); 129 | } 130 | 131 | private void refreshContacts(String stringFilter) { 132 | contactList.setContainerDataSource(new BeanItemContainer<>( 133 | Contact.class, service.findAll(stringFilter))); 134 | contactForm.setVisible(false); 135 | } 136 | 137 | /* 138 | * Deployed as a Servlet or Portlet. 139 | * 140 | * You can specify additional servlet parameters like the URI and UI class 141 | * name and turn on production mode when you have finished developing the 142 | * application. 143 | */ 144 | @WebServlet(urlPatterns = "/*") 145 | @VaadinServletConfiguration(ui = AddressbookUI.class, productionMode = false) 146 | public static class MyUIServlet extends VaadinServlet { 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/utilities/StringUtilities.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | import java.lang.reflect.Modifier; 6 | import java.text.ParseException; 7 | import java.text.SimpleDateFormat; 8 | import java.util.ArrayList; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | 16 | /** 17 | * An utility class that is used to split an string into an array list and providing mechanism to 18 | * build a HashMap value based on a variable number of arguements. 19 | * @author Seshagiri Sriram 20 | * @version 1.0 21 | * 22 | */ 23 | public class StringUtilities { 24 | /** 25 | * The string separator for splitting a string into a list 26 | */ 27 | private final static String COMMA_SEPARATOR = ","; 28 | /** 29 | * The String separator for splitting a parameter value. 30 | * Parameters are expected to be in form: "parametername=value" 31 | */ 32 | private final static String PARAM_SEPARATOR = "="; 33 | /** 34 | * The String separator for splitting a parameter value into appropriate type. 35 | * Required for HQL Queries, never for Native SQL queries 36 | * Parameters are expected to be in form: "parametername=value:type (int, string, float, double)" 37 | */ 38 | private final static String TYPE_SEPARATOR = ";"; 39 | /** 40 | * The String separator for splitting a date parameter value into appropriate format. 41 | */ 42 | private final static String DATEFORMAT_SEPARATOR = "@"; 43 | 44 | /** 45 | * The method to be invoked to convert a given String value to a specific Object type 46 | */ 47 | private final static String CONVERTOR_METHOD_NAME = "valueOf" ; 48 | 49 | /** 50 | * The String to represent the type "DATE" 51 | */ 52 | private final static String DATE_TYPE = "date" ; 53 | 54 | /** 55 | * Default Date format to which the date will be formatted 56 | */ 57 | 58 | private final static String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss" ; 59 | /** 60 | * Variable to represent the type "STRING" 61 | */ 62 | private final static String STRING_TYPE ="string"; 63 | /** 64 | * Logger enabled for the current class 65 | */ 66 | private static final Logger LOG =LoggerFactory.getLogger(StringUtilities.class); 67 | 68 | /** Primitive type name -> class map. */ 69 | private static final HashMap> PRIMITIVE_NAME_TYPE_MAP = new HashMap>(); 70 | 71 | /** Setup the primitives map. */ 72 | static { 73 | PRIMITIVE_NAME_TYPE_MAP.put("boolean", Boolean.class); 74 | PRIMITIVE_NAME_TYPE_MAP.put("int", Integer.class); 75 | PRIMITIVE_NAME_TYPE_MAP.put("long", Long.class); 76 | PRIMITIVE_NAME_TYPE_MAP.put("float", Float.class); 77 | PRIMITIVE_NAME_TYPE_MAP.put("double", Double.class); 78 | } 79 | 80 | /** 81 | * given a comma separated string and type, returns an ArrayList of specific types 82 | * @param strParamValueList The string (assumed to be comma separated). Usually meant for use in creating 83 | * parameter values for passing in IN Clauses 84 | * @param type The type of the Arraylist passed 85 | * @return ArrayList if passed value is not null or empty, null otherwise 86 | */ 87 | public static List convertStringToList(String strParamValueList,String type){ 88 | if (strParamValueList==null||strParamValueList.trim().isEmpty()) return null; 89 | ArrayList list = new ArrayList(); 90 | String arr[] = strParamValueList.trim().split(COMMA_SEPARATOR); 91 | for(String tmpString: arr){ 92 | list.add(convert(tmpString,type)); 93 | } 94 | return list; 95 | } 96 | 97 | /** 98 | * given a variable list of String parameters, forms a hash map 99 | * @param strParamValueList Variable list of arguments each of format: key=kevalue;type. 100 | * For the type date,you can even pass the dateformat value as key=keyvalue@dateformat;type. 101 | * If dateformat is not passed default format yyyy-MM-dd HH:mm:ss will be taken. 102 | * @return HashMap if no arguments are passed, returns an empty list, else populated hashmap 103 | * support only int, string, boolean, float, double, long, date 104 | */ 105 | public static HashMap createParameterList(String... strParamValueList){ 106 | HashMap hMap = new HashMap(); 107 | for(String strArg: strParamValueList){ 108 | String type = null; 109 | if(strArg.contains(TYPE_SEPARATOR)){ 110 | type = strArg.split(TYPE_SEPARATOR)[1]; 111 | strArg = strArg.split(TYPE_SEPARATOR)[0]; 112 | } 113 | if (strArg.contains(PARAM_SEPARATOR)){ 114 | String arr[] = strArg.split(PARAM_SEPARATOR); 115 | if (arr[1].contains(COMMA_SEPARATOR)){ 116 | hMap.put(arr[0], convertStringToList(arr[1],type)); 117 | } 118 | else { 119 | hMap.put(arr[0], convert(arr[1],type)); 120 | } 121 | } 122 | } 123 | return hMap; 124 | } 125 | 126 | /** 127 | * Converts the given String value to the intended type of Object 128 | * @param value The String value to be converted 129 | * @param type The type to which the value needs to be converted 130 | * @return Object Returns values as such if type or value is empty or null,else returns the converted Object 131 | */ 132 | private static Object convert(String value, String types) { 133 | 134 | Class finalClass = null ; 135 | //If value or type passed is null or empty or string return back value as such 136 | if ((value == null) || value.isEmpty() || types == null || types.isEmpty() || types.equalsIgnoreCase(STRING_TYPE)) return value; 137 | 138 | String type = types.toLowerCase(); 139 | 140 | if (type.equals(DATE_TYPE)) return convertStringToDate(value); 141 | 142 | //Based on the passed type load the wrapper class. 143 | //If the given type not permitted returns values as such 144 | if(PRIMITIVE_NAME_TYPE_MAP.containsKey(type)) 145 | finalClass = PRIMITIVE_NAME_TYPE_MAP.get(type); 146 | 147 | try { 148 | //Invoking the valueOf method of the Wrapper Class dynamically using reflection 149 | if(finalClass!=null){ 150 | Method method = finalClass.getMethod(CONVERTOR_METHOD_NAME, String.class); 151 | int mods = method.getModifiers(); 152 | if (Modifier.isStatic(mods) && Modifier.isPublic(mods)) { 153 | return method.invoke(null, value); 154 | } 155 | } 156 | } 157 | catch (NoSuchMethodException e) { 158 | LoggerStackTraceUtil.printErrorMessage(e); 159 | } 160 | catch (IllegalAccessException e) { 161 | // this won't happen 162 | LoggerStackTraceUtil.printErrorMessage(e); 163 | } 164 | catch (InvocationTargetException e) { 165 | // when this happens, the string cannot be converted to the intended type 166 | // we are ignoring it here - the original string will be returned 167 | LoggerStackTraceUtil.printErrorMessage(e); 168 | } 169 | 170 | return value; 171 | } 172 | 173 | /** 174 | * Convert the given date value in string to date object 175 | * @param dateString The date to be formatted 176 | * @return Object Returns the corresponding Date object 177 | */ 178 | private static Object convertStringToDate(String dateString) { 179 | String dateFormat = null; 180 | Object finalDate = null; 181 | String dateStringVal=null; 182 | //If the incoming date string contains the format as well parse using the given format, else parse using default 183 | dateFormat = (dateString.contains(DATEFORMAT_SEPARATOR)) ? dateString.split(DATEFORMAT_SEPARATOR)[1] : DATE_FORMAT ; 184 | dateStringVal = (dateString.contains(DATEFORMAT_SEPARATOR)) ? dateString.split(DATEFORMAT_SEPARATOR)[0] : dateString ; 185 | SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat); 186 | 187 | try{ 188 | finalDate = dateFormatter.parse(dateStringVal); 189 | }catch(ParseException e){ 190 | LoggerStackTraceUtil.printErrorMessage(e); 191 | } 192 | return finalDate; 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /src/main/pmd/pmd.xsl: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | - 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | PMD <xsl:value-of select="//pmd/@version"/> Report: Demo Utilities 24 | 81 | 82 | 83 | 84 | 85 | 86 | 88 | 89 | 90 |
87 |

PMD Report: Addressbook Web Application. Generated on

91 |
92 | 93 | 94 | 95 |
96 | 97 | 98 | 99 |
100 | 101 | 102 | 103 |
104 | 105 | 106 | 107 | 108 |
109 | 110 | 111 | 112 | 113 |
114 | 115 | 116 | 117 | 118 |

Rules

119 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 129 | 130 | 132 | 133 | 134 | 135 | 137 | 138 | 139 | 140 | 143 | 146 | 150 | 151 | 152 | 153 |
RuleViolationsSeverity
141 | [] 142 | 144 | 145 |
147 | 148 |
149 |
154 |
155 | 156 | 157 | 158 | 159 |

Files

160 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 173 | 174 | 176 | 177 | 178 | 179 | 180 | 181 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 |
File
5
4
3
2
1
182 | 183 | 184 |
194 |
195 | 196 | 197 | 198 | 199 | 200 | 201 |

File

202 | 203 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 217 | 227 | 230 | 231 | 232 |
ViolationError DescriptionLine
215 |
216 |
218 | [.] 219 | - 220 | 221 | 222 | 223 | 224 | 225 | 226 | 228 | - 229 |
233 | Back to top 234 |
235 | 236 | 237 | 238 | 239 |

Summary

240 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 |
FilesTotal
Priority 1: ShowStopper
Priority 2:Critical
Priority 3:Important/Urgent
Priority 4:Low - Change recommended
Priority 5:Low - Change Optional
262 |
263 | 264 | 265 | 266 | 267 | a 268 | b 269 | 270 | 271 |
272 | 273 | 274 | 275 | 276 | -------------------------------------------------------------------------------- /src/main/pmd/ruleset_basics.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | These are the rules by which Applications will be built. 8 | 9 | 10 | 26 | 3 27 | 3 28 | 3 29 | 3 30 | 3 31 | 3 32 | 3 33 | 5 34 | 5 35 | 5 36 | 3 37 | 5 38 | 3 39 | 5 40 | 1 41 | 2 42 | 3 43 | 3 44 | 3 45 | 2 46 | 2 47 | 2 48 | 2 49 | 3 50 | 3 51 | 3 52 | 3 53 | 3 54 | 5 55 | 5 56 | 5 57 | 5 58 | 5 59 | 5 60 | 5 61 | 5 62 | 5 63 | 5 64 | 5 65 | 5 66 | 5 67 | 5 68 | 5 69 | 5 70 | 5 71 | 5 72 | 4 73 | 4 74 | 3 75 | 3 76 | 3 77 | 3 78 | 3 79 | 3 80 | 3 81 | 3 82 | 2 83 | 2 84 | 2 85 | 3 86 | 2 87 | 4 88 | 4 89 | 2 90 | 3 91 | 1 92 | 2 93 | 3 94 | 2 95 | 4 96 | 3 97 | 3 98 | 3 99 | 2 100 | 2 101 | 3 102 | 3 103 | 3 104 | 1 105 | 3 106 | 3 107 | 2 108 | 3 109 | 3 110 | 2 111 | 4 112 | 3 113 | 3 114 | 3 115 | 3 116 | 2 117 | 2 118 | 5 119 | 5 120 | 121 | -------------------------------------------------------------------------------- /src/main/java/com/edurekademo/utilities/GenericComparator.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | import java.io.Serializable; 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | import java.util.Comparator; 6 | import java.util.Date; 7 | 8 | /** 9 | * Sorting - Generic Comparator 10 | * 11 | * @author Seshagiri Sriram 12 | * @version 1.0 13 | * @since Janauary 12, 2015 14 | * 15 | * This is an adaptation of a genenic comparator found on github linked from myjeeva.com 16 | * Many thanks for the code! 17 | */ 18 | 19 | @SuppressWarnings("rawtypes") 20 | public class GenericComparator implements Comparator, Serializable { 21 | protected static final long serialVersionUID = -2293914106471884607L; 22 | protected static final int LESSER = -1; 23 | protected static final int EQUAL = 0; 24 | protected static final int GREATER = 1; 25 | protected static final String METHOD_GET_PREFIX = "get"; 26 | protected static final String DATATYPE_STRING = "java.lang.String"; 27 | protected static final String DATATYPE_DATE = "java.util.Date"; 28 | protected static final String DATATYPE_INTEGER = "java.lang.Integer"; 29 | protected static final String DATATYPE_LONG = "java.lang.Long"; 30 | protected static final String DATATYPE_FLOAT = "java.lang.Float"; 31 | protected static final String DATATYPE_DOUBLE = "java.lang.Double"; 32 | protected static final String DATATYPE_BOOLEAN = "java.lang.Boolean"; 33 | 34 | protected enum CompareMode { EQUAL, LESS_THAN, GREATER_THAN, DEFAULT } 35 | // generic comparator attributes 36 | protected String targetMethod; 37 | protected boolean sortAscending; 38 | 39 | /** 40 | *

default constructor - assumes comparator for Type List

41 | * 42 | *

For Example-

43 | * List<Integer> aa = new ArrayList<Integer>();
44 | * List<String> bb = new ArrayList<String>();
45 | * List<Date> cc = new ArrayList<Date>();
46 | *

and so on..

47 | * 48 | * @param sortAscending - a {@link boolean} - true ascending order or false descending order 49 | */ 50 | 51 | public GenericComparator(boolean sortAscending) { 52 | super(); 53 | this.targetMethod = null; 54 | this.sortAscending = sortAscending; 55 | } 56 | 57 | /** 58 | *

constructor with sortField parameter for Derived type of Class default sorting is ascending order

59 | * 60 | *

For Example-

61 | *

PersonVO person = new PersonVO();
62 | * person.setId(10001);
63 | * person.setName("Jacob");
64 | * person.setHeight(5.2F);
65 | * person.setEmailId("jacob@example.example");
66 | * person.setSalary(10500L);
67 | * person.setDob(new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse("Jan 1, 1970"));

68 | *

and person2, person3, so on.. And Defining & adding all the created objects in to below list

69 | *

List<PersonVO> persons = new ArrayList<PersonVO>();
70 | * persons.add(person1);
71 | * persons.add(person2);
72 | * persons.add(person3);
and so on
73 | * 74 | * @param sortField - a {@link java.lang.String} - which field requires sorting; as per above example "sorting required for name field" 75 | */ 76 | public GenericComparator(String sortField) { 77 | super(); 78 | this.targetMethod = prepareTargetMethod(sortField); 79 | this.sortAscending = true; 80 | } 81 | 82 | /** 83 | *

constructor with sortField, sortAscending parameter for Derived type of Class

84 | * 85 | *

For Example-

86 | *

PersonVO person = new PersonVO();
87 | * person.setId(10001);
88 | * person.setName("Jacob");
89 | * person.setHeight(5.2F);
90 | * person.setEmailId("jacob@example.example");
91 | * person.setSalary(10500L);
92 | * person.setDob(new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse("Jan 1, 1970"));

93 | *

and person2, person3, so on.. And Defining & adding all the created objects in to below list

94 | *

List<PersonVO> persons = new ArrayList<PersonVO>();
95 | * persons.add(person1);
96 | * persons.add(person2);
97 | * persons.add(person3);
and so on
98 | * @param sortField - a {@link java.lang.String} - which field requires sorting; as per above example "sorting required for name field" 99 | * @param sortAscending - a {@link boolean} - true ascending order or false descending order 100 | */ 101 | 102 | public GenericComparator(String sortField, boolean sortAscending) { 103 | super(); 104 | this.targetMethod = prepareTargetMethod(sortField); 105 | this.sortAscending = sortAscending; 106 | } 107 | 108 | /** 109 | * {@inheritDoc} 110 | */ 111 | public int compare(Object o1, Object o2) { 112 | int response = LESSER; 113 | Object v1,v2; 114 | String returnType; 115 | try { 116 | if(this.targetMethod==null){ 117 | v1=o1; 118 | v2=02; 119 | returnType=o1.getClass().getName(); 120 | }else{ 121 | v1=getValue(o1); 122 | v2=getValue(o2); 123 | returnType=getMethod(o1).getReturnType().getName(); 124 | } 125 | 126 | CompareMode cm = findCompareMode(v1, v2); 127 | if (!cm.equals(CompareMode.DEFAULT)) { 128 | return compareAlternate(cm); 129 | } 130 | response = compareActual(v1, v2, returnType); 131 | } 132 | // in JSE 1.7 the below is accepted 133 | /* 134 | catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException nsme) { 135 | } */ 136 | catch (NoSuchMethodException e){ 137 | LoggerStackTraceUtil.printErrorMessage(e); 138 | }catch (IllegalAccessException e){ 139 | LoggerStackTraceUtil.printErrorMessage(e); 140 | }catch (InvocationTargetException e){ 141 | LoggerStackTraceUtil.printErrorMessage(e); 142 | } 143 | return response; 144 | } 145 | 146 | //---------------------------------------------------------------------------------// 147 | // Private methods used by {@link com.myjeeva.comparator.GenericComparator} // 148 | //---------------------------------------------------------------------------------// 149 | /** 150 | * alternate to actual value comparison i.e., either (lsh & rhs) one the value could be null 151 | * 152 | * @param cm - a enum used to idetify the position for sorting 153 | */ 154 | protected int compareAlternate(CompareMode cm) { 155 | int compareState = LESSER; 156 | switch(cm) { 157 | case LESS_THAN: 158 | compareState = LESSER * determinePosition(); 159 | break; 160 | case GREATER_THAN: 161 | compareState = GREATER * determinePosition(); 162 | break; 163 | case EQUAL: 164 | compareState = EQUAL * determinePosition(); 165 | break; 166 | } 167 | return compareState; 168 | } 169 | /** 170 | * actual value comparison for sorting; both lsh & rhs value available 171 | * 172 | * @param v1 - value of lhs 173 | * @param v2 - value of rhs 174 | * @param returnType - datatype of given values 175 | * @return int - compare return value 176 | */ 177 | private int compareActual(Object v1, Object v2, String returnType) { 178 | String obj = returnType; 179 | if ("java.lang.Object".equals(obj) && v1!=null) { 180 | obj = v1.getClass().getName(); 181 | } 182 | int acutal = LESSER; 183 | 184 | if (obj.equals(DATATYPE_INTEGER)) { 185 | acutal = ((Integer) v1).compareTo((Integer) v2) * determinePosition(); 186 | } else if (obj.equals(DATATYPE_LONG)) { 187 | acutal = ((Long) v1).compareTo((Long) v2) * determinePosition(); 188 | } else if (obj.equals(DATATYPE_STRING)) { 189 | acutal = ((String) v1).compareTo((String) v2) * determinePosition(); 190 | } else if (obj.equals(DATATYPE_DATE)) { 191 | acutal = ((Date) v1).compareTo((Date) v2) * determinePosition(); 192 | } else if (obj.equals(DATATYPE_FLOAT)) { 193 | acutal = ((Float) v1).compareTo((Float) v2) * determinePosition(); 194 | } else if (obj.equals(DATATYPE_DOUBLE)) { 195 | acutal = ((Double) v1).compareTo((Double) v2) * determinePosition(); 196 | } else if (obj.equals(DATATYPE_BOOLEAN)) { 197 | acutal = ((Boolean) v1).compareTo((Boolean) v2) * determinePosition(); 198 | } 199 | return acutal; 200 | } 201 | /** 202 | * preparing target name of getter method for given sort field 203 | * 204 | * @param name a {@link java.lang.String} 205 | * @return methodName a {@link java.lang.String} 206 | */ 207 | protected final static String prepareTargetMethod(String name) { 208 | StringBuffer fieldName = new StringBuffer(METHOD_GET_PREFIX); 209 | fieldName.append(name.substring(0, 1).toUpperCase()).append(name.substring(1)); 210 | return fieldName.toString(); 211 | } 212 | 213 | /** 214 | * fetching method from Class object through reflect 215 | * 216 | * @param obj - a {@link java.lang.Object} - input object 217 | * @return method - a {@link java.lang.reflect.Method} 218 | * @throws NoSuchMethodException 219 | */ 220 | protected final Method getMethod(Object obj) throws NoSuchMethodException { 221 | return obj.getClass().getMethod(targetMethod, null); 222 | } 223 | 224 | /** 225 | * dynamically invoking given method with given object through reflect 226 | * 227 | * @param method - a {@link java.lang.reflect.Method} 228 | * @param obj - a {@link java.lang.Object} 229 | * @return object - a {@link java.lang.Object} - return of given method 230 | * @throws InvocationTargetException 231 | * @throws IllegalAccessException 232 | */ 233 | 234 | private final static Object invoke(Method method, Object obj) throws InvocationTargetException, IllegalAccessException { 235 | return method.invoke(obj, null); 236 | } 237 | /** 238 | * fetching a value from given object 239 | * 240 | * @param obj - a {@link java.lang.Object} 241 | * @return object - a {@link java.lang.Object} - return of given method 242 | * @throws InvocationTargetException 243 | * @throws IllegalAccessException 244 | * @throws NoSuchMethodException 245 | */ 246 | protected Object getValue(Object obj) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { 247 | return invoke(getMethod(obj), obj); 248 | } 249 | /** 250 | * identifying the comparison mode for given value 251 | * 252 | * @param o1 - a {@link java.lang.Object} 253 | * @param o2 - a {@link java.lang.Object} 254 | * @return compareMode - a {@link com.edurekademo.utilities.GenericComparator.CompareMode} 255 | */ 256 | protected CompareMode findCompareMode(Object o1, Object o2) { 257 | CompareMode cm = CompareMode.LESS_THAN; 258 | if(null != o1 & null != o2) { 259 | cm = CompareMode.DEFAULT; 260 | } else if (null == o1 & null != o2) { 261 | cm = CompareMode.LESS_THAN; 262 | } else if (null != o1 & null == o2) { 263 | cm = CompareMode.GREATER_THAN; 264 | } else if (null == o1 & null == o2) { 265 | cm = CompareMode.EQUAL; 266 | } 267 | return cm; 268 | } 269 | /** 270 | * Determining positing for sorting 271 | * 272 | * @return -1 to change the sort order if appropriate. 273 | */ 274 | protected int determinePosition() { 275 | return sortAscending ? GREATER : LESSER; 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /src/test/java/com/edurekademo/utilities/TestGenericComparator.java: -------------------------------------------------------------------------------- 1 | package com.edurekademo.utilities; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | 6 | import com.edurekademo.utilities.GenericComparator; 7 | import com.edurekademo.utilities.CaseInsensitiveComparator; 8 | 9 | import junit.framework.Test; 10 | import junit.framework.TestCase; 11 | import junit.framework.TestSuite; 12 | import org.junit.*; 13 | /** 14 | * @author Seshagiri Sriram 15 | * 16 | */ 17 | 18 | @SuppressWarnings({"rawtypes","unchecked"}) 19 | 20 | public class TestGenericComparator 21 | extends TestCase 22 | { 23 | public void initialize(ArrayList myData) { 24 | UnitDTO d1 = new UnitDTO(); 25 | d1.setDeptID(100);d1.setEmpID(200);d1.setEmpName("Sriram");d1.setSpare(new Double(18.0));d1.setSpare2(new Double(18.0)); 26 | UnitDTO d2 = new UnitDTO(); 27 | d2.setDeptID(100);d2.setEmpID(201);d2.setEmpName("Somebody");d2.setSpare(new Double(11.0));d2.setSpare2(new Double(11.0)); 28 | UnitDTO d3 = new UnitDTO(); 29 | d3.setDeptID(100);d3.setEmpID(100);d3.setEmpName("Rajan");d3.setSpare(new Double(12.0));d3.setSpare2(new Double(12.0)); 30 | UnitDTO d4 = new UnitDTO(); 31 | d4.setDeptID(100);d4.setEmpID(102);d4.setEmpName("Vellman");d4.setSpare(new Double(10.0));d4.setSpare2(new Double(10.0)); 32 | UnitDTO d5 = new UnitDTO(); 33 | d5.setDeptID(100);d5.setEmpID(110);d5.setEmpName("Asma");d5.setSpare(new Double(10.0));d5.setSpare2(new Double(10.0)); 34 | myData.add(d1); myData.add(d2); myData.add(d3); myData.add(d4); myData.add(d5); 35 | 36 | } 37 | public void initialize2(ArrayList myData) { 38 | UnitDTO d1 = new UnitDTO(); 39 | d1.setDeptID(100);d1.setEmpID(200);d1.setEmpName("Sriram");d1.setSpare(new Double(18.0));d1.setSpare2("A"); 40 | UnitDTO d2 = new UnitDTO(); 41 | d2.setDeptID(100);d2.setEmpID(201);d2.setEmpName("Somebody");d2.setSpare(new Double(11.0));d2.setSpare2("B"); 42 | UnitDTO d3 = new UnitDTO(); 43 | d3.setDeptID(100);d3.setEmpID(100);d3.setEmpName("Rajan");d3.setSpare(new Double(12.0));d3.setSpare2("C"); 44 | UnitDTO d4 = new UnitDTO(); 45 | d4.setDeptID(100);d4.setEmpID(102);d4.setEmpName("Vellman");d4.setSpare(new Double(10.0));d4.setSpare2("D"); 46 | UnitDTO d5 = new UnitDTO(); 47 | d5.setDeptID(100);d5.setEmpID(110);d5.setEmpName("Asma");d5.setSpare(new Double(10.0));d5.setSpare2("Z"); 48 | myData.add(d1); myData.add(d2); myData.add(d3); myData.add(d4); myData.add(d5); 49 | 50 | } 51 | public void initialize3(ArrayList myData) { 52 | UnitDTO d1 = new UnitDTO(); 53 | d1.setDeptID(100);d1.setEmpID(200);d1.setEmpName("Sriram");d1.setSpare(new Double(18.0));d1.setSpare2("A"); 54 | UnitDTO d2 = new UnitDTO(); 55 | d2.setDeptID(100);d2.setEmpID(201);d2.setEmpName("asma");d2.setSpare(new Double(11.0));d2.setSpare2("B"); 56 | UnitDTO d3 = new UnitDTO(); 57 | d3.setDeptID(100);d3.setEmpID(100);d3.setEmpName("Rajan");d3.setSpare(new Double(12.0));d3.setSpare2("C"); 58 | UnitDTO d4 = new UnitDTO(); 59 | d4.setDeptID(100);d4.setEmpID(102);d4.setEmpName("Vellman");d4.setSpare(new Double(10.0));d4.setSpare2("D"); 60 | UnitDTO d5 = new UnitDTO(); 61 | d5.setDeptID(100);d5.setEmpID(110);d5.setEmpName("Asma");d5.setSpare(new Double(10.0));d5.setSpare2("Z"); 62 | 63 | UnitDTO d6 = new UnitDTO(); 64 | d6.setDeptID(100);d6.setEmpID(110);d6.setEmpName("ASMA");d6.setSpare(new Double(10.0));d6.setSpare2("Z"); 65 | 66 | myData.add(d1); myData.add(d2); myData.add(d3); myData.add(d4); myData.add(d5); myData.add(d6); 67 | 68 | } 69 | /** 70 | * Create the test case 71 | * 72 | * @param testName name of the test case 73 | */ 74 | public TestGenericComparator( String testName ) 75 | { 76 | super( testName ); 77 | } 78 | 79 | /** 80 | * @return the suite of tests being tested 81 | */ 82 | public static Test suite() 83 | { 84 | return new TestSuite( TestGenericComparator.class ); 85 | } 86 | 87 | 88 | /** 89 | * Test for Sorting by Emp Name Ascending 90 | */ 91 | public void testSortEmpNameAsc() { 92 | ArrayList myData = new ArrayList(); initialize(myData); 93 | Collections.sort(myData, new GenericComparator("empName", true)); // sort ascending.. 94 | assertEquals("Asma", ((UnitDTO)myData.get(0)).getEmpName()); 95 | } 96 | 97 | /** 98 | * Test for Sorting by Emp Name Descending 99 | */ 100 | public void testSortEmpNameDesc() { 101 | ArrayList myData = new ArrayList(); initialize(myData); 102 | Collections.sort(myData, new GenericComparator("empName", false)); // sort ascending.. 103 | assertEquals("Vellman", ((UnitDTO)myData.get(0)).getEmpName()); 104 | 105 | } 106 | 107 | 108 | /** 109 | * Test for Sorting by Emp ID Ascending 110 | */ 111 | @Ignore("testSortIDAsc") 112 | public void testSortEmpIDAsc() { 113 | ArrayList myData = new ArrayList(); initialize(myData); 114 | 115 | Collections.sort(myData, new GenericComparator("empID", true)); // sort ascending.. 116 | assertEquals("Rajan", ((UnitDTO)myData.get(0)).getEmpName()); 117 | } 118 | 119 | 120 | /** 121 | * Test for Sorting besy Emp ID Descending... 122 | */ 123 | 124 | public void testSortEmpIDDesc() { 125 | ArrayList myData = new ArrayList(); initialize(myData); 126 | Collections.sort(myData, new GenericComparator("empID", false)); // sort Descending 127 | assertEquals("Somebody", ((UnitDTO)myData.get(0)).getEmpName()); 128 | 129 | } 130 | 131 | /** 132 | * Test for Sorting by spare Ascending 133 | */ 134 | public void testSortEmpSpareAsc() { 135 | ArrayList myData = new ArrayList(); initialize(myData); 136 | Collections.sort(myData, new GenericComparator("spare", true)); // sort ascending 137 | assertEquals("Vellman", ((UnitDTO)myData.get(0)).getEmpName()); 138 | } 139 | 140 | /** 141 | * Test for Sorting by spare Descending 142 | */ 143 | public void testSortEmpSpareDesc() { 144 | ArrayList myData = new ArrayList(); initialize(myData); 145 | Collections.sort(myData, new GenericComparator("spare", false)); // sort Descending 146 | assertEquals("Sriram", ((UnitDTO)myData.get(0)).getEmpName()); 147 | 148 | } 149 | 150 | 151 | /** 152 | * Test for Sorting by spare2 Descending 153 | */ 154 | public void testSortEmpSpareDesc2() { 155 | ArrayList myData = new ArrayList(); initialize(myData); 156 | 157 | Collections.sort(myData, new GenericComparator("spare2", false)); // sort Descending 158 | assertEquals("Sriram", ((UnitDTO)myData.get(0)).getEmpName()); 159 | 160 | } 161 | 162 | /** 163 | * Test for Sorting by spare2 Ascending 164 | */ 165 | public void testSortEmpSpareAsc2() { 166 | ArrayList myData = new ArrayList(); initialize(myData); 167 | 168 | Collections.sort(myData, new GenericComparator("spare2", true)); // sort ascending 169 | assertEquals("Vellman", ((UnitDTO)myData.get(0)).getEmpName()); 170 | 171 | } 172 | 173 | /** 174 | * Test for Sorting by spare2 Ascending 175 | */ 176 | public void testSortEmpSpare2StringAsc() { 177 | ArrayList myData = new ArrayList(); initialize2(myData); 178 | Collections.sort(myData, new GenericComparator("spare2", true)); // sort ascending 179 | assertEquals("A", ((UnitDTO)myData.get(0)).getSpare2()); 180 | } 181 | 182 | /** 183 | * Test for Sorting by spare2 Desc 184 | */ 185 | public void testSortEmpSpare2StringDesc() { 186 | ArrayList myData = new ArrayList(); initialize2(myData); 187 | Collections.sort(myData, new GenericComparator("spare2", false)); // sort Descending 188 | assertEquals("Z", ((UnitDTO)myData.get(0)).getSpare2()); 189 | } 190 | /** 191 | * Test for Sorting by caseInsensitive Emp Name Ascending 192 | */ 193 | public void testSortEmpNameAscNewComparator() { 194 | ArrayList myData = new ArrayList(); initialize3(myData); 195 | Collections.sort(myData, new CaseInsensitiveComparator("empName", true)); // sort ascending.. 196 | assertEquals("Asma".toUpperCase(), ((UnitDTO)myData.get(0)).getEmpName().toUpperCase()); 197 | assertEquals("Asma".toUpperCase(), ((UnitDTO)myData.get(1)).getEmpName().toUpperCase()); 198 | 199 | } 200 | 201 | 202 | 203 | /** 204 | * Test for Sorting caseInsensitive by Emp Name Ascending 205 | */ 206 | public void testSortEmpNameAscNewComparator3Element() { 207 | ArrayList myData = new ArrayList(); initialize3(myData); 208 | Collections.sort(myData, new CaseInsensitiveComparator("empName", true)); // sort ascending.. 209 | assertEquals("Asma".toUpperCase(), ((UnitDTO)myData.get(0)).getEmpName().toUpperCase()); 210 | assertEquals("Asma".toUpperCase(), ((UnitDTO)myData.get(1)).getEmpName().toUpperCase()); 211 | assertEquals("Asma".toUpperCase(), ((UnitDTO)myData.get(2)).getEmpName().toUpperCase()); 212 | 213 | } 214 | 215 | /** 216 | * Test for Sorting caseInsensitive by Emp Name Descending 217 | */ 218 | public void testSortEmpNameDescNewComparator3Element() { 219 | ArrayList myData = new ArrayList(); initialize3(myData); 220 | Collections.sort(myData, new CaseInsensitiveComparator("empName", false)); // sort ascending.. 221 | assertEquals("Asma".toUpperCase(), ((UnitDTO)myData.get(3)).getEmpName().toUpperCase()); 222 | assertEquals("Asma".toUpperCase(), ((UnitDTO)myData.get(4)).getEmpName().toUpperCase()); 223 | assertEquals("Asma".toUpperCase(), ((UnitDTO)myData.get(5)).getEmpName().toUpperCase()); 224 | 225 | } 226 | 227 | public void testDoubleSort() { 228 | ArrayList myData = new ArrayList(); 229 | UnitDTO d1 = new UnitDTO(); 230 | d1.setDeptID(100);d1.setEmpID(200);d1.setEmpName("A");d1.setSpare(new Double(18.0));d1.setSpare2(new Double(18.0)); 231 | UnitDTO d2 = new UnitDTO(); 232 | d2.setDeptID(100);d2.setEmpID(199);d2.setEmpName("D");d2.setSpare(new Double(11.0));d2.setSpare2(new Double(11.0)); 233 | UnitDTO d3 = new UnitDTO(); 234 | d3.setDeptID(100);d3.setEmpID(201);d3.setEmpName("C");d3.setSpare(new Double(12.0));d3.setSpare2(new Double(12.0)); 235 | myData.add(d1); myData.add(d2); myData.add(d3); 236 | Collections.sort(myData, new GenericComparator("empID", true)); // sort Asc 237 | assertEquals (Integer.valueOf(3), writeList(myData)); 238 | Collections.sort(myData, new GenericComparator("empName", true)); // sort Asc 239 | assertEquals (Integer.valueOf(3), writeList(myData)); 240 | assertFalse( ((UnitDTO)myData.get(1)).getEmpID() < ((UnitDTO)myData.get(2)).getEmpID()); 241 | } 242 | private Integer writeList(ArrayList s){ 243 | Integer c = new Integer(s.size()); 244 | return c; 245 | } 246 | 247 | 248 | } 249 | -------------------------------------------------------------------------------- /src/main/pmd/ruleset_j2ee.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | These are the rules by which J2EE/Web Applications will be built. 8 | 9 | 10 | 17 | 3 18 | 3 19 | 3 20 | 21 | 25 | 26 | Scripts should be part of Tag Libraries, rather than part of JSP pages. 27 | 28 | 2 29 | 30 | 31 | 32 | 10) ] 34 | ]]> 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 59 | 60 | 61 | ]]> 62 | 63 | 64 | 65 | 69 | 70 | Scriptlets should be factored into Tag Libraries or JSP declarations, rather than being part of JSP pages. 71 | 72 | 3 73 | 74 | 75 | 76 | 81 | 82 | 83 | 84 | 85 | 87 | 88 | <% 89 | response.setHeader("Pragma", "No-cache"); 90 | %> 91 | 92 | 93 | String title = "Hello world!"; 94 | 95 | 96 | ]]> 97 | 98 | 99 | 100 | 104 | or tags, or attributes like "align='center'". ]]> 106 | 107 | 3 108 | 109 |

text

111 | ]]> 112 | 113 | 114 | 115 | 116 | 120 | 121 | Do not use an attribute called 'class'. Use "styleclass" for CSS styles. 122 | 123 | 2 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 134 |

Some text

135 | 136 | ]]> 137 |
138 |
139 | 140 | 144 | 145 | Do not do a forward from within a JSP file. 146 | 147 | 3 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 158 | ]]> 159 | 160 | 161 | 162 | 166 | 167 | IFrames which are missing a src element can cause security information popups in IE if you are accessing the page 168 | through SSL. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q261188 169 | 170 | 2 171 | 172 | 173 | 174 | 177 | 178 | 179 | 180 | 181 | bad example><BODY> 183 | <iframe></iframe> 184 | </BODY> </HTML> 185 | 186 | <HTML><title>good example><BODY> 187 | <iframe src="foo"></iframe> 188 | </BODY> </HTML> 189 | ]]> 190 | </example> 191 | </rule> 192 | 193 | <rule name="NoHtmlComments" language="jsp" since="3.6" 194 | message="Use JSP comments instead of HTML comments" 195 | class="net.sourceforge.pmd.lang.rule.XPathRule" 196 | externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoHtmlComments"> 197 | <description> 198 | In a production system, HTML comments increase the payload 199 | between the application server to the client, and serve 200 | little other purpose. Consider switching to JSP comments. 201 | </description> 202 | <priority>2</priority> 203 | <properties> 204 | <property name="xpath"> 205 | <value> 206 | <![CDATA[ 207 | //CommentTag 208 | ]]> 209 | </value> 210 | </property> 211 | </properties> 212 | <example> 213 | <![CDATA[ 214 | <HTML><title>bad example><BODY> 215 | <!-- HTML comment --> 216 | </BODY> </HTML> 217 | 218 | <HTML><title>good example><BODY> 219 | <%-- JSP comment --%> 220 | </BODY> </HTML> 221 | ]]> 222 | </example> 223 | </rule> 224 | 225 | <rule name="DuplicateJspImports" since="3.7" 226 | message="Avoid duplicate imports such as ''{0}''" 227 | class="net.sourceforge.pmd.lang.jsp.rule.basic.DuplicateJspImportsRule" 228 | externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#DuplicateJspImports"> 229 | <description><![CDATA[Avoid duplicate import statements inside JSP's. ]]> 230 | </description> 231 | <priority>3</priority> 232 | <example> 233 | <![CDATA[ 234 | <%@ page import=\"com.foo.MyClass,com.foo.MyClass\"%><html><body><b><img src=\"<%=Some.get()%>/foo\">xx</img>text</b></body></html> 235 | ]]> 236 | </example> 237 | </rule> 238 | 239 | <rule name="JspEncoding" language="jsp" since="4.0" 240 | class="net.sourceforge.pmd.lang.rule.XPathRule" 241 | message="JSP file should use UTF-8 encoding" 242 | externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#JspEncoding"> 243 | <description> 244 | <![CDATA[ 245 | A missing 'meta' tag or page directive will trigger this rule, as well as a non-UTF-8 charset. 246 | ]]> 247 | </description> 248 | <priority>3</priority> 249 | <properties> 250 | <property name="xpath"> 251 | <value> 252 | <![CDATA[ 253 | //Content[ 254 | not(Element[@Name="meta"][ 255 | Attribute[@Name="content"]/AttributeValue[contains(lower-case(@Image),"charset=utf-8")] 256 | ]) 257 | and 258 | not(JspDirective[@Name='page']/JspDirectiveAttribute[@Name='contentType'][contains(lower-case(@Value),"charset=utf-8")]) 259 | ] 260 | ]]> 261 | </value> 262 | </property> 263 | </properties> 264 | <example> 265 | <![CDATA[ 266 | Most browsers should be able to interpret the following headers: 267 | 268 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> 269 | 270 | <meta http-equiv="Content-Type"  content="text/html; charset=UTF-8" /> 271 | ]]> 272 | </example> 273 | </rule> 274 | 275 | <rule 276 | name="NoInlineScript" language="jsp" since="4.0" 277 | class="net.sourceforge.pmd.lang.rule.XPathRule" 278 | message="Avoiding inlining HTML script content" 279 | externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoInlineScript"> 280 | <description> 281 | <![CDATA[ 282 | Avoid inlining HTML script content. Consider externalizing the HTML script using the 'src' attribute on the <script> element. 283 | Externalized script could be reused between pages. Browsers can also cache the script, reducing overall download bandwidth. 284 | ]]> 285 | </description> 286 | <priority>3</priority> 287 | <properties> 288 | <property name="xpath"> 289 | <value> 290 | <![CDATA[ 291 | //HtmlScript[@Image != ''] 292 | ]]> 293 | </value> 294 | </property> 295 | </properties> 296 | <example> 297 | <![CDATA[ 298 | Most browsers should be able to interpret the following headers: 299 | 300 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> 301 | 302 | <meta http-equiv="Content-Type"  content="text/html; charset=UTF-8" /> 303 | ]]> 304 | </example> 305 | </rule> 306 | 307 | <rule 308 | name="NoUnsanitizedJSPExpression" since="5.1.4" 309 | class="net.sourceforge.pmd.lang.jsp.rule.basic.NoUnsanitizedJSPExpressionRule" 310 | message="Using unsanitized JSP expression can lead to Cross Site Scripting (XSS) attacks" 311 | externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoUnsanitizedJSPExpression"> 312 | <description> 313 | Avoid using expressions without escaping / sanitizing. This could lead to cross site scripting - as the expression 314 | would be interpreted by the browser directly (e.g. "<script>alert('hello');</script>"). 315 | </description> 316 | <priority>3</priority> 317 | <example> 318 | <![CDATA[ 319 | <%@ page contentType="text/html; charset=UTF-8" %> 320 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 321 | ${expression} <!-- don't use this --> 322 | ${fn:escapeXml(expression)} <!-- instead, escape it --> 323 | <c:out value="${expression}" /> <!-- or use c:out --> 324 | ]]> 325 | </example> 326 | </rule> 327 | 328 | </ruleset> 329 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4 | <modelVersion>4.0.0</modelVersion> 5 | <groupId>com.edurekademo.tutorial</groupId> 6 | <artifactId>addressbook</artifactId> 7 | <packaging>war</packaging> 8 | <version>2.0</version> 9 | <name>Vaadin Addressbook example</name> 10 | 11 | <properties> 12 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 13 | <failOnMissingWebXml>false</failOnMissingWebXml> 14 | <vaadin.version>8.0.0.alpha2</vaadin.version> 15 | <vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version> 16 | </properties> 17 | 18 | <repositories> 19 | <repository> 20 | <id>vaadin-prereleases</id> 21 | <name>Vaadin Pre-releases</name> 22 | <url>https://maven.vaadin.com/vaadin-prereleases</url> 23 | </repository> 24 | <!-- Essential Vaadin artifacts are in maven central, but maven.vaadin.com 25 | contains a huge set of additional libraries. See vaadin.com/directory --> 26 | <repository> 27 | <id>vaadin-addons</id> 28 | <url>http://maven.vaadin.com/vaadin-addons</url> 29 | </repository> 30 | 31 | <repository> 32 | <id>vaadin-snapshots</id> 33 | <url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url> 34 | <releases> 35 | <enabled>false</enabled> 36 | </releases> 37 | <snapshots> 38 | <enabled>true</enabled> 39 | </snapshots> 40 | </repository> 41 | </repositories> 42 | 43 | <pluginRepositories> 44 | <pluginRepository> 45 | <id>vaadin-snapshots</id> 46 | <url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url> 47 | <releases> 48 | <enabled>false</enabled> 49 | </releases> 50 | <snapshots> 51 | <enabled>true</enabled> 52 | </snapshots> 53 | </pluginRepository> 54 | </pluginRepositories> 55 | 56 | 57 | <dependencies> 58 | <dependency> 59 | <groupId>com.vaadin</groupId> 60 | <artifactId>vaadin-compatibility-server</artifactId> 61 | <version>${vaadin.version}</version> 62 | </dependency> 63 | <dependency> 64 | <groupId>com.vaadin</groupId> 65 | <artifactId>vaadin-compatibility-shared</artifactId> 66 | <version>${vaadin.version}</version> 67 | </dependency> 68 | <dependency> 69 | <groupId>com.vaadin</groupId> 70 | <artifactId>vaadin-compatibility-client-compiled</artifactId> 71 | <version>${vaadin.version}</version> 72 | </dependency> 73 | <dependency> 74 | <groupId>com.vaadin</groupId> 75 | <artifactId>vaadin-themes</artifactId> 76 | <version>${vaadin.version}</version> 77 | </dependency> 78 | <dependency> 79 | <groupId>javax.servlet</groupId> 80 | <artifactId>javax.servlet-api</artifactId> 81 | <version>3.0.1</version> 82 | <scope>compile</scope> 83 | </dependency> 84 | <!-- The huge set of awesome Java libraries are available as such 85 | for Vaadin developers, you should take the advantage of those. In this app 86 | we just use the commons-beanutils to help implementing the fake backend. --> 87 | <dependency> 88 | <groupId>commons-beanutils</groupId> 89 | <artifactId>commons-beanutils</artifactId> 90 | <version>1.9.2</version> 91 | <type>jar</type> 92 | </dependency> 93 | 94 | <!-- LOGGING --> 95 | <dependency> 96 | <groupId>log4j</groupId> 97 | <artifactId>log4j</artifactId> 98 | <version>1.2.9</version> 99 | </dependency> 100 | <dependency> 101 | <groupId>org.slf4j</groupId> 102 | <artifactId>slf4j-api</artifactId> 103 | <version>1.7.7</version> 104 | </dependency> 105 | <dependency> 106 | <groupId>org.slf4j</groupId> 107 | <artifactId>slf4j-simple</artifactId> 108 | <version>1.7.7</version> 109 | </dependency> 110 | <dependency> 111 | <groupId>org.slf4j</groupId> 112 | <artifactId>slf4j-log4j12</artifactId> 113 | <version>1.7.7</version> 114 | </dependency> 115 | 116 | <!-- TESTING --> 117 | <dependency> 118 | <groupId>junit</groupId> 119 | <artifactId>junit</artifactId> 120 | <version>4.7</version> 121 | <scope>test</scope> 122 | </dependency> 123 | 124 | 125 | <!-- COMMONS --> 126 | <dependency> 127 | <groupId>commons-httpclient</groupId> 128 | <artifactId>commons-httpclient</artifactId> 129 | <version>3.1</version> 130 | </dependency> 131 | 132 | <dependency> 133 | <groupId>org.apache.commons</groupId> 134 | <artifactId>commons-lang3</artifactId> 135 | <version>3.1</version> 136 | </dependency> 137 | 138 | <!-- JSON --> 139 | <dependency> 140 | <groupId>org.json</groupId> 141 | <artifactId>json</artifactId> 142 | <version>20140107</version> 143 | </dependency> 144 | <dependency> 145 | <groupId>org.codehaus.jackson</groupId> 146 | <artifactId>jackson-jaxrs</artifactId> 147 | <version>1.9.4</version> 148 | </dependency> 149 | 150 | <!-- XML --> 151 | <dependency> 152 | <groupId>com.sun.xml.security</groupId> 153 | <artifactId>xml-security-impl</artifactId> 154 | <version>1.0</version> 155 | </dependency> 156 | 157 | 158 | </dependencies> 159 | 160 | <build> 161 | <plugins> 162 | <plugin> 163 | <groupId>org.apache.maven.plugins</groupId> 164 | <artifactId>maven-compiler-plugin</artifactId> 165 | <version>3.2</version> 166 | <configuration> 167 | <source>1.8</source> 168 | <target>1.8</target> 169 | </configuration> 170 | </plugin> 171 | <plugin> 172 | <groupId>org.eclipse.jetty</groupId> 173 | <artifactId>jetty-maven-plugin</artifactId> 174 | <version>9.2.3.v20140905</version> 175 | </plugin> 176 | 177 | <plugin> 178 | <groupId>org.apache.maven.plugins</groupId> 179 | <artifactId>maven-surefire-plugin</artifactId> 180 | <version>2.19.1</version> 181 | <configuration> 182 | <parallel>methods</parallel> 183 | <threadCount>10</threadCount> 184 | <includes> 185 | <include>**/Test*.java</include> 186 | <include>**/Test.java</include> 187 | <include>**/TestCase.java</include> 188 | </includes> 189 | <excludes> 190 | <exclude>**/*Abstract*Test.java</exclude> 191 | </excludes> 192 | </configuration> 193 | </plugin> 194 | 195 | </plugins> 196 | <finalName>addressbook</finalName> 197 | </build> 198 | 199 | 200 | <reporting> 201 | <plugins> 202 | <plugin> 203 | <groupId>org.apache.maven.plugins</groupId> 204 | <artifactId>maven-surefire-report-plugin</artifactId> 205 | <version>2.19.1</version> 206 | </plugin> 207 | </plugins> 208 | </reporting> 209 | 210 | <profiles> 211 | <profile> 212 | <id>development</id> 213 | <activation> 214 | <activeByDefault>true</activeByDefault> 215 | </activation> 216 | 217 | </profile> 218 | <profile> 219 | <id>metrics</id> 220 | <build> 221 | <plugins> 222 | <!-- CHECKSTYLE --> 223 | <!--<plugin>--> 224 | <!--<artifactId>maven-checkstyle-plugin</artifactId>--> 225 | <!--<version>2.9.1</version>--> 226 | <!--<dependencies>--> 227 | <!--<dependency>--> 228 | <!--<groupId>com.wakaleo.gameoflife</groupId>--> 229 | <!--<artifactId>gameoflife-build</artifactId>--> 230 | <!--<version>${project.version}</version>--> 231 | <!--</dependency>--> 232 | <!--</dependencies>--> 233 | <!--<configuration>--> 234 | <!--<configLocation>custom-checkstyle.xml</configLocation>--> 235 | <!--</configuration>--> 236 | <!--</plugin>--> 237 | 238 | <!-- PMD --> 239 | <plugin> 240 | <groupId>org.apache.maven.plugins</groupId> 241 | <artifactId>maven-pmd-plugin</artifactId> 242 | <version>3.2</version> 243 | <configuration> 244 | <targetJdk>1.8</targetJdk> 245 | <aggregate>true</aggregate> 246 | <format>xml</format> 247 | <!-- CPD options --> 248 | <minimumTokens>20</minimumTokens> 249 | <!--<ignoreIdentifiers>true</ignoreIdentifiers>--> 250 | <failOnViolation>true</failOnViolation> 251 | <failurePriority>2</failurePriority> 252 | </configuration> 253 | </plugin> 254 | 255 | <!-- FINDBUGS --> 256 | <plugin> 257 | <artifactId>findbugs-maven-plugin</artifactId> 258 | <version>2.4.0</version> 259 | <configuration> 260 | <effort>Max</effort> 261 | <xmlOutput>true</xmlOutput> 262 | </configuration> 263 | </plugin> 264 | </plugins> 265 | </build> 266 | </profile> 267 | <profile> 268 | <id>maven3</id> 269 | <activation> 270 | <activeByDefault>true</activeByDefault> 271 | </activation> 272 | <build> 273 | <plugins> 274 | <plugin> 275 | <groupId>org.apache.maven.plugins</groupId> 276 | <artifactId>maven-enforcer-plugin</artifactId> 277 | <version>1.0</version> 278 | <executions> 279 | <execution> 280 | <id>enforce-versions</id> 281 | <goals> 282 | <goal>enforce</goal> 283 | </goals> 284 | <configuration> 285 | <rules> 286 | <requireMavenVersion> 287 | <version>[3.0,)</version> 288 | </requireMavenVersion> 289 | </rules> 290 | </configuration> 291 | </execution> 292 | </executions> 293 | </plugin> 294 | <plugin> 295 | <groupId>org.apache.maven.plugins</groupId> 296 | <artifactId>maven-site-plugin</artifactId> 297 | <version>3.3</version> 298 | <configuration> 299 | <reportPlugins> 300 | <plugin> 301 | <artifactId>maven-project-info-reports-plugin</artifactId> 302 | <version>2.7</version> 303 | </plugin> 304 | <plugin> 305 | <groupId>org.jacoco</groupId> 306 | <artifactId>jacoco-maven-plugin</artifactId> 307 | <version>0.7.2.201409121644</version> 308 | </plugin> 309 | <plugin> 310 | <groupId>org.apache.maven.plugins</groupId> 311 | <artifactId>maven-checkstyle-plugin</artifactId> 312 | <version>3.0.1</version> 313 | <!--<configuration>--> 314 | <!--<configLocation>gol-checkstyle.xml</configLocation>--> 315 | <!--</configuration>--> 316 | </plugin> 317 | <plugin> 318 | <groupId>org.apache.maven.plugins</groupId> 319 | <artifactId>maven-pmd-plugin</artifactId> 320 | <version>3.2</version> 321 | <configuration> 322 | <targetJdk>1.8</targetJdk> 323 | <aggregate>true</aggregate> 324 | <format>xml</format> 325 | <rulesets> 326 | <ruleset>/pmd-rules.xml</ruleset> 327 | </rulesets> 328 | <!-- CPD options --> 329 | <minimumTokens>20</minimumTokens> 330 | <ignoreIdentifiers>true</ignoreIdentifiers> 331 | </configuration> 332 | </plugin> 333 | <plugin> 334 | <groupId>org.codehaus.mojo</groupId> 335 | <artifactId>findbugs-maven-plugin</artifactId> 336 | <version>2.4.0</version> 337 | <configuration> 338 | <effort>Max</effort> 339 | <xmlOutput>true</xmlOutput> 340 | </configuration> 341 | </plugin> 342 | <plugin> 343 | <artifactId>maven-javadoc-plugin</artifactId> 344 | <version>2.9.1</version> 345 | <configuration> 346 | <source>1.8</source> 347 | <doclet> 348 | gr.spinellis.umlgraph.doclet.UmlGraphDoc 349 | </doclet> 350 | <docletArtifact> 351 | <groupId>gr.spinellis</groupId> 352 | <artifactId>UmlGraph</artifactId> 353 | <version>4.6</version> 354 | </docletArtifact> 355 | <additionalparam> 356 | -inferrel -inferdep -hide java.* -collpackages 357 | java.util.* -attributes -operations 358 | -enumerations -enumconstants 359 | </additionalparam> 360 | </configuration> 361 | </plugin> 362 | <plugin> 363 | <groupId>org.apache.maven.plugins</groupId> 364 | <artifactId>maven-jxr-plugin</artifactId> 365 | <version>2.4</version> 366 | </plugin> 367 | </reportPlugins> 368 | </configuration> 369 | <dependencies> 370 | <dependency> 371 | <groupId>com.edurekademo.tutorial</groupId> 372 | <artifactId>addressbook</artifactId> 373 | <version>${project.version}</version> 374 | </dependency> 375 | </dependencies> 376 | </plugin> 377 | </plugins> 378 | </build> 379 | </profile> 380 | <profile> 381 | <id>maven2</id> 382 | <build> 383 | <plugins> 384 | <plugin> 385 | <groupId>org.apache.maven.plugins</groupId> 386 | <artifactId>maven-enforcer-plugin</artifactId> 387 | <version>1.0</version> 388 | <executions> 389 | <execution> 390 | <id>enforce-versions</id> 391 | <goals> 392 | <goal>enforce</goal> 393 | </goals> 394 | <configuration> 395 | <rules> 396 | <requireMavenVersion> 397 | <version>[2.0.9, 2.2.1]</version> 398 | </requireMavenVersion> 399 | </rules> 400 | </configuration> 401 | </execution> 402 | </executions> 403 | </plugin> 404 | <plugin> 405 | <groupId>org.apache.maven.plugins</groupId> 406 | <artifactId>maven-site-plugin</artifactId> 407 | <version>2.1.1</version> 408 | <dependencies> 409 | <dependency> 410 | <groupId>com.edurekademo.tutorial</groupId> 411 | <artifactId>addressbook</artifactId> 412 | <version>${project.version}</version> 413 | </dependency> 414 | </dependencies> 415 | </plugin> 416 | </plugins> 417 | </build> 418 | <reporting> 419 | <plugins> 420 | <plugin> 421 | <groupId>org.codehaus.mojo</groupId> 422 | <artifactId>cobertura-maven-plugin</artifactId> 423 | <version>${cobertura.version}</version> 424 | <configuration> 425 | <formats> 426 | <format>html</format> 427 | <format>xml</format> 428 | </formats> 429 | </configuration> 430 | </plugin> 431 | <plugin> 432 | <groupId>org.apache.maven.plugins</groupId> 433 | <artifactId>maven-pmd-plugin</artifactId> 434 | <version>2.5</version> 435 | <configuration> 436 | <targetJdk>1.8</targetJdk> 437 | <aggregate>true</aggregate> 438 | <format>xml</format> 439 | <rulesets> 440 | <ruleset>/pmd-rules.xml</ruleset> 441 | </rulesets> 442 | <!-- CPD options --> 443 | <minimumTokens>20</minimumTokens> 444 | <ignoreIdentifiers>true</ignoreIdentifiers> 445 | 446 | </configuration> 447 | </plugin> 448 | <plugin> 449 | <groupId>org.apache.maven.plugins</groupId> 450 | <artifactId>maven-checkstyle-plugin</artifactId> 451 | <version>2.9.1</version> 452 | <configuration> 453 | <configLocation>addressbook-build/checkstyle.xml</configLocation> 454 | </configuration> 455 | </plugin> 456 | <plugin> 457 | <groupId>org.codehaus.mojo</groupId> 458 | <artifactId>findbugs-maven-plugin</artifactId> 459 | <version>2.4.0</version> 460 | <configuration> 461 | <effort>Max</effort> 462 | <xmlOutput>true</xmlOutput> 463 | </configuration> 464 | </plugin> 465 | <plugin> 466 | <artifactId>maven-javadoc-plugin</artifactId> 467 | <version>2.7</version> 468 | <configuration> 469 | <source>1.8</source> 470 | <doclet> 471 | gr.spinellis.umlgraph.doclet.UmlGraphDoc 472 | </doclet> 473 | <docletArtifact> 474 | <groupId>gr.spinellis</groupId> 475 | <artifactId>UmlGraph</artifactId> 476 | <version>4.6</version> 477 | </docletArtifact> 478 | <additionalparam> 479 | -inferrel -inferdep -hide java.* -collpackages 480 | java.util.* -attributes -operations 481 | -enumerations -enumconstants 482 | </additionalparam> 483 | </configuration> 484 | </plugin> 485 | <plugin> 486 | <groupId>org.apache.maven.plugins</groupId> 487 | <artifactId>maven-jxr-plugin</artifactId> 488 | <version>2.1</version> 489 | </plugin> 490 | </plugins> 491 | </reporting> 492 | </profile> 493 | </profiles> 494 | 495 | </project> 496 | --------------------------------------------------------------------------------