You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/06/12 18:44:55 UTC
svn commit: r413706 - in /incubator/roller/branches/roller_2.4_appd9:
nbproject/ src/org/apache/roller/webservices/atomprotocol/
Author: snoopdave
Date: Mon Jun 12 09:44:54 2006
New Revision: 413706
URL: http://svn.apache.org/viewvc?rev=413706&view=rev
Log:
First cut of PaceMediaEntries5 implementation
Modified:
incubator/roller/branches/roller_2.4_appd9/nbproject/ (props changed)
incubator/roller/branches/roller_2.4_appd9/nbproject/project.xml
incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomHandler.java
incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomService.java
incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomServlet.java
incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java
Propchange: incubator/roller/branches/roller_2.4_appd9/nbproject/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jun 12 09:44:54 2006
@@ -0,0 +1,2 @@
+.LCKproject.xml~
+private
Modified: incubator/roller/branches/roller_2.4_appd9/nbproject/project.xml
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_2.4_appd9/nbproject/project.xml?rev=413706&r1=413705&r2=413706&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.4_appd9/nbproject/project.xml (original)
+++ incubator/roller/branches/roller_2.4_appd9/nbproject/project.xml Mon Jun 12 09:44:54 2006
@@ -4,7 +4,7 @@
<configuration>
<general-data xmlns="http://www.netbeans.org/ns/freeform-project/1">
<!--Do not use Project Properties customizer when editing this file manually.-->
- <name>roller_trunk</name>
+ <name>roller_2.4_appd9</name>
<!--
<properties>
<property name="src.dir">../src</property>
Modified: incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomHandler.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomHandler.java?rev=413706&r1=413705&r2=413706&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomHandler.java (original)
+++ incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomHandler.java Mon Jun 12 09:44:54 2006
@@ -25,6 +25,8 @@
* Interface to be supported by an Atom server, expected lifetime: one request.
* AtomServlet calls this generic interface instead of Roller specific APIs.
* <p />
+ * Based on: draft-ietf-atompub-protocol-08.txt + PaceMediaEntries5
+ * <p />
* Designed to be Roller independent.
*
* @author David M Johnson
@@ -37,7 +39,7 @@
/**
* Return introspection document
*/
- public AtomService getIntrospection(String[] pathInfo) throws Exception;
+ public AtomService getIntrospection() throws Exception;
/**
* Return collection
@@ -62,6 +64,7 @@
* @param pathInfo Path info portion of URL
*/
public Entry putEntry(String[] pathInfo, Entry entry) throws Exception;
+
/**
* Delete entry specified by pathInfo.
@@ -75,35 +78,34 @@
* @param contentType MIME type of uploaded content
* @param data Binary data representing uploaded content
*/
- public Entry postMedia(String[] pathInfo, String name, String contentType,
- InputStream is) throws Exception;
+ public Entry postMedia(
+ String[] pathInfo, String name, String contentType, InputStream is) throws Exception;
/**
* Update a resource.
* @param pathInfo Path info portion of URL
*/
- public Entry putMedia(String[] pathInfo, String contentType,
- InputStream is) throws Exception;
-
- /**
- * Delete resource specified by pathInfo.
- * @param pathInfo Path info portion of URL
- */
- public void deleteMedia(String[] pathInfo) throws Exception;
-
+ public Entry putMedia(
+ String[] pathInfo, String contentType, InputStream is) throws Exception;
+
/**
- * Get resrouce entry.
- * @param pathInfo Path info portion of URL
+ * Return true if specified pathinfo represents URI of introspection doc.
*/
- public Entry getMedia(String[] pathInfo) throws Exception;
-
public boolean isIntrospectionURI(String [] pathInfo);
+ /**
+ * Return true if specified pathinfo represents URI of collection.
+ */
public boolean isCollectionURI(String [] pathInfo);
- public boolean isEntryCollectionURI(String [] pathInfo);
- public boolean isMediaCollectionURI(String [] pathInfo);
-
+
+ /**
+ * Return true if specified pathinfo represents URI of Atom entry.
+ */
public boolean isEntryURI(String[] pathInfo);
- public boolean isMediaURI(String[] pathInfo);
+
+ /**
+ * Return true if specified pathinfo represents URI of media file.
+ */
+ public boolean isMediaEditURI(String[] pathInfo);
}
Modified: incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomService.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomService.java?rev=413706&r1=413705&r2=413706&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomService.java (original)
+++ incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomService.java Mon Jun 12 09:44:54 2006
@@ -26,10 +26,14 @@
/**
* This class models an Atom workspace.
+ * <p />
+ * Based on: draft-ietf-atompub-protocol-08.txt + PaceMediaEntries5
+ * <p />
+ * Designed to be Roller independent.
+ *
* @author Dave Johnson
*/
-/* Based on: draft-ietf-atompub-protocol-08.txt
- *
+/*
* appService =
* element app:service {
* appCommonAttributes,
@@ -45,12 +49,12 @@
* <collection
* title="My Blog Entries"
* href="http://example.org/reilly/main" >
- * <member-type>entry</member-type>
+ * <accept>entry</accept>
* </collection>
* <collection
* title="Pictures"
* href="http://example.org/reilly/pic" >
- * <member-type>media</member-type>
+ * <accept>*</accept>
* </collection>
* </workspace>
* </service>
@@ -117,20 +121,19 @@
/**
* This class models an Atom workspace collection.
* @author Dave Johnson
- */
+ */
/* appCollection =
* element app:collection {
* appCommonAttributes,
* attribute title { text },
* attribute href { text },
- * ( appMemberType
- * & appListTemplate
+ * ( appAccept?
* & extensionElement* )
* }
*/
public static class Collection {
private String title = null;
- private String memberType = "entry"; // or "media"
+ private String accept = "entry";
private String listTemplate = null;
private String href = null;
@@ -138,14 +141,16 @@
}
/**
- * Member type May be "entry" or "media".
+ * Comma separated list of media-ranges accepted by collection
+ * or "entry" to indicate Atom entries only. Leaving null will
+ * default to entries only.
*/
- public String getMemberType() {
- return memberType;
+ public String getAccept() {
+ return accept;
}
- public void setMemberType(String memberType) {
- this.memberType = memberType;
+ public void setAccept(String accept) {
+ this.accept = accept;
}
/** The URI of the collection */
@@ -224,9 +229,9 @@
AtomService.Collection collection = new AtomService.Collection();
collection.setTitle(element.getAttribute("title").getValue());
collection.setHref(element.getAttribute("href").getValue());
- Element memberType = element.getChild("member-type", ns);
+ Element memberType = element.getChild("accept", ns);
if (memberType != null) {
- collection.setMemberType(memberType.getText());
+ collection.setAccept(memberType.getText());
}
return collection;
}
@@ -238,8 +243,8 @@
element.setAttribute("title", collection.getTitle());
element.setAttribute("href", collection.getHref());
- Element memberType = new Element("member-type", ns);
- memberType.setText(collection.getMemberType());
+ Element memberType = new Element("accept", ns);
+ memberType.setText(collection.getAccept());
element.addContent(memberType);
return element;
Modified: incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomServlet.java?rev=413706&r1=413705&r2=413706&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomServlet.java (original)
+++ incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/AtomServlet.java Mon Jun 12 09:44:54 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.roller.webservices.atomprotocol;
+package org.apache.roller.webservices.atomprotocol;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -88,7 +88,7 @@
try {
if (handler.isIntrospectionURI(pathInfo)) {
// return an Atom Service document
- AtomService service = handler.getIntrospection(pathInfo);
+ AtomService service = handler.getIntrospection();
Document doc = AtomService.serviceToDocument(service);
res.setContentType("application/xml; charset=utf-8");
Writer writer = res.getWriter();
@@ -97,7 +97,8 @@
outputter.output(doc, writer);
writer.close();
res.setStatus(HttpServletResponse.SC_OK);
- } else if (handler.isCollectionURI(pathInfo)) {
+ }
+ else if (handler.isCollectionURI(pathInfo)) {
// return a collection
Feed col = handler.getCollection(pathInfo);
col.setFeedType(FEED_TYPE);
@@ -110,7 +111,8 @@
outputter.output(feedDoc, writer);
writer.close();
res.setStatus(HttpServletResponse.SC_OK);
- } else if (handler.isEntryURI(pathInfo)) {
+ }
+ else if (handler.isEntryURI(pathInfo)) {
// return an entry
Entry entry = handler.getEntry(pathInfo);
if (entry != null) {
@@ -121,17 +123,6 @@
} else {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
- } else if (handler.isMediaURI(pathInfo)) {
- // return a resource entry
- Entry entry = handler.getMedia(pathInfo);
- if (entry != null) {
- Writer writer = res.getWriter();
- res.setContentType("application/atom+xml; charset=utf-8");
- serializeEntry(entry, writer);
- writer.close();
- } else {
- res.setStatus(HttpServletResponse.SC_NOT_FOUND);
- }
} else {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
@@ -158,44 +149,50 @@
if (userName != null) {
String[] pathInfo = getPathInfo(req);
try {
- if (handler.isEntryCollectionURI(pathInfo)) {
-
- // parse incoming entry
- Entry unsavedEntry = parseEntry(
- new InputStreamReader(req.getInputStream()));
-
- // call handler to post it
- Entry savedEntry = handler.postEntry(pathInfo, unsavedEntry);
- Iterator links = savedEntry.getAlternateLinks().iterator();
-
- // return alternate link as Location header
- while (links.hasNext()) {
- Link link = (Link) links.next();
- if (link.getRel().equals("alternate") || link.getRel() == null) {
- res.addHeader("Location", link.getHref());
- break;
+ if (handler.isCollectionURI(pathInfo)) {
+
+ if (req.getContentType().startsWith("application/atom+xml")) {
+
+ // parse incoming entry
+ Entry unsavedEntry = parseEntry(
+ new InputStreamReader(req.getInputStream()));
+
+ // call handler to post it
+ Entry savedEntry = handler.postEntry(pathInfo, unsavedEntry);
+
+ // return alternate link as Location header
+ Iterator links = savedEntry.getAlternateLinks().iterator();
+ while (links.hasNext()) {
+ Link link = (Link) links.next();
+ if (link.getRel().equals("alternate") || link.getRel() == null) {
+ res.addHeader("Location", link.getHref());
+ break;
+ }
}
+ // write entry back out to response
+ res.setStatus(HttpServletResponse.SC_CREATED);
+ res.setContentType("application/atom+xml; charset=utf-8");
+ Writer writer = res.getWriter();
+ serializeEntry(savedEntry, writer);
+ writer.close();
+
+ } else {
+ // get incoming file name from HTTP header
+ String name = req.getHeader("Title");
+
+ // hand input stream of to hander to post file
+ Entry resource = handler.postMedia(
+ pathInfo, name, req.getContentType(), req.getInputStream());
+
+ res.setStatus(HttpServletResponse.SC_CREATED);
+ com.sun.syndication.feed.atom.Content content =
+ (com.sun.syndication.feed.atom.Content)resource.getContents().get(0);
+ res.setHeader("Location", content.getSrc());
+ Writer writer = res.getWriter();
+ serializeEntry(resource, writer);
+ writer.close();
}
- // write entry back out to response
- res.setStatus(HttpServletResponse.SC_CREATED);
- res.setContentType("application/atom+xml; charset=utf-8");
- Writer writer = res.getWriter();
- serializeEntry(savedEntry, writer);
- writer.close();
- } else if (handler.isMediaCollectionURI(pathInfo)) {
- // get incoming file name from HTTP header
- String name = req.getHeader("Title");
- // hand input stream of to hander to post file
- Entry resource = handler.postMedia(
- pathInfo, name, req.getContentType(), req.getInputStream());
- res.setStatus(HttpServletResponse.SC_CREATED);
- com.sun.syndication.feed.atom.Content content =
- (com.sun.syndication.feed.atom.Content)resource.getContents().get(0);
- res.setHeader("Location", content.getSrc());
- Writer writer = res.getWriter();
- serializeEntry(resource, writer);
- writer.close();
} else {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
@@ -223,6 +220,7 @@
String[] pathInfo = getPathInfo(req);
try {
if (handler.isEntryURI(pathInfo)) {
+
// parse incoming entry
Entry unsavedEntry = parseEntry(
new InputStreamReader(req.getInputStream()));
@@ -236,7 +234,9 @@
serializeEntry(updatedEntry, writer);
res.setStatus(HttpServletResponse.SC_OK);
writer.close();
- } else if (handler.isMediaURI(pathInfo)) {
+
+ } else if (handler.isMediaEditURI(pathInfo)) {
+
// hand input stream to handler
Entry updatedEntry = handler.putMedia(
pathInfo, req.getContentType(), req.getInputStream());
@@ -247,6 +247,7 @@
serializeEntry(updatedEntry, writer);
writer.close();
res.setStatus(HttpServletResponse.SC_OK);
+
} else {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
@@ -275,10 +276,8 @@
if (handler.isEntryURI(pathInfo)) {
handler.deleteEntry(pathInfo);
res.setStatus(HttpServletResponse.SC_OK);
- } else if (handler.isMediaURI(pathInfo)) {
- handler.deleteMedia(pathInfo);
- res.setStatus(HttpServletResponse.SC_OK);
- } else {
+ }
+ else {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
} catch (Throwable e) {
@@ -325,7 +324,7 @@
// count on client to preserve foreign markup as it should.
Element rollerElement = new Element("atom-draft",
"http://rollerweblogger.org/namespaces/app");
- rollerElement.setText("8");
+ rollerElement.setText("9");
entryElement.addContent(rollerElement);
XMLOutputter outputter = new XMLOutputter();
Modified: incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java?rev=413706&r1=413705&r2=413706&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java (original)
+++ incubator/roller/branches/roller_2.4_appd9/src/org/apache/roller/webservices/atomprotocol/RollerAtomHandler.java Mon Jun 12 09:44:54 2006
@@ -59,23 +59,37 @@
/**
* Roller's Atom Protocol implementation.
* <pre>
- * Here are the URIs suppored:
+ * Each Roller workspace has two collections, one that accepts entries and
+ * that accepts everything. The entries collection represents the weblog
+ * entries in a single weblog and the everything collection represents that
+ * weblog's uploaded-files.
+ *
+ * Here are the APP URIs suppored by Roller:
+ *
+ * /app
+ * Introspection doc
+ *
+ * /app/<weblog-handle>/entries
+ * Entry collection for a blog
+ *
+ * /app/<weblog-handle>/entries/<offset>
+ * Entry collection for a blog, with offset
+ *
+ * /app/<weblog-handle>/entry/<id>
+ * Individual entry (i.e. edit URI)
+ *
+ * /app/<weblog-handle>/resources
+ * Resource (i.e. file-uploads) collection for a blog
+ *
+ * /app/<weblog-handle>/resources/<offset>
+ * Resource collection for a blog, with offset
+ *
+ * /app/<weblog-handle>/resource-link/<name>
+ * Individual resource metadata (i.e. edit URI)
+ *
+ * /app/<weblog-handle>/resource/<name>
+ * Individual resource data (i.e. media-edit URI)
*
- * URI type URI form Handled by
- * -------- -------- ----------
- * Introspection URI / getIntrosection()
- * Collection URI /blog-name/<collection-name> getCollection()
- * Member URI /blog-name/<object-name> post<object-name>()
- * Member URI /blog-name/<object-name>/id get<object-name>()
- * Member URI /blog-name/<object-name>/id put<object-name>()
- * Member URI /blog-name/<object-name>/id delete<object-name>()
- *
- * Until group blogging is supported weblogHandle == blogname.
- *
- * Collection-names Object-names
- * ---------------- ------------
- * entries entry
- * resources resource
* </pre>
*
* @author David M Johnson
@@ -130,35 +144,32 @@
* Return Atom service document for site, getting blog-name from pathInfo.
* The workspace will contain collections for entries, categories and resources.
*/
- public AtomService getIntrospection(String[] pathInfo) throws Exception {
- if (pathInfo.length == 0) {
- String absUrl = mRollerContext.getAbsoluteContextUrl(mRequest);
- AtomService service = new AtomService();
- List perms = mRoller.getUserManager().getAllPermissions(user);
- if (perms != null) {
- for (Iterator iter=perms.iterator(); iter.hasNext();) {
- PermissionsData perm = (PermissionsData)iter.next();
- String handle = perm.getWebsite().getHandle();
- AtomService.Workspace workspace = new AtomService.Workspace();
- workspace.setTitle(Utilities.removeHTML(perm.getWebsite().getName()));
- service.addWorkspace(workspace);
-
- AtomService.Collection entryCol = new AtomService.Collection();
- entryCol.setTitle("Weblog Entries");
- entryCol.setMemberType("entry");
- entryCol.setHref(absUrl + "/app/"+handle+"/entries");
- workspace.addCollection(entryCol);
-
- AtomService.Collection uploadCol = new AtomService.Collection();
- uploadCol.setTitle("Media Files");
- uploadCol.setMemberType("media");
- uploadCol.setHref(absUrl + "/app/"+handle+"/resources");
- workspace.addCollection(uploadCol);
- }
+ public AtomService getIntrospection() throws Exception {
+ String absUrl = mRollerContext.getAbsoluteContextUrl(mRequest);
+ AtomService service = new AtomService();
+ List perms = mRoller.getUserManager().getAllPermissions(user);
+ if (perms != null) {
+ for (Iterator iter=perms.iterator(); iter.hasNext();) {
+ PermissionsData perm = (PermissionsData)iter.next();
+ String handle = perm.getWebsite().getHandle();
+ AtomService.Workspace workspace = new AtomService.Workspace();
+ workspace.setTitle(Utilities.removeHTML(perm.getWebsite().getName()));
+ service.addWorkspace(workspace);
+
+ AtomService.Collection entryCol = new AtomService.Collection();
+ entryCol.setTitle("Weblog Entries");
+ entryCol.setAccept("entry");
+ entryCol.setHref(absUrl + "/app/"+handle+"/entries");
+ workspace.addCollection(entryCol);
+
+ AtomService.Collection uploadCol = new AtomService.Collection();
+ uploadCol.setTitle("Media Files");
+ uploadCol.setAccept("*");
+ uploadCol.setHref(absUrl + "/app/"+handle+"/resources");
+ workspace.addCollection(uploadCol);
}
- return service;
}
- throw new Exception("ERROR: bad URL in getIntrospection()");
+ return service;
}
//----------------------------------------------------------------- collections
@@ -176,7 +187,7 @@
public Feed getCollection(String[] pathInfo) throws Exception {
int start = 0;
if (pathInfo.length > 2) {
- try {
+ try {
String s = pathInfo[2].trim();
start = Integer.parseInt(s);
} catch (Throwable t) {
@@ -220,7 +231,7 @@
}
List links = new ArrayList();
if (entries.size() > max) { // add next link
- int nextOffset = start + max;
+ int nextOffset = start + max;
String url = absUrl + "/app/" + website.getHandle() + "/entries/" + nextOffset;
Link nextLink = new Link();
nextLink.setRel("next");
@@ -252,19 +263,19 @@
WebsiteData website = mRoller.getUserManager().getWebsiteByHandle(handle);
FileManager fmgr = mRoller.getFileManager();
File[] files = fmgr.getFiles(website.getHandle());
- if (canView(website)) {
+ if (canView(website)) {
Feed feed = new Feed();
List atomEntries = new ArrayList();
int count = 0;
if (files != null && start < files.length) {
- for (int i=start; i<(start + max) && i<(files.length); i++) {
+ for (int i=start; i<(start + max) && i<(files.length); i++) {
Entry entry = createAtomResourceEntry(website, files[i]);
atomEntries.add(entry);
count++;
}
}
if (start + count < files.length) { // add next link
- int nextOffset = start + max;
+ int nextOffset = start + max;
String url = absUrl + "/app/" + website.getHandle() + "/resources/" + nextOffset;
Link nextLink = new Link();
nextLink.setRel("next");
@@ -287,7 +298,7 @@
return feed;
}
throw new Exception("ERROR: not authorized");
- }
+ }
//--------------------------------------------------------------------- entries
@@ -303,7 +314,7 @@
WeblogManager mgr = mRoller.getWeblogManager();
WeblogEntryData rollerEntry = createRollerEntry(website, entry);
rollerEntry.setCreator(this.user);
- mgr.saveWeblogEntry(rollerEntry);
+ mgr.saveWeblogEntry(rollerEntry);
mRoller.flush();
// Throttle one entry per second
@@ -313,7 +324,7 @@
CacheManager.invalidate(website);
if (rollerEntry.isPublished()) {
mRoller.getIndexManager().addEntryReIndexOperation(rollerEntry);
- }
+ }
return createAtomEntry(rollerEntry);
}
throw new Exception("ERROR not authorized to edit website");
@@ -325,14 +336,22 @@
public Entry getEntry(String[] pathInfo) throws Exception {
if (pathInfo.length == 3) // URI is /blogname/entries/entryid
{
- WeblogEntryData entry =
- mRoller.getWeblogManager().getWeblogEntry(pathInfo[2]);
- if (entry != null && !canView(entry)) {
- throw new Exception("ERROR not authorized to view entry");
- } else if (entry != null) {
- return createAtomEntry(entry);
+ if (pathInfo[1].equals("entry")) {
+ WeblogEntryData entry =
+ mRoller.getWeblogManager().getWeblogEntry(pathInfo[2]);
+ if (entry != null && !canView(entry)) {
+ throw new Exception("ERROR not authorized to view entry");
+ } else if (entry != null) {
+ return createAtomEntry(entry);
+ }
+ return null;
+ } else if (pathInfo[1].equals("resource-link")) {
+ String handle = pathInfo[0];
+ WebsiteData website = mRoller.getUserManager().getWebsiteByHandle(handle);
+ String uploadPath = RollerFactory.getRoller().getFileManager().getUploadUrl();
+ File resource = new File(uploadPath + File.separator + pathInfo[2]);
+ return createAtomResourceEntry(website, resource);
}
- return null;
}
throw new Exception("ERROR: bad URI");
}
@@ -362,7 +381,7 @@
CacheManager.invalidate(rollerEntry.getWebsite());
if (rollerEntry.isPublished()) {
mRoller.getIndexManager().addEntryReIndexOperation(rollerEntry);
- }
+ }
return createAtomEntry(rollerEntry);
}
throw new Exception("ERROR not authorized to put entry");
@@ -374,17 +393,34 @@
* Delete entry, URI like this /blog-name/entry/id
*/
public void deleteEntry(String[] pathInfo) throws Exception {
- if (pathInfo.length == 3) // URI is /blogname/entries/entryid
+ if (pathInfo.length == 3) // URI is /blogname/entry/entryid
{
- WeblogEntryData rollerEntry =
- mRoller.getWeblogManager().getWeblogEntry(pathInfo[2]);
- if (canEdit(rollerEntry)) {
- WeblogManager mgr = mRoller.getWeblogManager();
- mgr.removeWeblogEntry(rollerEntry);
- mRoller.flush();
- CacheManager.invalidate(rollerEntry.getWebsite());
- mRoller.getIndexManager().removeEntryIndexOperation(rollerEntry);
- return;
+ if (pathInfo[1].equals("entry")) {
+ WeblogEntryData rollerEntry =
+ mRoller.getWeblogManager().getWeblogEntry(pathInfo[2]);
+ if (canEdit(rollerEntry)) {
+ WeblogManager mgr = mRoller.getWeblogManager();
+ mgr.removeWeblogEntry(rollerEntry);
+ mRoller.flush();
+ CacheManager.invalidate(rollerEntry.getWebsite());
+ mRoller.getIndexManager().removeEntryIndexOperation(rollerEntry);
+ return;
+ } else throw new Exception("ERROR not authorized to edit website");
+ }
+ else if (pathInfo[1].equals("resource-link")) {
+ String handle = pathInfo[0];
+ WebsiteData website = mRoller.getUserManager().getWebsiteByHandle(handle);
+ if (canEdit(website) && pathInfo.length > 1) {
+ try {
+ FileManager fmgr = mRoller.getFileManager();
+ fmgr.deleteFile(website.getHandle(), pathInfo[2]);
+ } catch (Exception e) {
+ String msg = "ERROR in atom.deleteResource";
+ mLogger.error(msg,e);
+ throw new Exception(msg);
+ }
+ return;
+ } else throw new Exception("ERROR not authorized to edit website");
}
throw new Exception("ERROR not authorized to delete entry");
}
@@ -399,7 +435,7 @@
* TODO: do we need to handle mutli-part MIME uploads?
* TODO: use Jakarta Commons File-upload?
*/
- public Entry postMedia(String[] pathInfo,
+ public Entry postMedia(String[] pathInfo,
String name, String contentType, InputStream is)
throws Exception {
// authenticated client posted a weblog entry
@@ -429,7 +465,7 @@
File resource = new File(fmgr.getUploadDir() + File.separator + name);
return createAtomResourceEntry(website, resource);
}
-
+
} catch (Exception e) {
String msg = "ERROR in atom.postResource";
mLogger.error(msg,e);
@@ -442,19 +478,8 @@
}
/**
- * Get absolute path to resource specified by path info.
- */
- public Entry getMedia(String[] pathInfo) throws Exception {
- String handle = pathInfo[0];
- WebsiteData website = mRoller.getUserManager().getWebsiteByHandle(handle);
- String uploadPath = RollerFactory.getRoller().getFileManager().getUploadUrl();
- File resource = new File(uploadPath + File.separator + pathInfo[2]);
- return createAtomResourceEntry(website, resource);
- }
-
- /**
* Update resource specified by pathInfo using data from input stream.
- * Expects pathInfo of form /blog-name/resources/name
+ * Expects pathInfo of form /blog-name/resource/name
*/
public Entry putMedia(String[] pathInfo,
String contentType, InputStream is) throws Exception {
@@ -464,28 +489,7 @@
}
throw new Exception("ERROR: bad pathInfo");
}
-
- /**
- * Delete resource specified by pathInfo.
- * Expects pathInfo of form /blog-name/resources/name
- */
- public void deleteMedia(String[] pathInfo) throws Exception {
- // authenticated client posted a weblog entry
- String handle = pathInfo[0];
- WebsiteData website = mRoller.getUserManager().getWebsiteByHandle(handle);
- if (canEdit(website) && pathInfo.length > 1) {
- try {
- FileManager fmgr = mRoller.getFileManager();
- fmgr.deleteFile(website.getHandle(), pathInfo[2]);
- } catch (Exception e) {
- String msg = "ERROR in atom.deleteResource";
- mLogger.error(msg,e);
- throw new Exception(msg);
- }
- }
- else throw new Exception("ERROR not authorized to edit website");
- }
-
+
//------------------------------------------------------------------ URI testers
/**
@@ -501,13 +505,14 @@
*/
public boolean isEntryURI(String[] pathInfo) {
if (pathInfo.length > 1 && pathInfo[1].equals("entry")) return true;
+ if (pathInfo.length > 1 && pathInfo[1].equals("resource-link")) return true;
return false;
}
-
+
/**
- * True if URL is a resource URI.
+ * True if URL is media edit URI. Media can be udpated, but not metadata.
*/
- public boolean isMediaURI(String[] pathInfo) {
+ public boolean isMediaEditURI(String[] pathInfo) {
if (pathInfo.length > 1 && pathInfo[1].equals("resource")) return true;
return false;
}
@@ -530,30 +535,6 @@
return false;
}
- /**
- * True if URL is a entry collection URI.
- */
- public boolean isEntryCollectionURI(String[] pathInfo) {
- if (pathInfo.length > 1 && pathInfo[1].equals("entries")) return true;
- return false;
- }
-
- /**
- * True if URL is a resource collection URI.
- */
- public boolean isMediaCollectionURI(String[] pathInfo) {
- if (pathInfo.length > 1 && pathInfo[1].equals("resources")) return true;
- return false;
- }
-
- /**
- * True if URL is a category collection URI.
- */
- public boolean isCategoryCollectionURI(String[] pathInfo) {
- if (pathInfo.length > 1 && pathInfo[1].equals("categories")) return true;
- return false;
- }
-
//------------------------------------------------------------------ permissions
/**
@@ -662,18 +643,18 @@
int p = userPass.indexOf(":");
if (p != -1) {
userID = userPass.substring(0, p);
- UserData user = mRoller.getUserManager().getUserByUsername(userID);
+ UserData user = mRoller.getUserManager().getUserByUsername(userID);
boolean enabled = user.getEnabled().booleanValue();
- if (enabled) {
+ if (enabled) {
// are passwords encrypted?
- RollerContext rollerContext =
- RollerContext.getRollerContext();
- String encrypted =
- RollerConfig.getProperty("passwds.encryption.enabled");
+ RollerContext rollerContext =
+ RollerContext.getRollerContext();
+ String encrypted =
+ RollerConfig.getProperty("passwds.encryption.enabled");
password = userPass.substring(p+1);
if ("true".equalsIgnoreCase(encrypted)) {
- password = Utilities.encodePassword(password,
- RollerConfig.getProperty("passwds.encryption.algorithm"));
+ password = Utilities.encodePassword(password,
+ RollerConfig.getProperty("passwds.encryption.algorithm"));
}
valid = user.getPassword().equals(password);
}
@@ -708,12 +689,12 @@
atomEntry.setTitle( entry.getTitle());
atomEntry.setContents( contents);
atomEntry.setPublished( entry.getPubTime());
- atomEntry.setUpdated( entry.getUpdateTime());
-
- UserData creator = entry.getCreator();
+ atomEntry.setUpdated( entry.getUpdateTime());
+
+ UserData creator = entry.getCreator();
Person author = new Person();
- author.setName( creator.getUserName());
- author.setEmail( creator.getEmailAddress());
+ author.setName( creator.getUserName());
+ author.setEmail( creator.getEmailAddress());
atomEntry.setAuthors( Collections.singletonList(author));
List categories = new ArrayList();
@@ -732,7 +713,7 @@
Link editlink = new Link();
editlink.setRel("edit");
editlink.setHref(absUrl + "/app/"
- + entry.getWebsite().getHandle() + "/entry/" + entry.getId());
+ + entry.getWebsite().getHandle() + "/entry/" + entry.getId());
List otherlinks = new ArrayList();
otherlinks.add(editlink);
atomEntry.setOtherLinks(otherlinks);
@@ -740,35 +721,42 @@
List modules = new ArrayList();
PubControlModule pubControl = new PubControlModuleImpl();
pubControl.setDraft(
- !WeblogEntryData.PUBLISHED.equals(entry.getStatus()));
+ !WeblogEntryData.PUBLISHED.equals(entry.getStatus()));
modules.add(pubControl);
atomEntry.setModules(modules);
return atomEntry;
}
- private Entry createAtomResourceEntry(WebsiteData website, File file) {
+ private Entry createAtomResourceEntry(WebsiteData website, File file) {
String absUrl = mRollerContext.getAbsoluteContextUrl(mRequest);
String editURI = absUrl
+ "/app/" + website.getHandle()
+ + "/resource-link/" + file.getName();
+ String editMediaURI = absUrl
+ + "/app/" + website.getHandle()
+ "/resource/" + file.getName();
String viewURI = absUrl
+ "/resources/" + website.getHandle()
+ "/" + file.getName();
FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
String contentType = map.getContentType(file);
-
+
Entry entry = new Entry();
entry.setTitle(file.getName());
entry.setUpdated(new Date(file.lastModified()));
-
- Link editlink = new Link();
- editlink.setRel("edit");
- editlink.setHref(editURI);
- List otherlinks = new ArrayList();
- otherlinks.add(editlink);
+
+ List otherlinks = new ArrayList();
entry.setOtherLinks(otherlinks);
-
+ Link editlink = new Link();
+ editlink.setRel("edit");
+ editlink.setHref(editURI);
+ otherlinks.add(editlink);
+ Link editMedialink = new Link();
+ editMedialink.setRel("edit-media");
+ editMedialink.setHref(editMediaURI);
+ otherlinks.add(editMedialink);
+
Content content = new Content();
content.setSrc(viewURI);
content.setType(contentType);
@@ -803,9 +791,9 @@
rollerEntry.setPubTime(pubTime);
rollerEntry.setUpdateTime(updateTime);
rollerEntry.setWebsite(website);
-
- PubControlModule control =
- (PubControlModule)entry.getModule("http://purl.org/atom/app#");
+
+ PubControlModule control =
+ (PubControlModule)entry.getModule("http://purl.org/atom/app#");
if (control!=null && control.getDraft()) {
rollerEntry.setStatus(WeblogEntryData.DRAFT);
} else {
@@ -822,8 +810,8 @@
String catString = cat.getTerm() != null ? cat.getTerm() : cat.getLabel();
if (catString != null) {
WeblogCategoryData rollerCat =
- mRoller.getWeblogManager().getWeblogCategoryByPath(
- website, catString);
+ mRoller.getWeblogManager().getWeblogCategoryByPath(
+ website, catString);
if (rollerCat != null) {
// Found a valid category, so break out
rollerEntry.setCategory(rollerCat);
@@ -837,4 +825,5 @@
}
return rollerEntry;
}
+
}