Archive for the ‘Misc’ Category

Hierarchical SQL Queries in Adobe CQ5

Friday, December 13th, 2013
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
119
120
121
122
123
124
125
126
127
128
129
130
package com.globalbin.web.servlets;

import java.io.IOException;
import java.io.Writer;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.Row;
import javax.jcr.query.RowIterator;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.jcr.api.SlingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service(Servlet.class)
@Properties({
    @Property(name="service.description", value="MultiLevel Servlet"),
    @Property(name="service.vendor", value="The Global Bin"),
    @Property(name="sling.servlet.extensions", value="json"),
    @Property(name="sling.servlet.paths", value="/bin/multi")
})

public class MultiLevelQueryServlet extends SlingAllMethodsServlet {
   
    private static final long serialVersionUID = 1L;
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    private Session session;
   
    @Reference
    private SlingRepository repository;
    protected void bindRepository(SlingRepository repository) {
        this.repository = repository;
    }
   
    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
            throws ServletException, IOException {

        String term = request.getParameter("q");
        String sqlQuery = "SELECT * FROM [cq:Page] AS parent INNER JOIN [nt:base] AS child "
         + "ON ISCHILDNODE(child,parent) WHERE ISDESCENDANTNODE(parent, '/content/geometrixx/en/events') AND "
         + "CONTAINS(child.*, '"+ term +"')";
               
        JSONArray found = sqlQueryJcr(sqlQuery);
        log.info(">> SQL QUERY: " + sqlQuery);
        response.setContentType("application/json");
        Writer w = response.getWriter();
        w.write(found.toString());
    }
   
    private JSONArray sqlQueryJcr(String queryString) {
        JSONArray results = new JSONArray();
        try {
            session = this.repository.loginAdministrative(null);
            QueryManager qm = session.getWorkspace().getQueryManager();
            Query query = qm.createQuery(queryString, Query.JCR_SQL2);
            RowIterator ri = query.execute().getRows();        
            while (ri.hasNext()) {
                  JSONObject dbObj = new JSONObject();
                  Row row = ri.nextRow();
                  Node parent = row.getNode("parent");
                  dbObj.put("result-"+parent.getPath(), nodeToJsonObject(parent));
                  results.put(dbObj);
            }
        } catch (RepositoryException re) {
            log.error(">>> ERROR:" + re.getMessage());
        } catch (Exception e) {
            log.error("> ERROR:" + e.getMessage());
        } finally {
            session.logout();
        }
        return results;
    }
   
    private JSONArray nodesToJsonArray(NodeIterator ni) {
        JSONArray jsonArray = new JSONArray();
        while (ni.hasNext()) {
            Node node = ni.nextNode();
            JSONObject obj = new JSONObject();
            try {
                obj.put( node.getName(), nodeToJsonObject(node));
            } catch (JSONException e) {
                log.error(e.getMessage());
            } catch (RepositoryException e) {
                log.error(e.getMessage());
            }
            jsonArray.put(obj);
        }
        return jsonArray;
    }
   
    private JSONObject nodeToJsonObject(Node node) {
        JSONObject obj = new JSONObject();
        try {
            PropertyIterator pi = node.getProperties();
            while (pi.hasNext()) {
                javax.jcr.Property prop = pi.nextProperty();
                if (prop.isMultiple()) {
                    obj.put(prop.getName(), "[multi]");
                } else {
                    obj.put(prop.getName(), prop.getString());                 
                }
            }
            NodeIterator children = node.getNodes();
            obj.put("nodes-of-" + node.getName(), nodesToJsonArray(children));
        } catch (JSONException e) {
            log.error(e.getMessage());
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }      
        return obj;
    }
}

Create A Template App with Secha Touch and PhoneGap

Monday, May 13th, 2013

Install the following packages:

  • PhoneGap SDK
  • Sencha Touch SDK
  • Sencha Cmd
  • Adroid Development Toolkit

Create this Bash script for running the Sencha Cmd and PhoneGap generators. You can add it your ~/bin directory or anywhere where it is visible from your file path. Edit the paths to match your specific versions of Sencha Touch and PhoneGap.

#!/bin/bash

PROJECT_DIR="anywhere"
PROJECT_NAME="Anywhere"
PACKAGE_NAME="com.globalbin.mobile"
DEV_DIR="~/Development"
SENCHA_SDK="~/touch-2.2.0"
SENCHA_CMD="~/bin/Sencha/Cmd/3.1.1.274"
CORDOVA_VER="2.7.0"
PHONEGAP="~/phonegap-2.7.0/lib"
APP_DIR=$DEV_DIR"/"$PROJECT_DIR

echo "Creating Sench Touch + PhoneGap App for Android:"
echo "SENCHA_SDK="$SENCHA_SDK
echo "SENCHA_CMD="$SENCHA_CMD
echo "PHONEGAP="$PHONEGAP
echo "-------------------"
echo "Project Name: " $PROJECT_NAME
echo "Package Name: " $PACKAGE_NAME
echo "Project Directory: " $APP_DIR

echo "Sencha Touch App..."
cd $SENCHA_SDK
pwd
$SENCHA_CMD/sencha generate app $PROJECT_NAME $APP_DIR
cp $PHONEGAP"/android/cordova-"$CORDOVA_VER".js" $APP_DIR
ls -al $APP_DIR

echo "PhoneGap App ..."
$PHONEGAP/android/bin/create $APP_DIR/build/$PROJECT_NAME/android $PACKAGE_NAME $PROJECT_NAME

Add these Ant build targets to the build.xml file:

   <target name="-after-build">
      <delete dir="${build.dir}/android/assets/www"/>
      <copy todir="${build.dir}/android/assets/www">
        <fileset dir="${build.dir}/package"/>
      </copy>
    </target>

Notes:
Sencha 2.2 had issues with Ruby 2.0 and I was getting Ant build errors (Compass failing).
I had to install GCC 4.2 which was no longer available in OSX Lion.

$ brew tap --repair homebrew/dupes
$ brew install apple-gcc42
$ export CC=/usr/local/bin/gcc-4.2
$ rvm pkg install readline
$ rvm install 1.9.3
$ gem update system
$ gem install compass

Run the build again:

$ sencha app build package && build/MyApp/android/cordova/debug

Recent Video Projects

Thursday, September 22nd, 2011

Caitlin Mae’s 18th Birthday [Online Edit]

Special performance by the family

Other recent video projects

Abbey Road and Native Instruments

Friday, March 12th, 2010
http://www.native-instruments.com/fileadmin/ni_media/producer/kontaktsoundpack/ABBEY_ROAD/video/INTRO_film_LOW_2.flv

Philip Bloom with the Canon 7D and 5DMk2

Wednesday, March 3rd, 2010

Here’s a neat short taken at the Sutro Baths in San Francisco:

And another really cool clip of his 5-day visit to Skywalker Ranch to demo the capabilities of these Canon DSLRs to the Lucasfilm folks.  Nice story on his blog too: