December 19th, 2020 by Lincoln Baxter III

PrettyTime 5.0.0.Final Released – New APIs, JDK 8 DateTime support

We are proud to announce the 5.0.0.Final version of PrettyTime. This release includes several bug-fixes, an improved NLP (time parsing) module, new methods for more convenient configuration of time units, and support for the JDK 8 DateTime API:
public void showMeJDK8() throws Exception
   {
      PrettyTime t = new PrettyTime();
      Assert.assertEquals("3 months from now", t.format(LocalDateTime.now().plusMonths(3)));
   }
}

Improvements in the NLP module (based on Natty.) Updated to version 0.13.0

Get PrettyTime 5.0.0.Final

January 16th, 2015 by Lincoln Baxter III

Simple Java EE (JSF) Login Page with JBoss PicketLink Security

Several years ago I wrote a tutorial about using Acegi/Spring Security with JavaServer Faces (JSF) to create a simple authentication / Login page; however, times have changed and Java EE is back in action. I would no longer consider Spring a “requirement” when building a Java EE application. More specifically, if you are using the core Contexts and Dependency Injection (CDI) framework that serves as the backbone for the entire Java EE framework, Spring Security becomes less attractive (because it’s not compatible without using Spring itself, and Spring is a replacement for CDI).

This article will explore how to create a JSF login backed by the standards-compliant CDI framework (that is included with Java EE), and the PicketLink security framework (an open-source project from JBoss). Examples for this article were sourced from the very comprehensive, and quite understandable quick-start application from the PicketLink project itself.

December 23rd, 2014 by Lincoln Baxter III

PrettyTime 3.2.7.Final Released (Social-style time formatting for Java)

Happy Holidays!

I am proud to announce the immediate availability of OCPsoft PrettyTime 3.2.7.Final, the open-source social-style time formatting library for Java.

PrettyTime allows you to create human-readable timestamps such as “3 minutes ago” or “just now”, and is used in other open-source tools such as JBoss Tools, and JBoss Developer Studio.

Release Notes:

This release contains new translations for Turkamen (tk-TM) and translation spelling/grammar revisions for several other language bundles. Additionally, we have resolved an issue with precise time calculations that caused PrettyTime to print multiple instances of the same time unit when using custom time-unit configurations.

Get PrettyTime!

Enjoy, and happy holidays,
Lincoln and the OCPsoft team.

May 2nd, 2014 by Lincoln Baxter III

How to interrupt a long-running “infinite” Java regular expression

If you’ve ever done a lot of work with Regular Expressions, you’re probably familiar with the concept of catastrophic backtracking, which means that the engine is forced to calculate permutations of exponential proportions. For instance, click here run this example and see how long it takes (should be about 5-10 seconds to time out):
LongRunningRegexExample.java
public class LongRunningRegexExample
{
   public static void main(String[] args) throws InterruptedException
   {
      final Pattern pattern = Pattern.compile("(0*)*A");
      final String input = "00000000000000000000000000";

      long startTime = System.currentTimeMillis();
      Matcher matcher = pattern.matcher(input);
      matcher.find(); // runs for a long time!
      System.out.println("Regex took:" + (System.currentTimeMillis() - startTime) + "ms");
   }
}
However, a small change results in near instantaneous response. Why?
December 10th, 2013 by Lincoln Baxter III

Rewrite 2.0.9.Final and PrettyTime 3.2.3.Final Released (Introducing Proxy Support)

Rewrite 2.0.9.Final

We are proud to announce the availability of Rewrite 2.0.9.Final, which introduces “rewrite-config-proxy”, fixes several minor issues, and adds support for Response.isCommitted(), making it far simpler to perform certain operations if the response has already been committed by a prior rule or 3rd party servlet filter.

rewrite-config-proxy

Provides an easy-to-use Operation that allows any inbound request to be proxied to another URL – even on a different server. Headers, cookies, etc, are preserved:

To use this configuration extension, you will need to add it to your POM file:

<dependency>
   <groupId>org.ocpsoft.rewrite</groupId>
   <artifactId>rewrite-config-proxy</artifactId>
   <version>2.0.9.Final</version>
</dependency>
Now add a rule to your ConfigurationProvider:
.addRule()
.when(Direction.isInbound())
.perform(Proxy.to("http://example.com"))

And of course, it supports parameterization:

.addRule()
.when(Direction.isInbound().and(Path.matches("/{p}")))
.perform(Proxy.to("http://example.com/{p}?foo=bar"))

response.isCommitted()

Provides a simple condition for determining whether the response has been committed or not for the current request. This is useful for aborting rewrite processing after a certain point in your configuration:
.addRule()
.when(Response.isCommitted().and(Direction.isInbound()))
.perform(Lifecycle.abort())

More issues resolved in Rewrite 2.0.9.Final:

