Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 20402 invoked from network); 28 Nov 2008 12:30:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Nov 2008 12:30:49 -0000 Received: (qmail 85331 invoked by uid 500); 28 Nov 2008 12:31:01 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 85294 invoked by uid 500); 28 Nov 2008 12:31:01 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 85285 invoked by uid 99); 28 Nov 2008 12:31:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Nov 2008 04:31:01 -0800 X-ASF-Spam-Status: No, hits=-1998.5 required=10.0 tests=ALL_TRUSTED,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Nov 2008 12:29:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 30018238889E; Fri, 28 Nov 2008 04:29:50 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r721453 - in /incubator/sling/trunk: ./ samples/espblog/ samples/espblog/src/ samples/espblog/src/main/ samples/espblog/src/main/java/ samples/espblog/src/main/java/org/ samples/espblog/src/main/java/org/apache/ samples/espblog/src/main/jav... Date: Fri, 28 Nov 2008 12:29:49 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081128122950.30018238889E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Fri Nov 28 04:29:48 2008 New Revision: 721453 URL: http://svn.apache.org/viewvc?rev=721453&view=rev Log: SLING-673, ESP-based blog sample, based on a contribution by Michael Marth, thanks! Added: incubator/sling/trunk/samples/espblog/ (with props) incubator/sling/trunk/samples/espblog/README.txt (with props) incubator/sling/trunk/samples/espblog/pom.xml (with props) incubator/sling/trunk/samples/espblog/src/ incubator/sling/trunk/samples/espblog/src/main/ incubator/sling/trunk/samples/espblog/src/main/java/ incubator/sling/trunk/samples/espblog/src/main/java/org/ incubator/sling/trunk/samples/espblog/src/main/java/org/apache/ incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/ incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/ incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/ incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/ThumbnailGeneratorService.java (with props) incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/internal/ incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/internal/ThumbnailGeneratorServiceImpl.java (with props) incubator/sling/trunk/samples/espblog/src/main/resources/ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/admin.esp incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/constants.esp incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/espblog.css (with props) incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/header.esp incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/list.esp incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/menu.esp incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/sling-logo.png (with props) incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp Modified: incubator/sling/trunk/pom.xml Modified: incubator/sling/trunk/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/pom.xml?rev=721453&r1=721452&r2=721453&view=diff ============================================================================== --- incubator/sling/trunk/pom.xml (original) +++ incubator/sling/trunk/pom.xml Fri Nov 28 04:29:48 2008 @@ -121,6 +121,7 @@ samples/path-based-rtp samples/webloader/service samples/webloader/ui + samples/espblog launchpad/base Propchange: incubator/sling/trunk/samples/espblog/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Fri Nov 28 04:29:48 2008 @@ -0,0 +1,11 @@ +target +bin +*.iml +*.ipr +*.iws +.settings +.project +.classpath +.externalToolBuilders +maven-eclipse.xml + Added: incubator/sling/trunk/samples/espblog/README.txt URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/README.txt?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/README.txt (added) +++ incubator/sling/trunk/samples/espblog/README.txt Fri Nov 28 04:29:48 2008 @@ -0,0 +1,46 @@ +Sling ESP blog sample +--------------------- + +WHY THIS SAMPLE? +---------------- +This demonstrates the use of ESP server-side javascript to implement a simple +blog, with file attachments. + +A java service uses JCR observation to detect incoming files (either uploaded +via the blog forms, or copied via WebDAV), and creates thumbnails of files image +files, to demonstrate observation and OSGi SCR services. + +HOW TO INSTALL +-------------- +Build this bundle and install it in Sling. + +For example, if Sling is running on port 8888 (which happens if you start +the launchpad/testing module with "mvn jetty:run"), this will build and +install it: + + mvn -P autoInstallBundle clean install -Dsling.url=http://localhost:8888/system/console + +To verify that the bundle is correctly installed: + +1) http://localhost:8888/apps/espblog/html.esp must return the html.esp + script. + +2) The console at http://localhost:8888/system/console/bundles must + list the bundle named "Sling - ESP blog sample" as active. + +You also need to set "allow anonymous access" to false in the +SlingAuthenticator config, via http://localhost:8888/system/console/configMgr + +HOW TO TEST +----------- +http://localhost:8888/content/espblog/*.html must display the "Sling ESP +blog sample" page, with the Home/Admin/New Post/... menu. + +Create a new post using the "New Post" menu. + +The post can include an attachment, if that's an image the included +ThumbnailGeneratorService generates thumbnails in different sizes, displayed +on the post's page. This happens asynchronously, so depending on your +machine's speed the thumbnails might only appear after a few seconds. + +The ESP scripts are found under /apps/espblog in the repository. \ No newline at end of file Propchange: incubator/sling/trunk/samples/espblog/README.txt ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/sling/trunk/samples/espblog/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/pom.xml?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/pom.xml (added) +++ incubator/sling/trunk/samples/espblog/pom.xml Fri Nov 28 04:29:48 2008 @@ -0,0 +1,95 @@ + + + + 4.0.0 + + + org.apache.sling + sling + 3-incubator + ../../../parent/pom.xml + + + org.apache.sling.samples + org.apache.sling.samples.espblog + bundle + 2.0.3-incubator-SNAPSHOT + Sling - ESP blog sample + + Sample Sling application - blog written using ESP scripts. + + + + scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/samples/espblog + scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/samples/espblog + http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog + + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + initial-content + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + org.apache.sling.samples.espblog.internal + + + + + + + + org.apache.sling + org.apache.sling.api + 2.0.2-incubator + provided + + + org.apache.sling + org.apache.sling.jcr.api + 2.0.2-incubator + provided + + + org.apache.felix + org.osgi.compendium + provided + + + org.apache.felix + org.osgi.core + provided + + + org.slf4j + slf4j-api + provided + + + + \ No newline at end of file Propchange: incubator/sling/trunk/samples/espblog/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/ThumbnailGeneratorService.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/ThumbnailGeneratorService.java?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/ThumbnailGeneratorService.java (added) +++ incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/ThumbnailGeneratorService.java Fri Nov 28 04:29:48 2008 @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.sling.samples.espblog; + +/** Empty interface, the SCR plugin requires one + * to process our service implementation. + */ +public interface ThumbnailGeneratorService { +} \ No newline at end of file Propchange: incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/ThumbnailGeneratorService.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/ThumbnailGeneratorService.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/internal/ThumbnailGeneratorServiceImpl.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/internal/ThumbnailGeneratorServiceImpl.java?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/internal/ThumbnailGeneratorServiceImpl.java (added) +++ incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/internal/ThumbnailGeneratorServiceImpl.java Fri Nov 28 04:29:48 2008 @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.sling.samples.espblog.internal; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +import javax.imageio.ImageIO; +import javax.jcr.Node; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.observation.Event; +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; +import javax.jcr.observation.ObservationManager; + +import org.apache.sling.jcr.api.SlingRepository; +import org.apache.sling.samples.espblog.ThumbnailGeneratorService; +import org.osgi.service.component.ComponentContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Observe the espblog content for changes, and generate + * thumbnails when images are added. + * + * @scr.service + * @scr.component immediate="true" metatype="false" + * @scr.property name="service.description" value="Sling ESP blog sample thumbnails generator" + * @scr.property name="service.vendor" value="Apache Software Foundation" + * + */ +public class ThumbnailGeneratorServiceImpl implements ThumbnailGeneratorService, EventListener { + + private Session session; + private ObservationManager observationManager; + + /** @scr.reference */ + private SlingRepository repository; + + /** @scr.property value="/content/espblog" */ + private static final String CONTENT_PATH_PROPERTY = "content.path"; + + private static final Logger log = LoggerFactory + .getLogger(ThumbnailGeneratorServiceImpl.class); + + private Map supportedMimeTypes = new HashMap(); + + protected void activate(ComponentContext context) throws Exception { + supportedMimeTypes.put("image/jpeg", ".jpg"); + supportedMimeTypes.put("image/png", ".png"); + + String contentPath = (String)context.getProperties().get(CONTENT_PATH_PROPERTY); + + session = repository.loginAdministrative(null); + if (repository.getDescriptor(Repository.OPTION_OBSERVATION_SUPPORTED).equals("true")) { + observationManager = session.getWorkspace().getObservationManager(); + String[] types = { "nt:file" }; + observationManager.addEventListener(this, Event.NODE_ADDED, contentPath, true, null, types, false); + } + } + + protected void deactivate(ComponentContext componentContext) throws RepositoryException { + if(observationManager != null) { + observationManager.removeEventListener(this); + } + if (session != null) { + session.logout(); + session = null; + } + } + + public void onEvent(EventIterator it) { + while (it.hasNext()) { + Event event = it.nextEvent(); + try { + if (event.getType() == Event.NODE_ADDED && !(event.getPath().contains("thumbnails"))) { + log.info("new upload: {}", event.getPath()); + Node addedNode = session.getRootNode().getNode(event.getPath().substring(1)); + processNewNode(addedNode); + log.info("finished processing of {}", event.getPath()); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + } + } + } + + private String getMimeType(Node n) throws RepositoryException { + String result = null; + final String mimeType = n.getProperty("jcr:mimeType").getString(); + + for(String key : supportedMimeTypes.keySet()) { + if(mimeType!=null && mimeType.startsWith(key)) { + result = key; + break; + } + } + + if(result == null) { + log.info("Node {} rejected, unsupported mime-type {}", n.getPath(), mimeType); + } + + if(n.getName().startsWith(".")) { + log.info("Node {} rejected, name starts with '.'", n.getPath(), mimeType); + result = null; + } + + return result; + } + + private void processNewNode(Node addedNode) throws Exception { + final String mimeType = getMimeType(addedNode); + if (mimeType == null) { + return; + } + final String suffix = supportedMimeTypes.get(mimeType); + + // Scale to a temp file for simplicity + log.info("Creating thumbnails for node {}", addedNode.getPath()); + final int [] widths = { 50, 100, 250 }; + for(int width : widths) { + createThumbnail(addedNode, width, mimeType, suffix); + } + } + + private void createThumbnail(Node image, int scalePercent, String mimeType, String suffix) throws Exception { + final File tmp = File.createTempFile(getClass().getSimpleName(), suffix); + try { + scale(image.getProperty("jcr:data").getStream(), scalePercent, new FileOutputStream(tmp), suffix); + + // Create thumbnail node and set the mandatory properties + Node thumbnailFolder = getThumbnailFolder(image); + Node thumbnail = thumbnailFolder.addNode(image.getParent().getName() + "_" + scalePercent + suffix, "nt:file"); + Node contentNode = thumbnail.addNode("jcr:content", "nt:resource"); + contentNode.setProperty("jcr:data", new FileInputStream(tmp)); + contentNode.setProperty("jcr:lastModified", Calendar.getInstance()); + contentNode.setProperty("jcr:mimeType", mimeType); + + session.save(); + + log.info("Created thumbnail " + contentNode.getPath()); + } finally { + if(tmp != null) { + tmp.delete(); + } + } + + } + + private Node getThumbnailFolder(Node addedNode) throws Exception { + Node post = addedNode.getParent().getParent().getParent(); + if (post.hasNode("thumbnails")) { + log.info("thumbnails node exists already at " + post.getPath()); + return post.getNode("thumbnails"); + } else { + Node t = post.addNode("thumbnails", "nt:folder"); + session.save(); + return t; + } + } + + public void scale(InputStream inputStream, int width, OutputStream outputStream, String suffix) throws IOException { + if(inputStream == null) { + throw new IOException("InputStream is null"); + } + + final BufferedImage src = ImageIO.read(inputStream); + if(src == null) { + final StringBuffer sb = new StringBuffer(); + for(String fmt : ImageIO.getReaderFormatNames()) { + sb.append(fmt); + sb.append(' '); + } + throw new IOException("Unable to read image, registered formats: " + sb); + } + + final double scale = (double)width / src.getWidth(); + + int destWidth = width; + int destHeight = new Double(src.getHeight() * scale).intValue(); + log.debug("Generating thumbnail, w={}, h={}", destWidth, destHeight); + BufferedImage dest = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB); + Graphics2D g = dest.createGraphics(); + AffineTransform at = AffineTransform.getScaleInstance((double) destWidth / src.getWidth(), (double) destHeight / src.getHeight()); + g.drawRenderedImage(src, at); + ImageIO.write(dest, suffix.substring(1), outputStream); + } +} \ No newline at end of file Propchange: incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/internal/ThumbnailGeneratorServiceImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/samples/espblog/src/main/java/org/apache/sling/samples/espblog/internal/ThumbnailGeneratorServiceImpl.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/admin.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/admin.esp?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/admin.esp (added) +++ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/admin.esp Fri Nov 28 04:29:48 2008 @@ -0,0 +1,82 @@ + + +<% +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +%> + + +<% +pageTitle = "Blog admin" +load("header.esp") +%> + +
+ +
+ + + +
+

