abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r575441 - in /incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter: ./ annotation/
Date Thu, 13 Sep 2007 20:34:22 GMT
Author: jmsnell
Date: Thu Sep 13 13:34:21 2007
New Revision: 575441

URL: http://svn.apache.org/viewvc?rev=575441&view=rev
Log:
Continuing work on the annotation converter

Added:
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Charset.java
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/EntityTag.java
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/LastModified.java
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Slug.java
Modified:
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java

Modified: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java?rev=575441&r1=575440&r2=575441&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java
(original)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java
Thu Sep 13 13:34:21 2007
@@ -22,14 +22,31 @@
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URL;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collection;
+import java.util.Date;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.abdera.converter.annotation.BaseURI;
+import org.apache.abdera.converter.annotation.Charset;
+import org.apache.abdera.converter.annotation.EntityTag;
+import org.apache.abdera.converter.annotation.Language;
+import org.apache.abdera.converter.annotation.LastModified;
+import org.apache.abdera.converter.annotation.Slug;
+import org.apache.abdera.converter.impl.StringConverter;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.AtomDate;
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+
 @SuppressWarnings("unchecked")
 public abstract class BaseConverter<T> 
   extends Converter<T> {
@@ -72,7 +89,90 @@
         ((ConventionConversionContext)context)
           .getConventions();
       for (AccessibleObject accessor : objectContext.getAccessors()) {
-        process(source, objectContext, context, conventions, dest, accessor);
+        if (dest instanceof Base && 
+            accessor.isAnnotationPresent(Language.class) || 
+            Language.class.equals(conventions.matchConvention(accessor))) {
+          Object value = eval(accessor,source);
+          ObjectContext valueContext = new ObjectContext(value,source,accessor);
+          StringConverter c = new StringConverter();
+          StringBuffer buf = c.convert(value, valueContext, context);
+          if (buf != null) {
+            if (dest instanceof Document) ((Document)dest).setLanguage(buf.toString());
+            else if (dest instanceof Element) ((Element)dest).setLanguage(buf.toString());
+          }
+        } else if (dest instanceof Base &&
+            accessor.isAnnotationPresent(BaseURI.class) || 
+            BaseURI.class.equals(conventions.matchConvention(accessor))) {
+          
+          Object value = eval(accessor,source);
+          String iri = null;
+          if (value instanceof URI) {
+            iri = value.toString();
+          } else if (value instanceof URL) {
+            iri = value.toString();
+          } else if (value instanceof IRI) {
+            iri = value.toString();
+          } else {
+            ObjectContext valueContext = new ObjectContext(value,source,accessor);
+            StringConverter c = new StringConverter();
+            StringBuffer buf = c.convert(value, valueContext, context);
+            iri = buf.toString();
+          }
+          if (iri != null) {
+            if (dest instanceof Document) ((Document)dest).setBaseUri(iri);
+            else if (dest instanceof Element) ((Element)dest).setBaseUri(iri);
+          }
+        } else if (dest instanceof Document && 
+          accessor.isAnnotationPresent(Slug.class) || 
+          Slug.class.equals(conventions.matchConvention(accessor))) {
+            Object value = eval(accessor,source);
+            ObjectContext valueContext = new ObjectContext(value,source,accessor);
+            StringConverter c = new StringConverter();
+            StringBuffer buf = c.convert(value, valueContext, context);
+            if (buf != null) ((Document)dest).setSlug(buf.toString());
+        } else if (dest instanceof Document && 
+            accessor.isAnnotationPresent(LastModified.class) || 
+            LastModified.class.equals(conventions.matchConvention(accessor))) {
+          Object value = eval(accessor,source);
+          Document doc = (Document)dest;
+          if (value instanceof Date) {
+            doc.setLastModified((Date)value);
+          } else if (value instanceof Calendar) {
+            Calendar cal = (Calendar)value;
+            doc.setLastModified(cal.getTime());
+          } else if (value instanceof Long) {
+            Long l = (Long) value;
+            doc.setLastModified(new Date(l.longValue()));
+          } else if (value instanceof String) {
+            doc.setLastModified(AtomDate.parse((String)value));
+          } else {
+            StringConverter s = new StringConverter();
+            StringBuffer v = s.convert(source, objectContext, context);
+            if (v != null) doc.setLastModified(AtomDate.parse(v.toString()));
+          }
+        } else if (dest instanceof Document && 
+            accessor.isAnnotationPresent(Charset.class) || 
+            Charset.class.equals(conventions.matchConvention(accessor))) {
+          Object value = eval(accessor,source);
+          ObjectContext valueContext = new ObjectContext(value,source,accessor);
+          StringConverter c = new StringConverter();
+          StringBuffer buf = c.convert(value, valueContext, context);
+          if (buf != null) ((Document)dest).setCharset(buf.toString());
+        } else if (dest instanceof Document && 
+            accessor.isAnnotationPresent(EntityTag.class) || 
+            EntityTag.class.equals(conventions.matchConvention(accessor))) {
+              Object value = eval(accessor,source);
+              if (value instanceof org.apache.abdera.util.EntityTag) {
+                ((Document)dest).setEntityTag((org.apache.abdera.util.EntityTag)value);
+              } else {
+                ObjectContext valueContext = new ObjectContext(value,source,accessor);
+                StringConverter c = new StringConverter();
+                StringBuffer buf = c.convert(value, valueContext, context);
+                if (buf != null) ((Document)dest).setEntityTag(buf.toString());
+              }
+        } else {
+          process(source, objectContext, context, conventions, dest, accessor);
+        }
       }      
       finish(
         source, 

Modified: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java?rev=575441&r1=575440&r2=575441&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java
(original)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java
Thu Sep 13 13:34:21 2007
@@ -24,6 +24,7 @@
 import org.apache.abdera.converter.annotation.BaseURI;
 import org.apache.abdera.converter.annotation.Categories;
 import org.apache.abdera.converter.annotation.Category;
+import org.apache.abdera.converter.annotation.Charset;
 import org.apache.abdera.converter.annotation.Collection;
 import org.apache.abdera.converter.annotation.Content;
 import org.apache.abdera.converter.annotation.ContentType;
@@ -33,6 +34,7 @@
 import org.apache.abdera.converter.annotation.Draft;
 import org.apache.abdera.converter.annotation.Edited;
 import org.apache.abdera.converter.annotation.Email;
+import org.apache.abdera.converter.annotation.EntityTag;
 import org.apache.abdera.converter.annotation.Entry;
 import org.apache.abdera.converter.annotation.Extension;
 import org.apache.abdera.converter.annotation.Generator;
@@ -42,6 +44,7 @@
 import org.apache.abdera.converter.annotation.Icon;
 import org.apache.abdera.converter.annotation.Label;
 import org.apache.abdera.converter.annotation.Language;
+import org.apache.abdera.converter.annotation.LastModified;
 import org.apache.abdera.converter.annotation.Length;
 import org.apache.abdera.converter.annotation.Link;
 import org.apache.abdera.converter.annotation.Logo;
@@ -51,6 +54,7 @@
 import org.apache.abdera.converter.annotation.Rel;
 import org.apache.abdera.converter.annotation.Rights;
 import org.apache.abdera.converter.annotation.Scheme;
+import org.apache.abdera.converter.annotation.Slug;
 import org.apache.abdera.converter.annotation.Source;
 import org.apache.abdera.converter.annotation.Src;
 import org.apache.abdera.converter.annotation.Subtitle;
@@ -111,7 +115,11 @@
     URI.class, 
     Value.class, 
     Version.class, 
-    Workspace.class
+    Workspace.class,
+    Slug.class,
+    EntityTag.class,
+    Charset.class,
+    LastModified.class
    };
   
   public DefaultConventions() {

Added: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Charset.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Charset.java?rev=575441&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Charset.java
(added)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Charset.java
Thu Sep 13 13:34:21 2007
@@ -0,0 +1,30 @@
+/*
+* 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.converter.annotation;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target({METHOD,FIELD})
+@Convention(".*charset")
+public @interface Charset {}

Added: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/EntityTag.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/EntityTag.java?rev=575441&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/EntityTag.java
(added)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/EntityTag.java
Thu Sep 13 13:34:21 2007
@@ -0,0 +1,30 @@
+/*
+* 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.converter.annotation;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target({METHOD,FIELD})
+@Convention(".*entitytag")
+public @interface EntityTag {}

Added: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/LastModified.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/LastModified.java?rev=575441&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/LastModified.java
(added)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/LastModified.java
Thu Sep 13 13:34:21 2007
@@ -0,0 +1,30 @@
+/*
+* 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.converter.annotation;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target({METHOD,FIELD})
+@Convention(".*lastmodified")
+public @interface LastModified {}

Added: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Slug.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Slug.java?rev=575441&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Slug.java
(added)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Slug.java
Thu Sep 13 13:34:21 2007
@@ -0,0 +1,30 @@
+/*
+* 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.converter.annotation;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target({METHOD,FIELD})
+@Convention(".*slug")
+public @interface Slug {}



Mime
View raw message