+ All Categories
Home > Documents > CGS – 4854 Summer 2012

CGS – 4854 Summer 2012

Date post: 22-Feb-2016
Category:
Upload: lisbet
View: 54 times
Download: 0 times
Share this document with a friend
Description:
CGS – 4854 Summer 2012 . Instructor: Francisco R. Ortega Chapter 5. Web Site Construction and Management. Today’s Lecture. Brief review of Log4J Chapter 5 Remember – Mid-Term next class. Mid-Term. Mid-Term June 21 st . Chapters 1,2,3 and 4. Possible review for mid-term - PowerPoint PPT Presentation
86
CGS – 4854 Summer 2012 Web Site Con struction and Management Instructor: Francisco R. Ortega Chapter 5
Transcript

PowerPoint Presentation

CGS 4854 Summer 2012 Web Site Construction and ManagementInstructor: Francisco R. Ortega Chapter 5

1Todays LectureBrief review of Log4JChapter 5 Remember Mid-Term next class2Mid-TermMid-Term June 21st. Chapters 1,2,3 and 4. Possible review for mid-term June 14 (after quiz 4) or June 19Extra Credit for Mid-Term Extra credit question : Regular Expressions (if covered before the exam)You are allowed to bring two letter size paper to the exam3ASCII Table (Part 1)

4Regular ExpressionsMatch strings of text (wiki) Sequence of regular expressions is known as a patternRegular expressions containWildcardsSpecial characters Escape sequences

5Regular Expressions 101Characters match themselves except: [\^$.|?*+()\ suppresses the meaning of special characters[] starts a character class. We match one from the class.- specifies a range of characters^ negates a character class. matches any single character except line break| matches either the left, or the right (or)6Character Classes[xyz] : will match x or y or z[a-z] : will match lowercase letters[a-zA-Z] : will match all letters[a-Z] :will not match any letters (why?) [A-z] : will match all letters but additional symbols. Why?[^abc] : Any character except for a,b or c.

7Predefined classesCharacter classMeaning.Any character except line termination\dA digit: [0-9]\DA non digit [^0-9]\sA whitespace character\SA non-whitespace character\wA word character [a-zA-Z_0-9]\WA non word character8Escape Sequence\. : would match a period[.] : would match a period\ does not lose special meaning inside square brackets [\d]9Alternationyes|noyes|no|maybeIt will match either yes,no or maybae. But only one of them. 10Grouping and Capturing(pattern)Capturing pattern.Can retrieve values from \1 thru \9ExampleText: abyes3[a-z] ([a-z]) (yes|no) \d \1 is equal to b\2 is equal to yes(?:pattern)Only used for grouping 11Ignoring case(?i)yes|no[yY] [eE] [sS] | [Nn] [Oo]12RepetitionRepetition SymbolMeaning*Matches zero or more occurrences of the preceding pattern?Matches zero or one occurrences of the preceding pattern+Matches one or more occurrences of the preceding pattern{m,n}Range of times that the pattern can repeat. ? Same as {0,1}{m}Range of exactly how many times that will match the pattern.{m,}Range of at least times that will match the pattern. + same as {1,}13Regex in javaYou will need to use two backslashes Regex: \dJava regex: \\d

14Hibernate (wiki)Mapping from Java classes to database tablesMapping Java data types to SQLdata types Data query and retrieval facilities.Generates the SQL calls Required Validation 15Hibernate Required ValidationUses annotations @Pattern(regexp = , message = Some Message)There is a default messageAnnotations@Pattern@NotNull (do not use with primitives)Annotations to be used with Numbers@Min ( value = 20) @Max (value = 100)@Range(min= 0 , max =100)Annotations for Collections will be covered in Ch. 616Required Validation@Pattern(regex=".*\\S.*", message="cannot be empty")@NotNullpublic String getHobby() { return hobby;}

If more than one annotation, then is assume that logical operator is AND17Question.*\S.* In java .*\\S.*

18JSP Hobby ${helper.errors.hobby}
Aversion ${helper.errors.aversion} 19Min/Max

20Creating Error MessagesClass that performs validation is:ValidatorOnly one instance is neededCreated from Validator FactoryOnly one instance is needed

21Creating Error MessagesProtected static final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); Protected static final Validator validator = validatorFactory.getValidator(); Array of validation is created by calling validators validate method.Set violations = validator.validate(data);

22Implementing ValidationUsing the array provided by hibernate Linear SearchUsing a Map (HashMap)Insert O(1) Get/Set O(1) Contain Key Average O(1 + n/k) worst case is O(n)Where have we seen something similar to the map structure in this class?Request.getSession().setAttribute(helper,this);

23Changes to HelpererrorMapsetErrorsgetErrors()clearErrors()

All of this can be found in HelperBaseCh5 in the shared folder. 24HelperBaseCh5HelperBaseHttpServletRequest requestHttpServletResponse responseLogger loggerMap errorMapAbstract copyFromSession()addHelperToSession()executeButtonMethod()fillBeanFromRequest()setErrors()getErrors()isValid()25java.util.Map ExampleMap myMap = new HashMap 69Looping in JSP using JSTL

70Using Persistent Data (page 177/178) Add Hibernate Jar FilesInitialize Hibernate when controller is loaded into memoryAdd the WebappListener to shared PackageAdd the Statements to the web.xml fileAnnotate the bean class as an entityAdd an Id field to the bean (PersistentBase)Add properties to bean71Using Persistent Data (page 177/178) Add statements to web.xml Add initHibernate method to ControllerHelperModify process Method (next slide)In the process page, display the data from the database using Expression Language72ControllerHelper: PersistentDataModify processMethod (see page 179) public String processMethod(){ if (!isValid(data)) { return jspLocation(Expired.jsp);} HibernateHelper.updateDB(data); List list = hibernateHelper.getListData(data.getClass()); Request.setAttribute(database,list); return jsplocation(Process.jsp);}

73PersistentBaseBasic description of class follows74initSessionFactoryInitialized hibernate for applicationstatic public void initSessionFactory(Properties props, Class ... mappings)static public void initSessionFactory(Class ... mappings)ExamplesinitSessionFactory(props,RequestDataPersistent.class)initSessionFactory(props,bean1.class, bean2.class,bean3.class,bean4.class,)

75createTableCreate tables from specified beans. static public void createTable(Properties props, Class... mappings) ExamplescreateTable(props,RequestDataPersistent.class)createTable(props,bean1.class, bean2.class,bean3.class,bean4.class,)

76closeFactoryIt closes the Hibernate Factory that was created with the InitSessionFactorystatic public void closeFactory() 77updateDBUpdates database from bean or list of beansstatic public void updateDB(Object obj)Single beanstatic public void updateDB(java.util.List list)List of beans

78saveDBSaves bean to Database. static public void saveDB(Object obj)79removeDBRemoves bean from DBstatic public void removeDB(Object obj)80getListDatastatic public java.util.List getListData( Class classBean, String strKey, Object value)static public java.util.List getListData( Class classBean, String strKey1, Object value1, String strKey2, Object value2)static public java.util.List getListData( Class classBean)81getListData82getFirstMatch static public Object getFirstMatch( Class classBean, String strKey, Object value)static public Object getFirstMatch83getKeyDatastatic public Object getKeyData(Class beanClass, long itemId)84isSessionOpenstatic public boolean isSessionOpen()85Next classWe will start Chapter 68646176.0


Recommended