<%= pageTitle %>

+ + + + + + + + + + <% + df = new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm" ); + + posts = currentNode.getNodes() + for (a in posts) { + post = posts[a] + if(!post.created) { + // does not look like one of our posts + continue; + } + %> + + + + + + + + + <%}%> +
TitleDateControls
<%=post.title%><%=df.format(post.created.getTime())%>View Edit +
+ + + +
+
+
+ + \ No newline at end of file Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/constants.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/constants.esp?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/constants.esp (added) +++ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/constants.esp Fri Nov 28 04:29:48 2008 @@ -0,0 +1,22 @@ +<% +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +%> + +<% +BLOG_TITLE="Sling ESP blog sample"; +%> \ No newline at end of file Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp (added) +++ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp Fri Nov 28 04:29:48 2008 @@ -0,0 +1,64 @@ + + +<% +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +%> + + +<% +pageTitle = currentNode.title ? currentNode.title : "New post"; +load("header.esp"); +%> + + +
+ +
+ + + +
+

<%= pageTitle %>

+ +
" enctype="multipart/form-data"> + +

+ ">

+ +

+

+ +

+ + + + + + +
+
+ + Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/espblog.css URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/espblog.css?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/espblog.css (added) +++ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/espblog.css Fri Nov 28 04:29:48 2008 @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* @override http://incubator.apache.org/sling/site/media.data/site.css */ + +body { background-color: #ffffff; color: #3b3b3b; font-family: Tahoma, Arial, sans-serif; font-size: 10pt; line-height: 140% } +h1, h2, h3, h4, h5, h6 { font-weight: normal; color: #000000; line-height: 100%; } +h1 { font-size: 200% } +h2 { font-size: 175% } +h3 { font-size: 150% } +h4 { font-size: 140% } +h5 { font-size: 130% } +h6 { font-size: 120% } +a { color: #1980af } +a:visited { color: #1980af } +a:hover { color: #1faae9 } +.title { position: absolute; left: 1px; right: 1px; top:25px; height: 81px; background: url(http://incubator.apache.org/sling/site/media.data/gradient.png) repeat-x; background-position: bottom; } +.logo { position: absolute; width: 15em; height: 81px; text-align: center; } +.header { text-align: right; margin-right: 20pt; } +.menu { border-top: 10px solid #f9bb00; position: absolute; top: 107px; left: 1px; width: 15em; bottom: 0px; padding: 0px; background-color: #fcfcfc } +.menu ul { background-color: #fdf5d9; list-style: none; padding-left: 4em; margin-top: 0px; padding-top: 2em; padding-bottom: 2em; margin-left: 0px; color: #4a4a43} +.menu a { text-decoration: none; color: #4a4a43 } +.main { position: absolute; border-top: 10px solid #cde0ea; top: 107px; left: 15em; right: 1px; margin-left: 2px; padding-right: 4em; padding-left: 1em; padding-top: 1em;} +.code { color: black; background-color: #eeeeee; border: solid 1px black; margin-top: 0.5em; margin-bottom: 0.5em; } +.codeHeader { text-align: center; font-family: monospace; border-bottom:1px solid black; padding-top: 0.5em; padding-bottom: 0.5em; margin-bottom: 0.5em; } +.codeContent { padding: 0.5em } +.codeContent pre { margin: 0em } +.code-keyword { color: #880000 } +.code-quote { color: #008800 } +.code-object { color: #0000dd } +.code-java { margin: 0em } +.preformatted { color: black; background-color: #eeeeee; border: solid 1px black; padding: 0.5em } +.preformattedContent pre { margin: 0em } +table.confluenceTable { border-collapse:collapse; margin:5px; } +table.confluenceTable th.confluenceTh { background-color:#FDF5D9; border:1px solid #CCCCCC; padding:3px 4px; text-align:center; } +table.confluenceTable td.confluenceTd { border:1px solid #CCCCCC; padding:3px 4px; } +.infoMacro { background-color: #D8E4F1; border: 1px solid #3C78B5; } +.noteMacro { background-color: #FFFFCE; border: 1px solid #F0C000; } +.tipMacro { background-color: #DDFFDD; border: 1px solid #009900; } +.warningMacro { background-color: #FFCCCC; border: 1px solid #CC0000; } +.note { font-size: 80%; } \ No newline at end of file Propchange: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/espblog.css ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/espblog.css ------------------------------------------------------------------------------ svn:executable = * Propchange: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/espblog.css ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/header.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/header.esp?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/header.esp (added) +++ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/header.esp Fri Nov 28 04:29:48 2008 @@ -0,0 +1,31 @@ +<% +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +%> + +<% +load("constants.esp"); +if(typeof(pageTitle) == "undefined") { + pageTitle = BLOG_TITLE; +} +%> + + + + + <%= pageTitle %> + \ No newline at end of file Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp (added) +++ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp Fri Nov 28 04:29:48 2008 @@ -0,0 +1,103 @@ + + +<% +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +%> + + +<% +load("header.esp"); +load("constants.esp"); + +function render(attachmentNode) { + if(attachmentNode.getNode("jcr:content").getProperty("jcr:mimeType").getString().substring(0,5) == "image") { + %>

