index
int64
0
0
repo_id
stringlengths
9
205
file_path
stringlengths
31
246
content
stringlengths
1
12.2M
__index_level_0__
int64
0
10k
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/ObjectContext.java
/* * 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.ext.serializer; import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @SuppressWarnings("unchecked") public class ObjectContext { private final Class objectType; private final Object parent; private final AccessibleObject accessor; private final Annotation[] annotations; private final Serializer serializer; private final Field[] fields; private final Method[] methods; public ObjectContext(Object object) { this(object, null, null); } public ObjectContext(Object object, Object parent, AccessibleObject accessor) { this.objectType = object != null ? object.getClass() : accessor != null ? AbstractSerializationContext .getReturnType(accessor) : null; this.parent = parent; this.accessor = accessor; this.annotations = initAnnotations(); this.serializer = initSerializer(); this.fields = initFields(); this.methods = initMethods(); } private Field[] initFields() { Field[] fields = objectType.getFields(); List<Field> list = new ArrayList<Field>(); for (Field field : fields) { int mods = field.getModifiers(); // ignore static fields if (!Modifier.isStatic(mods)) { list.add(field); } } return list.toArray(new Field[list.size()]); } private Method[] initMethods() { Method[] methods = objectType.getMethods(); List<Method> list = new ArrayList<Method>(); for (Method method : methods) { // only methods that have no parameters, return a value, are not // abstract and are not static int mods = method.getModifiers(); if (!Modifier.isStatic(mods) && !Modifier.isAbstract(mods) && method.getParameterTypes().length == 0 && method.getReturnType() != Void.class) { list.add(method); } } return list.toArray(new Method[list.size()]); } private Annotation[] initAnnotations() { Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>(); if (objectType != null) { for (Annotation annotation : objectType.getAnnotations()) { annotations.put(annotation.annotationType(), annotation); } } if (accessor != null) { for (Annotation annotation : accessor.getAnnotations()) { annotations.put(annotation.annotationType(), annotation); } } return annotations.values().toArray(new Annotation[annotations.size()]); } private Serializer initSerializer() { try { org.apache.abdera.ext.serializer.annotation.Serializer ser = getAnnotation(org.apache.abdera.ext.serializer.annotation.Serializer.class); if (ser != null) { Class<? extends Serializer> serclass = ser.value(); return serclass.newInstance(); } return null; } catch (Throwable t) { throw new SerializationException(t); } } public AccessibleObject getAccessor() { return accessor; } public Object getParent() { return parent; } public Class getObjectType() { return objectType; } public <X extends Annotation> X getAnnotation(Class<X> annotationType) { for (Annotation annotation : annotations) { if (annotation.annotationType() == annotationType) return (X)annotation; } return null; } public Annotation[] getAnnotations() { return annotations; } public Serializer getSerializer() { return serializer; } public Field[] getFields() { return fields; } public Method[] getMethods() { return methods; } public AccessibleObject[] getAccessors() { List<AccessibleObject> list = new ArrayList<AccessibleObject>(); for (Method method : methods) list.add(method); for (Field field : fields) list.add(field); return list.toArray(new AccessibleObject[list.size()]); } public AccessibleObject[] getAccessors(Class<? extends Annotation> annotation, Conventions conventions) { List<AccessibleObject> accessors = new ArrayList<AccessibleObject>(); for (AccessibleObject accessor : getAccessors()) { if (accessor.isAnnotationPresent(annotation) || annotation.equals(conventions.matchConvention(accessor))) { accessors.add(accessor); } } return accessors.toArray(new AccessibleObject[accessors.size()]); } public AccessibleObject getAccessor(Class<? extends Annotation> annotation, Conventions conventions) { for (AccessibleObject accessor : getAccessors()) { if (accessor.isAnnotationPresent(annotation) || annotation.equals(conventions.matchConvention(accessor))) { return accessor; } } return null; } }
7,500
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/SerializerProvider.java
/* * 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.ext.serializer; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; @SuppressWarnings("unchecked") public abstract class SerializerProvider implements Iterable<Map.Entry<Class, Serializer>> { protected Map<Class, Serializer> serializers = new HashMap<Class, Serializer>(); protected void setConverter(Class type, Serializer serializer) { serializers.put(type, serializer); } public Iterator<Entry<Class, Serializer>> iterator() { return serializers.entrySet().iterator(); } }
7,501
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/ConventionSerializationContext.java
/* * 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.ext.serializer; import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; import org.apache.abdera.Abdera; import org.apache.abdera.writer.StreamWriter; public class ConventionSerializationContext extends DefaultSerializationContext { private static final long serialVersionUID = 7504071837124132972L; protected Conventions conventions; public ConventionSerializationContext(StreamWriter streamWriter) { this(new Abdera(), streamWriter); } public ConventionSerializationContext(Conventions conventions, StreamWriter streamWriter) { this(null, conventions, streamWriter); } public ConventionSerializationContext(Abdera abdera, StreamWriter streamWriter) { super(abdera, streamWriter); this.conventions = new DefaultConventions(); initSerializers(); } public ConventionSerializationContext(Abdera abdera, Conventions conventions, StreamWriter streamWriter) { super(abdera, streamWriter); this.conventions = conventions; initSerializers(); } public Conventions getConventions() { return conventions; } public void setConventions(Conventions conventions) { this.conventions = conventions; } public boolean hasSerializer(AccessibleObject accessor) { boolean answer = super.hasSerializer(accessor); if (answer) return true; Class<? extends Annotation> annotation = getConventions().matchConvention(accessor); return annotation != null && hasSerializer(annotation); } private <T> void initSerializers() { for (Class<? extends Annotation> type : conventions) { org.apache.abdera.ext.serializer.annotation.Serializer serializer = type.getAnnotation(org.apache.abdera.ext.serializer.annotation.Serializer.class); if (serializer != null) { try { Serializer ser = serializer.value().newInstance(); this.setSerializer(type, ser); } catch (Throwable t) { throw new SerializationException(t); } } } } }
7,502
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/SerializationException.java
/* * 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.ext.serializer; public class SerializationException extends RuntimeException { private static final long serialVersionUID = 3399703987771955406L; public SerializationException() { super(); } public SerializationException(String message, Throwable cause) { super(message, cause); } public SerializationException(String message) { super(message); } public SerializationException(Throwable cause) { super(cause); } }
7,503
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/AbstractConventions.java
/* * 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.ext.serializer; import java.io.Serializable; import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Member; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.regex.Pattern; import org.apache.abdera.ext.serializer.annotation.Convention; public abstract class AbstractConventions implements Conventions, Cloneable, Serializable { private final Map<Class<? extends Annotation>, Pattern> conventions = new HashMap<Class<? extends Annotation>, Pattern>(); private final boolean isCaseSensitive; protected AbstractConventions() { this(false); } protected AbstractConventions(boolean isCaseSensitive) { this.isCaseSensitive = isCaseSensitive; } public Iterator<Class<? extends Annotation>> iterator() { return conventions.keySet().iterator(); } public void setConvention(String pattern, Class<? extends Annotation> annotationType) { Pattern regex = isCaseSensitive ? Pattern.compile(pattern) : Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); conventions.put(annotationType, regex); } public void setConvention(Class<? extends Annotation> annotationType) { Convention conv = annotationType.getAnnotation(Convention.class); if (conv == null) throw new IllegalArgumentException("No Convention Annotation [" + annotationType + "]"); setConvention(conv.value(), annotationType); } public Class<? extends Annotation> matchConvention(AccessibleObject accessor) { return matchConvention(accessor, null); } public Class<? extends Annotation> matchConvention(AccessibleObject accessor, Class<? extends Annotation> expect) { if (accessor == null) return null; String name = ((Member)accessor).getName(); for (Map.Entry<Class<? extends Annotation>, Pattern> entry : conventions.entrySet()) { if (entry.getValue().matcher(name).matches() && (expect == null || expect == entry.getKey())) return entry.getKey(); } return null; } public boolean isMatch(AccessibleObject accessor, Class<? extends Annotation> expect) { return matchConvention(accessor, expect) != null; } @Override public int hashCode() { final int PRIME = 31; int result = 1; result = PRIME * result + ((conventions == null) ? 0 : conventions.hashCode()); result = PRIME * result + (isCaseSensitive ? 1231 : 1237); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final AbstractConventions other = (AbstractConventions)obj; if (conventions == null) { if (other.conventions != null) return false; } else if (!conventions.equals(other.conventions)) return false; if (isCaseSensitive != other.isCaseSensitive) return false; return true; } public Conventions clone() { try { return (Conventions)super.clone(); } catch (CloneNotSupportedException e) { return copy(); } } protected Conventions copy() { throw new SerializationException(new CloneNotSupportedException()); } }
7,504
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/AbstractSerializationContext.java
/* * 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.ext.serializer; import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import org.apache.abdera.Abdera; import org.apache.abdera.ext.serializer.impl.FOMSerializer; import org.apache.abdera.model.Element; import org.apache.abdera.writer.StreamWriter; @SuppressWarnings("unchecked") public abstract class AbstractSerializationContext implements SerializationContext { private final Abdera abdera; private final StreamWriter streamWriter; private final Map<Class, Serializer> serializers = new HashMap<Class, Serializer>(); protected AbstractSerializationContext(StreamWriter streamWriter) { this(new Abdera(), streamWriter); } protected AbstractSerializationContext(Abdera abdera, StreamWriter streamWriter) { this.abdera = abdera; this.streamWriter = streamWriter; setSerializer(Element.class, new FOMSerializer()); } public StreamWriter getStreamWriter() { return this.streamWriter; } public Abdera getAbdera() { return abdera; } public Serializer getSerializer(ObjectContext objectContext) { try { Class type = objectContext.getObjectType(); Serializer serializer = serializers.get(type); if (serializer == null) serializer = objectContext.getSerializer(); if (serializer == null) { for (Annotation annotation : objectContext.getAnnotations()) { serializer = serializers.get(annotation.annotationType()); if (serializer != null) return serializer; } } if (serializer == null && !type.isAnnotation()) { for (Class knownType : serializers.keySet()) { if (!knownType.isAnnotation() && knownType.isAssignableFrom(type)) { return serializers.get(knownType); } } } return serializer; } catch (Throwable t) { throw new SerializationException(t); } } public boolean hasSerializer(ObjectContext objectContext) { return getSerializer(objectContext) != null; } public boolean hasSerializer(Object object) { return hasSerializer(new ObjectContext(object)); } public boolean hasSerializer(Object object, Object parent, AccessibleObject accessor) { return hasSerializer(new ObjectContext(object, parent, accessor)); } public boolean hasSerializer(Class<?> type) { if (serializers.containsKey(type)) return true; if (!type.isAnnotation()) { for (Class<?> t : serializers.keySet()) { if (!t.isAnnotation() && t.isAssignableFrom(type)) return true; } } return false; } public boolean hasSerializer(AccessibleObject accessor) { Class<? extends Object> returnType = getReturnType(accessor); org.apache.abdera.ext.serializer.annotation.Serializer serializer = accessor.getAnnotation(org.apache.abdera.ext.serializer.annotation.Serializer.class); if (serializer != null && hasSerializer(serializer.value())) return true; if (returnType != null && hasSerializer(returnType)) return true; return false; } public void setSerializer(Class type, Serializer Serializer) { serializers.put(type, Serializer); } public void serialize(Object object) { serialize(object, new ObjectContext(object)); } public void serialize(Object object, ObjectContext objectContext) { if (objectContext == null) objectContext = new ObjectContext(object); Serializer serializer = getSerializer(objectContext); if (serializer != null) serialize(object, objectContext, serializer); else throw new SerializationException("No Serializer available for " + objectContext.getObjectType()); } public void serialize(Object object, Serializer serializer) { serialize(object, new ObjectContext(object), serializer); } public void serialize(Object object, ObjectContext objectContext, Serializer serializer) { if (objectContext == null) objectContext = new ObjectContext(object); Serializer overrideSerializer = getSerializer(objectContext); if (overrideSerializer != null) serializer = overrideSerializer; if (serializer != null) { serializer.serialize(object, objectContext, this); } else { throw new SerializationException("No Serializer available for " + objectContext.getObjectType()); } } public static Class<? extends Object> getReturnType(AccessibleObject accessor) { if (accessor instanceof Field) return ((Field)accessor).getType(); else if (accessor instanceof Method) return ((Method)accessor).getReturnType(); else return null; } }
7,505
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/DefaultConventions.java
/* * 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.ext.serializer; import java.lang.annotation.Annotation; import org.apache.abdera.ext.serializer.annotation.Accept; import org.apache.abdera.ext.serializer.annotation.Author; import org.apache.abdera.ext.serializer.annotation.BaseURI; import org.apache.abdera.ext.serializer.annotation.Categories; import org.apache.abdera.ext.serializer.annotation.Category; import org.apache.abdera.ext.serializer.annotation.Collection; import org.apache.abdera.ext.serializer.annotation.Content; import org.apache.abdera.ext.serializer.annotation.Contributor; import org.apache.abdera.ext.serializer.annotation.Control; import org.apache.abdera.ext.serializer.annotation.DateTime; import org.apache.abdera.ext.serializer.annotation.Draft; import org.apache.abdera.ext.serializer.annotation.Edited; import org.apache.abdera.ext.serializer.annotation.Email; import org.apache.abdera.ext.serializer.annotation.Entry; import org.apache.abdera.ext.serializer.annotation.Extension; import org.apache.abdera.ext.serializer.annotation.Generator; import org.apache.abdera.ext.serializer.annotation.HrefLanguage; import org.apache.abdera.ext.serializer.annotation.ID; import org.apache.abdera.ext.serializer.annotation.IRI; import org.apache.abdera.ext.serializer.annotation.Icon; import org.apache.abdera.ext.serializer.annotation.Label; import org.apache.abdera.ext.serializer.annotation.Language; import org.apache.abdera.ext.serializer.annotation.Length; import org.apache.abdera.ext.serializer.annotation.Link; import org.apache.abdera.ext.serializer.annotation.Logo; import org.apache.abdera.ext.serializer.annotation.MediaType; import org.apache.abdera.ext.serializer.annotation.Person; import org.apache.abdera.ext.serializer.annotation.Published; import org.apache.abdera.ext.serializer.annotation.Rel; import org.apache.abdera.ext.serializer.annotation.Rights; import org.apache.abdera.ext.serializer.annotation.Scheme; import org.apache.abdera.ext.serializer.annotation.Source; import org.apache.abdera.ext.serializer.annotation.Src; import org.apache.abdera.ext.serializer.annotation.Subtitle; import org.apache.abdera.ext.serializer.annotation.Summary; import org.apache.abdera.ext.serializer.annotation.Text; import org.apache.abdera.ext.serializer.annotation.Title; import org.apache.abdera.ext.serializer.annotation.URI; import org.apache.abdera.ext.serializer.annotation.Updated; import org.apache.abdera.ext.serializer.annotation.Value; import org.apache.abdera.ext.serializer.annotation.Version; import org.apache.abdera.ext.serializer.annotation.Workspace; public class DefaultConventions extends AbstractConventions { private static final long serialVersionUID = 6797950641657672805L; private static final Class<?>[] annotations = {Accept.class, Author.class, BaseURI.class, Categories.class, Category.class, Collection.class, Content.class, Contributor.class, Control.class, Draft.class, Edited.class, Email.class, Entry.class, Extension.class, Generator.class, HrefLanguage.class, Icon.class, ID.class, Label.class, Language.class, Length.class, Link.class, Logo.class, MediaType.class, Published.class, Rel.class, Rights.class, Scheme.class, Source.class, Src.class, Subtitle.class, Summary.class, Title.class, Updated.class, URI.class, Value.class, Version.class, Workspace.class, Text.class, DateTime.class, Person.class, IRI.class}; @SuppressWarnings("unchecked") public DefaultConventions() { super(false); for (Class<?> type : annotations) setConvention((Class<? extends Annotation>)type); } }
7,506
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/Serializer.java
/* * 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.ext.serializer; public abstract class Serializer { /** * Serializes the given object to the specified writer */ public void serialize(Object object, SerializationContext serializationContext) { serialize(object, new ObjectContext(object), serializationContext); } /** * Serializes the given object to the specified writer */ public abstract void serialize(Object object, ObjectContext context, SerializationContext serializationContext); }
7,507
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/SerializationContext.java
/* * 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.ext.serializer; import java.io.Serializable; import java.lang.reflect.AccessibleObject; import org.apache.abdera.Abdera; import org.apache.abdera.writer.StreamWriter; public interface SerializationContext extends Serializable { Abdera getAbdera(); StreamWriter getStreamWriter(); void serialize(Object object); void serialize(Object object, ObjectContext objectContext); void serialize(Object object, Serializer serializer); void serialize(Object object, ObjectContext objectContext, Serializer serializer); void setSerializer(Class<?> type, Serializer serializer); Serializer getSerializer(ObjectContext objectContext); boolean hasSerializer(ObjectContext objectContext); boolean hasSerializer(Object object); boolean hasSerializer(Object object, Object parent, AccessibleObject accessor); boolean hasSerializer(Class<?> type); boolean hasSerializer(AccessibleObject accessor); }
7,508
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/BaseSerializer.java
/* * 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.ext.serializer; import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Dictionary; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.annotation.Attribute; import org.apache.abdera.ext.serializer.annotation.BaseURI; import org.apache.abdera.ext.serializer.annotation.Extension; import org.apache.abdera.ext.serializer.annotation.Language; import org.apache.abdera.ext.serializer.annotation.Value; import org.apache.abdera.ext.serializer.impl.ExtensionSerializer; import org.apache.abdera.ext.serializer.impl.SimpleElementSerializer; import org.apache.abdera.i18n.rfc4646.Lang; import org.apache.abdera.writer.StreamWriter; @SuppressWarnings("unchecked") public abstract class BaseSerializer extends Serializer { public static final String DEFAULT = "##default"; protected abstract void init(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions); protected abstract void finish(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions); protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { } public void serialize(Object source, ObjectContext objectContext, SerializationContext context) { Conventions conventions = ((ConventionSerializationContext)context).getConventions(); init(source, objectContext, context, conventions); process(source, objectContext, context, conventions); finish(source, objectContext, context, conventions); } protected void writeTextValue(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions); Object value = null; if (accessor != null) { value = eval(accessor, source); } context.getStreamWriter().writeElementText(value != null ? toString(value) : toString(source)); } protected void writeExtensions(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { AccessibleObject[] accessors = objectContext.getAccessors(Extension.class, conventions); for (AccessibleObject accessor : accessors) { Object value = eval(accessor, source); ObjectContext valueContext = new ObjectContext(value, source, accessor); Extension extension = valueContext.getAnnotation(Extension.class); boolean simple = extension != null ? extension.simple() : false; Serializer ser = context.getSerializer(valueContext); if (ser == null) { if (simple) { QName qname = getQName(accessor); ser = new SimpleElementSerializer(qname); } else { ser = context.getSerializer(valueContext); if (ser == null) { QName qname = getQName(accessor); ser = new ExtensionSerializer(qname); } } } ser.serialize(value, valueContext, context); } } protected void writeAttributes(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeCommon(source, objectContext, context, conventions); StreamWriter sw = context.getStreamWriter(); AccessibleObject[] accessors = objectContext.getAccessors(Attribute.class, conventions); for (AccessibleObject accessor : accessors) { QName qname = getQName(accessor); Object value = eval(accessor, source); if (value != null) sw.writeAttribute(qname, toString(value)); } } protected boolean writeElement(Class<? extends Annotation> annotation, Serializer serializer, Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { AccessibleObject accessor = objectContext.getAccessor(annotation, conventions); if (accessor != null) { Object value = eval(accessor, source); ObjectContext valueContext = new ObjectContext(value, source, accessor); serializer.serialize(value, valueContext, context); return true; } return false; } protected void writeElements(Class<? extends Annotation> annotation, Serializer serializer, Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { AccessibleObject[] accessors = objectContext.getAccessors(annotation, conventions); for (AccessibleObject accessor : accessors) { if (accessor != null) { Object value = eval(accessor, source); Object[] values = toArray(value); for (Object val : values) { ObjectContext valueContext = new ObjectContext(val, source, accessor); serializer.serialize(val, valueContext, context); } } } } public static Object eval(AccessibleObject accessor, Object parent) { try { if (accessor instanceof Field) return ((Field)accessor).get(parent); else if (accessor instanceof Method) return ((Method)accessor).invoke(parent, new Object[0]); else return null; } catch (Throwable t) { throw new SerializationException(t); } } protected boolean hasAnnotation(AnnotatedElement item, Class<? extends Annotation> annotation) { return item.isAnnotationPresent(annotation); } protected void writeElement(StreamWriter sw, QName qname, String value) { sw.startElement(qname).writeElementText(value).endElement(); } public static String toString(Object value) { if (value == null) return null; Object[] values = toArray(value); StringBuilder buf = new StringBuilder(); for (int n = 0; n < values.length; n++) { if (n > 0) buf.append(", "); buf.append(values[n].toString()); } return buf.toString(); } public static Object[] toArray(Object value) { if (value == null) return new Object[0]; if (value.getClass().isArray()) { return (Object[])value; } else if (value instanceof Collection) { return ((Collection)value).toArray(); } else if (value instanceof Map) { return ((Map)value).values().toArray(); } else if (value instanceof Dictionary) { List<Object> list = new ArrayList<Object>(); Enumeration e = ((Dictionary)value).elements(); while (e.hasMoreElements()) list.add(e.nextElement()); return list.toArray(); } else if (value instanceof Iterator) { List<Object> list = new ArrayList<Object>(); Iterator i = (Iterator)value; while (i.hasNext()) list.add(i.next()); return list.toArray(); } else if (value instanceof Enumeration) { List<Object> list = new ArrayList<Object>(); Enumeration e = (Enumeration)value; while (e.hasMoreElements()) list.add(e.nextElement()); return list.toArray(); } else if (value instanceof Iterable) { List<Object> list = new ArrayList<Object>(); Iterable v = (Iterable)value; Iterator i = v.iterator(); while (i.hasNext()) list.add(i.next()); return list.toArray(); } else { return new Object[] {value}; } } protected static boolean isUndefined(String value) { return value == null || DEFAULT.equals(value); } protected static QName getQName(AccessibleObject accessor) { Extension ext = accessor.getAnnotation(Extension.class); if (ext != null) return getQName(ext); Attribute attr = accessor.getAnnotation(Attribute.class); if (attr != null) return getQName(attr); return new QName(accessor instanceof Method ? ((Method)accessor).getName() : ((Field)accessor).getName()); } protected static QName getQName(Extension extension) { QName qname = null; if (extension != null) { if (isUndefined(extension.prefix()) && isUndefined(extension.ns()) && isUndefined(extension.name())) { qname = new QName(extension.ns(), extension.name(), extension.prefix()); } else if (isUndefined(extension.prefix()) && !isUndefined(extension.ns()) && !isUndefined(extension.name())) { qname = new QName(extension.ns(), extension.name()); } else if (!isUndefined(extension.name())) { qname = new QName(extension.name()); } } return qname; } protected static QName getQName(Attribute attribute) { QName qname = null; if (attribute != null) { if (isUndefined(attribute.prefix()) && isUndefined(attribute.ns()) && isUndefined(attribute.name())) { qname = new QName(attribute.ns(), attribute.name(), attribute.prefix()); } else if (isUndefined(attribute.prefix()) && !isUndefined(attribute.ns()) && !isUndefined(attribute.name())) { qname = new QName(attribute.ns(), attribute.name()); } else if (!isUndefined(attribute.name())) { qname = new QName(attribute.name()); } } return qname; } @SuppressWarnings("deprecation") protected void writeCommon(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { StreamWriter sw = context.getStreamWriter(); String lang = null; AccessibleObject accessor = objectContext.getAccessor(Language.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) { if (value instanceof Lang || value instanceof org.apache.abdera.i18n.lang.Lang) { lang = value.toString(); } else { lang = toString(value); } } } if (lang == null) { Language _lang = objectContext.getAnnotation(Language.class); if (_lang != null && !_lang.value().equals(DEFAULT)) { lang = _lang.value(); } } if (lang != null) sw.writeLanguage(lang); String base = null; accessor = objectContext.getAccessor(BaseURI.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) base = toString(value); } if (base != null) sw.writeBase(base); } }
7,509
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/GeneratorSerializer.java
/* * 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.ext.serializer.impl; import java.lang.reflect.AccessibleObject; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Generator; import org.apache.abdera.ext.serializer.annotation.URI; import org.apache.abdera.util.Constants; import org.apache.abdera.writer.StreamWriter; public class GeneratorSerializer extends ElementSerializer { public GeneratorSerializer() { super(Constants.GENERATOR); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); StreamWriter sw = context.getStreamWriter(); Generator _generator = objectContext.getAnnotation(Generator.class); String uri = null; AccessibleObject accessor = objectContext.getAccessor(URI.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) uri = toString(value); } if (uri == null) { URI _uri = objectContext.getAnnotation(URI.class); if (_uri != null && !_uri.value().equals(DEFAULT)) { uri = _uri.value(); } } if (uri == null && _generator != null && !_generator.uri().equals(DEFAULT)) { uri = _generator.uri(); } if (uri != null) sw.writeAttribute("uri", uri); String version = null; accessor = objectContext.getAccessor(URI.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) version = toString(value); } if (version == null) { URI _version = objectContext.getAnnotation(URI.class); if (_version != null && !_version.value().equals(DEFAULT)) { version = _version.value(); } } if (version == null && _generator != null && !_generator.version().equals(DEFAULT)) { version = _generator.version(); } if (version != null) sw.writeAttribute("version", version); writeTextValue(source, objectContext, context, conventions); } }
7,510
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/SimpleElementSerializer.java
/* * 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.ext.serializer.impl; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; public class SimpleElementSerializer extends ElementSerializer { public SimpleElementSerializer(QName qname) { super(qname); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); writeTextValue(source, objectContext, context, conventions); } }
7,511
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/TextSerializer.java
/* * 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.ext.serializer.impl; import java.lang.reflect.AccessibleObject; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Text; import org.apache.abdera.ext.serializer.annotation.Value; import org.apache.abdera.model.Div; import org.apache.abdera.model.Element; import org.apache.abdera.model.Text.Type; import org.apache.abdera.writer.StreamWriter; public class TextSerializer extends ElementSerializer { public TextSerializer(QName qname) { super(qname); } public TextSerializer() { super(null); } protected void init(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { Type type = Type.TEXT; Object contentValue = null; ObjectContext valueContext = null; AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions); if (accessor != null && !(source instanceof Element)) { contentValue = eval(accessor, source); valueContext = new ObjectContext(contentValue, source, accessor); Text _text = valueContext.getAnnotation(Text.class); type = _text != null ? _text.type() : type; } else { Text _text = objectContext.getAnnotation(Text.class); type = _text != null ? _text.type() : type; contentValue = source; valueContext = objectContext; } QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor()); StreamWriter sw = context.getStreamWriter(); sw.startText(qname, type); writeAttributes(source, objectContext, context, conventions); switch (type) { case TEXT: case HTML: sw.writeElementText(toString(contentValue)); break; case XHTML: Div div = null; if (contentValue instanceof Div) div = (Div)contentValue; else { div = context.getAbdera().getFactory().newDiv(); div.setValue(toString(contentValue)); } context.serialize(div, new ObjectContext(div)); break; } } }
7,512
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/EntrySerializer.java
/* * 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.ext.serializer.impl; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Author; import org.apache.abdera.ext.serializer.annotation.Category; import org.apache.abdera.ext.serializer.annotation.Content; import org.apache.abdera.ext.serializer.annotation.Contributor; import org.apache.abdera.ext.serializer.annotation.Control; import org.apache.abdera.ext.serializer.annotation.Edited; import org.apache.abdera.ext.serializer.annotation.ID; import org.apache.abdera.ext.serializer.annotation.Link; import org.apache.abdera.ext.serializer.annotation.Published; import org.apache.abdera.ext.serializer.annotation.Rights; import org.apache.abdera.ext.serializer.annotation.Summary; import org.apache.abdera.ext.serializer.annotation.Title; import org.apache.abdera.ext.serializer.annotation.Updated; import org.apache.abdera.util.Constants; public class EntrySerializer extends ElementSerializer { public EntrySerializer() { super(Constants.ENTRY); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); writeElement(ID.class, new IRISerializer(Constants.ID), source, objectContext, context, conventions); writeElement(Title.class, new TextSerializer(Constants.TITLE), source, objectContext, context, conventions); writeElement(Summary.class, new TextSerializer(Constants.SUMMARY), source, objectContext, context, conventions); writeElement(Rights.class, new TextSerializer(Constants.RIGHTS), source, objectContext, context, conventions); writeElement(Updated.class, new DateTimeSerializer(Constants.UPDATED), source, objectContext, context, conventions); writeElement(Published.class, new DateTimeSerializer(Constants.PUBLISHED), source, objectContext, context, conventions); writeElement(Edited.class, new DateTimeSerializer(Constants.EDITED), source, objectContext, context, conventions); writeElement(Content.class, new ContentSerializer(), source, objectContext, context, conventions); writeElement(Control.class, new ControlSerializer(), source, objectContext, context, conventions); writeElements(Link.class, new LinkSerializer(), source, objectContext, context, conventions); writeElements(Category.class, new CategorySerializer(), source, objectContext, context, conventions); writeElements(Author.class, new PersonSerializer(Constants.AUTHOR), source, objectContext, context, conventions); writeElements(Contributor.class, new PersonSerializer(Constants.CONTRIBUTOR), source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); } }
7,513
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/ControlSerializer.java
/* * 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.ext.serializer.impl; import java.lang.reflect.AccessibleObject; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.Serializer; import org.apache.abdera.ext.serializer.annotation.Draft; import org.apache.abdera.util.Constants; public class ControlSerializer extends ElementSerializer { public ControlSerializer() { super(Constants.CONTROL); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); AccessibleObject accessor = objectContext.getAccessor(Draft.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value instanceof Boolean) { String val = ((Boolean)value).booleanValue() ? "yes" : "no"; ObjectContext valueContext = new ObjectContext(val); Serializer ser = new SimpleElementSerializer(Constants.DRAFT); ser.serialize(val, valueContext, context); } else { ObjectContext valueContext = new ObjectContext(value); context.serialize(value, valueContext); } } writeExtensions(source, objectContext, context, conventions); } }
7,514
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/ContentSerializer.java
/* * 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.ext.serializer.impl; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.lang.reflect.AccessibleObject; import javax.activation.DataHandler; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.SerializationException; import org.apache.abdera.ext.serializer.annotation.Content; import org.apache.abdera.ext.serializer.annotation.MediaType; import org.apache.abdera.ext.serializer.annotation.Value; import org.apache.abdera.model.Div; import org.apache.abdera.model.Document; import org.apache.abdera.model.Element; import org.apache.abdera.model.Content.Type; import org.apache.abdera.util.Constants; import org.apache.abdera.writer.StreamWriter; public class ContentSerializer extends ElementSerializer { public ContentSerializer() { super(Constants.CONTENT); } protected void init(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { Type type = Type.TEXT; Object contentValue = null; ObjectContext valueContext = null; AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions); if (accessor != null && !(source instanceof Element)) { contentValue = eval(accessor, source); valueContext = new ObjectContext(contentValue, source, accessor); Content _content = valueContext.getAnnotation(Content.class); type = _content != null ? _content.type() : type; } else { Content _content = objectContext.getAnnotation(Content.class); type = _content != null ? _content.type() : type; contentValue = source; valueContext = objectContext; } StreamWriter sw = context.getStreamWriter(); sw.startContent(type); writeAttributes(source, objectContext, context, conventions); if (type == Type.MEDIA || type == Type.XML) { String mediatype = null; AccessibleObject mtaccessor = valueContext.getAccessor(MediaType.class, conventions); if (mtaccessor != null) { Object mtvalue = eval(mtaccessor, contentValue); mediatype = mtvalue != null ? toString(mtvalue) : null; } if (mediatype == null) { MediaType mt = valueContext.getAnnotation(MediaType.class); mediatype = mt != null && !mt.value().equals(DEFAULT) ? mt.value() : null; } if (mediatype != null) sw.writeAttribute("type", mediatype); } switch (type) { case TEXT: case HTML: sw.writeElementText(toString(contentValue)); break; case XHTML: Div div = null; if (contentValue instanceof Div) div = (Div)contentValue; else { div = context.getAbdera().getFactory().newDiv(); div.setValue(toString(contentValue)); } context.serialize(div, new ObjectContext(div)); break; case XML: Element el = null; if (contentValue instanceof Element) el = (Element)contentValue; else { StringReader sr = new StringReader(toString(contentValue)); Document<Element> doc = context.getAbdera().getParser().parse(sr); el = doc.getRoot(); } context.serialize(el, new ObjectContext(el)); break; case MEDIA: try { if (contentValue instanceof DataHandler) sw.writeElementText((DataHandler)contentValue); else if (contentValue instanceof InputStream) sw.writeElementText((InputStream)contentValue); else sw.writeElementText(toString(contentValue)); } catch (IOException e) { throw new SerializationException(e); } } } }
7,515
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/DateTimeSerializer.java
/* * 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.ext.serializer.impl; import java.lang.reflect.AccessibleObject; import java.util.Calendar; import java.util.Date; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Value; import org.apache.abdera.model.AtomDate; import org.apache.abdera.writer.StreamWriter; public class DateTimeSerializer extends ElementSerializer { public DateTimeSerializer(QName qname) { super(qname); } public DateTimeSerializer() { super(null); } protected void init(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor()); StreamWriter sw = context.getStreamWriter(); sw.startElement(qname); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); Object value = null; if (!(source instanceof Long)) { AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions); if (accessor != null) { value = eval(accessor, source); } } writeValue(value != null ? value : source, context); } private void writeValue(Object value, SerializationContext context) { StreamWriter sw = context.getStreamWriter(); Date date = null; if (value == null) return; if (value instanceof Date) { date = (Date)value; } else if (value instanceof Calendar) { date = ((Calendar)value).getTime(); } else if (value instanceof Long) { date = new Date(((Long)value).longValue()); } else if (value instanceof String) { date = AtomDate.parse((String)value); } else { date = AtomDate.parse(value.toString()); } sw.writeElementText(date); } }
7,516
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/FeedSerializer.java
/* * 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.ext.serializer.impl; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Entry; import org.apache.abdera.util.Constants; public class FeedSerializer extends SourceSerializer { public FeedSerializer() { super(Constants.FEED); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { super.process(source, objectContext, context, conventions); writeElements(Entry.class, new EntrySerializer(), source, objectContext, context, conventions); } }
7,517
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/WorkspaceSerializer.java
/* * 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.ext.serializer.impl; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Collection; import org.apache.abdera.util.Constants; public class WorkspaceSerializer extends ElementSerializer { public WorkspaceSerializer() { super(Constants.WORKSPACE); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); writeElements(Collection.class, new CollectionSerializer(), source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); } }
7,518
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/CollectionSerializer.java
/* * 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.ext.serializer.impl; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Accept; import org.apache.abdera.ext.serializer.annotation.Categories; import org.apache.abdera.ext.serializer.annotation.Title; import org.apache.abdera.util.Constants; public class CollectionSerializer extends ElementSerializer { public CollectionSerializer() { super(Constants.COLLECTION); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); writeElement(Title.class, new TextSerializer(Constants.TITLE), source, objectContext, context, conventions); writeElements(Accept.class, new SimpleElementSerializer(Constants.ACCEPT), source, objectContext, context, conventions); writeElements(Categories.class, new CategoriesSerializer(), source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); } }
7,519
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/ExtensionSerializer.java
/* * 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.ext.serializer.impl; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; public class ExtensionSerializer extends ElementSerializer { public ExtensionSerializer() { super(null); } public ExtensionSerializer(QName qname) { super(qname); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); } }
7,520
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/IRISerializer.java
/* * 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.ext.serializer.impl; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.writer.StreamWriter; public class IRISerializer extends ElementSerializer { public IRISerializer(QName qname) { super(qname); } public IRISerializer() { super(null); } protected void init(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor()); StreamWriter sw = context.getStreamWriter(); sw.startElement(qname); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); writeTextValue(source, objectContext, context, conventions); } }
7,521
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/LinkSerializer.java
/* * 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.ext.serializer.impl; import java.lang.reflect.AccessibleObject; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.HrefLanguage; import org.apache.abdera.ext.serializer.annotation.Link; import org.apache.abdera.ext.serializer.annotation.MediaType; import org.apache.abdera.ext.serializer.annotation.Rel; import org.apache.abdera.ext.serializer.annotation.Title; import org.apache.abdera.ext.serializer.annotation.Value; import org.apache.abdera.util.Constants; import org.apache.abdera.writer.StreamWriter; public class LinkSerializer extends ElementSerializer { public LinkSerializer() { super(Constants.LINK); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { StreamWriter sw = context.getStreamWriter(); Link _link = objectContext.getAnnotation(Link.class); String rel = null; AccessibleObject accessor = objectContext.getAccessor(Rel.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) rel = toString(value); } if (rel == null) { Rel _rel = objectContext.getAnnotation(Rel.class); if (_rel != null && !_rel.value().equals(DEFAULT)) { rel = _rel.value(); } } if (rel == null && _link != null && !_link.rel().equals(DEFAULT)) { rel = _link.rel(); } if (rel != null) sw.writeAttribute("rel", rel); String type = null; accessor = objectContext.getAccessor(MediaType.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) type = toString(value); } if (type == null) { MediaType _type = objectContext.getAnnotation(MediaType.class); if (_type != null && !_type.value().equals(DEFAULT)) { type = _type.value(); } } if (type == null && _link != null && !_link.type().equals(DEFAULT)) { type = _link.type(); } if (type != null) sw.writeAttribute("type", type); String title = null; accessor = objectContext.getAccessor(Title.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) title = toString(value); } if (title == null && _link != null && !_link.title().equals(DEFAULT)) { title = _link.title(); } if (title != null) sw.writeAttribute("title", title); String hreflang = null; accessor = objectContext.getAccessor(HrefLanguage.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) hreflang = toString(value); } if (hreflang == null) { HrefLanguage _hreflang = objectContext.getAnnotation(HrefLanguage.class); if (_hreflang != null && !_hreflang.value().equals(DEFAULT)) { hreflang = _hreflang.value(); } } if (hreflang == null && _link != null && !_link.hreflang().equals(DEFAULT)) { hreflang = _link.hreflang(); } if (hreflang != null) sw.writeAttribute("hreflang", hreflang); String href = null; accessor = objectContext.getAccessor(Value.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) href = toString(value); } if (href == null) href = toString(source); if (href != null) sw.writeAttribute("href", href); writeAttributes(source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); } }
7,522
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/CategoriesSerializer.java
/* * 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.ext.serializer.impl; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Category; import org.apache.abdera.util.Constants; public class CategoriesSerializer extends ElementSerializer { public CategoriesSerializer() { super(Constants.CATEGORIES); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); writeElements(Category.class, new CategorySerializer(), source, objectContext, context, conventions); } }
7,523
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/ServiceSerializer.java
/* * 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.ext.serializer.impl; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Workspace; import org.apache.abdera.util.Constants; public class ServiceSerializer extends ElementSerializer { public ServiceSerializer() { super(Constants.SERVICE); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); writeElements(Workspace.class, new WorkspaceSerializer(), source, objectContext, context, conventions); } }
7,524
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/SourceSerializer.java
/* * 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.ext.serializer.impl; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Author; import org.apache.abdera.ext.serializer.annotation.Category; import org.apache.abdera.ext.serializer.annotation.Contributor; import org.apache.abdera.ext.serializer.annotation.ID; import org.apache.abdera.ext.serializer.annotation.Icon; import org.apache.abdera.ext.serializer.annotation.Link; import org.apache.abdera.ext.serializer.annotation.Logo; import org.apache.abdera.ext.serializer.annotation.Rights; import org.apache.abdera.ext.serializer.annotation.Subtitle; import org.apache.abdera.ext.serializer.annotation.Title; import org.apache.abdera.ext.serializer.annotation.Updated; import org.apache.abdera.util.Constants; public class SourceSerializer extends ElementSerializer { public SourceSerializer() { super(Constants.SOURCE); } protected SourceSerializer(QName qname) { super(qname); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); writeElement(ID.class, new IRISerializer(Constants.ID), source, objectContext, context, conventions); writeElement(Icon.class, new IRISerializer(Constants.ICON), source, objectContext, context, conventions); writeElement(Logo.class, new IRISerializer(Constants.LOGO), source, objectContext, context, conventions); writeElement(Title.class, new TextSerializer(Constants.TITLE), source, objectContext, context, conventions); writeElement(Subtitle.class, new TextSerializer(Constants.SUBTITLE), source, objectContext, context, conventions); writeElement(Rights.class, new TextSerializer(Constants.RIGHTS), source, objectContext, context, conventions); writeElement(Updated.class, new DateTimeSerializer(Constants.UPDATED), source, objectContext, context, conventions); writeElements(Link.class, new LinkSerializer(), source, objectContext, context, conventions); writeElements(Category.class, new CategorySerializer(), source, objectContext, context, conventions); writeElements(Author.class, new PersonSerializer(Constants.AUTHOR), source, objectContext, context, conventions); writeElements(Contributor.class, new PersonSerializer(Constants.CONTRIBUTOR), source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); } }
7,525
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/PersonSerializer.java
/* * 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.ext.serializer.impl; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Email; import org.apache.abdera.ext.serializer.annotation.URI; import org.apache.abdera.ext.serializer.annotation.Value; import org.apache.abdera.util.Constants; import org.apache.abdera.writer.StreamWriter; public class PersonSerializer extends ElementSerializer { public PersonSerializer(QName qname) { super(qname); } public PersonSerializer() { super(null); } protected void init(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor()); StreamWriter sw = context.getStreamWriter(); sw.startElement(qname); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { writeAttributes(source, objectContext, context, conventions); if (!writeElement(Value.class, new SimpleElementSerializer(Constants.NAME), source, objectContext, context, conventions)) { context.getStreamWriter().startElement(Constants.NAME).writeElementText(toString(source)).endElement(); } writeElement(Email.class, new SimpleElementSerializer(Constants.EMAIL), source, objectContext, context, conventions); writeElement(URI.class, new SimpleElementSerializer(Constants.URI), source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); } }
7,526
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/CategorySerializer.java
/* * 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.ext.serializer.impl; import java.lang.reflect.AccessibleObject; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.ext.serializer.annotation.Category; import org.apache.abdera.ext.serializer.annotation.Label; import org.apache.abdera.ext.serializer.annotation.Scheme; import org.apache.abdera.ext.serializer.annotation.Value; import org.apache.abdera.util.Constants; import org.apache.abdera.writer.StreamWriter; public class CategorySerializer extends ElementSerializer { public CategorySerializer() { super(Constants.CATEGORY); } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { StreamWriter sw = context.getStreamWriter(); Category _category = objectContext.getAnnotation(Category.class); String scheme = null; AccessibleObject accessor = objectContext.getAccessor(Scheme.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) scheme = toString(value); } if (scheme == null) { Scheme _scheme = objectContext.getAnnotation(Scheme.class); if (_scheme != null && !_scheme.value().equals(DEFAULT)) { scheme = _scheme.value(); } } if (scheme == null && _category != null && !_category.scheme().equals(DEFAULT)) { scheme = _category.scheme(); } if (scheme != null) sw.writeAttribute("scheme", scheme); String label = null; accessor = objectContext.getAccessor(Label.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) label = toString(value); } if (label == null) { Label _label = objectContext.getAnnotation(Label.class); if (_label != null && !_label.value().equals(DEFAULT)) { label = _label.value(); } } if (label == null && _category != null && !_category.label().equals(DEFAULT)) { label = _category.label(); } if (label != null) sw.writeAttribute("label", label); String term = null; accessor = objectContext.getAccessor(Value.class, conventions); if (accessor != null) { Object value = eval(accessor, source); if (value != null) term = toString(value); } if (term == null) term = toString(source); if (term != null) sw.writeAttribute("term", term); writeAttributes(source, objectContext, context, conventions); writeExtensions(source, objectContext, context, conventions); } }
7,527
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/FOMSerializer.java
/* * 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.ext.serializer.impl; import java.util.List; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.BaseSerializer; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.model.Comment; import org.apache.abdera.model.Element; import org.apache.abdera.model.ProcessingInstruction; import org.apache.abdera.model.TextValue; import org.apache.abdera.writer.StreamWriter; import org.apache.abdera.xpath.XPath; public class FOMSerializer extends BaseSerializer { public FOMSerializer() { } protected void finish(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { } protected void init(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { } protected void process(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { StreamWriter sw = context.getStreamWriter(); if (!(source instanceof Element)) return; Element element = (Element)source; sw.startElement(element.getQName()); for (QName attr : element.getAttributes()) sw.writeAttribute(attr, element.getAttributeValue(attr)); XPath xpath = context.getAbdera().getXPath(); List<?> children = xpath.selectNodes("node()", element); for (Object child : children) { if (child instanceof Element) { process(child, new ObjectContext(child), context, conventions); } else if (child instanceof Comment) { Comment comment = (Comment)child; sw.writeComment(comment.getText()); } else if (child instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction)child; sw.writePI(pi.getText(), pi.getTarget()); } else if (child instanceof TextValue) { TextValue tv = (TextValue)child; sw.writeElementText(tv.getText()); } } sw.endElement(); } }
7,528
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/impl/ElementSerializer.java
/* * 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.ext.serializer.impl; import javax.xml.namespace.QName; import org.apache.abdera.ext.serializer.BaseSerializer; import org.apache.abdera.ext.serializer.Conventions; import org.apache.abdera.ext.serializer.ObjectContext; import org.apache.abdera.ext.serializer.SerializationContext; import org.apache.abdera.writer.StreamWriter; public class ElementSerializer extends BaseSerializer { protected final QName qname; public ElementSerializer(QName qname) { this.qname = qname; } public ElementSerializer() { this.qname = null; } protected void finish(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { context.getStreamWriter().endElement(); } protected void init(Object source, ObjectContext objectContext, SerializationContext context, Conventions conventions) { QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor()); StreamWriter sw = context.getStreamWriter(); sw.startElement(qname); writeCommon(source, objectContext, context, conventions); } }
7,529
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Feed.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.FeedSerializer; @Retention(RUNTIME) @Target( {TYPE}) @Convention(".*feed") @Serializer(FeedSerializer.class) public @interface Feed { }
7,530
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Convention.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {ANNOTATION_TYPE}) public @interface Convention { String value(); }
7,531
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Published.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.DateTimeSerializer; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*published") @Serializer(DateTimeSerializer.class) public @interface Published { }
7,532
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Extension.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.ExtensionSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*extension") @Serializer(ExtensionSerializer.class) public @interface Extension { boolean simple() default false; String name() default "##default"; String ns() default "##default"; String prefix() default "##default"; }
7,533
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Text.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.TextSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*text") @Serializer(TextSerializer.class) public @interface Text { org.apache.abdera.model.Text.Type type() default org.apache.abdera.model.Text.Type.TEXT; }
7,534
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Label.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*label") public @interface Label { String value() default "##default"; }
7,535
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Link.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.LinkSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*link") @Serializer(LinkSerializer.class) public @interface Link { String rel() default "##default"; String type() default "##default"; String hreflang() default "##default"; String title() default "##default"; }
7,536
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/ID.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.IRISerializer; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*id") @Serializer(IRISerializer.class) public @interface ID { }
7,537
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Control.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.ControlSerializer; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*control") @Serializer(ControlSerializer.class) public @interface Control { }
7,538
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Email.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*email") public @interface Email { }
7,539
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Collection.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.CollectionSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*collection") @Serializer(CollectionSerializer.class) public @interface Collection { }
7,540
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Title.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.TextSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*title") @Serializer(TextSerializer.class) public @interface Title { }
7,541
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Edited.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.DateTimeSerializer; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*edited") @Serializer(DateTimeSerializer.class) public @interface Edited { }
7,542
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Rights.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.TextSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*rights") @Serializer(TextSerializer.class) public @interface Rights { }
7,543
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/BaseURI.java
/* * 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.ext.serializer.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(".*baseuri") public @interface BaseURI { }
7,544
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/EntityTag.java
/* * 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.ext.serializer.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 { }
7,545
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Category.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.CategorySerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*category|.*categories") @Serializer(CategorySerializer.class) public @interface Category { String scheme() default "##default"; String label() default "##default"; }
7,546
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Rel.java
/* * 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.ext.serializer.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(".*rel") public @interface Rel { String value() default "##default"; }
7,547
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Length.java
/* * 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.ext.serializer.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(".*hreflength") public @interface Length { }
7,548
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Updated.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.DateTimeSerializer; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*updated") @Serializer(DateTimeSerializer.class) public @interface Updated { }
7,549
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Logo.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.IRISerializer; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*logo") @Serializer(IRISerializer.class) public @interface Logo { }
7,550
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Author.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*author(?:s)?") public @interface Author { }
7,551
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Icon.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.IRISerializer; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*icon") @Serializer(IRISerializer.class) public @interface Icon { }
7,552
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Contributor.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.PersonSerializer; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*contributor") @Serializer(PersonSerializer.class) public @interface Contributor { }
7,553
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Accept.java
/* * 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.ext.serializer.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(".*accept") public @interface Accept { }
7,554
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/HrefLanguage.java
/* * 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.ext.serializer.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(".*hreflang|.*hreflanguage") public @interface HrefLanguage { String value() default "##default"; }
7,555
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/MediaType.java
/* * 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.ext.serializer.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(".*mediatype") public @interface MediaType { String value() default "##default"; }
7,556
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Person.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.PersonSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*person") @Serializer(PersonSerializer.class) public @interface Person { }
7,557
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Service.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.ServiceSerializer; @Retention(RUNTIME) @Target( {TYPE}) @Convention(".*service") @Serializer(ServiceSerializer.class) public @interface Service { }
7,558
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/IRI.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.IRISerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*iri") @Serializer(IRISerializer.class) public @interface IRI { }
7,559
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Subtitle.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.TextSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*subtitle") @Serializer(TextSerializer.class) public @interface Subtitle { }
7,560
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/LastModified.java
/* * 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.ext.serializer.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 { }
7,561
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/URI.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*uri") public @interface URI { String value() default "##default"; }
7,562
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Attribute.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*attribute") public @interface Attribute { String name() default "##default"; String ns() default "##default"; String prefix() default "##default"; }
7,563
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Value.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.TYPE; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*value") public @interface Value { }
7,564
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Source.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.SourceSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*source") @Serializer(SourceSerializer.class) public @interface Source { }
7,565
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Language.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.TYPE; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*lang|.*language") public @interface Language { String value() default "##default"; }
7,566
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Serializer.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD, ANNOTATION_TYPE}) public @interface Serializer { Class<? extends org.apache.abdera.ext.serializer.Serializer> value(); }
7,567
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/DateTime.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.DateTimeSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*date|.*time") @Serializer(DateTimeSerializer.class) public @interface DateTime { }
7,568
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Scheme.java
/* * 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.ext.serializer.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(".*scheme") public @interface Scheme { String value() default "##default"; }
7,569
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Src.java
/* * 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.ext.serializer.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(".*src") public @interface Src { }
7,570
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Workspace.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.WorkspaceSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*workspace") @Serializer(WorkspaceSerializer.class) public @interface Workspace { }
7,571
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Draft.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Retention(RUNTIME) @Target( {METHOD, FIELD}) @Convention(".*draft") public @interface Draft { }
7,572
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Version.java
/* * 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.ext.serializer.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(".*version") public @interface Version { String value() default "##default"; }
7,573
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Entry.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.EntrySerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*entry|.*entries") @Serializer(EntrySerializer.class) public @interface Entry { }
7,574
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Summary.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.TextSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*summary") @Serializer(TextSerializer.class) public @interface Summary { }
7,575
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Content.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.ContentSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*content") @Serializer(ContentSerializer.class) public @interface Content { org.apache.abdera.model.Content.Type type() default org.apache.abdera.model.Content.Type.TEXT; }
7,576
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Categories.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.CategoriesSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*categories") @Serializer(CategoriesSerializer.class) public @interface Categories { }
7,577
0
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer
Create_ds/abdera/extensions/serializer/src/main/java/org/apache/abdera/ext/serializer/annotation/Generator.java
/* * 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.ext.serializer.annotation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import org.apache.abdera.ext.serializer.impl.GeneratorSerializer; @Retention(RUNTIME) @Target( {TYPE, METHOD, FIELD}) @Convention(".*generator") @Serializer(GeneratorSerializer.class) public @interface Generator { String version() default "##default"; String uri() default "##default"; }
7,578
0
Create_ds/abdera/extensions/oauth/src/test/java/org/apache/abdera/ext
Create_ds/abdera/extensions/oauth/src/test/java/org/apache/abdera/ext/oauth/OAuthSchemeTest.java
/* * 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.ext.oauth; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.Test; public class OAuthSchemeTest { OAuthScheme scheme = new OAuthScheme(); OAuthCredentials credentials; @Test public void testAuthenticate() throws Exception { credentials = new OAuthCredentials("dpf43f3p2l4k3l03", "nnch734d00sl2jdk", "HMAC-SHA1", "http://photos.example.net/"); String header = scheme.authenticate(credentials, "get", "http://photos.example.net?file=vacation.jpg"); assertNotNull(header); String regex = "OAuth realm=\"[^\"]+\", oauth_consumer_key=\"[^\"]+\", " + "oauth_token=\"[^\"]+\", oauth_signature_method=\"[^\"]+\", oauth_signature=\"[^\"]+\", " + "oauth_timestamp=\"[^\"]+\", oauth_nonce=\"[^\"]+\"(, oauth_version=\"[^\"]+\")?"; assertTrue(header.matches(regex)); } }
7,579
0
Create_ds/abdera/extensions/oauth/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthCredentials.java
/* * 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.ext.oauth; import java.security.cert.Certificate; import org.apache.commons.httpclient.Credentials; /** * OAuth credentials * * @see http://oauth.org * @see http://oauth.googlecode.com/svn/spec/branches/1.0/drafts/7/spec.html * @author David Calavera */ public class OAuthCredentials implements Credentials { private String consumerKey; private String token; private String signatureMethod; private String realm; private String version; private Certificate cert; public OAuthCredentials() { super(); } public OAuthCredentials(String consumerKey, String token, String signatureMethod, String realm) { this(consumerKey, token, signatureMethod, realm, "1.0"); } public OAuthCredentials(String consumerKey, String token, String signatureMethod, String realm, String version) { this(consumerKey, token, signatureMethod, realm, version, null); } public OAuthCredentials(String consumerKey, String token, String signatureMethod, String realm, String version, Certificate cert) { super(); this.consumerKey = consumerKey; this.token = token; this.signatureMethod = signatureMethod; this.realm = realm; this.version = version; this.cert = cert; } public String getConsumerKey() { return consumerKey; } public void setConsumerKey(String consumerKey) { this.consumerKey = consumerKey; } public String getSignatureMethod() { return signatureMethod; } public void setSignatureMethod(String signatureMethod) { this.signatureMethod = signatureMethod; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public String getRealm() { return realm; } public void setRealm(String realm) { this.realm = realm; } public String getVersion() { return version; } public void setVersion(String version) { this.version = version; } public Certificate getCert() { return cert; } public void setCert(Certificate cert) { this.cert = cert; } }
7,580
0
Create_ds/abdera/extensions/oauth/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/oauth/src/main/java/org/apache/abdera/ext/oauth/OAuthScheme.java
/* * 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.ext.oauth; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.security.SecureRandom; import java.security.cert.Certificate; import java.util.Date; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.Mac; import org.apache.abdera.protocol.client.AbderaClient; import org.apache.abdera.protocol.client.util.MethodHelper; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.auth.AuthScheme; import org.apache.commons.httpclient.auth.AuthenticationException; import org.apache.commons.httpclient.auth.RFC2617Scheme; import org.apache.commons.httpclient.methods.DeleteMethod; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.methods.OptionsMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; /** * OAuth Scheme implementation for use with HTTP Commons AbderaClient * * @see http://oauth.org * @see http://oauth.googlecode.com/svn/spec/branches/1.0/drafts/7/spec.html * @author David Calavera */ public class OAuthScheme extends RFC2617Scheme implements AuthScheme { private enum OAUTH_KEYS { OAUTH_CONSUMER_KEY, OAUTH_TOKEN, OAUTH_SIGNATURE_METHOD, OAUTH_TIMESTAMP, OAUTH_NONCE, OAUTH_VERSION, OAUTH_SIGNATURE; public String toLowerCase() { return this.toString().toLowerCase(); } } private final int NONCE_LENGTH = 16; public static void register(AbderaClient abderaClient, boolean exclusive) { AbderaClient.registerScheme("OAuth", OAuthScheme.class); if (exclusive) ((AbderaClient)abderaClient).setAuthenticationSchemePriority("OAuth"); else ((AbderaClient)abderaClient).setAuthenticationSchemeDefaults(); } public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException { return authenticate(credentials, resolveMethod(method, uri)); } public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException { if (credentials instanceof OAuthCredentials) { OAuthCredentials oauthCredentials = (OAuthCredentials)credentials; String nonce = generateNonce(); long timestamp = new Date().getTime() / 1000; String signature = generateSignature(oauthCredentials, method, nonce, timestamp); return "OAuth realm=\"" + oauthCredentials.getRealm() + "\", " + OAUTH_KEYS.OAUTH_CONSUMER_KEY.toLowerCase() + "=\"" + oauthCredentials.getConsumerKey() + "\", " + OAUTH_KEYS.OAUTH_TOKEN.toLowerCase() + "=\"" + oauthCredentials.getToken() + "\", " + OAUTH_KEYS.OAUTH_SIGNATURE_METHOD.toLowerCase() + "=\"" + oauthCredentials.getSignatureMethod() + "\", " + OAUTH_KEYS.OAUTH_SIGNATURE.toLowerCase() + "=\"" + signature + "\", " + OAUTH_KEYS.OAUTH_TIMESTAMP.toLowerCase() + "=\"" + timestamp + "\", " + OAUTH_KEYS.OAUTH_NONCE.toLowerCase() + "=\"" + nonce + "\", " + OAUTH_KEYS.OAUTH_VERSION.toLowerCase() + "=\"" + oauthCredentials.getVersion() + "\""; } else { return null; } } private HttpMethod resolveMethod(String method, String uri) throws AuthenticationException { if (method.equalsIgnoreCase("get")) { return new GetMethod(uri); } else if (method.equalsIgnoreCase("post")) { return new PostMethod(uri); } else if (method.equalsIgnoreCase("put")) { return new PutMethod(uri); } else if (method.equalsIgnoreCase("delete")) { return new DeleteMethod(uri); } else if (method.equalsIgnoreCase("head")) { return new HeadMethod(uri); } else if (method.equalsIgnoreCase("options")) { return new OptionsMethod(uri); } else { // throw new AuthenticationException("unsupported http method : " + method); return new MethodHelper.ExtensionMethod(method, uri); } } private String generateSignature(OAuthCredentials credentials, HttpMethod method, String nonce, long timestamp) throws AuthenticationException { try { String baseString = method.getName().toUpperCase() + method.getURI().toString() + OAUTH_KEYS.OAUTH_CONSUMER_KEY.toLowerCase() + "=" + credentials.getConsumerKey() + OAUTH_KEYS.OAUTH_TOKEN.toLowerCase() + "=" + credentials.getToken() + OAUTH_KEYS.OAUTH_SIGNATURE_METHOD.toLowerCase() + "=" + credentials.getSignatureMethod() + OAUTH_KEYS.OAUTH_TIMESTAMP.toLowerCase() + "=" + timestamp + OAUTH_KEYS.OAUTH_NONCE.toLowerCase() + "=" + nonce + OAUTH_KEYS.OAUTH_VERSION.toLowerCase() + "=" + credentials.getVersion(); return sign(credentials.getSignatureMethod(), URLEncoder.encode(baseString, "UTF-8"), credentials.getCert()); } catch (URIException e) { throw new AuthenticationException(e.getMessage(), e); } catch (UnsupportedEncodingException e) { throw new AuthenticationException(e.getMessage(), e); } } private String generateNonce() throws AuthenticationException { try { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); byte[] temp = new byte[NONCE_LENGTH]; sr.nextBytes(temp); String n = new String(Hex.encodeHex(temp)); return n; } catch (Exception e) { throw new AuthenticationException(e.getMessage(), e); } } private String sign(String method, String baseString, Certificate cert) throws AuthenticationException { if (method.equalsIgnoreCase("HMAC-MD5") || method.equalsIgnoreCase("HMAC-SHA1")) { try { String[] tokens = method.split("-"); String methodName = tokens[0].substring(0, 1).toUpperCase() + tokens[0].substring(1).toLowerCase() + tokens[1]; KeyGenerator kg = KeyGenerator.getInstance(methodName); Mac mac = Mac.getInstance(kg.getAlgorithm()); mac.init(kg.generateKey()); byte[] result = mac.doFinal(baseString.getBytes()); return new String(Base64.encodeBase64(result)); } catch (Exception e) { throw new AuthenticationException(e.getMessage(), e); } } else if (method.equalsIgnoreCase("md5")) { return new String(Base64.encodeBase64(DigestUtils.md5(baseString))); } else if (method.equalsIgnoreCase("sha1")) { return new String(Base64.encodeBase64(DigestUtils.sha(baseString))); } else if (method.equalsIgnoreCase("RSA-SHA1")) { if (cert == null) { throw new AuthenticationException("a cert is mandatory to use SHA1 with RSA"); } try { Cipher cipher = Cipher.getInstance("SHA1withRSA"); cipher.init(Cipher.ENCRYPT_MODE, cert); byte[] result = cipher.doFinal(baseString.getBytes()); return new String(Base64.encodeBase64(result)); } catch (Exception e) { throw new AuthenticationException(e.getMessage(), e); } } else { throw new AuthenticationException("unsupported algorithm method: " + method); } } public String getSchemeName() { return "OAuth"; } public boolean isComplete() { return true; } public boolean isConnectionBased() { return true; } }
7,581
0
Create_ds/abdera/extensions/sharing/src/test/java/org/apache/abdera/test/ext
Create_ds/abdera/extensions/sharing/src/test/java/org/apache/abdera/test/ext/sharing/SharingTest.java
/* * 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.test.ext.sharing; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.StringReader; import java.util.Date; import java.util.List; import org.apache.abdera.Abdera; import org.apache.abdera.ext.sharing.Conflicts; import org.apache.abdera.ext.sharing.History; import org.apache.abdera.ext.sharing.Related; import org.apache.abdera.ext.sharing.Sharing; import org.apache.abdera.ext.sharing.SharingHelper; import org.apache.abdera.ext.sharing.Sync; import org.apache.abdera.ext.sharing.Unpublished; import org.apache.abdera.ext.sharing.SharingHelper.ConflictResolver; import org.apache.abdera.factory.Factory; import org.apache.abdera.model.AtomDate; import org.apache.abdera.model.Document; import org.apache.abdera.model.Entry; import org.apache.abdera.model.Feed; import org.junit.Test; public class SharingTest { @Test public void testSharingFactory() throws Exception { Abdera abdera = new Abdera(); Factory factory = abdera.getFactory(); Conflicts conflicts = factory.newElement(SharingHelper.SSE_CONFLICTS); assertNotNull(conflicts); History history = factory.newElement(SharingHelper.SSE_HISTORY); assertNotNull(history); Related related = factory.newElement(SharingHelper.SSE_RELATED); assertNotNull(related); Sharing sharing = factory.newElement(SharingHelper.SSE_SHARING); assertNotNull(sharing); Sync sync = factory.newElement(SharingHelper.SSE_SYNC); assertNotNull(sync); Unpublished unpub = factory.newElement(SharingHelper.SSE_UNPUBLISHED); assertNotNull(unpub); } @Test public void testSimpleExample() throws Exception { String ex = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<feed xmlns=\"http://www.w3.org/2005/Atom\" " + "xmlns:sx=\"http://feedsync.org/2007/feedsync\">" + "<title>To Do List</title>" + "<subtitle>A list of items to do</subtitle>" + "<link rel=\"self\" href=\"http://example.com/partial.xml\"/>" + "<author>" + "<name>Ray Ozzie</name>" + "</author>" + "<updated>2005-05-21T11:43:33Z</updated>" + "<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0aaa</id>" + "<sx:sharing since=\"2005-02-13T18:30:02Z\" " + "until=\"2005-05-23T18:30:02Z\" >" + "<sx:related link=\"http://example.com/all.xml\" type=\"complete\" />" + "<sx:related link=\"http://example.com/B.xml\" type=\"aggregated\" " + "title=\"To Do List (Jacks Copy)\" />" + "</sx:sharing>" + "<entry>" + "<title>Buy groceries</title>" + "<content>Get milk, eggs, butter and bread</content>" + "<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0aa0</id>" + "<author>" + "<name>Ray Ozzie</name>" + "</author>" + "<updated>2005-05-21T11:43:33Z</updated>" + "<sx:sync id=\"item 1_myapp_2005-05-21T11:43:33Z\" updates=\"3\">" + "<sx:history sequence=\"3\" when=\"2005-05-21T11:43:33Z\" by=\"JEO2000\"/>" + "<sx:history sequence=\"2\" when=\"2005-05-21T10:43:33Z\" by=\"REO1750\"/>" + "<sx:history sequence=\"1\" when=\"2005-05-21T09:43:33Z\" by=\"REO1750\"/>" + "</sx:sync>" + "</entry></feed>"; StringReader rdr = new StringReader(ex); Abdera abdera = new Abdera(); Document<Feed> doc = abdera.getParser().parse(rdr); Feed feed = doc.getRoot(); assertTrue(SharingHelper.hasSharing(feed)); Sharing sharing = SharingHelper.getSharing(feed, false); assertNotNull(sharing); Date since = AtomDate.parse("2005-02-13T18:30:02Z"); Date until = AtomDate.parse("2005-05-23T18:30:02Z"); assertEquals(since, sharing.getSince()); assertEquals(until, sharing.getUntil()); assertEquals(2, sharing.getRelated().size()); Related rel = sharing.getRelated().get(0); assertEquals("http://example.com/all.xml", rel.getLink().toString()); assertEquals(Related.Type.COMPLETE, rel.getType()); rel = sharing.getRelated().get(1); assertEquals("http://example.com/B.xml", rel.getLink().toString()); assertEquals(Related.Type.AGGREGATED, rel.getType()); Entry entry = feed.getEntries().get(0); Sync sync = SharingHelper.getSync(entry, false); assertNotNull(sync); assertEquals("item 1_myapp_2005-05-21T11:43:33Z", sync.getId()); assertEquals(3, sync.getUpdates()); assertEquals(3, sync.getHistory().size()); Date d1 = AtomDate.parse("2005-05-21T11:43:33Z"); Date d2 = AtomDate.parse("2005-05-21T10:43:33Z"); Date d3 = AtomDate.parse("2005-05-21T09:43:33Z"); History history = sync.getHistory().get(0); assertEquals(3, history.getSequence()); assertEquals(d1, history.getWhen()); assertEquals("JEO2000", history.getBy()); history = sync.getHistory().get(1); assertEquals(2, history.getSequence()); assertEquals(d2, history.getWhen()); assertEquals("REO1750", history.getBy()); history = sync.getHistory().get(2); assertEquals(1, history.getSequence()); assertEquals(d3, history.getWhen()); assertEquals("REO1750", history.getBy()); } @Test public void testCreateOperation() throws Exception { Abdera abdera = new Abdera(); Entry entry = SharingHelper.createEntry(abdera, "jms"); Sync sync = SharingHelper.getSync(entry, false); assertNotNull(sync); assertNotNull(sync.getId()); assertEquals(1, sync.getUpdates()); assertEquals(1, sync.getHistory().size()); History history = sync.getTopmostHistory(); assertEquals(1, history.getSequence()); assertEquals("jms", history.getBy()); } @Test public void testUpdateOperation() throws Exception { Abdera abdera = new Abdera(); Entry entry = SharingHelper.createEntry(abdera, "jms"); SharingHelper.updateEntry(entry, "jms"); Sync sync = SharingHelper.getSync(entry, false); assertNotNull(sync); assertNotNull(sync.getId()); assertEquals(2, sync.getUpdates()); assertEquals(2, sync.getHistory().size()); History history = sync.getTopmostHistory(); assertEquals(2, history.getSequence()); assertEquals("jms", history.getBy()); } @Test public void testDeleteOperation() throws Exception { Abdera abdera = new Abdera(); Entry entry = SharingHelper.createEntry(abdera, "jms"); Sync sync = SharingHelper.getSync(entry, false); assertNotNull(sync); assertFalse(sync.isDeleted()); SharingHelper.deleteEntry(entry, "jms"); sync = SharingHelper.getSync(entry, false); assertNotNull(sync); assertTrue(sync.isDeleted()); assertNotNull(sync.getId()); assertEquals(2, sync.getUpdates()); assertEquals(2, sync.getHistory().size()); History history = sync.getTopmostHistory(); assertEquals(2, history.getSequence()); assertEquals("jms", history.getBy()); } @Test public void testConflict() throws Exception { Abdera abdera = new Abdera(); Feed f1 = abdera.newFeed(); Feed f2 = abdera.newFeed(); Entry e1 = SharingHelper.createEntry(abdera, "jms", f1); Entry e2 = SharingHelper.createEntry(abdera, "jms", f2); Sync s1 = SharingHelper.getSync(e1, false); Sync s2 = SharingHelper.getSync(e2, false); s2.setId(s1.getId()); SharingHelper.updateEntry(e1, "bob"); SharingHelper.updateEntry(e2, "jms"); SharingHelper.mergeFeeds(f1, f2); assertEquals(1, f2.getEntries().size()); Entry entry = f2.getEntries().get(0); Sync sync = SharingHelper.getSync(entry); Conflicts conflicts = sync.getConflicts(); assertNotNull(conflicts); assertEquals(1, conflicts.getEntries().size()); Entry conflict = conflicts.getEntries().get(0); assertNotNull(conflict); ConflictResolver r = new ConflictResolver() { public Entry resolve(Entry entry, List<Entry> conflicts) { Sync sync = SharingHelper.getSync(entry, false); Conflicts c = sync.getConflicts(false); if (c != null) c.discard(); return entry; // take the latest } }; entry = SharingHelper.resolveConflicts(entry, r, "jms"); sync = SharingHelper.getSync(entry); conflicts = sync.getConflicts(); assertNull(conflicts); assertEquals(4, sync.getHistory().size()); } @Test public void testUnpublish() throws Exception { Abdera abdera = new Abdera(); Feed feed = abdera.newFeed(); Entry entry = feed.addEntry(); assertEquals(1, feed.getEntries().size()); entry = SharingHelper.unpublish(entry); assertEquals(0, feed.getEntries().size()); Unpublished unpub = SharingHelper.getUnpublished(feed); assertEquals(1, unpub.getEntries().size()); SharingHelper.republish(entry); unpub = SharingHelper.getUnpublished(feed); assertEquals(0, unpub.getEntries().size()); assertEquals(1, feed.getEntries().size()); } }
7,582
0
Create_ds/abdera/extensions/sharing/src/test/java/org/apache/abdera/test/ext
Create_ds/abdera/extensions/sharing/src/test/java/org/apache/abdera/test/ext/sharing/TestSuite.java
/* * 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.test.ext.sharing; import org.junit.internal.TextListener; import org.junit.runner.JUnitCore; public class TestSuite { public static void main(String[] args) { JUnitCore runner = new JUnitCore(); runner.addListener(new TextListener(System.out)); runner.run(SharingTest.class); } }
7,583
0
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext/sharing/Conflicts.java
/* * 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.ext.sharing; import java.util.List; import javax.xml.namespace.QName; import org.apache.abdera.factory.Factory; import org.apache.abdera.model.Element; import org.apache.abdera.model.Entry; import org.apache.abdera.model.ExtensibleElementWrapper; import org.apache.abdera.util.Constants; public class Conflicts extends ExtensibleElementWrapper { public Conflicts(Element internal) { super(internal); } public Conflicts(Factory factory, QName qname) { super(factory, qname); } public List<Entry> getEntries() { return getExtensions(Constants.ENTRY); } public void addEntry(Entry entry) { addExtension((Entry)entry.clone()); } }
7,584
0
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext/sharing/Sharing.java
/* * 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.ext.sharing; import java.util.Date; import java.util.List; import javax.xml.namespace.QName; import org.apache.abdera.factory.Factory; import org.apache.abdera.model.AtomDate; import org.apache.abdera.model.Element; import org.apache.abdera.model.ExtensibleElementWrapper; public class Sharing extends ExtensibleElementWrapper { public Sharing(Element internal) { super(internal); } public Sharing(Factory factory, QName qname) { super(factory, qname); } public Date getSince() { String since = getAttributeValue("since"); return since != null ? AtomDate.parse(since) : null; } public void setSince(Date since) { if (since != null) { setAttributeValue("since", AtomDate.format(since)); } else { removeAttribute(new QName("since")); } } public Date getUntil() { String until = getAttributeValue("until"); return until != null ? AtomDate.parse(until) : null; } public void setUntil(Date until) { if (until != null) { setAttributeValue("until", AtomDate.format(until)); } else { removeAttribute(new QName("until")); } } public Date getExpires() { String expires = getAttributeValue("expires"); return expires != null ? AtomDate.parse(expires) : null; } public void setExpires(Date expires) { if (expires != null) { setAttributeValue("expires", AtomDate.format(expires)); } else { removeAttribute(new QName("expires")); } } public List<Related> getRelated() { return getExtensions(SharingHelper.SSE_RELATED); } public void addRelated(Related related) { addExtension(related); } public Related addRelated() { return getFactory().newElement(SharingHelper.SSE_RELATED, this); } public Related addRelated(String link, String title, Related.Type type) { Related related = addRelated(); related.setLink(link); related.setTitle(title); related.setType(type); return related; } }
7,585
0
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext/sharing/SharingHelper.java
/* * 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.ext.sharing; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.namespace.QName; import org.apache.abdera.Abdera; import org.apache.abdera.model.Base; import org.apache.abdera.model.Entry; import org.apache.abdera.model.Feed; import org.apache.abdera.model.Source; public class SharingHelper { public static final String SSENS = "http://feedsync.org/2007/feedsync"; public static final String SSEPFX = "sx"; public static final QName SSE_SHARING = new QName(SSENS, "sharing", SSEPFX); public static final QName SSE_RELATED = new QName(SSENS, "related", SSEPFX); public static final QName SSE_CONFLICTS = new QName(SSENS, "conflicts", SSEPFX); public static final QName SSE_HISTORY = new QName(SSENS, "history", SSEPFX); public static final QName SSE_SYNC = new QName(SSENS, "sync", SSEPFX); public static final QName SSE_UNPUBLISHED = new QName(SSENS, "unpublished", SSEPFX); protected static boolean isTrue(String value) { return value.equalsIgnoreCase("true") || value.equals("1") || value.equals("-1") || value.equals("yes"); } public static <T extends Source> Sharing getSharing(T source) { return getSharing(source, false); } public static <T extends Source> Sharing getSharing(T source, boolean create) { Sharing sharing = source.getExtension(SSE_SHARING); if (sharing == null && create) sharing = source.addExtension(SSE_SHARING); return sharing; } public static <T extends Source> boolean hasSharing(T source) { return getSharing(source) != null; } public static Unpublished getUnpublished(Feed feed) { return getUnpublished(feed, false); } public static Unpublished getUnpublished(Feed feed, boolean create) { Unpublished unpub = feed.getExtension(SSE_UNPUBLISHED); if (unpub == null && create) unpub = feed.addExtension(SSE_UNPUBLISHED); return unpub; } public static Sync getSync(Entry entry) { return getSync(entry, false); } public static Sync getSync(Entry entry, boolean create) { Sync sync = entry.getExtension(SSE_SYNC); if (sync == null && create) sync = entry.addExtension(SSE_SYNC); return sync; } public static boolean hasSync(Entry entry) { return getSync(entry, false) != null; } public static Entry createEntry(Abdera abdera, String by) { return createEntry(abdera, by, null); } public static Entry createEntry(Abdera abdera, String by, Feed feed) { Entry entry = feed != null ? feed.addEntry() : abdera.newEntry(); entry.newId(); Sync sync = getSync(entry, true); sync.setId(entry.getId().toString()); sync.setUpdates(1); History history = sync.addHistory(); history.setSequence(sync.getUpdates()); history.setWhen(new Date()); history.setBy(by); return entry; } public static void deleteEntry(Entry entry, String by) { Sync sync = getSync(entry, true); sync.incrementUpdates(); sync.setDeleted(true); History history = sync.addHistory(); history.setSequence(sync.getUpdates()); history.setWhen(new Date()); history.setBy(by); } public static void updateEntry(Entry entry, String by) { Sync sync = getSync(entry, true); sync.incrementUpdates(); History history = sync.addHistory(); history.setSequence(sync.getUpdates()); history.setWhen(new Date()); history.setBy(by); } public static Map<String, Entry> getSyncIdMap(Feed feed) { Map<String, Entry> entries = new HashMap<String, Entry>(); for (Entry entry : feed.getEntries()) { Sync sync = getSync(entry, false); if (sync != null) { String id = sync.getId(); if (id != null) { entries.put(id, entry); } } } return entries; } public static boolean isSubsumed(Sync s1, Sync s2) { if (s1 == null && s2 == null) return false; if (s1 == null && s2 != null) return true; if (s1 != null && s2 == null) return false; if (s1.equals(s2)) return false; if (!s1.getId().equals(s2.getId())) return false; History h1 = s1.getFirstChild(SSE_HISTORY); for (History h2 : s2.getHistory()) { if (isSubsumed(h1, h2)) return true; } return false; } public static boolean isSubsumed(History h1, History h2) { if (h1 == null && h2 == null) return false; if (h1 == null && h2 != null) return true; if (h1 != null && h2 == null) return false; if (h1.equals(h2)) return false; String h1by = h1.getBy(); String h2by = h2.getBy(); if (h1by != null) { if (h2by != null && h1by.equals(h2by) && h2.getSequence() >= h1.getSequence()) return true; } else { if (h2by == null && h1.getWhen().equals(h2.getWhen()) && h1.getSequence() == h2.getSequence()) return true; } return false; } public static Sync pickWinner(Sync s1, Sync s2) { if (s1 == null && s2 == null) return null; if (s1 == null && s2 != null) return s2; if (s1 != null && s2 == null) return s1; if (s1.equals(s2)) return s1; if (!s1.getId().equals(s2.getId())) return null; if (s1.getUpdates() > s2.getUpdates()) return s1; if (s1.getUpdates() == s2.getUpdates()) { History h1 = s1.getTopmostHistory(); History h2 = s2.getTopmostHistory(); Date d1 = h1.getWhen(); Date d2 = h2.getWhen(); if (d1 != null && d2 == null) return s1; if (d1.after(d2)) return s1; if (d1.equals(d2)) { String b1 = h1.getBy(); String b2 = h2.getBy(); if (b1 != null && b2 == null) return s1; if (b1.compareTo(b2) > 0) return s1; } } return s2; } private static List<Entry> getConflicts(Entry entry) { List<Entry> list = new ArrayList<Entry>(); Sync sync = getSync(entry, false); if (sync != null) { Conflicts conflicts = sync.getConflicts(false); if (conflicts != null) { list.addAll(conflicts.getEntries()); } } list.add(entry); return list; } private static Entry compareConflicts(Entry w, List<Entry> outerList, List<Entry> innerList, List<Entry> results) { Entry[] outer = outerList.toArray(new Entry[outerList.size()]); Entry[] inner = innerList.toArray(new Entry[innerList.size()]); for (Entry x : outer) { Sync s1 = getSync(x, false); boolean ok = true; for (Entry y : inner) { Sync s2 = getSync(y, false); if (isSubsumed(s1, s2)) { outerList.remove(s1); ok = false; break; } } if (ok) { results.add(x); if (w == null) w = x; else { Sync s2 = getSync(w); if (pickWinner(s1, s2) == s1) w = x; } } } return w; } public static void mergeFeeds(Feed source, Feed dest) { Map<String, Entry> destentries = getSyncIdMap(dest); for (Entry entry : source.getEntries()) { Sync s2 = getSync(entry, false); if (s2 != null) { String id = s2.getId(); if (id != null) { Entry existing = destentries.get(id); if (existing == null) { Entry e = (Entry)entry.clone(); dest.addEntry(e); } else { Sync s1 = getSync(existing, false); List<Entry> c1 = getConflicts(existing); List<Entry> c2 = getConflicts(entry); List<Entry> m = new ArrayList<Entry>(); Entry w = null; w = compareConflicts(w, c1, c2, m); w = compareConflicts(w, c2, c1, m); // if (w != null) dest.addEntry((Entry)w.clone()); if (s1.isNoConflicts()) return; if (m.size() > 0) { Sync sync = getSync(w, true); sync.setConflicts(null); Conflicts conflicts = sync.getConflicts(true); for (Entry e : m) { if (e != w) conflicts.addEntry(e); } } } } } // otherwise skip the entry } } private static void mergeConflictItems(Entry entry, List<Entry> conflicts) { Sync sync = getSync(entry, true); for (Entry x : conflicts) { Sync xsync = getSync(x, false); if (xsync != null) { List<History> list = xsync.getHistory(); History[] history = list.toArray(new History[list.size()]); for (History h1 : history) { h1 = (History)h1.clone(); h1.discard(); boolean ok = true; for (History h2 : sync.getHistory()) { if (isSubsumed(h1, h2)) { ok = false; break; } } if (ok) sync.addHistory((History)h1); } } } } public static Entry resolveConflicts(Entry entry, ConflictResolver resolver, String by) { List<Entry> conflicts = getConflicts(entry); entry = resolver.resolve(entry, conflicts); updateEntry(entry, by); mergeConflictItems(entry, conflicts); return entry; } public static interface ConflictResolver { Entry resolve(Entry entry, List<Entry> conflicts); } public static Entry unpublish(Entry entry) { if (entry == null) return null; Base base = entry.getParentElement(); if (base == null || !(base instanceof Feed)) return null; Feed feed = (Feed)base; Unpublished unpub = getUnpublished(feed, true); Entry newentry = (Entry)entry.clone(); // Use addExtension instead of addEntry because addEntry clones the node unpub.addExtension(newentry); entry.discard(); return newentry; } public static Entry republish(Entry entry) { if (entry == null) return null; Base base = entry.getParentElement(); if (base == null || !(base instanceof Unpublished)) return null; Unpublished unpub = (Unpublished)base; Feed feed = unpub.getParentElement(); Entry newentry = (Entry)entry.clone(); feed.addEntry(newentry); entry.discard(); return newentry; } public static void publish(Feed feed, Date expires, boolean initial) { if (initial) { Sharing sharing = getSharing(feed, true); Date since = getMin(feed); Date until = getMax(feed); sharing.setSince(since); sharing.setUntil(until); sharing.setExpires(expires); } else { Sharing sharing = getSharing(feed, false); if (sharing != null) { sharing.setExpires(expires); } else { publish(feed, expires, true); } } } private static Date getMax(Feed feed) { Date d = null; for (Entry entry : feed.getEntries()) { Date updated = entry.getUpdated(); if (d == null) d = updated; if (updated.after(d)) d = updated; } return d; } private static Date getMin(Feed feed) { Date d = null; for (Entry entry : feed.getEntries()) { Date updated = entry.getUpdated(); if (d == null) d = updated; if (updated.before(d)) d = updated; } return d; } public static boolean hasConflicts(Entry entry) { Sync sync = getSync(entry); if (sync != null) { Conflicts conflicts = sync.getConflicts(); if (conflicts != null) { if (conflicts.getEntries().size() > 0) { return true; } } } return false; } public static boolean isValidEndpointIdentifier(String id) { if (id == null) return false; char[] chars = id.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (!is_alphanum(c) && !is_reserved_or_other(c) && !is_hex(chars, i)) { return false; } } return true; } private static boolean is_alphanum(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); } private static boolean is_reserved_or_other(char c) { return c == '/' || c == '?' || c == '#' || c == '(' || c == ')' || c == '+' || c == ',' || c == '-' || c == '.' || c == ':' || c == '=' || c == '@' || c == ';' || c == '$' || c == '_' || c == '!' || c == '*' || c == '\''; } private static boolean is_hex(char[] chars, int i) { if (chars[i] == '%') { if (i + 2 > chars.length) return false; return is_hex(chars[i], chars[i + 1], chars[i + 2]); } return false; } private static boolean is_hexdigit(char c) { return (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || (c >= '0' && c <= '9'); } private static boolean is_hex(char c, char c2, char c3) { return (c == '%' && is_hexdigit(c2) && is_hexdigit(c3)); } }
7,586
0
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext/sharing/Unpublished.java
/* * 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.ext.sharing; import java.util.List; import javax.xml.namespace.QName; import org.apache.abdera.factory.Factory; import org.apache.abdera.model.Element; import org.apache.abdera.model.Entry; import org.apache.abdera.model.ExtensibleElementWrapper; import org.apache.abdera.util.Constants; public class Unpublished extends ExtensibleElementWrapper { public Unpublished(Element internal) { super(internal); } public Unpublished(Factory factory, QName qname) { super(factory, qname); } public List<Entry> getEntries() { return getExtensions(Constants.ENTRY); } public void addEntry(Entry entry) { addExtension((Entry)entry.clone()); } }
7,587
0
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext/sharing/Sync.java
/* * 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.ext.sharing; import java.util.Date; import java.util.List; import javax.xml.namespace.QName; import org.apache.abdera.factory.Factory; import org.apache.abdera.model.Element; import org.apache.abdera.model.ExtensibleElementWrapper; public class Sync extends ExtensibleElementWrapper { public Sync(Element internal) { super(internal); } public Sync(Factory factory, QName qname) { super(factory, qname); } public String getId() { return getAttributeValue("id"); } public void setId(String id) { if (id != null) { setAttributeValue("id", id); } else { removeAttribute(new QName("id")); } } public int getUpdates() { String updates = getAttributeValue("updates"); return updates != null ? Integer.parseInt(updates) : 0; } public void setUpdates(int updates) { if (updates > 0) { setAttributeValue("updates", Integer.toString(updates)); } else { removeAttribute(new QName("updates")); } } public void incrementUpdates() { setUpdates(getUpdates() + 1); } public boolean isDeleted() { String deleted = getAttributeValue("deleted"); return deleted != null ? SharingHelper.isTrue(deleted) : false; } public void setDeleted(boolean deleted) { if (deleted) { setAttributeValue("deleted", "true"); } else { removeAttribute(new QName("deleted")); } } public boolean isNoConflicts() { String noconflicts = getAttributeValue("noconflicts"); return noconflicts != null ? SharingHelper.isTrue(noconflicts) : false; } public void setNoConflicts(boolean noconflicts) { if (noconflicts) { setAttributeValue("noconflicts", "true"); } else { removeAttribute(new QName("noconflicts")); } } public List<History> getHistory() { return getExtensions(SharingHelper.SSE_HISTORY); } public void addHistory(History history) { this.addExtension(history); } public History addHistory() { return this.addExtension(SharingHelper.SSE_HISTORY, SharingHelper.SSE_HISTORY); } public History addHistory(int sequence, Date when, String by) { History history = addHistory(); history.setSequence(sequence); history.setWhen(when); history.setBy(by); return history; } public History getTopmostHistory() { return this.getFirstChild(SharingHelper.SSE_HISTORY); } public Conflicts getConflicts() { return getConflicts(false); } public void setConflicts(Conflicts conflicts) { Conflicts con = getConflicts(); if (con != null) con.discard(); if (conflicts != null) addExtension(conflicts); } public Conflicts getConflicts(boolean create) { Conflicts con = getExtension(SharingHelper.SSE_CONFLICTS); if (con == null && create) con = getFactory().newElement(SharingHelper.SSE_CONFLICTS, this.getInternal()); return con; } }
7,588
0
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext/sharing/History.java
/* * 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.ext.sharing; import java.util.Date; import javax.xml.namespace.QName; import org.apache.abdera.factory.Factory; import org.apache.abdera.model.AtomDate; import org.apache.abdera.model.Element; import org.apache.abdera.model.ElementWrapper; public class History extends ElementWrapper { public History(Element internal) { super(internal); } public History(Factory factory, QName qname) { super(factory, qname); } public int getSequence() { String sequence = getAttributeValue("sequence"); return sequence != null ? Integer.parseInt(sequence) : 0; } public void setSequence(int sequence) { if (sequence > 0) { setAttributeValue("sequence", Integer.toString(sequence)); } else { removeAttribute(new QName("sequence")); } } public Date getWhen() { String when = getAttributeValue("when"); return when != null ? AtomDate.parse(when) : null; } public void setWhen(Date when) { if (when != null) { setAttributeValue("when", AtomDate.format(when)); } else { removeAttribute(new QName("when")); } } public String getBy() { return getAttributeValue("by"); } public void setBy(String by) { if (by != null) { if (!SharingHelper.isValidEndpointIdentifier(by)) throw new IllegalArgumentException("Invalid Endpoint Identifier"); setAttributeValue("by", by); } else { removeAttribute(new QName("by")); } } }
7,589
0
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext/sharing/Related.java
/* * 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.ext.sharing; import javax.xml.namespace.QName; import org.apache.abdera.factory.Factory; import org.apache.abdera.i18n.iri.IRI; import org.apache.abdera.model.Element; import org.apache.abdera.model.ElementWrapper; public class Related extends ElementWrapper { public static enum Type { COMPLETE, AGGREGATED }; public Related(Element internal) { super(internal); } public Related(Factory factory, QName qname) { super(factory, qname); } public IRI getLink() { String link = getAttributeValue("link"); return link != null ? new IRI(link) : null; } public void setLink(String link) { if (link != null) { setAttributeValue("link", new IRI(link).toString()); } else { removeAttribute(new QName("link")); } } public String getTitle() { return getAttributeValue("title"); } public void setTitle(String title) { if (title != null) { setAttributeValue("title", title); } else { removeAttribute(new QName("title")); } } public Type getType() { String type = getAttributeValue("type"); return type != null ? Type.valueOf(type.toUpperCase()) : null; } public void setType(Type type) { if (type != null) { setAttributeValue("type", type.name().toLowerCase()); } else { removeAttribute(new QName("type")); } } }
7,590
0
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext
Create_ds/abdera/extensions/sharing/src/main/java/org/apache/abdera/ext/sharing/SharingExtensionFactory.java
/* * 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.ext.sharing; import org.apache.abdera.util.AbstractExtensionFactory; public class SharingExtensionFactory extends AbstractExtensionFactory { public SharingExtensionFactory() { super(SharingHelper.SSENS); addImpl(SharingHelper.SSE_CONFLICTS, Conflicts.class); addImpl(SharingHelper.SSE_HISTORY, History.class); addImpl(SharingHelper.SSE_RELATED, Related.class); addImpl(SharingHelper.SSE_SHARING, Sharing.class); addImpl(SharingHelper.SSE_SYNC, Sync.class); addImpl(SharingHelper.SSE_UNPUBLISHED, Unpublished.class); } }
7,591
0
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/TestSuite.java
/* * 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.test.ext.opensearch; import org.apache.abdera.test.ext.opensearch.model.OpenSearchAtomTest; import org.apache.abdera.test.ext.opensearch.model.OpenSearchDescriptionTest; import org.apache.abdera.test.ext.opensearch.model.TestSelectNodes; import org.apache.abdera.test.ext.opensearch.server.impl.AbstractOpenSearchUrlAdapterTest; import org.apache.abdera.test.ext.opensearch.server.impl.SimpleOpenSearchInfoTest; import org.apache.abdera.test.ext.opensearch.server.processors.OpenSearchDescriptionRequestProcessorTest; import org.apache.abdera.test.ext.opensearch.server.processors.OpenSearchUrlRequestProcessorTest; import org.junit.internal.TextListener; import org.junit.runner.JUnitCore; public class TestSuite { public static void main(String[] args) { JUnitCore runner = new JUnitCore(); runner.addListener(new TextListener(System.out)); runner.run(OpenSearchAtomTest.class, OpenSearchDescriptionTest.class, AbstractOpenSearchUrlAdapterTest.class, SimpleOpenSearchInfoTest.class, OpenSearchDescriptionRequestProcessorTest.class, OpenSearchUrlRequestProcessorTest.class, TestSelectNodes.class); } }
7,592
0
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/JettyServer.java
/* * 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.test.ext.opensearch.server; import org.apache.abdera.protocol.server.Provider; import org.apache.abdera.protocol.server.servlet.AbderaServlet; import org.mortbay.jetty.Server; import org.mortbay.jetty.servlet.Context; import org.mortbay.jetty.servlet.ServletHolder; public class JettyServer { public static final int DEFAULT_PORT = 9002; private final int port; private Server server; public JettyServer() { this(DEFAULT_PORT); } public JettyServer(int port) { this.port = port; } public void start(final Provider myProvider) throws Exception { server = new Server(port); Context context = new Context(server, "/", Context.SESSIONS); ServletHolder servletHolder = new ServletHolder(new AbderaServlet() { protected Provider createProvider() { myProvider.init(this.getAbdera(), this.getProperties(this.getServletConfig())); return myProvider; } }); context.addServlet(servletHolder, "/*"); server.start(); } public void stop() throws Exception { server.stop(); } }
7,593
0
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/AbstractOpenSearchServerTest.java
/* * 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.test.ext.opensearch.server; import java.util.HashMap; import java.util.Map; import org.apache.abdera.ext.opensearch.OpenSearchConstants; import org.apache.abdera.ext.opensearch.model.Query; import org.apache.abdera.ext.opensearch.server.OpenSearchInfo; import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchInfo; import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchQueryInfo; import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchUrlInfo; import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchUrlParameterInfo; import org.custommonkey.xmlunit.SimpleNamespaceContext; import org.custommonkey.xmlunit.XMLAssert; import org.custommonkey.xmlunit.XMLUnit; public abstract class AbstractOpenSearchServerTest extends XMLAssert { protected static final String DESCRIPTION = "This is a description"; protected static final String SHORT_NAME = "This is a short name"; protected static final String TAG1 = "FirstTag"; protected static final String TAG2 = "SecondTag"; protected static final String TAGS = TAG1 + " " + TAG2; protected static final String SEARCH_PATH_1 = "/search1"; protected static final String SEARCH_PATH_2 = "/search2"; protected static final String TEMPLATE_PARAM_1_NAME = "q"; protected static final String TEMPLATE_PARAM_1_VALUE = "searchTerms"; protected static final String TEMPLATE_PARAM_2_NAME = "c"; protected static final String TEMPLATE_PARAM_2_VALUE = "count"; protected static final String QUERY_TERMS = "term1 term2"; static { Map<String, String> nsContext = new HashMap<String, String>(); nsContext.put(OpenSearchConstants.OS_PREFIX, OpenSearchConstants.OPENSEARCH_NS); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(nsContext)); } protected OpenSearchInfo createOpenSearchInfo() throws Exception { SimpleOpenSearchInfo osInfo = new SimpleOpenSearchInfo(); SimpleOpenSearchQueryInfo osQueryInfo = new SimpleOpenSearchQueryInfo(); SimpleOpenSearchUrlInfo osUrlInfo1 = new SimpleOpenSearchUrlInfo(); SimpleOpenSearchUrlInfo osUrlInfo2 = new SimpleOpenSearchUrlInfo(); SimpleOpenSearchUrlParameterInfo osParamInfo1 = new SimpleOpenSearchUrlParameterInfo(); SimpleOpenSearchUrlParameterInfo osParamInfo2 = new SimpleOpenSearchUrlParameterInfo(); osInfo.setShortName(SHORT_NAME); osInfo.setDescription(DESCRIPTION); osInfo.setTags(TAG1, TAG2); osQueryInfo.setRole(Query.Role.EXAMPLE); osQueryInfo.setSearchTerms(QUERY_TERMS); osInfo.setQueries(osQueryInfo); osUrlInfo1.setSearchPath(SEARCH_PATH_1); osUrlInfo2.setSearchPath(SEARCH_PATH_2); osParamInfo1.setName(TEMPLATE_PARAM_1_NAME); osParamInfo1.setValue(TEMPLATE_PARAM_1_VALUE); osParamInfo2.setName(TEMPLATE_PARAM_2_NAME); osParamInfo2.setValue(TEMPLATE_PARAM_2_VALUE); osParamInfo2.setOptional(true); osUrlInfo1.setSearchParameters(osParamInfo1, osParamInfo2); osUrlInfo2.setSearchParameters(osParamInfo1, osParamInfo2); osInfo.setUrls(osUrlInfo1, osUrlInfo2); return osInfo; } }
7,594
0
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/AbstractOpenSearchUrlAdapterTest.java
/* * 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.test.ext.opensearch.server.impl; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.apache.abdera.ext.opensearch.OpenSearchConstants; import org.apache.abdera.ext.opensearch.model.IntegerElement; import org.apache.abdera.ext.opensearch.server.OpenSearchInfo; import org.apache.abdera.ext.opensearch.server.impl.AbstractOpenSearchUrlAdapter; import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchUrlInfo; import org.apache.abdera.ext.opensearch.server.processors.OpenSearchTargetTypes; import org.apache.abdera.ext.opensearch.server.processors.OpenSearchUrlRequestProcessor; import org.apache.abdera.model.Document; import org.apache.abdera.model.Entry; import org.apache.abdera.model.Feed; import org.apache.abdera.model.Person; import org.apache.abdera.protocol.client.AbderaClient; import org.apache.abdera.protocol.client.ClientResponse; import org.apache.abdera.protocol.server.RequestContext; import org.apache.abdera.protocol.server.RequestProcessor; import org.apache.abdera.protocol.server.TargetType; import org.apache.abdera.protocol.server.WorkspaceInfo; import org.apache.abdera.protocol.server.impl.DefaultProvider; import org.apache.abdera.protocol.server.impl.DefaultWorkspaceManager; import org.apache.abdera.protocol.server.impl.RouteManager; import org.apache.abdera.test.ext.opensearch.server.AbstractOpenSearchServerTest; import org.apache.abdera.test.ext.opensearch.server.JettyServer; import org.apache.axiom.testutils.PortAllocator; import org.junit.After; import org.junit.Before; import org.junit.Test; public class AbstractOpenSearchUrlAdapterTest extends AbstractOpenSearchServerTest { private int port; private JettyServer server; private OpenSearchInfo osInfo; private OpenSearchUrlRequestProcessor osUrlProcessor; @Before public void setUp() throws Exception { port = PortAllocator.allocatePort(); server = new JettyServer(port); this.osInfo = this.createOpenSearchInfo(); ((SimpleOpenSearchUrlInfo)osInfo.getUrls()[0]).setOpenSearchUrlAdapter(new TestingOpenSearchUrlAdapter()); this.osUrlProcessor = new OpenSearchUrlRequestProcessor(); this.osUrlProcessor.setOpenSearchInfo(this.osInfo); Map<TargetType, RequestProcessor> processors = new HashMap<TargetType, RequestProcessor>(); processors.put(OpenSearchTargetTypes.OPENSEARCH_URL, osUrlProcessor); DefaultWorkspaceManager wsManager = new DefaultWorkspaceManager(); wsManager.setWorkspaces(new LinkedList<WorkspaceInfo>()); RouteManager routeManager = new RouteManager(); routeManager.addRoute("service", "/", TargetType.TYPE_SERVICE).addRoute("feed", "/atom/:collection", TargetType.TYPE_COLLECTION) .addRoute("entry", "/atom/:collection/:entry", TargetType.TYPE_ENTRY) .addRoute("categories", "/atom/:collection/:entry;categories", TargetType.TYPE_CATEGORIES) .addRoute("osSearch1", "/search1", OpenSearchTargetTypes.OPENSEARCH_URL); DefaultProvider provider = new DefaultProvider("/"); provider.setWorkspaceManager(wsManager); provider.setTargetResolver(routeManager); provider.setTargetBuilder(routeManager); provider.addRequestProcessors(processors); this.server.start(provider); } @After public void tearDown() throws Exception { this.server.stop(); } @Test public void testOpenSearchFeedResponse() throws Exception { AbderaClient client = new AbderaClient(); ClientResponse response = client.get("http://localhost:" + port + "/search1?q=test1&c=1"); assertEquals(200, response.getStatus()); Document<Feed> feedDoc = response.getDocument(); Feed feed = feedDoc.getRoot(); assertEquals(TestingOpenSearchUrlAdapter.OS_FEED_ID, feed.getId().toString()); assertEquals(TestingOpenSearchUrlAdapter.OS_FEED_TITLE, feed.getTitle()); assertEquals(TestingOpenSearchUrlAdapter.OS_FEED_AUTHOR, feed.getAuthor().getName()); assertEquals(2, ((IntegerElement)feed.getExtension(OpenSearchConstants.TOTAL_RESULTS)).getValue()); assertEquals(2, feed.getEntries().size()); assertNotNull(feed.getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_ID)); assertNotNull(feed.getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_ID)); assertEquals(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_TITLE, feed .getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_ID).getTitle()); assertEquals(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_DESC, feed .getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_ID).getContent()); assertEquals(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_TITLE, feed .getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_ID).getTitle()); assertEquals(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_DESC, feed .getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_ID).getContent()); } private class TestingOpenSearchUrlAdapter extends AbstractOpenSearchUrlAdapter<SearchResult> { public static final String OS_FEED_AUTHOR = "Sergio Bossa"; public static final String OS_FEED_ID = "http://www.acme.org/feed/id"; public static final String OS_FEED_TITLE = "Feed Title"; public static final String SEARCH_RESULT_1_DESC = "Search Result 1 description"; public static final String SEARCH_RESULT_1_ID = "urn:1"; public static final String SEARCH_RESULT_1_TITLE = "Search Result 1 title"; public static final String SEARCH_RESULT_2_DESC = "Search Result 2 description"; public static final String SEARCH_RESULT_2_ID = "urn:2"; public static final String SEARCH_RESULT_2_TITLE = "Search Result 2 title"; protected String getOpenSearchFeedId(RequestContext request) { return OS_FEED_ID; } protected String getOpenSearchFeedTitle(RequestContext request) { return OS_FEED_TITLE; } protected Person getOpenSearchFeedAuthor(RequestContext request) { Person p = request.getAbdera().getFactory().newAuthor(); p.setName(OS_FEED_AUTHOR); return p; } protected Date getOpenSearchFeedUpdatedDate(RequestContext request) { return new Date(); } protected List<SearchResult> doSearch(RequestContext request, Map<String, String> parameters) { List<SearchResult> result = new LinkedList<SearchResult>(); SearchResult sr1 = new SearchResult(SEARCH_RESULT_1_ID, SEARCH_RESULT_1_TITLE, SEARCH_RESULT_1_DESC); SearchResult sr2 = new SearchResult(SEARCH_RESULT_2_ID, SEARCH_RESULT_2_TITLE, SEARCH_RESULT_2_DESC); result.add(sr1); result.add(sr2); return result; } protected void fillEntry(Entry entry, SearchResult entity) { entry.setId(entity.getId()); entry.setTitle(entity.getTitle()); entry.setContent(entity.getDescription()); } } private class SearchResult { private String id; private String title; private String description; public SearchResult(String id, String title, String description) { this.id = id; this.title = title; this.description = description; } public String getTitle() { return this.title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return this.description; } public void setDescription(String description) { this.description = description; } public String getId() { return this.id; } public void setId(String id) { this.id = id; } } }
7,595
0
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/SimpleOpenSearchInfoTest.java
/* * 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.test.ext.opensearch.server.impl; import java.io.StringWriter; import org.apache.abdera.Abdera; import org.apache.abdera.ext.opensearch.model.OpenSearchDescription; import org.apache.abdera.ext.opensearch.model.Query; import org.apache.abdera.ext.opensearch.server.OpenSearchInfo; import org.apache.abdera.i18n.iri.IRI; import org.apache.abdera.protocol.server.RequestContext; import org.apache.abdera.test.ext.opensearch.server.AbstractOpenSearchServerTest; import org.junit.Before; import org.junit.Test; import static org.easymock.EasyMock.*; public class SimpleOpenSearchInfoTest extends AbstractOpenSearchServerTest { private OpenSearchInfo osInfo; @Before public void setUp() throws Exception { this.osInfo = this.createOpenSearchInfo(); } @Test public void testOpenSearchDescriptionCreationFromOpenSearchInfo() throws Exception { RequestContext requestMock = createMock(RequestContext.class); expect(requestMock.getAbdera()).andReturn(Abdera.getInstance()).anyTimes(); expect(requestMock.getBaseUri()).andReturn(new IRI("http://www.acme.org/")).anyTimes(); replay(requestMock); OpenSearchDescription description = this.osInfo.asOpenSearchDescriptionElement(requestMock); StringWriter writer = new StringWriter(); description.writeTo(writer); String result = writer.toString(); System.out.print(result); assertXpathEvaluatesTo(SHORT_NAME, "/os:OpenSearchDescription/os:ShortName", result); assertXpathEvaluatesTo(DESCRIPTION, "/os:OpenSearchDescription/os:Description", result); assertXpathEvaluatesTo(TAGS, "/os:OpenSearchDescription/os:Tags", result); assertXpathEvaluatesTo(Query.Role.EXAMPLE.toString().toLowerCase(), "/os:OpenSearchDescription/os:Query/@role", result); assertXpathEvaluatesTo(QUERY_TERMS, "/os:OpenSearchDescription/os:Query/@searchTerms", result); assertXpathEvaluatesTo("application/atom+xml", "/os:OpenSearchDescription/os:Url[1]/@type", result); assertXpathEvaluatesTo("http://www.acme.org/search1?q={searchTerms}&c={count?}", "/os:OpenSearchDescription/os:Url[1]/@template", result); assertXpathEvaluatesTo("application/atom+xml", "/os:OpenSearchDescription/os:Url[2]/@type", result); assertXpathEvaluatesTo("http://www.acme.org/search2?q={searchTerms}&c={count?}", "/os:OpenSearchDescription/os:Url[2]/@template", result); } }
7,596
0
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchUrlRequestProcessorTest.java
/* * 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.test.ext.opensearch.server.processors; import java.io.IOException; import java.io.Writer; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import org.apache.abdera.ext.opensearch.server.OpenSearchInfo; import org.apache.abdera.ext.opensearch.server.OpenSearchUrlAdapter; import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchUrlInfo; import org.apache.abdera.ext.opensearch.server.processors.OpenSearchTargetTypes; import org.apache.abdera.ext.opensearch.server.processors.OpenSearchUrlRequestProcessor; import org.apache.abdera.protocol.client.AbderaClient; import org.apache.abdera.protocol.client.ClientResponse; import org.apache.abdera.protocol.server.RequestContext; import org.apache.abdera.protocol.server.RequestProcessor; import org.apache.abdera.protocol.server.ResponseContext; import org.apache.abdera.protocol.server.TargetType; import org.apache.abdera.protocol.server.WorkspaceInfo; import org.apache.abdera.protocol.server.context.SimpleResponseContext; import org.apache.abdera.protocol.server.impl.DefaultProvider; import org.apache.abdera.protocol.server.impl.DefaultWorkspaceManager; import org.apache.abdera.protocol.server.impl.RouteManager; import org.apache.abdera.test.ext.opensearch.server.AbstractOpenSearchServerTest; import org.apache.abdera.test.ext.opensearch.server.JettyServer; import org.apache.axiom.testutils.PortAllocator; import org.junit.After; import org.junit.Before; import org.junit.Test; public class OpenSearchUrlRequestProcessorTest extends AbstractOpenSearchServerTest { private int port; private JettyServer server; private OpenSearchInfo osInfo; private OpenSearchUrlRequestProcessor osUrlProcessor; @Before public void setUp() throws Exception { port = PortAllocator.allocatePort(); server = new JettyServer(port); this.osInfo = this.createOpenSearchInfo(); ((SimpleOpenSearchUrlInfo)osInfo.getUrls()[0]).setOpenSearchUrlAdapter(new TestingOpenSearchUrlAdapter1()); ((SimpleOpenSearchUrlInfo)osInfo.getUrls()[1]).setOpenSearchUrlAdapter(new TestingOpenSearchUrlAdapter2()); this.osUrlProcessor = new OpenSearchUrlRequestProcessor(); this.osUrlProcessor.setOpenSearchInfo(this.osInfo); Map<TargetType, RequestProcessor> processors = new HashMap<TargetType, RequestProcessor>(); processors.put(OpenSearchTargetTypes.OPENSEARCH_URL, osUrlProcessor); DefaultWorkspaceManager wsManager = new DefaultWorkspaceManager(); wsManager.setWorkspaces(new LinkedList<WorkspaceInfo>()); RouteManager routeManager = new RouteManager(); routeManager.addRoute("service", "/", TargetType.TYPE_SERVICE).addRoute("feed", "/atom/:collection", TargetType.TYPE_COLLECTION) .addRoute("entry", "/atom/:collection/:entry", TargetType.TYPE_ENTRY) .addRoute("categories", "/atom/:collection/:entry;categories", TargetType.TYPE_CATEGORIES) .addRoute("osSearch1", "/search1", OpenSearchTargetTypes.OPENSEARCH_URL) .addRoute("osSearch2", "/search2", OpenSearchTargetTypes.OPENSEARCH_URL) .addRoute("osSearch3", "/search3", OpenSearchTargetTypes.OPENSEARCH_URL); DefaultProvider provider = new DefaultProvider("/"); provider.setWorkspaceManager(wsManager); provider.setTargetResolver(routeManager); provider.setTargetBuilder(routeManager); provider.addRequestProcessors(processors); this.server.start(provider); } @After public void tearDown() throws Exception { this.server.stop(); } @Test public void testProcessSuccessfully() throws Exception { AbderaClient client = new AbderaClient(); ClientResponse response = null; // Test with first adapter: response = client.get("http://localhost:" + port + "/search1?q=test1&c=1"); assertEquals(200, response.getStatus()); // Test with second adapter: client.get("http://localhost:" + port + "/search2?q=test2&c=1"); assertEquals(200, response.getStatus()); } @Test public void testProcessFailsBecauseOfNoAdapterFound() throws Exception { AbderaClient client = new AbderaClient(); ClientResponse response = null; // No adapter found for this Open Search url: response = client.get("http://localhost:" + port + "/search3?q=test1&c=1"); assertEquals(404, response.getStatus()); } private class TestingOpenSearchUrlAdapter1 implements OpenSearchUrlAdapter { public ResponseContext search(RequestContext request, Map<String, String> parameters) { assertEquals(SEARCH_PATH_1, request.getTargetPath().substring(0, request.getTargetPath().indexOf("?"))); assertNotNull(parameters.get(TEMPLATE_PARAM_1_NAME)); assertEquals("test1", parameters.get(TEMPLATE_PARAM_1_NAME)); assertNotNull(parameters.get(TEMPLATE_PARAM_2_NAME)); assertEquals("1", parameters.get(TEMPLATE_PARAM_2_NAME)); return new SimpleResponseContext() { protected void writeEntity(Writer writer) throws IOException { } public boolean hasEntity() { return false; } }.setStatus(200); } } private class TestingOpenSearchUrlAdapter2 implements OpenSearchUrlAdapter { public ResponseContext search(RequestContext request, Map<String, String> parameters) { assertEquals(SEARCH_PATH_2, request.getTargetPath().substring(0, request.getTargetPath().indexOf("?"))); assertNotNull(parameters.get(TEMPLATE_PARAM_1_NAME)); assertEquals("test2", parameters.get(TEMPLATE_PARAM_1_NAME)); assertNotNull(parameters.get(TEMPLATE_PARAM_2_NAME)); assertEquals("1", parameters.get(TEMPLATE_PARAM_2_NAME)); return new SimpleResponseContext() { protected void writeEntity(Writer writer) throws IOException { } public boolean hasEntity() { return false; } }.setStatus(200); } } }
7,597
0
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchDescriptionRequestProcessorTest.java
/* * 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.test.ext.opensearch.server.processors; import java.io.StringWriter; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import org.apache.abdera.ext.opensearch.OpenSearchConstants; import org.apache.abdera.ext.opensearch.model.Query; import org.apache.abdera.ext.opensearch.server.OpenSearchInfo; import org.apache.abdera.ext.opensearch.server.processors.OpenSearchDescriptionRequestProcessor; import org.apache.abdera.ext.opensearch.server.processors.OpenSearchTargetTypes; import org.apache.abdera.model.Document; import org.apache.abdera.protocol.Response.ResponseType; import org.apache.abdera.protocol.client.AbderaClient; import org.apache.abdera.protocol.client.ClientResponse; import org.apache.abdera.protocol.server.RequestProcessor; import org.apache.abdera.protocol.server.TargetType; import org.apache.abdera.protocol.server.WorkspaceInfo; import org.apache.abdera.protocol.server.impl.DefaultProvider; import org.apache.abdera.protocol.server.impl.DefaultWorkspaceManager; import org.apache.abdera.protocol.server.impl.RouteManager; import org.apache.abdera.test.ext.opensearch.server.AbstractOpenSearchServerTest; import org.apache.abdera.test.ext.opensearch.server.JettyServer; import org.apache.abdera.util.MimeTypeHelper; import org.apache.axiom.testutils.PortAllocator; import org.junit.After; import org.junit.Before; import org.junit.Test; public class OpenSearchDescriptionRequestProcessorTest extends AbstractOpenSearchServerTest { private int port; private JettyServer server; private OpenSearchInfo osInfo; private OpenSearchDescriptionRequestProcessor osRequestProcessor; @Before public void setUp() throws Exception { port = PortAllocator.allocatePort(); server = new JettyServer(port); this.osInfo = this.createOpenSearchInfo(); this.osRequestProcessor = new OpenSearchDescriptionRequestProcessor(); this.osRequestProcessor.setOpenSearchInfo(osInfo); Map<TargetType, RequestProcessor> processors = new HashMap<TargetType, RequestProcessor>(); processors.put(OpenSearchTargetTypes.OPENSEARCH_DESCRIPTION, osRequestProcessor); DefaultWorkspaceManager wsManager = new DefaultWorkspaceManager(); wsManager.setWorkspaces(new LinkedList<WorkspaceInfo>()); RouteManager routeManager = new RouteManager(); routeManager.addRoute("service", "/", TargetType.TYPE_SERVICE).addRoute("feed", "/atom/:collection", TargetType.TYPE_COLLECTION) .addRoute("entry", "/atom/:collection/:entry", TargetType.TYPE_ENTRY) .addRoute("categories", "/atom/:collection/:entry;categories", TargetType.TYPE_CATEGORIES) .addRoute("osDescription", "/search", OpenSearchTargetTypes.OPENSEARCH_DESCRIPTION); DefaultProvider provider = new DefaultProvider("/"); provider.setWorkspaceManager(wsManager); provider.setTargetResolver(routeManager); provider.setTargetBuilder(routeManager); provider.addRequestProcessors(processors); this.server.start(provider); } @After public void tearDown() throws Exception { this.server.stop(); } @Test public void testOpenSearchDescriptionRequestProcessorOutput() throws Exception { AbderaClient client = new AbderaClient(); ClientResponse resp = client.get("http://localhost:" + port + "/search"); assertNotNull(resp); assertEquals(ResponseType.SUCCESS, resp.getType()); assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), OpenSearchConstants.OPENSEARCH_DESCRIPTION_CONTENT_TYPE)); Document doc = resp.getDocument(); StringWriter writer = new StringWriter(); doc.writeTo(writer); String result = writer.toString(); System.out.println(result); assertXpathEvaluatesTo(SHORT_NAME, "/os:OpenSearchDescription/os:ShortName", result); assertXpathEvaluatesTo(DESCRIPTION, "/os:OpenSearchDescription/os:Description", result); assertXpathEvaluatesTo(TAGS, "/os:OpenSearchDescription/os:Tags", result); assertXpathEvaluatesTo(Query.Role.EXAMPLE.toString().toLowerCase(), "/os:OpenSearchDescription/os:Query/@role", result); assertXpathEvaluatesTo(QUERY_TERMS, "/os:OpenSearchDescription/os:Query/@searchTerms", result); assertXpathEvaluatesTo("application/atom+xml", "/os:OpenSearchDescription/os:Url[1]/@type", result); assertXpathEvaluatesTo("http://localhost:" + port + "/search1?q={searchTerms}&c={count?}", "/os:OpenSearchDescription/os:Url[1]/@template", result); assertXpathEvaluatesTo("application/atom+xml", "/os:OpenSearchDescription/os:Url[2]/@type", result); assertXpathEvaluatesTo("http://localhost:" + port + "/search2?q={searchTerms}&c={count?}", "/os:OpenSearchDescription/os:Url[2]/@template", result); } }
7,598
0
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch
Create_ds/abdera/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/model/TestSelectNodes.java
package org.apache.abdera.test.ext.opensearch.model; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.List; import org.apache.abdera.Abdera; import org.apache.abdera.ext.opensearch.OpenSearchConstants; import org.apache.abdera.ext.opensearch.model.IntegerElement; import org.apache.abdera.model.Feed; import org.apache.abdera.writer.Writer; import org.apache.abdera.xpath.XPath; import org.junit.Test; public class TestSelectNodes { @Test public void testXPath() throws IOException { Feed f = Abdera.getInstance().newFeed(); IntegerElement ext = f.addExtension(OpenSearchConstants.START_INDEX); ext.setValue(101); XPath path = Abdera.getNewXPath(); List result = path.selectNodes("node()", ext); assertTrue(result.size() > 0); } @Test public void testJson() throws IOException { Abdera abdera = Abdera.getInstance(); Feed f = abdera.newFeed(); IntegerElement ext = f.addExtension(OpenSearchConstants.START_INDEX); ext.setValue(101); Writer json = abdera.getWriterFactory().getWriter("json"); StringWriter stWriter = new StringWriter(); PrintWriter pWriter = new PrintWriter(stWriter); f.writeTo(json, pWriter); assertTrue(stWriter.toString().contains("101")); assertTrue(stWriter.toString().contains("os:startIndex")); } }
7,599