Commit 9b323274 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
logo.png

3.25 KB

maven.jar.override = on
maven.jar.commons-beautils = ${basedir}/lib/commons-beautils-1.6.1.jar
maven.jar.commons-jelly = ${basedir}/lib/commons-jelly-1.0-beta-4-SNAPSHOT.jar
maven.jar.freemarker = ${basedir}/lib/freemarker.jar
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<!-- the version of maven's project object model -->
<pomVersion>3</pomVersion>
<!-- a unique name for this project -->
<id>jcc</id>
<!-- a short but descriptive name for the project -->
<name>JCC</name>
<!-- The version of the project under development, e.g.
1.1, 1.2, 2.0-dev -->
<currentVersion>0.1-DEVELOPMENT</currentVersion>
<!-- the year the project started -->
<inceptionYear>2003</inceptionYear>
<!-- the top level of java packages that this project defines
e.g. if your project contains the packages
com.mycompany.accounts.reports, com.mycompany.accounts.reports
and com.mycompany.accounts.utils, the package would be
'com.mycompany.accounts' -->
<package>org.apache.maven.examples.simplejava</package>
<!-- a short description of what the project does -->
<shortDescription>A simple java project</shortDescription>
<!-- any mailing lists for the project -->
<mailingLists/>
<!-- who the developers are for the project -->
<developers />
<!-- jar files the project is dependent on -->
<dependencies>
<dependency>
<id>commons-lang</id>
<version>2.0</version>
</dependency>
<dependency>
<id>commons-beanutils</id>
<version>1.6.1</version>
</dependency>
<dependency>
<id>commons-betwixt</id>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<id>commons-cli</id>
<version>1.0</version>
</dependency>
<dependency>
<id>commons-collections</id>
<version>2.1</version>
</dependency>
<dependency>
<id>commons-digester</id>
<version>1.5</version>
</dependency>
<dependency>
<id>commons-logging</id>
<version>1.0.3</version>
</dependency>
<dependency>
<id>log4j</id>
<version>1.2.8</version>
</dependency>
<dependency>
<id>commons-jelly</id>
<version>1.0-beta-4-SNAPSHOT</version>
</dependency>
<dependency>
<id>commons-jexl</id>
<version>1.0-beta-1</version>
</dependency>
<dependency>
<id>velocity</id>
<version>1.3</version>
</dependency>
<dependency>
<id>dom4j</id>
<version>1.4</version>
</dependency>
<dependency>
<id>freemarker</id>
<version>2.2.4</version>
</dependency>
</dependencies>
<!-- build information for the project -->
<build>
<sourceDirectory>src/java</sourceDirectory>
<unitTestSourceDirectory>src/test</unitTestSourceDirectory>
<unitTest>
<includes>
<include>**/*Test.java</include>
</includes>
</unitTest>
</build>
</project>
One Two Three, Test
\ No newline at end of file
One Two Three, Test
\ No newline at end of file
Date date = new Date();
Date rounded = DateUtils.round( date, Calendar.ERA );
System.out.println( rounded );
\ No newline at end of file
/*
* ========================================================================
*
* Copyright 2005 Tim O'Brien.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================================================================
*/
package com.discursive.jccook.bean;
public class Author {
private String name;
private String favoriteColor;
public Author() {}
public Author(String name, String favoriteColor) {
this.name = name;
this.favoriteColor = favoriteColor;
}
public String getName() { return name; }
public void setName(String name) {
this.name = name;
}
public String getFavoriteColor() { return favoriteColor; }
public void setFavoriteColor(String favoriteColor) {
this.favoriteColor = favoriteColor;
}
}
/*
* ========================================================================
*
* Copyright 2005 Tim O'Brien.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================================================================
*/
package com.discursive.jccook.bean;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.beanutils.PropertyUtils;
public final class BeanUtilExample {
private BeanUtilExample() {
}
private static String propName = "author.name";
public static void main(String[] pArgs) {
if (pArgs.length > 0 && pArgs[0] != null) {
propName = pArgs[0];
}
System.out.println("Getting Property: " + propName);
List books = createBooks();
Iterator i = books.iterator();
while( i.hasNext() ) {
Book book = (Book) i.next();
Object propVal = null;
try {
propVal = PropertyUtils.getProperty(book, propName);
} catch (Exception e) {
System.out.println(
"Error getting property: "
+ propName
+ ", from book: "
+ book.getName()
+ ", exception: "
+ e.getMessage());
}
System.out.println("Property Value: " + propVal);
}
}
private static List createBooks() {
List retList = new ArrayList();
retList.add(new Book("Java Threads", new Author("Oaks", "Pistachio")));
retList.add(new Book("Hamlet", new Author("Willy", "Rocky Road")));
return retList;
}
}
/*
* ========================================================================
*
* Copyright 2005 Tim O'Brien.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================================================================
*/
package com.discursive.jccook.bean;
import java.util.ArrayList;
import java.util.List;
public class Book {
private String name;
private Author author;
private List chapters = new ArrayList();
public Book() {}
public Book(String pName, Author pAuthor) {
setName(pName);
setAuthor(pAuthor);
}
public void addChapter( Chapter chapter ) { chapters.add( chapter ); }
public String getName() { return name; }
public void setName(String pName) { name = pName; }
public Author getAuthor() { return author; }
public void setAuthor(Author pAuthor) { author = pAuthor; }
public List getChapters() { return chapters; }
public void setChapters(List list) { chapters = list; }
}
/*
* ========================================================================
*
* Copyright 2005 Tim O'Brien.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================================================================
*/
package com.discursive.jccook.bean;
import java.util.HashMap;
import java.util.Map;
public class Chapter {
private String title;
private Map sections = new HashMap();
public Chapter() {}
public Chapter(String title) { this.title = title; }
public void addSection( String sectionName, String summary ) {
sections.put( sectionName, summary );
}
public Map getSections() { return sections; }
public void setSections(Map map) { sections = map; }
public String getTitle() { return title; }
public void setTitle(String string) { title = string; }
}
/*
* ========================================================================
*
* Copyright 2005 Tim O'Brien.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================================================================
*/
package com.discursive.jccook.bean;
import org.apache.commons.beanutils.PropertyUtils;
public class NestedPropertyExample {
public static void main(String[] args) {
NestedPropertyExample example = new NestedPropertyExample();
example.start();
}
private void start() {
// Create an author
Author wolfe = new Author( "Tom Wolfe", "Green" );
Book theRightStuff = new Book( "The Right Stuff", wolfe );
try {
String bookName = (String) PropertyUtils.getSimpleProperty( theRightStuff, "name" );
String authorName = (String) PropertyUtils.getNestedProperty( theRightStuff, "author.name" );
System.out.println( "The book is " + bookName );
System.out.println( "The author is " + authorName );
} catch (Exception e) {
System.out.println( "There was a problem getting a bean property." );
e.printStackTrace();
}
}
}
/*
* ========================================================================
*
* Copyright 2005 Tim O'Brien.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================================================================
*/
package com.discursive.jccook.bean;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.PropertyUtils;
public class SimplePropertyExample {
public static void main(String[] args) {
SimplePropertyExample example = new SimplePropertyExample();
example.start();
}
private void start() {
// Create an author
Author wolfe = new Author( "Tom Wolfe", "Green" );
try {
String name = (String) PropertyUtils.getSimpleProperty( wolfe, "name" );
String favoriteColor = (String) PropertyUtils.getSimpleProperty( wolfe, "favoriteColor" );
System.out.println( "The Author has some properties: " + name + ", " + favoriteColor );
} catch (IllegalAccessException e) {
System.out.println( "You are not allowed to access a property!" );
} catch (InvocationTargetException e) {
System.out.println( "There was a problem invoking the method." );
} catch (NoSuchMethodException e) {
System.out.println( "The is no method to get a property." );
}
}
}
/*
* ========================================================================
*
* Copyright 2005 Tim O'Brien.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================================================================
*/
package com.discursive.jccook.cmdline;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
public class CliBasicExample {
public static void main(String[] args) throws Exception {
CommandLineParser parser = new BasicParser();
Options options = new Options();
options.addOption("h", "help", false, "Print this usage information");
options.addOption("v", "verbose", false, "Print out VERBOSE debugging information" );
options.addOption("f", "file", true, "File to save program output to");
CommandLine commandLine = parser.parse( options, args );
boolean verbose = false;
String file = "";
if( commandLine.hasOption('h') ) {
System.out.println( "Help Message");
System.exit(0);
}
if( commandLine.hasOption('v') ) {
verbose = true;
}
if( commandLine.hasOption('f') ) {
file = commandLine.getOptionValue('f');
}
System.exit(0);
}
}
/*
* ========================================================================
*
* Copyright 2005 Tim O'Brien.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================================================================
*/
package com.discursive.jccook.cmdline;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
public class CliComplexExample {
public static void main(String[] args) throws Exception {
CommandLineParser parser = new BasicParser();
Options options = new Options();
options.addOption("h", "help", false, "Print this usage information");
options.addOption("v", "verbose", false, "Print out VERBOSE debugging information" );
OptionGroup optionGroup = new OptionGroup();
optionGroup.addOption( OptionBuilder.hasArg(true).create('f') );
optionGroup.addOption( OptionBuilder.hasArg(true).create('m') );
options.addOptionGroup( optionGroup );
CommandLine commandLine = parser.parse( options, args );
boolean verbose = false;
String file = "";
String mail = "";
if( commandLine.hasOption('h') ) {
System.out.println( "Help Message");
System.exit(0);
}
if( commandLine.hasOption('v') ) {
verbose = true;
}
if( commandLine.hasOption('f') ) {
file = commandLine.getOptionValue('f');
} else if( commandLine.hasOption('m') ) {
mail = commandLine.getOptionValue('m');
}
System.exit(0);
}
}
/*
* ========================================================================
*
* Copyright 2005 Tim O'Brien.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================================================================
*/
package com.discursive.jccook.cmdline;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
public class CliUsageExample {
CommandLineParser parser;
Options options;
CommandLine commandLine;
private static final String USAGE = "java com.discursive.jccook.cmdline.CliExample";