<% + } else { + %>

Download <%=attachmentNode.getName()%>

<% + } +} + +function renderMedia(postNode, mediaFolderName) { + if(postNode.hasNode(mediaFolderName)) { + %>

<%= mediaFolderName %>

<% + var nodes = currentNode.getNode(mediaFolderName).getNodes(); + for(i in nodes) { + render(nodes[i]); + } + } +} +%> + +
+ +
+ + + +
+

<%= BLOG_TITLE %>

+
+

<%=currentNode.title ? currentNode.title : ""%>

+

<%=currentNode.posttext ? currentNode.posttext : ""%>

+ + <% + if(currentNode.hasNode("comments")) { + %>

Comments

<% + comments = currentNode.getNode("comments").getNodes() + for (a in comments) { + comment = comments[a] + if(comment.commenttext){ + %> + +
+ <%=comment.commenter ? comment.commenter : "an anonymous coward"%> said: +

<%=comment.commenttext%>

+
+ + <% + } + } + } + %> + + <% if(currentNode.title) { %> +

Comment on this post

+
+

+

+

+ + +
+ <% } %> +
+
+ <% renderMedia(currentNode, "attachments"); %> + <% renderMedia(currentNode, "thumbnails"); %> +
+
+ + Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/list.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/list.esp?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/list.esp (added) +++ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/list.esp Fri Nov 28 04:29:48 2008 @@ -0,0 +1,72 @@ + + +<% +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +%> + +<% + var queryManager = currentNode.getSession().getWorkspace().getQueryManager(); + if(request.getParameter('qt')) { + var query = queryManager.createQuery("/jcr:root/content/espblog/posts/element(*, nt:unstructured)[jcr:contains(., '"+request.getParameter("qt")+"')] order by @created descending", "xpath"); + } else { + var query = queryManager.createQuery("/jcr:root/content/espblog/posts/element(*, nt:unstructured) order by @created descending", "xpath"); + } + var result = query.execute().getNodes(); +%> + + + + <% + load("header.esp"); + %> + + +
+ +
+ + + +
+