PrettyTime 3.2.3.Final

We are proud to announce the availability of PrettyTime 3.2.3.Final, which fixes several minor issues with translation and Natural Language Parsing:

Get the updates

Get Rewrite

Get PrettyTime

November 13th, 2013 by Lincoln Baxter III

Creating a simple static file server with Rewrite

Today, I’d like to take a quick moment to demonstrate how to make a simple file server using [[Rewrite]], and any Servlet Container, such as Tomcat, Wildfly, or Jetty. This can enable much easier file updates for static content, such as preventing the need to re-deploy an entire application just to update an image, or document.

[[Rewrite]] is an open-source Routing ↑↓ and /url/{rewriting} solution for Servlet, Java Web Frameworks, and Java EE.

To start, you’ll need to include the Rewrite dependencies in your project. If you’re using maven, this is as simple as making sure your POM has the following entries (You’ll also need the Servlet API):

November 12th, 2013 by Lincoln Baxter III

PrettyTime 3.2.1.Final Released – Now with Czech language support

We are proud to announce the 3.2.1.Final version of PrettyTime. This release includes several bug-fixes, an improved NLP (time parsing) module, and a new method for more convenient configuration of time units:
public void exampleUnitConfiguration() {
    JustNow unit = t.getUnit(JustNow.class);
    unit.setMaxQuantity(1);
    // This means that "just now" will only be used to represent one millisecond difference between the target time and reference time. (the default is 5 minutes.)
}

Improvements in the NLP module (based on Natty.) include more resilient parsing of date offsets such as “the day before yesterday,” which previously resulted in a date that actually represented “yesterday.”

Get PrettyTime 3.2.1.Final and PrettyTime NLP 3.2.1.Final.

October 3rd, 2013 by Lincoln Baxter III

Create a dynamic Logout URL without a Servlet or JSP, using Rewrite

The code below implements a simple command mapping that binds logout functionality to a URL. To use this example, you must include the following [[Rewrite]] dependency in your project:

<dependency>
   <groupId>org.ocpsoft.rewrite</groupId>
   <artifactId>rewrite-servlet</artifactId>
   <version>${rewrite.version}</version>
</dependency>

Once your project is set up to include Rewrite, just paste the following code into your application source folder.

@RewriteConfiguration
public class LogoutConfiguration extends HttpConfigurationProvider
{

   @Override
   public Configuration getConfiguration(ServletContext context)
   {
      return ConfigurationBuilder.begin()
               .addRule()
               .when(Direction.isInbound().and(Path.matches("/logout")))
               .perform(new HttpOperation() {
                  @Override
                  public void performHttp(HttpServletRewrite event, EvaluationContext context)
                  {
                     event.getRequest().getSession().invalidate();
                  }
               }.and(Redirect.temporary(context.getContextPath() + "/")));
   }

   @Override
   public int priority()
   {
      return Integer.MIN_VALUE;
   }
}
September 30th, 2013 by Lincoln Baxter III

Rewrite 2.0.8.Final Released – Fixes critical parameterization bug

Bug Fixes

If you experienced problems with rule parameterization in Rewrite 2.0.7.Final, then sorry about that, and this release of [[Rewrite]] is for you: https://github.com/ocpsoft/rewrite/issues/133

Erroneous failures such as the following exception should be fixed by this release:

org.ocpsoft.rewrite.exception.ParameterizationException: The value of required parameter [s] was null.
	at org.ocpsoft.rewrite.param.RegexParameterizedPatternBuilder.extractBoundValues(RegexParameterizedPatternBuilder.java:262)
	at org.ocpsoft.rewrite.param.RegexParameterizedPatternBuilder.build(RegexParameterizedPatternBuilder.java:136)
	at org.ocpsoft.rewrite.servlet.config.Forward.performHttp(Forward.java:85)
	at org.ocpsoft.rewrite.servlet.config.HttpOperation.perform(HttpOperation.java:42)
	at org.ocpsoft.rewrite.servlet.config.rule.Join.perform(Join.java:264)

New Features

September 17th, 2013 by Lincoln Baxter III

Simplest RVM Installation Guide

Run this command to install the rvm command, a very simple and intuitive “Ruby Version Manager”:
mkdir -p ~/.rvm/src && cd ~/.rvm/src && rm -rf ./rvm && \
git clone --depth 1 git://github.com/wayneeseguin/rvm.git && \
cd rvm && ./install && \
echo "if [[ -s $HOME/.rvm/scripts/rvm ]]; then source $HOME/.rvm/scripts/rvm; fi" >> ~/.bashrc
Edit: Oops, I guess it can get even simpler: (Yes, the ‘\’ is intentional.)
\curl -L https://get.rvm.io | bash
Now use it:
rvm install 1.9.3
Source: An awesome Canadian website.