You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2008/01/22 23:32:04 UTC
svn commit: r614361 -
/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/
Author: jmsnell
Date: Tue Jan 22 14:32:03 2008
New Revision: 614361
URL: http://svn.apache.org/viewvc?rev=614361&view=rev
Log:
Finishing up support for categories elements/documents
Added:
incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java
incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java
incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java
incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java
Modified:
incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java
incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java
incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java
Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java?rev=614361&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoriesInfo.java Tue Jan 22 14:32:03 2008
@@ -0,0 +1,34 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.impl;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Categories;
+import org.apache.abdera.protocol.server.RequestContext;
+
+public interface CategoriesInfo
+ extends Iterable<CategoryInfo> {
+
+ boolean isFixed(RequestContext request);
+
+ String getScheme(RequestContext request);
+
+ String getHref(RequestContext request);
+
+ Categories asCategoriesElement(Abdera abdera);
+}
Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java?rev=614361&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CategoryInfo.java Tue Jan 22 14:32:03 2008
@@ -0,0 +1,33 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.impl;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Category;
+import org.apache.abdera.protocol.server.RequestContext;
+
+public interface CategoryInfo {
+
+ String getScheme(RequestContext request);
+
+ String getTerm(RequestContext request);
+
+ String getLabel(RequestContext request);
+
+ Category asCategoryElement(Abdera abdera);
+}
Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java?rev=614361&r1=614360&r2=614361&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/CollectionInfo.java Tue Jan 22 14:32:03 2008
@@ -30,5 +30,7 @@
boolean isAdapterFor(RequestContext request);
+ CategoriesInfo[] getCategoriesInfo(RequestContext request);
+
CollectionAdapter getCollectionAdapter(RequestContext request);
}
Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java?rev=614361&r1=614360&r2=614361&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java Tue Jan 22 14:32:03 2008
@@ -99,9 +99,30 @@
for (CollectionInfo ci : wi.getCollections(request)) {
sw.startCollection(ci.getHref(request))
.writeTitle(ci.getTitle(request))
- .writeAccepts(ci.getAccepts(request))
- // TODO: handle categories
- .endCollection();
+ .writeAccepts(ci.getAccepts(request));
+ CategoriesInfo[] catinfos = ci.getCategoriesInfo(request);
+ if (catinfos != null) {
+ for (CategoriesInfo catinfo : catinfos) {
+ String href = catinfo.getHref(request);
+ if (href != null) {
+ sw.startCategories()
+ .writeAttribute("href", href)
+ .endCategories();
+ } else {
+ sw.startCategories(
+ catinfo.isFixed(request),
+ catinfo.getScheme(request));
+ for (CategoryInfo cat : catinfo) {
+ sw.writeCategory(
+ cat.getTerm(request),
+ cat.getScheme(request),
+ cat.getLabel(request));
+ }
+ sw.endCategories();
+ }
+ }
+ }
+ sw.endCollection();
}
sw.endWorkspace();
}
Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java?rev=614361&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoriesInfo.java Tue Jan 22 14:32:03 2008
@@ -0,0 +1,138 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.impl;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Categories;
+import org.apache.abdera.protocol.server.RequestContext;
+
+public class SimpleCategoriesInfo
+ implements CategoriesInfo,
+ Serializable,
+ Cloneable {
+
+ private static final long serialVersionUID = 1L;
+ private final String href;
+ private final String scheme;
+ private final boolean fixed;
+ private final List<CategoryInfo> list = new ArrayList<CategoryInfo>();
+
+ public SimpleCategoriesInfo(
+ String href) {
+ this.href = href;
+ this.scheme = null;
+ this.fixed = false;
+ }
+
+ public SimpleCategoriesInfo(
+ String scheme,
+ boolean fixed,
+ CategoryInfo... categories) {
+ this.href = null;
+ this.scheme = scheme;
+ this.fixed = fixed;
+ addCategoryInfo(categories);
+ }
+
+ public String getHref(RequestContext request) {
+ return href;
+ }
+
+ public String getScheme(RequestContext request) {
+ return scheme;
+ }
+
+ public boolean isFixed(RequestContext request) {
+ return fixed;
+ }
+
+ public Iterator<CategoryInfo> iterator() {
+ return list.iterator();
+ }
+
+ public SimpleCategoriesInfo addCategoryInfo(CategoryInfo... categories) {
+ for (CategoryInfo cat : categories)
+ list.add(cat);
+ return this;
+ }
+
+ public SimpleCategoriesInfo setCategoryInfo(CategoryInfo... categories) {
+ list.clear();
+ return addCategoryInfo(categories);
+ }
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (fixed ? 1231 : 1237);
+ result = prime * result + ((href == null) ? 0 : href.hashCode());
+ result = prime * result + ((list == null) ? 0 : list.hashCode());
+ result = prime * result + ((scheme == null) ? 0 : scheme.hashCode());
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ final SimpleCategoriesInfo other = (SimpleCategoriesInfo) obj;
+ if (fixed != other.fixed) return false;
+ if (href == null) {
+ if (other.href != null) return false;
+ } else if (!href.equals(other.href)) return false;
+ if (list == null) {
+ if (other.list != null) return false;
+ } else if (!list.equals(other.list)) return false;
+ if (scheme == null) {
+ if (other.scheme != null) return false;
+ } else if (!scheme.equals(other.scheme)) return false;
+ return true;
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ return href != null ?
+ new SimpleCategoriesInfo(href) :
+ new SimpleCategoriesInfo(
+ scheme,
+ fixed,
+ list.toArray(
+ new CategoryInfo[list.size()]));
+ }
+ }
+
+ public Categories asCategoriesElement(Abdera abdera) {
+ Categories cats = abdera.getFactory().newCategories();
+ if (href != null) cats.setHref(href);
+ else {
+ cats.setFixed(fixed);
+ cats.setScheme(scheme);
+ for (CategoryInfo cat : this)
+ cats.addCategory(
+ cat.asCategoryElement(abdera));
+ }
+ return cats;
+ }
+}
Added: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java?rev=614361&view=auto
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java (added)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCategoryInfo.java Tue Jan 22 14:32:03 2008
@@ -0,0 +1,109 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.server.impl;
+
+import java.io.Serializable;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Category;
+import org.apache.abdera.protocol.server.RequestContext;
+
+public class SimpleCategoryInfo
+ implements CategoryInfo,
+ Serializable,
+ Cloneable {
+
+ private static final long serialVersionUID = -4013333222147077975L;
+ private final String label;
+ private final String term;
+ private final String scheme;
+
+ public SimpleCategoryInfo(
+ String term) {
+ this(term, null, null);
+ }
+
+ public SimpleCategoryInfo(
+ String term,
+ String scheme) {
+ this(term,scheme,null);
+ }
+
+ public SimpleCategoryInfo(
+ String term,
+ String scheme,
+ String label) {
+ this.term = term;
+ this.scheme = scheme;
+ this.label = label;
+ }
+
+ public String getLabel(RequestContext request) {
+ return label;
+ }
+
+ public String getScheme(RequestContext request) {
+ return scheme;
+ }
+
+ public String getTerm(RequestContext request) {
+ return term;
+ }
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((label == null) ? 0 : label.hashCode());
+ result = prime * result + ((scheme == null) ? 0 : scheme.hashCode());
+ result = prime * result + ((term == null) ? 0 : term.hashCode());
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ final SimpleCategoryInfo other = (SimpleCategoryInfo) obj;
+ if (label == null) {
+ if (other.label != null) return false;
+ } else if (!label.equals(other.label)) return false;
+ if (scheme == null) {
+ if (other.scheme != null) return false;
+ } else if (!scheme.equals(other.scheme)) return false;
+ if (term == null) {
+ if (other.term != null) return false;
+ } else if (!term.equals(other.term)) return false;
+ return true;
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ return new SimpleCategoryInfo(term,scheme,label);
+ }
+ }
+
+ public Category asCategoryElement(Abdera abdera) {
+ Category cat = abdera.getFactory().newCategory();
+ cat.setTerm(term);
+ if (scheme != null) cat.setScheme(scheme);
+ if (label != null) cat.setLabel(label);
+ return cat;
+ }
+}
Modified: incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java?rev=614361&r1=614360&r2=614361&view=diff
==============================================================================
--- incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java (original)
+++ incubator/abdera/java/branches/server_refactor/src/main/java/org/apache/abdera/protocol/server/impl/SimpleCollection.java Tue Jan 22 14:32:03 2008
@@ -17,17 +17,25 @@
*/
package org.apache.abdera.protocol.server.impl;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.abdera.protocol.server.CollectionAdapter;
import org.apache.abdera.protocol.server.RequestContext;
public class SimpleCollection
- implements CollectionInfo {
+ implements CollectionInfo,
+ Serializable {
+
+ private static final long serialVersionUID = 8026455829158149510L;
private final CollectionAdapter adapter;
private final String id;
private final String title;
private final String href;
private final String[] accepts;
+ private final List<CategoriesInfo> catinfos = new ArrayList<CategoriesInfo>();
public SimpleCollection(
CollectionAdapter adapter,
@@ -60,5 +68,19 @@
public CollectionAdapter getCollectionAdapter(RequestContext request) {
return adapter;
+ }
+
+ public CategoriesInfo[] getCategoriesInfo(RequestContext request) {
+ return catinfos.toArray(new CategoriesInfo[catinfos.size()]);
+ }
+
+ public void addCategoriesInfo(CategoriesInfo... catinfos) {
+ for (CategoriesInfo catinfo : catinfos)
+ this.catinfos.add(catinfo);
+ }
+
+ public void setCategoriesInfo(CategoriesInfo...catinfos) {
+ this.catinfos.clear();
+ addCategoriesInfo(catinfos);
}
}