<%= pageTitle %>

+

<%= request.getParameter('qt') ? "Search results" : "Recent posts" %>

+ +
+ <% + df = new Packages.java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm" ); + + while(result.hasNext()) { + post = result.nextNode() + %> + +

<%=post.title%>

+ Posted at <%=df.format(post.created.getTime())%>
+

<%=post.posttext%>
<%=post.hasNode("comments") ? "See comments" : "Be the first to comment"%>

+ <%}%> +
+
+ + \ No newline at end of file Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/menu.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/menu.esp?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/menu.esp (added) +++ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/menu.esp Fri Nov 28 04:29:48 2008 @@ -0,0 +1,32 @@ +<% +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +%> + +<% +load("constants.esp"); +%> + + \ No newline at end of file Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/sling-logo.png URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/sling-logo.png?rev=721453&view=auto ============================================================================== Binary file - no diff available. Propchange: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/sling-logo.png ------------------------------------------------------------------------------ svn:executable = * Propchange: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/sling-logo.png ------------------------------------------------------------------------------ svn:mime-type = image/png Added: incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp?rev=721453&view=auto ============================================================================== --- incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp (added) +++ incubator/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp Fri Nov 28 04:29:48 2008 @@ -0,0 +1,55 @@ + + +<% +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +%> + +<% + var queryManager = currentNode.getSession().getWorkspace().getQueryManager(); + var query = queryManager.createQuery("/jcr:root/content/espblog/posts/element(*, nt:unstructured) order by @created descending", "xpath"); + var result = query.execute().getNodes(); + +%> + + + + My Sling Blog + <%=request.getRequestURL()%> + RSS 2.0 feed of my Sling blog + + <% + df = new java.text.SimpleDateFormat( "EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z", Packages.java.util.Locale.US); + var counter = 0; + while(result.hasNext() && counter < 10) { + counter++; + post = result.nextNode() + %> + + + <%=post.title%> + http://<%=request.getServerName()%>:<%=request.getServerPort()%><%=post%>.html + <%=post.posttext%> + <%=df.format(post.created.getTime())%> + + + <% + } + %> + + + \ No newline at end of file