Hippo CMS and PostgreSQL - The Setup

Hippo CMS, PostgreSQL No Comments »

The original instructions on the Hippo site are somewhat outdated. Moreover, the linked blog post is currently down but archive.org still has a copy:

http://web.archive.org/web/20101026204317/http://gotext.org/people/bluesman/en/2009/10/english-configuring-hippo-7-for-postgresql-and-tomcat/

Most of the instructions are still relevant but it’s probably unnecessary to install HST 2, so the first step can be skipped.

The instructions starting at “Go to your-project-dir/cms/src/main/webapp/WEB-INF…” are still correct, however in the repository.xml the section


  <Security appName="Jackrabbit">    <AccessManager class=”org.hippoecm.repository.security.HippoAccessManager”/>    <LoginModule class=”org.hippoecm.repository.security.HippoLoginModule”/>  </Security>

now has to be 

  <Security appName="Jackrabbit">
    <SecurityManager class="org.hippoecm.repository.security.SecurityManager"/>
    <AccessManager class="org.hippoecm.repository.security.HippoAccessManager"/>
    <LoginModule class="org.hippoecm.repository.security.HippoLoginModule"/>
  </Security>

because of an upgrade. Note the new SecurityManager tag. You otherwise get

java.lang.ClassCastException: org.apache.jackrabbit.core.security.simple.SimpleSecurityManager cannot be cast to org.hippoecm.repository.security.SecurityManager

As for step three, it’s now unnecesary to copy around any jar files.

Simply add a dependency in <cms_root>/cms/pom.xml like so:

<dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.1-901.jdbc4</version>
</dependency>

Then run

mvn clean install

and enjoy a scalable and flexible backend for your Hippo CMS.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Date Formats in Clojurescript

Clojure, Clojurescript No Comments »

Formatting dates in JavaScript can be tricky, even getting the name of the month.

It’s possible to use the clunky $.datepicker.formatDate (); from jquery.ui, but in Clojurescript we have the Google Clojure library at our disposal.

Its goog.i18n.DateTimeFormat class has a few useful functions that can be applied like so:

Example usage:

> (format-date-generic :LONG_DATE (js/Date.))

> “July 14, 2012”

> (format-date-generic “dd MMMM yyyy” (js/Date.))

> “14 July 2012”

> (format-date-generic “MMMM” (js/Date.))

> “July”

Ah, there’s the name of the month!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Thumbs from Downloaded Images in Clojure

Clojure No Comments »

The code creates a thumb from either a local file or a remote URI. It combines ideas from a blog post dealing with image downoads in clojure and an older post dealing with thumbnail creation.

(import javax.imageio.ImageIO)
(import java.awt.image.BufferedImage)
(use [clojure.java.io :only [as-file input-stream output-stream] :as io])
 
(defn make-thumbnail-generic [input new-filename width]
(let [img (javax.imageio.ImageIO/read input)
imgtype (java.awt.image.BufferedImage/TYPE_INT_ARGB)
width (min (.getWidth img) width)
height (* (/ width (.getWidth img)) (.getHeight img))
simg (java.awt.image.BufferedImage. width height imgtype)
g (.createGraphics simg)]
(.drawImage g img 0 0 width height nil)
(.dispose g)
(javax.imageio.ImageIO/write simg “png” (as-file new-filename))))
 
(defn make-thumbnail-from-file [filename new-filename width]
(make-thumbnail-generic filename new-filename width))
 
(defn make-thumbnail-from-stream [uri file width]
(with-open [in (io/input-stream uri)
out (io/output-stream file)]
(make-thumbnail-generic in out width)))

Example usage:

(make-thumbnail-from-stream some-image-url (str “~/my_thumbs/” (some-image-id) “.png”) 100)

Enjoy!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Naïveté to Brilliance

Clojure No Comments »

Unlike Scala, even beginning learners of Clojure will experience the fun of functional programming almost immediately. 

Converting the Rails function “simple_format” from Ruby

def simple_format(text, html_options={}, options={})
        text = text ? text.to_str : ”
        text = text.dup if text.frozen?
        start_tag = tag(’p', html_options, true)
        text.gsub!(/\r\n?/, “\n”)                    # \r\n and \r -> \n
        text.gsub!(/\n\n+/, “</p>\n\n#{start_tag}”)  # 2+ newline  -> paragraph
        text.gsub!(/([^\n]\n)(?=[^\n])/, ‘\1<br />’) # 1 newline   -> br
        text.insert 0, start_tag
        text.concat(”</p>”)
        text = sanitize(text) unless options[:sanitize] == false
        text
      end

to Clojure (leaving out options)

(defn simple-format [text]
  (let [patterns 
      {#"\r\n?" "\n"  #"\n\n+" "</p>\n\n<p>" #"([^\n]\n)(?=[^\n])” (str #”$1″  “<br />”)}
      ]
    (str “<p>” (reduce #(clojure.string/replace %1  (key %2) (val %2)) text patterns) “</p>”)))

illustrates the fundamental naïveté of imperative programming with its silly reassignments, incidental state and mutability. It’s laughing at this and marvelling at the sheer brilliance of Clojure in equal measure that make Clojure so much fun.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

LessCss / Less.js With –watch Option Watching Included Files

LessCss No Comments »

Needed a less css compiler who watches changes to a main .less file as well as all those include with an @import statement.

Weighing the options:

One could just use an old version of the less gem that still supported the —watch option, i.e. the 1.x versions. However, the gem won’t track included/imported files, the obsolete more plugin was required for this in Ruby on Rails.

Peeking over the platform wall, the dotless compiler does all this well under Windows and it’s very fast. However, running this app with mono on Linux will not work with the —watch option, it will stop watching files after all and any file changes. This may be due to different backends of the mono FileSystemWatcher implementation on different Linux platforms, so YMMV.

Meanwhile, the author of less.js has declined to support the —watch option and has rejected at least one merge request with this functionality.

Solution:

Alas,  there’s a fork that supports watching the main file as well as all includes:

https://github.com/wvl/less.js

It works great and is stable. All you have to do is clone the repo and add bin/lessc to your path.

Now with a node installation (since recently there is a Windows installer) you should be good to go with silent and effortless server side compilation of less on all platforms.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in