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 2005/09/23 05:08:02 UTC
svn commit: r291064 - in
/incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation:
atomapi/ atomapi04/
Author: snoopdave
Date: Thu Sep 22 20:07:54 2005
New Revision: 291064
URL: http://svn.apache.org/viewcvs?rev=291064&view=rev
Log:
Updated Atom Protocol 04 updates
Modified:
incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomCollection.java
incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java
incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java
incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/AtomServlet.java
incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/RollerAtomHandler.java
incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/package.html
Modified: incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomCollection.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomCollection.java?rev=291064&r1=291063&r2=291064&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomCollection.java (original)
+++ incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomCollection.java Thu Sep 22 20:07:54 2005
@@ -60,9 +60,8 @@
Namespace.getNamespace("http://purl.org/atom/app#");
private List memberTypes = new ArrayList(); // array of strings
- private String dateRangeTemplate = null;
- private String indexTemplate = null;
-
+ private List searchTemplates = new ArrayList(); // array of strings
+
public AtomCollection()
{
}
@@ -72,14 +71,19 @@
return memberTypes;
}
- public void setMemberTypes(List memberTypes)
+ public void addMemberType(String memberType)
+ {
+ memberTypes.add(memberType);
+ }
+
+ public List getSearchTemplates()
{
- this.memberTypes = memberTypes;
+ return searchTemplates;
}
- public void addMemberType(String memberType)
+ public void addSearchTemplate(String searchTemplate)
{
- memberTypes.add(memberType);
+ searchTemplates.add(searchTemplate);
}
/** Deserialize an Atom Collection XML document into an object */
@@ -88,17 +92,18 @@
{
AtomCollection collection = new AtomCollection();
Element root = document.getRootElement();
-// if (root.getAttribute("next") != null)
-// {
-// collection.setNext(root.getAttribute("next").getValue());
-// }
-// List mems = root.getChildren("member", ns);
-// Iterator iter = mems.iterator();
-// while (iter.hasNext())
-// {
-// Element e = (Element) iter.next();
-// collection.addMember(AtomCollection.elementToMember(e));
-// }
+ List types = root.getChildren("member-type", ns);
+ for (Iterator i=types.iterator(); i.hasNext();)
+ {
+ Element e = (Element)i.next();
+ collection.addMemberType(e.getText());
+ }
+ List templates = root.getChildren("search-template", ns);
+ for (Iterator i=types.iterator(); i.hasNext();)
+ {
+ Element e = (Element)i.next();
+ collection.addMemberType(e.getText());
+ }
return collection;
}
@@ -106,18 +111,18 @@
public static Document collectionToDocument(AtomCollection collection)
{
Document doc = new Document();
-// Element root = new Element("collection", ns);
-// doc.setRootElement(root);
-// if (collection.getNext() != null)
-// {
-// root.setAttribute("next", collection.getNext());
-// }
-// Iterator iter = collection.getMembers().iterator();
-// while (iter.hasNext())
-// {
-// Member member = (Member) iter.next();
-// root.addContent(AtomCollection.memberToElement(member));
-// }
+ /*Element root = new Element("collection", ns);
+ doc.setRootElement(root);
+ if (collection.getNext() != null)
+ {
+ root.setAttribute("next", collection.getNext());
+ }
+ Iterator iter = collection.getMembers().iterator();
+ while (iter.hasNext())
+ {
+ Member member = (Member) iter.next();
+ root.addContent(AtomCollection.memberToElement(member));
+ }*/
return doc;
}
Modified: incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java?rev=291064&r1=291063&r2=291064&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java (original)
+++ incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/AtomServlet.java Thu Sep 22 20:07:54 2005
@@ -105,7 +105,7 @@
AtomCollection col = null;
if (ranges != null)
{
- // return a range of collection members
+ /* // return a range of collection members
AtomCollection.Range range =
AtomCollection.parseRange(req.getHeader("Range"));
int offset = 0;
@@ -115,7 +115,7 @@
offset = Integer.parseInt(offsetString);
}
col= handler.getCollection(
- pathInfo, range.start, range.end, offset);
+ pathInfo, range.start, range.end, offset); */
}
else
{
@@ -182,7 +182,7 @@
{
if (handler.isEntryCollectionURI(pathInfo))
{
- // parse incoming entry
+ /* // parse incoming entry
Entry unsavedEntry = parseEntry(
new InputStreamReader(req.getInputStream()));
@@ -202,7 +202,7 @@
res.setStatus(HttpServletResponse.SC_CREATED);
Writer writer = res.getWriter();
serializeEntry(savedEntry, writer);
- writer.close();
+ writer.close(); */
}
else if (handler.isResourceCollectionURI(pathInfo))
{
Modified: incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java?rev=291064&r1=291063&r2=291064&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java (original)
+++ incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi/RollerAtomHandler.java Thu Sep 22 20:07:54 2005
@@ -258,12 +258,12 @@
// build collection
AtomCollection col = new AtomCollection();
- if (entries.size() > mMaxEntries) {
+ /* if (entries.size() > mMaxEntries) {
// there are more entries, so include next link
WeblogEntryData lastEntry =
(WeblogEntryData)entries.get(entries.size() - 1);
col.setNext(createNextLink(lastEntry, start, end, offset));
- }
+ }
// add up to max entries to collection
int count = 0;
Iterator iter = entries.iterator();
@@ -275,7 +275,7 @@
member.setHref(absUrl
+ "/atom/" + handle + "/entry/" + rollerEntry.getId());
col.addMember(member);
- }
+ } */
return col;
}
throw new Exception("ERROR: not authorized");
@@ -293,14 +293,14 @@
File[] files = fmgr.getFiles(website);
if (canView(website)) {
AtomCollection col = new AtomCollection();
- for (int i=0; i<files.length; i++) {
+ /* for (int i=0; i<files.length; i++) {
AtomCollection.Member member = new AtomCollection.Member();
member.setTitle(files[i].getName());
member.setUpdated(new Date(files[i].lastModified()));
member.setHref(absUrl
+ "/atom/" + website.getHandle() + "/resource/" + files[i].getName() );
col.addMember(member);
- }
+ } */
return col;
}
throw new Exception("ERROR: not authorized");
@@ -318,7 +318,7 @@
List items = wmgr.getWeblogCategories(website);
if (canView(website)) {
AtomCollection col = new AtomCollection();
- Iterator iter = items.iterator();
+ /* Iterator iter = items.iterator();
Date now = new Date();
while (iter.hasNext()) {
WeblogCategoryData item = (WeblogCategoryData)iter.next();
@@ -330,7 +330,7 @@
member.setHref(absUrl + "/atom/"
+ website.getHandle() + "/category/" + item.getId());
col.addMember(member);
- }
+ } */
return col;
}
throw new Exception("ERROR: not authorized");
Modified: incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/AtomServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/AtomServlet.java?rev=291064&r1=291063&r2=291064&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/AtomServlet.java (original)
+++ incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/AtomServlet.java Thu Sep 22 20:07:54 2005
@@ -50,7 +50,7 @@
/**
* Atom Servlet implements Atom by calling a Roller independent handler.
- * @web.servlet name="AtomServlet"
+ * @web.servlet name="AtomServlet04"
* @web.servlet-mapping url-pattern="/atom04/*"
* @author David M Johnson
*/
@@ -162,6 +162,7 @@
else
{
res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ res.setHeader("WWW-Authenticate", "Basic realm=\"Protected Territory\"");
}
}
Modified: incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/RollerAtomHandler.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/RollerAtomHandler.java?rev=291064&r1=291063&r2=291064&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/RollerAtomHandler.java (original)
+++ incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/RollerAtomHandler.java Thu Sep 22 20:07:54 2005
@@ -31,7 +31,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.util.RequestUtils;
-import org.roller.RollerException;
import org.roller.model.FileManager;
import org.roller.model.Roller;
import org.roller.model.WeblogManager;
@@ -87,6 +86,7 @@
private RollerContext mRollerContext;
private String mUsername;
private int mMaxEntries = 20;
+ private static String ctx = "/atom04/";
//private MessageDigest md5Helper = null;
//private MD5Encoder md5Encoder = new MD5Encoder();
@@ -106,7 +106,8 @@
mRollerContext = RollerContext.getRollerContext(request);
// TODO: decide what to do about authentication, is WSSE going to fly?
- mUsername = authenticateWSSE(request);
+ mUsername = authenticateBASIC(request);
+ //mUsername = authenticateWSSE(request);
if (mUsername != null) {
try {
@@ -157,19 +158,19 @@
AtomService.Collection entryCol = new AtomService.Collection();
entryCol.setTitle("Collection: Weblog Entries for " + handle);
entryCol.setContents("entries");
- entryCol.setHref(absUrl + "/atom/"+handle+"/entries");
+ entryCol.setHref(absUrl + ctx +handle+"/entries");
workspace.addCollection(entryCol);
AtomService.Collection catCol = new AtomService.Collection();
catCol.setTitle("Collection: Categories for " + handle);
catCol.setContents("categories");
- catCol.setHref(absUrl + "/atom/"+handle+"/categories");
+ catCol.setHref(absUrl + ctx + handle+"/categories");
workspace.addCollection(catCol);
AtomService.Collection uploadCol = new AtomService.Collection();
uploadCol.setTitle("Collection: File uploads for " + handle);
uploadCol.setContents("generic");
- uploadCol.setHref(absUrl + "/atom/"+handle+"/resources");
+ uploadCol.setHref(absUrl + ctx + handle+"/resources");
workspace.addCollection(uploadCol);
}
}
@@ -273,7 +274,7 @@
member.setTitle(rollerEntry.getDisplayTitle());
member.setUpdated(rollerEntry.getUpdateTime());
member.setHref(absUrl
- + "/atom/" + handle + "/entry/" + rollerEntry.getId());
+ + ctx + handle + "/entry/" + rollerEntry.getId());
col.addMember(member);
}
return col;
@@ -298,7 +299,7 @@
member.setTitle(files[i].getName());
member.setUpdated(new Date(files[i].lastModified()));
member.setHref(absUrl
- + "/atom/" + website.getHandle() + "/resource/" + files[i].getName() );
+ + ctx + website.getHandle() + "/resource/" + files[i].getName() );
col.addMember(member);
}
return col;
@@ -327,7 +328,7 @@
if (name.equals("/")) continue;
member.setTitle(name);
member.setUpdated(now);
- member.setHref(absUrl + "/atom/"
+ member.setHref(absUrl + ctx
+ website.getHandle() + "/category/" + item.getId());
col.addMember(member);
}
@@ -648,7 +649,34 @@
//-------------------------------------------------------------- authentication
- /**
+ protected String authenticateBASIC(HttpServletRequest request) {
+ String authorization = request.getHeader("Authorization");
+ if (authorization != null) {
+ try {
+ StringTokenizer toker = new StringTokenizer(authorization, " ");
+ String basic = toker.nextToken();
+ if (toker.hasMoreTokens()) {
+ String digest = toker.nextToken();
+ String pair = new String(WSSEUtilities.base64Decode(digest));
+ toker = new StringTokenizer(pair,":");
+ String pairName = toker.nextToken();
+ UserData user = mRoller.getUserManager().getUser(pairName);
+ if (user != null && toker.hasMoreTokens()) {
+ String pairPass = toker.nextToken();
+ if (user.getPassword().equals(pairPass)) {
+ return pairName;
+ }
+ }
+ }
+ }
+ catch (Exception e) {
+ mLogger.error(e);
+ }
+ }
+ return null;
+ }
+
+ /**
* Perform WSSE authentication based on information in request.
* Will not work if Roller password encryption is turned on.
*/
@@ -698,7 +726,7 @@
/**
* Untested (and currently unused) implementation of BASIC authentication
*/
- public String authenticateBASIC(HttpServletRequest request) {
+ /*public String authenticateBASIC(HttpServletRequest request) {
boolean valid = false;
String userID = null;
String password = null;
@@ -715,8 +743,9 @@
if (p != -1) {
userID = userPass.substring(0, p);
UserData user = mRoller.getUserManager().getUser(userID);
- String realpassword = LoginServlet.getEncryptedPassword(
- request, user.getUserName(), user.getPassword());
+ //String realpassword = LoginServlet.getEncryptedPassword(
+ //request, user.getUserName(), user.getPassword());
+ String realpassword = user.getPassword();
password = userPass.substring(p+1);
if ( (!userID.trim().equals(user.getUserName()))
&& (!password.trim().equals(realpassword))) {
@@ -731,7 +760,7 @@
}
if (valid) return userID;
return null;
- }
+ }*/
//----------------------------------------------------------- internal utilities
@@ -743,7 +772,7 @@
WeblogEntryData entry, Date start, Date end, int offset) {
SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" );
String absUrl = mRollerContext.getAbsoluteContextUrl();
- String url = absUrl + "/atom/" + mUsername + "/entries/" + entry.getId();
+ String url = absUrl + ctx + mUsername + "/entries/" + entry.getId();
if (offset != -1 && start != null && end != null) {
url = url + "?Range=" + df.format(start) + "/" + df.format(end);
} else if (offset != -1 && start != null) {
@@ -806,8 +835,8 @@
updateTime = new Timestamp( entry.getUpdated().getTime() );
}
WeblogEntryData rollerEntry = new WeblogEntryData();
- rollerEntry.setTitle(entry.getTitle());
- rollerEntry.setText(entry.getContent().getValue());
+ if (entry.getTitle() != null) rollerEntry.setTitle(entry.getTitle());
+ if (entry.getContent() != null) rollerEntry.setText(entry.getContent().getValue());
rollerEntry.setPubTime(pubTime);
rollerEntry.setUpdateTime(updateTime);
rollerEntry.setWebsite(website);
Modified: incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/package.html
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/package.html?rev=291064&r1=291063&r2=291064&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/package.html (original)
+++ incubator/roller/branches/roller_2.0/sandbox/atomprotocol/src/org/roller/presentation/atomapi04/package.html Thu Sep 22 20:07:54 2005
@@ -4,7 +4,7 @@
<title></title>
</head>
<body>
-ROME-based Atom Protocol implementation.
-
+ROME-based <a href=
+"http://bitworking.org/projects/atom/draft-ietf-atompub-protocol-04.html">Atom Protocol 04</a> implementation.
</body>
</html>