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/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/OpenSearchDescriptionTest.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.model;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.opensearch.OpenSearchConstants;
import org.apache.abdera.ext.opensearch.model.OpenSearchDescription;
import org.apache.abdera.ext.opensearch.model.Query;
import org.apache.abdera.ext.opensearch.model.StringElement;
import org.apache.abdera.ext.opensearch.model.Url;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
import org.apache.abdera.parser.Parser;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Test;
public class OpenSearchDescriptionTest extends XMLAssert {
private static final String DESCRIPTION = "This is a description";
private static final String SHORT_NAME = "This is a short name";
private static final String TAG1 = "FirstTag";
private static final String TAG2 = "SecondTag";
private static final String TAGS = TAG1 + " " + TAG2;
private static final String URL_TEMPLATE = "http://example.com/?q={searchTerms}";
private static final String URL_TYPE = "application/atom+xml";
private 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));
}
@Test
public void testOpenSearchDescriptionDocumentCreation() throws Exception {
OpenSearchDescription document = new OpenSearchDescription(Abdera.getInstance());
document.setShortName(SHORT_NAME);
document.setDescription(DESCRIPTION);
document.setTags(TAG1, TAG2);
Url url = new Url(Abdera.getInstance());
url.setType(URL_TYPE);
url.setTemplate(URL_TEMPLATE);
Query query = new Query(Abdera.getInstance());
query.setRole(Query.Role.EXAMPLE);
query.setSearchTerms(QUERY_TERMS);
document.addUrls(url);
document.addQueries(query);
StringWriter writer = new StringWriter();
document.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(URL_TYPE, "/os:OpenSearchDescription/os:Url/@type", result);
assertXpathEvaluatesTo(URL_TEMPLATE, "/os:OpenSearchDescription/os:Url/@template", result);
assertXpathEvaluatesTo(Query.Role.EXAMPLE.toString().toLowerCase(),
"/os:OpenSearchDescription/os:Query/@role",
result);
assertXpathEvaluatesTo(QUERY_TERMS, "/os:OpenSearchDescription/os:Query/@searchTerms", result);
assertXpathEvaluatesTo(new Integer(1).toString(), "/os:OpenSearchDescription/os:Url/@indexOffset", result);
assertXpathEvaluatesTo(new Integer(1).toString(), "/os:OpenSearchDescription/os:Url/@pageOffset", result);
}
@Test
public void testOpenSearchDescriptionDocumentParsing() throws Exception {
Parser parser = Abdera.getNewParser();
InputStream stream = OpenSearchAtomTest.class.getResourceAsStream("/opensearchDescription.xml");
Document<Element> doc = parser.parse(stream);
StringElement shortName = doc.getRoot().getFirstChild(OpenSearchConstants.SHORT_NAME);
assertNotNull(shortName);
assertEquals(SHORT_NAME, shortName.getValue());
StringElement description = doc.getRoot().getFirstChild(OpenSearchConstants.DESCRIPTION);
assertNotNull(description);
assertEquals(DESCRIPTION, description.getValue());
StringElement tags = doc.getRoot().getFirstChild(OpenSearchConstants.TAGS);
assertNotNull(tags);
assertEquals(TAGS, tags.getValue());
Query q = doc.getRoot().getFirstChild(OpenSearchConstants.QUERY);
assertNotNull(q);
assertEquals(Query.Role.EXAMPLE, q.getRole());
assertEquals(QUERY_TERMS, q.getSearchTerms());
Url u = doc.getRoot().getFirstChild(OpenSearchConstants.URL);
assertNotNull(u);
assertEquals(URL_TYPE, u.getType());
assertEquals(URL_TEMPLATE, u.getTemplate());
}
}
| 7,600 |
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/OpenSearchAtomTest.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.model;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.opensearch.OpenSearchConstants;
import org.apache.abdera.ext.opensearch.model.IntegerElement;
import org.apache.abdera.ext.opensearch.model.Query;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.Feed;
import org.apache.abdera.parser.Parser;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Test;
public class OpenSearchAtomTest extends XMLAssert {
private static final int TOTAL_RESULTS = 47;
private static final int START_INDEX = 1;
private static final int ITEMS_PER_PAGE = 1;
private static final String QUERY_TERMS = "some content";
static {
Map<String, String> nsContext = new HashMap<String, String>();
nsContext.put(OpenSearchConstants.OS_PREFIX, OpenSearchConstants.OPENSEARCH_NS);
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(nsContext));
}
@Test
public void testAtomResponseCreation() throws Exception {
Feed feed = Abdera.getInstance().getFactory().newFeed();
feed.setId("http://example.com/opensearch+example");
feed.setTitle("An OpenSearch Example");
feed.setUpdated(new Date());
Query query = feed.addExtension(OpenSearchConstants.QUERY);
query.setRole(Query.Role.REQUEST);
query.setSearchTerms(QUERY_TERMS);
IntegerElement totalResults = feed.addExtension(OpenSearchConstants.TOTAL_RESULTS);
totalResults.setValue(TOTAL_RESULTS);
IntegerElement itemsPerPage = feed.addExtension(OpenSearchConstants.ITEMS_PER_PAGE);
itemsPerPage.setValue(ITEMS_PER_PAGE);
IntegerElement startIndex = feed.addExtension(OpenSearchConstants.START_INDEX);
startIndex.setValue(START_INDEX);
StringWriter writer = new StringWriter();
feed.writeTo(writer);
String result = writer.toString();
System.out.print(result);
assertXpathEvaluatesTo(String.valueOf(TOTAL_RESULTS), "//os:totalResults", result);
assertXpathEvaluatesTo(String.valueOf(ITEMS_PER_PAGE), "//os:itemsPerPage", result);
assertXpathEvaluatesTo(String.valueOf(START_INDEX), "//os:startIndex", result);
assertXpathEvaluatesTo(Query.Role.REQUEST.toString().toLowerCase(), "//os:Query/@role", result);
assertXpathEvaluatesTo(QUERY_TERMS, "//os:Query/@searchTerms", result);
}
@Test
public void testAtomResponseParsing() throws Exception {
Parser parser = Abdera.getNewParser();
InputStream stream = OpenSearchAtomTest.class.getResourceAsStream("/atomResponse.xml");
Document<Element> doc = parser.parse(stream);
IntegerElement tr = doc.getRoot().getFirstChild(OpenSearchConstants.TOTAL_RESULTS);
assertNotNull(tr);
assertEquals(47, tr.getValue());
IntegerElement ipp = doc.getRoot().getFirstChild(OpenSearchConstants.ITEMS_PER_PAGE);
assertNotNull(ipp);
assertEquals(1, ipp.getValue());
IntegerElement si = doc.getRoot().getFirstChild(OpenSearchConstants.START_INDEX);
assertNotNull(si);
assertEquals(1, si.getValue());
Query q = doc.getRoot().getFirstChild(OpenSearchConstants.QUERY);
assertNotNull(q);
assertEquals(Query.Role.REQUEST, q.getRole());
assertEquals(QUERY_TERMS, q.getSearchTerms());
}
@Test
public void testFeedSimpleExtension() throws Exception {
Feed feed = Abdera.getInstance().getFactory().newFeed();
feed.setId("http://example.com/opensearch+example");
feed.setTitle("An OpenSearch Example");
feed.setUpdated(new Date());
feed.addSimpleExtension(OpenSearchConstants.TOTAL_RESULTS, String.valueOf(TOTAL_RESULTS));
feed.addSimpleExtension(OpenSearchConstants.ITEMS_PER_PAGE, String.valueOf(ITEMS_PER_PAGE));
StringWriter writer = new StringWriter();
feed.writeTo(writer);
String result = writer.toString();
assertXpathEvaluatesTo(String.valueOf(TOTAL_RESULTS), "//os:totalResults", result);
assertXpathEvaluatesTo(String.valueOf(ITEMS_PER_PAGE), "//os:itemsPerPage", result);
}
}
| 7,601 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/OpenSearchConstants.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.opensearch;
import javax.xml.namespace.QName;
/**
* Simple container of Open Search XML model constants.
*/
public interface OpenSearchConstants {
public static final String OPENSEARCH_DESCRIPTION_CONTENT_TYPE = "application/opensearchdescription+xml";
public static final String OPENSEARCH_NS = "http://a9.com/-/spec/opensearch/1.1/";
public static final String OS_PREFIX = "os";
public static final String TOTAL_RESULTS_LN = "totalResults";
public static final String ITEMS_PER_PAGE_LN = "itemsPerPage";
public static final String START_INDEX_LN = "startIndex";
public static final String QUERY_LN = "Query";
public static final String QUERY_ROLE_LN = "role";
public static final String QUERY_TITLE_LN = "title";
public static final String QUERY_TOTALRESULTS_LN = "totalResult";
public static final String QUERY_SEARCHTERMS_LN = "searchTerms";
public static final String QUERY_COUNT_LN = "count";
public static final String QUERY_STARTINDEX_LN = "startIndex";
public static final String QUERY_STARTPAGE_LN = "startPage";
public static final String QUERY_LANGUAGE_LN = "language";
public static final String QUERY_INPUTENCODING_LN = "inputEncoding";
public static final String QUERY_OUTPUTENCODING_LN = "outputEncoding";
public static final QName TOTAL_RESULTS = new QName(OPENSEARCH_NS, TOTAL_RESULTS_LN, OS_PREFIX);
public static final QName ITEMS_PER_PAGE = new QName(OPENSEARCH_NS, ITEMS_PER_PAGE_LN, OS_PREFIX);
public static final QName START_INDEX = new QName(OPENSEARCH_NS, START_INDEX_LN, OS_PREFIX);
public static final QName QUERY = new QName(OPENSEARCH_NS, QUERY_LN, OS_PREFIX);
public static final String OPENSEARCH_DESCRIPTION_LN = "OpenSearchDescription";
public static final String DESCRIPTION_LN = "Description";
public static final String SHORT_NAME_LN = "ShortName";
public static final String TAGS_LN = "Tags";
public static final String URL_LN = "Url";
public static final String URL_TYPE_LN = "type";
public static final String URL_TEMPLATE_LN = "template";
public static final String URL_INDEXOFFSET_LN = "indexOffset";
public static final String URL_PAGEOFFSET_LN = "pageOffset";
public static final QName OPENSEARCH_DESCRIPTION = new QName(OPENSEARCH_NS, OPENSEARCH_DESCRIPTION_LN, OS_PREFIX);
public static final QName DESCRIPTION = new QName(OPENSEARCH_NS, DESCRIPTION_LN, OS_PREFIX);
public static final QName SHORT_NAME = new QName(OPENSEARCH_NS, SHORT_NAME_LN, OS_PREFIX);
public static final QName TAGS = new QName(OPENSEARCH_NS, TAGS_LN, OS_PREFIX);
public static final QName URL = new QName(OPENSEARCH_NS, URL_LN, OS_PREFIX);
}
| 7,602 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/OpenSearchUrlAdapter.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.opensearch.server;
import java.util.Map;
import org.apache.abdera.protocol.server.RequestContext;
import org.apache.abdera.protocol.server.ResponseContext;
/**
* The OpenSearchUrlAdapter interface provides the business logic for executing search operations and getting back
* Atom-based responses augmented with Open Search metadata.
*/
public interface OpenSearchUrlAdapter {
/**
* Make the actual search operation based on passed parameters.
*
* @param request The {@link org.apache.abdera.protocol.server.RequestContext} object.
* @param parameters Search parameters extracted from the request: they are the same parameters reported into the
* Open Search URL template.
*/
ResponseContext search(RequestContext request, Map<String, String> parameters);
}
| 7,603 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/OpenSearchInfo.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.opensearch.server;
import org.apache.abdera.ext.opensearch.model.OpenSearchDescription;
import org.apache.abdera.protocol.server.RequestContext;
/**
* Metadata interface holding information about the Open Search Description document.
*/
public interface OpenSearchInfo {
/**
* Get the Open Search document short name.
*/
String getShortName();
/**
* Get the Open Search document description.
*/
String getDescription();
/**
* Get the Open Search document tags.
*/
String[] getTags();
/**
* Get the Open Search queries.
*/
OpenSearchQueryInfo[] getQueries();
/**
* Get the Open Search URLs metadata.
*/
OpenSearchUrlInfo[] getUrls();
/**
* Create the related {@link org.apache.abdera.ext.opensearch.model.OpenSearchDescription} element.
*/
OpenSearchDescription asOpenSearchDescriptionElement(RequestContext request);
}
| 7,604 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/OpenSearchUrlInfo.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.opensearch.server;
import org.apache.abdera.ext.opensearch.model.Url;
import org.apache.abdera.protocol.server.RequestContext;
/**
* Metadata interface holding information about the Open Search URLs.
*/
public interface OpenSearchUrlInfo {
/**
* Get the URL content type.
*/
String getType();
/**
* Get the URL search path as appear after the servlet context path, and without the query string.
*/
String getSearchPath();
/**
* Get the URL search parameters.
*/
OpenSearchUrlParameterInfo[] getSearchParameters();
/**
* Get the {@link OpenSearchUrlAdapter} which will implement the actual search operation.
*/
OpenSearchUrlAdapter getOpenSearchUrlAdapter();
/**
* Create the related {@link org.apache.abdera.ext.opensearch.model.Url} element.
*/
Url asUrlElement(RequestContext request);
}
| 7,605 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/OpenSearchQueryInfo.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.opensearch.server;
import org.apache.abdera.ext.opensearch.model.Query;
import org.apache.abdera.protocol.server.RequestContext;
/**
* Metadata interface holding (limited) information about the Open Search query element.
*/
public interface OpenSearchQueryInfo {
/**
* Get the query role type.
*/
Query.Role getRole();
/**
* Get the query search terms.
*/
String getSearchTerms();
/**
* Create the related {@link org.apache.abdera.ext.opensearch.model.Query} element.
*/
Query asQueryElement(RequestContext request);
}
| 7,606 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/OpenSearchUrlParameterInfo.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.opensearch.server;
/**
* Metadata interface holding information about an Open Search URL parameter.
*/
public interface OpenSearchUrlParameterInfo {
/**
* Get the parameter name.
*/
String getName();
/**
* Get the parameter value.
*/
String getValue();
/**
* Return true if the parameter is optional, false otherwise.
*/
boolean isOptional();
}
| 7,607 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/impl/SimpleOpenSearchInfo.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.opensearch.server.impl;
import java.util.ArrayList;
import java.util.List;
import org.apache.abdera.ext.opensearch.model.OpenSearchDescription;
import org.apache.abdera.ext.opensearch.model.Query;
import org.apache.abdera.ext.opensearch.model.Url;
import org.apache.abdera.ext.opensearch.server.OpenSearchInfo;
import org.apache.abdera.ext.opensearch.server.OpenSearchQueryInfo;
import org.apache.abdera.ext.opensearch.server.OpenSearchUrlInfo;
import org.apache.abdera.protocol.server.RequestContext;
/**
* Simple {@link org.apache.abdera.ext.opensearch.server.OpenSearchInfo} implementation.
*/
public class SimpleOpenSearchInfo implements OpenSearchInfo {
private String shortName;
private String description;
private String[] tags;
private OpenSearchQueryInfo[] queries;
private OpenSearchUrlInfo[] urls;
public String getShortName() {
return this.shortName;
}
public void setShortName(String shortName) {
this.shortName = shortName;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public String[] getTags() {
return this.tags;
}
public void setTags(String... tags) {
this.tags = tags;
}
public OpenSearchQueryInfo[] getQueries() {
return this.queries;
}
public void setQueries(OpenSearchQueryInfo... queries) {
this.queries = queries;
}
public OpenSearchUrlInfo[] getUrls() {
return this.urls;
}
public void setUrls(OpenSearchUrlInfo... urls) {
this.urls = urls;
}
public OpenSearchDescription asOpenSearchDescriptionElement(RequestContext request) {
OpenSearchDescription document = new OpenSearchDescription(request.getAbdera());
document.setShortName(this.shortName);
document.setDescription(this.description);
document.setTags(this.tags);
if (this.urls != null) {
List<Url> urlElements = new ArrayList<Url>(this.urls.length);
for (OpenSearchUrlInfo urlInfo : this.urls) {
urlElements.add(urlInfo.asUrlElement(request));
}
document.addUrls(urlElements.toArray(new Url[this.urls.length]));
}
if (this.queries != null) {
List<Query> queryElements = new ArrayList<Query>(this.queries.length);
for (OpenSearchQueryInfo queryInfo : this.queries) {
queryElements.add(queryInfo.asQueryElement(request));
}
document.addQueries(queryElements.toArray(new Query[this.queries.length]));
}
return document;
}
}
| 7,608 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/impl/AbstractOpenSearchUrlAdapter.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.opensearch.server.impl;
import java.util.Date;
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.OpenSearchUrlAdapter;
import org.apache.abdera.factory.Factory;
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.server.RequestContext;
import org.apache.abdera.protocol.server.ResponseContext;
import org.apache.abdera.protocol.server.context.BaseResponseContext;
/**
* Abstract {@link org.apache.abdera.ext.opensearch.server.OpenSearchUrlAdapter} providing explicit methods to implement
* and/or override for executing the actual search and creating the Atom feed containing search results.
*
* @param <T> The generic object type representing a search result.
*/
public abstract class AbstractOpenSearchUrlAdapter<T> implements OpenSearchUrlAdapter {
public ResponseContext search(RequestContext request, Map<String, String> parameters) {
List<T> searchResults = this.doSearch(request, parameters);
Feed feed = this.createFeed(request, parameters, searchResults);
Document<Feed> document = feed.getDocument();
ResponseContext response = new BaseResponseContext<Document<Feed>>(document);
return response;
}
/**
* Get the identifier of the feed containing this search results.
*/
protected abstract String getOpenSearchFeedId(RequestContext request);
/**
* Get the title of the feed containing this search results.
*/
protected abstract String getOpenSearchFeedTitle(RequestContext request);
/**
* Get the author of the feed containing this search results.
*/
protected abstract Person getOpenSearchFeedAuthor(RequestContext request);
/**
* Get the update date of the feed containing this search results.
*/
protected abstract Date getOpenSearchFeedUpdatedDate(RequestContext request);
/**
* Do the actual search, returning a list of search results as generic objects.
*/
protected abstract List<T> doSearch(RequestContext request, Map<String, String> parameters);
/**
* Fill the given empty Atom entry from the given search result object.<br>
* This method is called once for every search result returned by the {#doSearch(RequestContext, Map<String,
* String>)} method.
*/
protected abstract void fillEntry(Entry entry, T entity);
/**
* Get the total number of results of this search.<br>
* By default, it's equal to the number of search results: override to provide a different behavior.<br>
* This element can be explicitly omitted from the feed by returning a negative value.
*/
protected int getOpenSearchFeedTotalResults(RequestContext request,
Map<String, String> parameters,
List<T> searchResults) {
return searchResults.size();
}
/**
* Get the number of items (entries) contained into this page (feed).<br>
* By default, it's equal to the number of search results: override to provide a different behavior.<br>
* This element can be explicitly omitted from the feed by returning a negative value.
*/
protected int getOpenSearchFeedItemsPerPage(RequestContext request,
Map<String, String> parameters,
List<T> searchResults) {
return searchResults.size();
}
/**
* Get the index number of the first result contained into this feed.<br>
* By default, this element is omitted: override to provide a different behavior.<br>
* This element can be explicitly omitted from the feed by returning a negative value.
*/
protected int getOpenSearchFeedStartIndex(RequestContext request,
Map<String, String> parameters,
List<T> searchResults) {
return -1;
}
/**
* Post process this feed in order to make custom modifications.<br>
* By default, this method does nothing: override to provide a different behavior.
*/
protected void postProcess(Feed feed, RequestContext request, Map<String, String> parameters, List<T> searchResults) {
}
private Feed createFeed(RequestContext searchRequest, Map<String, String> parameters, List<T> searchResults) {
Factory factory = searchRequest.getAbdera().getFactory();
Feed feed = factory.newFeed();
feed.setId(this.getOpenSearchFeedId(searchRequest));
feed.setTitle(this.getOpenSearchFeedTitle(searchRequest));
feed.addAuthor(this.getOpenSearchFeedAuthor(searchRequest));
feed.setUpdated(this.getOpenSearchFeedUpdatedDate(searchRequest));
feed.addLink(searchRequest.getUri().toString(), "self");
int totalResults = this.getOpenSearchFeedTotalResults(searchRequest, parameters, searchResults);
if (totalResults > -1) {
((IntegerElement)feed.addExtension(OpenSearchConstants.TOTAL_RESULTS)).setValue(totalResults);
}
int itemsPerPage = this.getOpenSearchFeedItemsPerPage(searchRequest, parameters, searchResults);
if (itemsPerPage > -1) {
((IntegerElement)feed.addExtension(OpenSearchConstants.ITEMS_PER_PAGE)).setValue(itemsPerPage);
}
int startIndex = this.getOpenSearchFeedStartIndex(searchRequest, parameters, searchResults);
if (startIndex > -1) {
((IntegerElement)feed.addExtension(OpenSearchConstants.START_INDEX)).setValue(startIndex);
}
for (T entity : searchResults) {
Entry entry = factory.newEntry();
this.fillEntry(entry, entity);
feed.addEntry(entry);
}
this.postProcess(feed, searchRequest, parameters, searchResults);
return feed;
}
}
| 7,609 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/impl/SimpleOpenSearchUrlInfo.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.opensearch.server.impl;
import org.apache.abdera.ext.opensearch.model.Url;
import org.apache.abdera.ext.opensearch.server.OpenSearchUrlAdapter;
import org.apache.abdera.ext.opensearch.server.OpenSearchUrlInfo;
import org.apache.abdera.ext.opensearch.server.OpenSearchUrlParameterInfo;
import org.apache.abdera.protocol.server.RequestContext;
/**
* Simple {@link org.apache.abdera.ext.opensearch.server.OpenSearchUrlInfo} implementation.
*/
public class SimpleOpenSearchUrlInfo implements OpenSearchUrlInfo {
private static final String ATOM_CONTENT_TYPE = "application/atom+xml";
private String searchPath;
private OpenSearchUrlParameterInfo[] searchParameters;
private OpenSearchUrlAdapter openSearchUrlAdapter;
public String getType() {
return ATOM_CONTENT_TYPE;
}
public String getSearchPath() {
return this.searchPath;
}
public void setSearchPath(String searchPath) {
this.searchPath = searchPath;
}
public OpenSearchUrlParameterInfo[] getSearchParameters() {
return this.searchParameters;
}
public void setSearchParameters(OpenSearchUrlParameterInfo... searchParameters) {
this.searchParameters = searchParameters;
}
public OpenSearchUrlAdapter getOpenSearchUrlAdapter() {
return this.openSearchUrlAdapter;
}
public void setOpenSearchUrlAdapter(OpenSearchUrlAdapter openSearchUrlAdapter) {
this.openSearchUrlAdapter = openSearchUrlAdapter;
}
public Url asUrlElement(RequestContext request) {
Url element = new Url(request.getAbdera());
element.setType(ATOM_CONTENT_TYPE);
StringBuilder template = new StringBuilder();
template.append(this.getTemplateUrl(request));
if (this.searchParameters != null) {
template.append("?");
for (int i = 0; i < this.searchParameters.length; i++) {
OpenSearchUrlParameterInfo param = this.searchParameters[i];
template.append(param.getName()).append("=").append("{").append(param.getValue());
if (param.isOptional()) {
template.append("?");
}
template.append("}");
if (i < this.searchParameters.length - 1) {
template.append("&");
}
}
}
element.setTemplate(template.toString());
return element;
}
private String getTemplateUrl(RequestContext request) {
String base = request.getBaseUri().toString();
String path = this.searchPath;
if (base.endsWith("/")) {
base = base.substring(0, base.length() - 1);
}
if (path.startsWith("/")) {
path = path.substring(1);
}
return base + "/" + path;
}
}
| 7,610 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/impl/SimpleOpenSearchQueryInfo.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.opensearch.server.impl;
import org.apache.abdera.ext.opensearch.model.Query;
import org.apache.abdera.ext.opensearch.model.Query.Role;
import org.apache.abdera.ext.opensearch.server.OpenSearchQueryInfo;
import org.apache.abdera.protocol.server.RequestContext;
/**
* Simple {@link org.apache.abdera.ext.opensearch.server.OpenSearchQueryInfo} implementation.
*/
public class SimpleOpenSearchQueryInfo implements OpenSearchQueryInfo {
private Query.Role role;
private String searchTerms;
public void setRole(Role role) {
this.role = role;
}
public Query.Role getRole() {
return this.role;
}
public void setSearchTerms(String searchTerms) {
this.searchTerms = searchTerms;
}
public String getSearchTerms() {
return this.searchTerms;
}
public Query asQueryElement(RequestContext request) {
Query query = new Query(request.getAbdera());
query.setRole(this.role);
query.setSearchTerms(this.searchTerms);
return query;
}
}
| 7,611 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/impl/SimpleOpenSearchUrlParameterInfo.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.opensearch.server.impl;
import org.apache.abdera.ext.opensearch.server.OpenSearchUrlParameterInfo;
/**
* Simple {@link org.apache.abdera.ext.opensearch.server.OpenSearchUrlParameterInfo} implementation.
*/
public class SimpleOpenSearchUrlParameterInfo implements OpenSearchUrlParameterInfo {
private String name;
private String value;
private boolean optional;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
public boolean isOptional() {
return this.optional;
}
public void setOptional(boolean optional) {
this.optional = optional;
}
}
| 7,612 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/processors/OpenSearchTargetTypes.java | package org.apache.abdera.ext.opensearch.server.processors;
import org.apache.abdera.protocol.server.TargetType;
/**
* Simple container of {@link org.apache.abdera.protocol.server.TargetType}s related to Open Search.
*/
public interface OpenSearchTargetTypes {
public static final TargetType OPENSEARCH_DESCRIPTION = TargetType.get("OPENSEARCH_DESCRIPTION", true);
public static final TargetType OPENSEARCH_URL = TargetType.get("OPENSEARCH_URL", true);
}
| 7,613 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/processors/OpenSearchDescriptionRequestProcessor.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.opensearch.server.processors;
import org.apache.abdera.ext.opensearch.OpenSearchConstants;
import org.apache.abdera.ext.opensearch.model.OpenSearchDescription;
import org.apache.abdera.ext.opensearch.server.OpenSearchInfo;
import org.apache.abdera.protocol.server.CollectionAdapter;
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.WorkspaceManager;
import org.apache.abdera.protocol.server.context.BaseResponseContext;
/**
* {@link org.apache.abdera.protocol.server.RequestProcessor} implementation for processing Open Search Description
* document GET requests.<br>
* This request processor needs an {@link org.apache.abdera.ext.opensearch.server.OpenSearchInfo} in order to provide
* information about the Open Search service.
*
* @see {@link #setOpenSearchInfo(OpenSearchInfo)}
*/
public class OpenSearchDescriptionRequestProcessor implements RequestProcessor {
private OpenSearchInfo openSearchInfo;
public ResponseContext process(RequestContext requestContext,
WorkspaceManager workspaceManager,
CollectionAdapter collectionAdapter) {
String method = requestContext.getMethod();
if (method.equalsIgnoreCase("GET")) {
OpenSearchDescription description = this.openSearchInfo.asOpenSearchDescriptionElement(requestContext);
ResponseContext response = new BaseResponseContext(description);
response.setContentType(OpenSearchConstants.OPENSEARCH_DESCRIPTION_CONTENT_TYPE);
return response;
} else {
return null;
}
}
public void setOpenSearchInfo(OpenSearchInfo openSearchInfo) {
this.openSearchInfo = openSearchInfo;
}
}
| 7,614 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/server/processors/OpenSearchUrlRequestProcessor.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.opensearch.server.processors;
import java.util.HashMap;
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.OpenSearchUrlInfo;
import org.apache.abdera.ext.opensearch.server.OpenSearchUrlParameterInfo;
import org.apache.abdera.protocol.server.CollectionAdapter;
import org.apache.abdera.protocol.server.ProviderHelper;
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.WorkspaceManager;
/**
* {@link org.apache.abdera.protocol.server.RequestProcessor} implementation for processing GET requests to Open Search
* urls and then delegating the actual search to the proper
* {@link org.apache.abdera.ext.opensearch.server.OpenSearchUrlAdapter}.<br>
* The proper {@link org.apache.abdera.ext.opensearch.server.OpenSearchUrlAdapter} is selected by searching the
* configured {@link org.apache.abdera.ext.opensearch.server.OpenSearchInfo} for an
* {@link org.apache.abdera.ext.opensearch.server.OpenSearchUrlInfo} with a matching search path.
*
* @see {@link #setOpenSearchInfo(OpenSearchInfo)}
*/
public class OpenSearchUrlRequestProcessor implements RequestProcessor {
private OpenSearchInfo openSearchInfo;
public ResponseContext process(final RequestContext requestContext,
final WorkspaceManager workspaceManager,
final CollectionAdapter collectionAdapter) {
String method = requestContext.getMethod();
if (method.equalsIgnoreCase("GET")) {
OpenSearchUrlInfo urlInfo = this.getMatchingUrlInfo(requestContext);
if (urlInfo != null) {
OpenSearchUrlAdapter adapter = urlInfo.getOpenSearchUrlAdapter();
if (adapter != null) {
Map<String, String> params = this.getUrlParametersFromRequest(requestContext, urlInfo);
return adapter.search(requestContext, params);
} else {
return ProviderHelper.notfound(requestContext);
}
} else {
return ProviderHelper.notfound(requestContext);
}
} else {
return null;
}
}
public void setOpenSearchInfo(OpenSearchInfo openSearchInfo) {
this.openSearchInfo = openSearchInfo;
}
private OpenSearchUrlInfo getMatchingUrlInfo(RequestContext request) {
String targetSearchPath =
this.stripSlashes(request.getTargetPath().substring(0, request.getTargetPath().indexOf("?")));
OpenSearchUrlInfo result = null;
for (OpenSearchUrlInfo urlInfo : this.openSearchInfo.getUrls()) {
String searchPath = this.stripSlashes(urlInfo.getSearchPath());
if (searchPath.equals(targetSearchPath)) {
result = urlInfo;
break;
}
}
return result;
}
private Map<String, String> getUrlParametersFromRequest(RequestContext request, OpenSearchUrlInfo urlInfo) {
Map<String, String> result = new HashMap<String, String>();
for (OpenSearchUrlParameterInfo paramInfo : urlInfo.getSearchParameters()) {
// TODO : enforce mandatory parameters?
String name = paramInfo.getName();
String value = request.getParameter(name);
if (value != null) {
result.put(name, value);
}
}
return result;
}
private String stripSlashes(String path) {
if (path.startsWith("/")) {
path = path.substring(1);
}
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
return path;
}
}
| 7,615 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/model/StringElement.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.opensearch.model;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
/**
* A generic string element.
*/
public class StringElement extends ElementWrapper {
public StringElement(Factory factory, QName qname) {
super(factory, qname);
}
public StringElement(Element internal) {
super(internal);
}
public String getValue() {
String value = this.getText();
return (value != null) ? value : "";
}
public void setValue(String value) {
this.setText(value);
}
}
| 7,616 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/model/Url.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.opensearch.model;
import org.apache.abdera.ext.opensearch.OpenSearchConstants;
import org.apache.abdera.Abdera;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
/**
* Open Search 1.1 Url element: describes an interface by which a search client can make search requests.<br>
* This supports all parts of the Open Search 1.1 Url specification.
*/
public class Url extends ElementWrapper {
public Url(Factory factory) {
super(factory, OpenSearchConstants.URL);
this.setAttributeValue(OpenSearchConstants.URL_INDEXOFFSET_LN, Integer.valueOf(1).toString());
this.setAttributeValue(OpenSearchConstants.URL_PAGEOFFSET_LN, Integer.valueOf(1).toString());
}
public Url(Abdera abdera) {
this(abdera.getFactory());
}
public Url(Element internal) {
super(internal);
}
public void setType(String type) {
if (type != null) {
this.setAttributeValue(OpenSearchConstants.URL_TYPE_LN, type);
} else {
this.removeAttribute(OpenSearchConstants.URL_TYPE_LN);
}
}
public String getType() {
return this.getAttributeValue(OpenSearchConstants.URL_TYPE_LN);
}
public void setTemplate(String template) {
if (template != null) {
this.setAttributeValue(OpenSearchConstants.URL_TEMPLATE_LN, template);
} else {
this.removeAttribute(OpenSearchConstants.URL_TEMPLATE_LN);
}
}
public String getTemplate() {
return this.getAttributeValue(OpenSearchConstants.URL_TEMPLATE_LN);
}
public void setIndexOffset(int offset) {
if (offset > -1) {
this.setAttributeValue(OpenSearchConstants.URL_INDEXOFFSET_LN, String.valueOf(offset));
} else {
this.removeAttribute(OpenSearchConstants.URL_INDEXOFFSET_LN);
}
}
public int getIndexOffset() {
String val = this.getAttributeValue(OpenSearchConstants.URL_INDEXOFFSET_LN);
return (val != null) ? Integer.parseInt(val) : -1;
}
public void setPageOffset(int offset) {
if (offset > -1) {
this.setAttributeValue(OpenSearchConstants.URL_PAGEOFFSET_LN, String.valueOf(offset));
} else {
this.removeAttribute(OpenSearchConstants.URL_PAGEOFFSET_LN);
}
}
public int getPageOffset() {
String val = this.getAttributeValue(OpenSearchConstants.URL_PAGEOFFSET_LN);
return (val != null) ? Integer.parseInt(val) : -1;
}
}
| 7,617 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/model/IntegerElement.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.opensearch.model;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
/**
* A generic integer element.
*/
public class IntegerElement extends ElementWrapper {
public IntegerElement(Factory factory, QName qname) {
super(factory, qname);
}
public IntegerElement(Element internal) {
super(internal);
}
public int getValue() {
String val = getText();
return (val != null) ? Integer.parseInt(val) : -1;
}
public void setValue(int value) {
this.setText(String.valueOf(value));
}
}
| 7,618 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/model/OpenSearchExtensionFactory.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.opensearch.model;
import org.apache.abdera.ext.opensearch.OpenSearchConstants;
import org.apache.abdera.util.AbstractExtensionFactory;
public final class OpenSearchExtensionFactory extends AbstractExtensionFactory implements OpenSearchConstants {
public OpenSearchExtensionFactory() {
super(OpenSearchConstants.OPENSEARCH_NS);
this.addImpl(QUERY, Query.class);
this.addImpl(ITEMS_PER_PAGE, IntegerElement.class);
this.addImpl(START_INDEX, IntegerElement.class);
this.addImpl(TOTAL_RESULTS, IntegerElement.class);
this.addImpl(OPENSEARCH_DESCRIPTION, OpenSearchDescription.class);
this.addImpl(SHORT_NAME, StringElement.class);
this.addImpl(DESCRIPTION, StringElement.class);
this.addImpl(TAGS, StringElement.class);
this.addImpl(URL, Url.class);
}
}
| 7,619 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/model/OpenSearchDescription.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.opensearch.model;
import java.util.List;
import org.apache.abdera.ext.opensearch.OpenSearchConstants;
import javax.xml.namespace.QName;
import org.apache.abdera.Abdera;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ExtensibleElementWrapper;
/**
* Open Search 1.1 Description Document element: used to describe the web interface of an Open Search based search
* engine.<br>
* Currently, this supports only a subset of the Open Search 1.1 Description Document element specification.
*/
public class OpenSearchDescription extends ExtensibleElementWrapper {
public OpenSearchDescription(Factory factory) {
super(factory, OpenSearchConstants.OPENSEARCH_DESCRIPTION);
}
public OpenSearchDescription(Abdera abdera) {
this(abdera.getFactory());
}
public OpenSearchDescription(Element internal) {
super(internal);
}
public void setShortName(String shortName) {
if (shortName == null) {
shortName = "";
}
this.setExtensionStringValue(OpenSearchConstants.SHORT_NAME, shortName);
}
public String getShortName() {
StringElement element = this.getExtension(OpenSearchConstants.SHORT_NAME);
return element.getValue();
}
public void setDescription(String description) {
if (description == null) {
description = "";
}
this.setExtensionStringValue(OpenSearchConstants.DESCRIPTION, description);
}
public String getDescription() {
StringElement element = this.getExtension(OpenSearchConstants.DESCRIPTION);
return element.getValue();
}
public void setTags(String... tags) {
if (tags != null && tags.length > 0) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < tags.length - 1; i++) {
builder.append(tags[i]).append(" ");
}
builder.append(tags[tags.length - 1]);
this.setExtensionStringValue(OpenSearchConstants.TAGS, builder.toString());
} else {
this.setExtensionStringValue(OpenSearchConstants.TAGS, "");
}
}
public String getTags() {
StringElement element = this.getExtension(OpenSearchConstants.TAGS);
return element.getValue();
}
public void addUrls(Url... urls) {
if (urls != null && urls.length > 0) {
for (Url url : urls) {
this.addExtension(url);
}
}
}
public List<Url> getUrls() {
return this.getExtensions(OpenSearchConstants.URL);
}
public void addQueries(Query... queries) {
if (queries != null && queries.length > 0) {
for (Query query : queries) {
this.addExtension(query);
}
}
}
public List<Query> getQueries() {
return this.getExtensions(OpenSearchConstants.QUERY);
}
private void setExtensionStringValue(QName extension, String value) {
StringElement element = this.getExtension(extension);
if (element == null) {
element = this.addExtension(extension);
}
element.setValue(value);
}
}
| 7,620 |
0 | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch | Create_ds/abdera/extensions/opensearch/src/main/java/org/apache/abdera/ext/opensearch/model/Query.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.opensearch.model;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.opensearch.OpenSearchConstants;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ExtensibleElementWrapper;
/**
* Open Search 1.1 Query element: defines a search query that can be performed by search clients.<br>
* This supports all parts of the Open Search 1.1 Url specification.
*/
public class Query extends ExtensibleElementWrapper {
public Query(Factory factory) {
super(factory, OpenSearchConstants.QUERY);
}
public Query(Abdera abdera) {
this(abdera.getFactory());
}
public Query(Element internal) {
super(internal);
}
public Role getRole() {
String role = this.getAttributeValue(OpenSearchConstants.QUERY_ROLE_LN);
if (role == null) {
return null;
}
try {
return Role.valueOf(role.toUpperCase());
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
public void setRole(Role role) {
if (role != null) {
this.setAttributeValue(OpenSearchConstants.QUERY_ROLE_LN, role.name().toLowerCase());
} else {
this.removeAttribute(OpenSearchConstants.QUERY_ROLE_LN);
}
}
public String getTitle() {
return this.getAttributeValue(OpenSearchConstants.QUERY_TITLE_LN);
}
public void setTitle(String title) {
if (title != null) {
if (title.length() > 256) {
throw new IllegalArgumentException("Title too long (max 256 characters)");
}
this.setAttributeValue(OpenSearchConstants.QUERY_TITLE_LN, title);
} else {
this.removeAttribute(OpenSearchConstants.QUERY_TITLE_LN);
}
}
public int getTotalResults() {
String val = this.getAttributeValue(OpenSearchConstants.QUERY_TOTALRESULTS_LN);
return (val != null) ? Integer.parseInt(val) : -1;
}
public void setTotalResults(int totalResults) {
if (totalResults > -1) {
this.setAttributeValue(OpenSearchConstants.QUERY_TOTALRESULTS_LN, String.valueOf(totalResults));
} else {
this.removeAttribute(OpenSearchConstants.QUERY_TOTALRESULTS_LN);
}
}
public String getSearchTerms() {
return this.getAttributeValue(OpenSearchConstants.QUERY_SEARCHTERMS_LN);
}
public void setSearchTerms(String terms) {
if (terms != null) {
this.setAttributeValue(OpenSearchConstants.QUERY_SEARCHTERMS_LN, terms);
} else {
this.removeAttribute(OpenSearchConstants.QUERY_SEARCHTERMS_LN);
}
}
public int getCount() {
String val = this.getAttributeValue(OpenSearchConstants.QUERY_COUNT_LN);
return (val != null) ? Integer.parseInt(val) : -1;
}
public void setCount(int count) {
if (count > -1) {
this.setAttributeValue(OpenSearchConstants.QUERY_COUNT_LN, String.valueOf(count));
} else {
this.removeAttribute(OpenSearchConstants.QUERY_COUNT_LN);
}
}
public int getStartIndex() {
String val = this.getAttributeValue(OpenSearchConstants.QUERY_STARTINDEX_LN);
return (val != null) ? Integer.parseInt(val) : -1;
}
public void setStartIndex(int startIndex) {
if (startIndex > -1) {
this.setAttributeValue(OpenSearchConstants.QUERY_STARTINDEX_LN, String.valueOf(startIndex));
} else {
this.removeAttribute(OpenSearchConstants.QUERY_STARTINDEX_LN);
}
}
public int getStartPage() {
String val = this.getAttributeValue(OpenSearchConstants.QUERY_STARTPAGE_LN);
return (val != null) ? Integer.parseInt(val) : -1;
}
public void setStartPage(int startPage) {
if (startPage > -1) {
this.setAttributeValue(OpenSearchConstants.QUERY_STARTPAGE_LN, String.valueOf(startPage));
} else {
this.removeAttribute(OpenSearchConstants.QUERY_STARTPAGE_LN);
}
}
public String getResultsLanguage() {
return this.getAttributeValue(OpenSearchConstants.QUERY_LANGUAGE_LN);
}
public void setResultsLanguage(String language) {
if (language != null) {
this.setAttributeValue(OpenSearchConstants.QUERY_LANGUAGE_LN, language);
} else {
this.removeAttribute(OpenSearchConstants.QUERY_LANGUAGE_LN);
}
}
public String getInputEncoding() {
return this.getAttributeValue(OpenSearchConstants.QUERY_INPUTENCODING_LN);
}
public void setInputEncoding(String encoding) {
if (encoding != null) {
this.setAttributeValue(OpenSearchConstants.QUERY_INPUTENCODING_LN, encoding);
} else {
this.removeAttribute(OpenSearchConstants.QUERY_INPUTENCODING_LN);
}
}
public String getOutputEncoding() {
return this.getAttributeValue(OpenSearchConstants.QUERY_OUTPUTENCODING_LN);
}
public void setOutputEncoding(String encoding) {
if (encoding != null) {
this.setAttributeValue(OpenSearchConstants.QUERY_OUTPUTENCODING_LN, encoding);
} else {
this.removeAttribute(OpenSearchConstants.QUERY_OUTPUTENCODING_LN);
}
}
public enum Role {
CORRECTION, EXAMPLE, RELATED, REQUEST, SUBSET, SUPERSET;
}
}
| 7,621 |
0 | Create_ds/abdera/extensions/rss/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/rss/src/test/java/org/apache/abdera/test/ext/rss/RssTest.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.rss;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.InputStream;
import java.util.List;
import org.apache.abdera.Abdera;
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.junit.Test;
public class RssTest {
@Test
public void testRSS1() {
Abdera abdera = new Abdera();
InputStream in = RssTest.class.getResourceAsStream("/rss1.rdf");
Document<Feed> doc = abdera.getParser().parse(in);
Feed feed = doc.getRoot();
assertEquals("XML.com", feed.getTitle());
assertEquals("http://xml.com/pub", feed.getAlternateLinkResolvedHref().toASCIIString());
assertEquals("XML.com features a rich mix of information and services \n for the XML community.", feed
.getSubtitle().trim());
assertNotNull(feed.getAuthor());
assertEquals("James Snell", feed.getAuthor().getName());
assertEquals("jasnell@example.com", feed.getAuthor().getEmail());
assertEquals(1, feed.getCategories().size());
assertEquals("Anything", feed.getCategories().get(0).getTerm());
assertEquals("foo", feed.getId().toASCIIString());
assertEquals("Copyright 2007 Foo", feed.getRights());
assertNotNull(feed.getUpdated());
assertEquals("en-US", feed.getLanguage());
assertEquals(1, feed.getContributors().size());
Person person = feed.getContributors().get(0);
assertEquals("John Doe", person.getName());
assertEquals("jdoe@example.org", person.getEmail());
List<Entry> entries = feed.getEntries();
assertEquals(2, entries.size());
Entry entry = entries.get(0);
assertEquals("Processing Inclusions with XSLT", entry.getTitle());
assertEquals("http://xml.com/pub/2000/08/09/xslt/xslt.html", entry.getId().toASCIIString());
assertEquals("http://xml.com/pub/2000/08/09/xslt/xslt.html", entry.getAlternateLinkResolvedHref()
.toASCIIString());
assertNotNull(entry.getSummary());
assertEquals("testing", entry.getContent());
person = entry.getAuthor();
System.out.println(person.getName());
assertEquals("Bob", person.getName());
entry = entries.get(1);
assertEquals("Putting RDF to Work", entry.getTitle());
assertEquals("http://xml.com/pub/2000/08/09/rdfdb/index.html", entry.getId().toASCIIString());
assertEquals("http://xml.com/pub/2000/08/09/rdfdb/index.html", entry.getAlternateLinkResolvedHref()
.toASCIIString());
assertNotNull(entry.getSummary());
assertEquals("testing", entry.getContent());
person = entry.getAuthor();
assertEquals("Joe", person.getName());
}
}
| 7,622 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssLink.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.rss;
import javax.activation.MimeType;
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.ExtensibleElementWrapper;
import org.apache.abdera.model.Link;
public class RssLink extends ExtensibleElementWrapper implements Link {
public RssLink(Element internal) {
super(internal);
}
public RssLink(Factory factory, QName qname) {
super(factory, qname);
}
public IRI getHref() {
String txt = getText();
return (txt != null) ? new IRI(txt) : null;
}
public String getHrefLang() {
return null;
}
public long getLength() {
return -1;
}
public MimeType getMimeType() {
return null;
}
public String getRel() {
QName qname = getQName();
if (qname.equals(RssConstants.QNAME_DOCS)) {
return "docs";
} else if (qname.equals(RssConstants.QNAME_COMMENTS)) {
return "comments";
} else {
return Link.REL_ALTERNATE;
}
}
public IRI getResolvedHref() {
return getHref();
}
public String getTitle() {
return null;
}
public Link setHref(String href) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setHrefLang(String lang) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setLength(long length) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setMimeType(String type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setRel(String rel) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setTitle(String title) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
}
| 7,623 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssCategory.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.rss;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ExtensibleElement;
import org.apache.abdera.model.ExtensibleElementWrapper;
public class RssCategory extends ExtensibleElementWrapper implements Category {
public RssCategory(Element internal) {
super(internal);
}
public RssCategory(Factory factory, QName qname) {
super(factory, qname);
}
public String getLabel() {
return null;
}
public IRI getScheme() {
String domain = this.getAttributeValue("domain");
return (domain != null) ? new IRI(this.getAttributeValue("domain")) : null;
}
public String getTerm() {
return getText();
}
public Category setLabel(String label) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Category setScheme(String scheme) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Category setTerm(String term) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends ExtensibleElement> T addExtension(Element extension) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> T addExtension(QName qname) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> T addExtension(String namespace, String localPart, String prefix) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Element addSimpleExtension(QName qname, String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Element addSimpleExtension(String namespace, String localPart, String prefix, String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> T getExtension(QName qname) {
return null;
}
public <T extends Element> T getExtension(Class<T> _class) {
return null;
}
public List<Element> getExtensions() {
return null;
}
public List<Element> getExtensions(String uri) {
return null;
}
public <T extends Element> List<T> getExtensions(QName qname) {
return null;
}
public String getSimpleExtension(QName qname) {
return null;
}
public String getSimpleExtension(String namespace, String localPart, String prefix) {
return null;
}
}
| 7,624 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssUriElement.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.rss;
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;
import org.apache.abdera.model.IRIElement;
public class RssUriElement extends ElementWrapper implements IRIElement {
public RssUriElement(Element internal) {
super(internal);
}
public RssUriElement(Factory factory, QName qname) {
super(factory, qname);
}
public IRI getResolvedValue() {
return getValue();
}
public IRI getValue() {
return new IRI(getText());
}
public IRIElement setNormalizedValue(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setValue(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
}
| 7,625 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssContent.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.rss;
import javax.activation.DataHandler;
import javax.activation.MimeType;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
public class RssContent extends ElementWrapper implements Content {
public RssContent(Element internal) {
super(internal);
}
public RssContent(Factory factory, QName qname) {
super(factory, qname);
}
public Type getContentType() {
return Type.HTML;
}
public DataHandler getDataHandler() {
return null;
}
public MimeType getMimeType() {
return null;
}
public IRI getResolvedSrc() {
return null;
}
public IRI getSrc() {
return null;
}
public String getValue() {
return getText();
}
public <T extends Element> T getValueElement() {
return null;
}
public String getWrappedValue() {
return getText();
}
public Content setContentType(Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setDataHandler(DataHandler dataHandler) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setMimeType(String type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setSrc(String src) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setValue(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> Content setValueElement(T value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setWrappedValue(String wrappedValue) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
}
| 7,626 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssFeed.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.rss;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.Collection;
import org.apache.abdera.model.DateTime;
import org.apache.abdera.model.Div;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.ExtensibleElement;
import org.apache.abdera.model.ExtensibleElementWrapper;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Generator;
import org.apache.abdera.model.IRIElement;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Person;
import org.apache.abdera.model.Source;
import org.apache.abdera.model.Text;
import org.apache.abdera.model.Text.Type;
public class RssFeed extends ExtensibleElementWrapper implements Feed {
public RssFeed(Element internal) {
super(internal);
}
public RssFeed(Factory factory, QName qname) {
super(factory, qname);
}
@SuppressWarnings("unused")
private RssChannel getChannel() {
RssChannel c = super.getExtension(RssConstants.QNAME_CHANNEL);
if (c == null)
c = super.getExtension(RssConstants.QNAME_RDF_CHANNEL);
return c;
}
public Feed addEntry(Entry entry) {
getChannel().addEntry(entry);
return this;
}
public Entry addEntry() {
return getChannel().addEntry();
}
public Source getAsSource() {
throw new UnsupportedOperationException("Converting to source is not supported");
}
public List<Entry> getEntries() {
return getChannel().getEntries();
}
public Entry getEntry(String id) {
return getChannel().getEntry(id);
}
public Feed insertEntry(Entry entry) {
getChannel().insertEntry(entry);
return this;
}
public Entry insertEntry() {
return getChannel().insertEntry();
}
public Feed sortEntries(Comparator<Entry> comparator) {
getChannel().sortEntries(comparator);
return this;
}
public Feed sortEntriesByEdited(boolean new_first) {
getChannel().sortEntriesByEdited(new_first);
return this;
}
public Feed sortEntriesByUpdated(boolean new_first) {
getChannel().sortEntriesByUpdated(new_first);
return this;
}
public <T extends Source> T addAuthor(Person person) {
getChannel().addAuthor(person);
return (T)this;
}
public Person addAuthor(String name) {
return getChannel().addAuthor(name);
}
public Person addAuthor(String name, String email, String iri) {
return getChannel().addAuthor(name, email, iri);
}
public <T extends Source> T addCategory(Category category) {
getChannel().addCategory(category);
return (T)this;
}
public Category addCategory(String term) {
return getChannel().addCategory(term);
}
public Category addCategory(String scheme, String term, String label) {
return getChannel().addCategory(scheme, term, label);
}
public <T extends Source> T addContributor(Person person) {
throw new UnsupportedOperationException("Contributor's are not supported");
}
public Person addContributor(String name) {
throw new UnsupportedOperationException("Contributor's are not supported");
}
public Person addContributor(String name, String email, String iri) {
throw new UnsupportedOperationException("Contributor's are not supported");
}
public <T extends Source> T addLink(Link link) {
getChannel().addLink(link);
return (T)this;
}
public Link addLink(String href) {
return getChannel().addLink(href);
}
public Link addLink(String href, String rel) {
return getChannel().addLink(href, rel);
}
public Link addLink(String href, String rel, String type, String title, String hreflang, long length) {
return getChannel().addLink(href, rel, type, title, hreflang, length);
}
public Link getAlternateLink() {
return getChannel().getAlternateLink();
}
public Link getAlternateLink(String type, String hreflang) {
return getChannel().getAlternateLink(type, hreflang);
}
public IRI getAlternateLinkResolvedHref() {
return getChannel().getAlternateLinkResolvedHref();
}
public IRI getAlternateLinkResolvedHref(String type, String hreflang) {
return getChannel().getAlternateLinkResolvedHref(type, hreflang);
}
public Person getAuthor() {
return getChannel().getAuthor();
}
public List<Person> getAuthors() {
return getChannel().getAuthors();
}
public List<Category> getCategories() {
return getChannel().getCategories();
}
public List<Category> getCategories(String scheme) {
return getChannel().getCategories(scheme);
}
public Collection getCollection() {
// TODO: should I support this?
return null;
}
public List<Person> getContributors() {
return getChannel().getContributors();
}
public Generator getGenerator() {
return getChannel().getGenerator();
}
public IRI getIcon() {
return getChannel().getIcon();
}
public IRIElement getIconElement() {
return getChannel().getIconElement();
}
public IRI getId() {
return getChannel().getId();
}
public IRIElement getIdElement() {
return getChannel().getIdElement();
}
public Link getLink(String rel) {
return getChannel().getLink(rel);
}
public IRI getLinkResolvedHref(String rel) {
return getChannel().getLinkResolvedHref(rel);
}
public List<Link> getLinks() {
return getChannel().getLinks();
}
public List<Link> getLinks(String rel) {
return getChannel().getLinks(rel);
}
public List<Link> getLinks(String... rel) {
return getChannel().getLinks(rel);
}
public IRI getLogo() {
return getChannel().getLogo();
}
public IRIElement getLogoElement() {
return getChannel().getLogoElement();
}
public String getRights() {
return getChannel().getRights();
}
public Text getRightsElement() {
return getChannel().getRightsElement();
}
public Type getRightsType() {
return getChannel().getRightsType();
}
public Link getSelfLink() {
return getChannel().getSelfLink();
}
public IRI getSelfLinkResolvedHref() {
return getChannel().getSelfLinkResolvedHref();
}
public String getSubtitle() {
return getChannel().getSubtitle();
}
public Text getSubtitleElement() {
return getChannel().getSubtitleElement();
}
public Type getSubtitleType() {
return getChannel().getSubtitleType();
}
public String getTitle() {
return getChannel().getTitle();
}
public Text getTitleElement() {
return getChannel().getTitleElement();
}
public Type getTitleType() {
return getChannel().getTitleType();
}
public Date getUpdated() {
return getChannel().getUpdated();
}
public DateTime getUpdatedElement() {
return getChannel().getUpdatedElement();
}
public String getUpdatedString() {
return getChannel().getUpdatedString();
}
public Date getPublished() {
return getChannel().getPublished();
}
public DateTime getPublisheddElement() {
return getChannel().getPublishedElement();
}
public String getPublishedString() {
return getChannel().getPublishedString();
}
public IRIElement newId() {
return getChannel().newId();
}
public <T extends Source> T setCollection(Collection collection) {
throw new UnsupportedOperationException("Collection is not supported");
}
public <T extends Source> T setGenerator(Generator generator) {
getChannel().setGenerator(generator);
return (T)this;
}
public Generator setGenerator(String iri, String version, String value) {
return getChannel().setGenerator(iri, version, value);
}
public IRIElement setIcon(String iri) {
return getChannel().setIcon(iri);
}
public <T extends Source> T setIconElement(IRIElement iri) {
getChannel().setIconElement(iri);
return (T)this;
}
public IRIElement setId(String id) {
return getChannel().setId(id);
}
public IRIElement setId(String id, boolean normalize) {
return getChannel().setId(id, normalize);
}
public <T extends Source> T setIdElement(IRIElement id) {
getChannel().setIdElement(id);
return (T)this;
}
public IRIElement setLogo(String iri) {
return getChannel().setLogo(iri);
}
public <T extends Source> T setLogoElement(IRIElement iri) {
getChannel().setLogoElement(iri);
return (T)this;
}
public Text setRights(String value) {
return getChannel().setRights(value);
}
public Text setRights(String value, Type type) {
return getChannel().setRights(value, type);
}
public Text setRights(Div value) {
return getChannel().setRights(value);
}
public Text setRightsAsHtml(String value) {
return getChannel().setRightsAsHtml(value);
}
public Text setRightsAsXhtml(String value) {
return getChannel().setRightsAsXhtml(value);
}
public <T extends Source> T setRightsElement(Text text) {
getChannel().setRightsElement(text);
return (T)this;
}
public Text setSubtitle(String value) {
return getChannel().setSubtitle(value);
}
public Text setSubtitle(String value, Type type) {
return getChannel().setSubtitle(value, type);
}
public Text setSubtitle(Div value) {
return getChannel().setSubtitle(value);
}
public Text setSubtitleAsHtml(String value) {
return getChannel().setSubtitleAsHtml(value);
}
public Text setSubtitleAsXhtml(String value) {
return getChannel().setSubtitleAsXhtml(value);
}
public <T extends Source> T setSubtitleElement(Text text) {
getChannel().setSubtitleElement(text);
return (T)this;
}
public Text setTitle(String value) {
return getChannel().setTitle(value);
}
public Text setTitle(String value, Type type) {
return getChannel().setTitle(value, type);
}
public Text setTitle(Div value) {
return getChannel().setTitle(value);
}
public Text setTitleAsHtml(String value) {
return getChannel().setTitleAsHtml(value);
}
public Text setTitleAsXhtml(String value) {
return getChannel().setTitleAsXhtml(value);
}
public <T extends Source> T setTitleElement(Text text) {
getChannel().setTitleElement(text);
return (T)this;
}
public DateTime setUpdated(Date value) {
return getChannel().setUpdated(value);
}
public DateTime setUpdated(String value) {
return getChannel().setUpdated(value);
}
public <T extends Source> T setUpdatedElement(DateTime dateTime) {
getChannel().setUpdatedElement(dateTime);
return (T)this;
}
public <T extends ExtensibleElement> T addExtension(Element extension) {
getChannel().addExtension(extension);
return (T)this;
}
public <T extends Element> T addExtension(QName qname) {
return (T)getChannel().addExtension(qname);
}
public <T extends Element> T addExtension(String namespace, String localPart, String prefix) {
return (T)getChannel().addExtension(namespace, localPart, prefix);
}
public Element addSimpleExtension(QName qname, String value) {
return getChannel().addSimpleExtension(qname, value);
}
public Element addSimpleExtension(String namespace, String localPart, String prefix, String value) {
return getChannel().addSimpleExtension(namespace, localPart, prefix, value);
}
public <T extends Element> T getExtension(QName qname) {
return (T)getChannel().getExtension(qname);
}
public <T extends Element> T getExtension(Class<T> _class) {
return getChannel().getExtension(_class);
}
public List<Element> getExtensions() {
return getChannel().getExtensions();
}
public List<Element> getExtensions(String uri) {
return getChannel().getExtensions(uri);
}
public <T extends Element> List<T> getExtensions(QName qname) {
return getChannel().getExtensions(qname);
}
public String getSimpleExtension(QName qname) {
return getChannel().getSimpleExtension(qname);
}
public String getSimpleExtension(String namespace, String localPart, String prefix) {
return getChannel().getSimpleExtension(namespace, localPart, prefix);
}
public String getAttributeValue(String name) {
return getChannel().getAttributeValue(name);
}
public String getAttributeValue(QName qname) {
return getChannel().getAttributeValue(qname);
}
public List<QName> getAttributes() {
return getChannel().getAttributes();
}
public List<QName> getExtensionAttributes() {
return getChannel().getExtensionAttributes();
}
public String getLanguage() {
return getChannel().getLanguage();
}
public <T extends Element> T removeAttribute(QName qname) {
getChannel().removeAttribute(qname);
return (T)this;
}
public <T extends Element> T setAttributeValue(String name, String value) {
getChannel().setAttributeValue(name, value);
return (T)this;
}
public <T extends Element> T setAttributeValue(QName qname, String value) {
getChannel().setAttributeValue(qname, value);
return (T)this;
}
public <T extends Element> T setBaseUri(IRI base) {
// throw new UnsupportedOperationException("Setting the base uri with xml:base is not supported");
return (T)this;
}
public <T extends Element> T setBaseUri(String base) {
// throw new UnsupportedOperationException("Setting the base uri with xml:base is not supported");
return (T)this;
}
public <T extends Element> T setLanguage(String language) {
getChannel().setLanguage(language);
return (T)this;
}
public String getVersion() {
return super.getAttributeValue("version");
}
public Feed getAsFeed() {
throw new UnsupportedOperationException("Converting to feed is not supported");
}
}
| 7,627 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssPerson.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.rss;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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.IRIElement;
import org.apache.abdera.model.Person;
import org.apache.abdera.model.PersonWrapper;
public class RssPerson extends PersonWrapper implements Person {
static String EMAIL_PATTERN =
"(([a-zA-Z0-9\\_\\-\\.\\+]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?))(\\?subject=\\S+)?";
private String email = null;
private String name = null;
public RssPerson(Element internal) {
super(internal);
Pattern p = Pattern.compile(EMAIL_PATTERN);
String t = getText();
Matcher m = p.matcher(t);
if (m.find()) {
email = m.group(0);
name =
t.replaceAll(email, "").replaceAll("[\\(\\)\\<\\>]", "").replaceAll("mailto:", "")
.replaceAll("\\<\\;", "").replaceAll("\\>\\;", "").trim();
}
}
public RssPerson(Factory factory, QName qname) {
super(factory, qname);
}
@Override
public String getEmail() {
return email;
}
@Override
public Element getEmailElement() {
return null;
}
@Override
public String getName() {
return name;
}
@Override
public Element getNameElement() {
return null;
}
@Override
public IRI getUri() {
return null;
}
@Override
public IRIElement getUriElement() {
return null;
}
@Override
public Element setEmail(String email) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
@Override
public Person setEmailElement(Element element) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
@Override
public Element setName(String name) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
@Override
public Person setNameElement(Element element) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
@Override
public IRIElement setUri(String uri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
@Override
public Person setUriElement(IRIElement element) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
}
| 7,628 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssText.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.rss;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Div;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
import org.apache.abdera.model.Text;
public class RssText extends ElementWrapper implements Text {
public RssText(Element internal) {
super(internal);
}
public RssText(Factory factory, QName qname) {
super(factory, qname);
}
public Type getTextType() {
return Type.HTML;
}
public String getValue() {
return getText();
}
public Div getValueElement() {
return null;
}
public String getWrappedValue() {
return getValue();
}
public Text setTextType(Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setValue(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setValueElement(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setWrappedValue(String wrappedValue) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
}
| 7,629 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssImage.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.rss;
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.ExtensibleElementWrapper;
import org.apache.abdera.model.IRIElement;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Text;
public class RssImage extends ExtensibleElementWrapper implements IRIElement {
public RssImage(Element internal) {
super(internal);
}
public RssImage(Factory factory, QName qname) {
super(factory, qname);
}
public IRI getResolvedValue() {
return getValue();
}
public IRI getValue() {
IRIElement iri = getExtension(RssConstants.QNAME_URL);
if (iri == null) {
iri = getExtension(RssConstants.QNAME_RDF_URL);
}
if (iri == null) {
String t = getAttributeValue(RssConstants.QNAME_RDF_ABOUT);
if (t != null)
return new IRI(t);
}
return (iri != null) ? iri.getValue() : null;
}
public IRIElement setNormalizedValue(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setValue(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public String getTitle() {
Text text = getExtension(RssConstants.QNAME_TITLE);
if (text == null)
text = getExtension(RssConstants.QNAME_RDF_TITLE);
return (text != null) ? text.getValue() : null;
}
public String getDescription() {
Text text = getExtension(RssConstants.QNAME_DESCRIPTION);
if (text == null)
text = getExtension(RssConstants.QNAME_RDF_DESCRIPTION);
return (text != null) ? text.getValue() : null;
}
public IRI getLink() {
Link link = getExtension(RssConstants.QNAME_LINK);
if (link == null)
link = getExtension(RssConstants.QNAME_RDF_LINK);
return (link != null) ? link.getHref() : null;
}
public int getWidth() {
String w = getSimpleExtension(RssConstants.QNAME_WIDTH);
return (w != null) ? Integer.parseInt(w) : -1;
}
public int getHeight() {
String w = getSimpleExtension(RssConstants.QNAME_HEIGHT);
return (w != null) ? Integer.parseInt(w) : -1;
}
}
| 7,630 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssSkipDays.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.rss;
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 RssSkipDays extends ExtensibleElementWrapper {
public RssSkipDays(Element internal) {
super(internal);
}
public RssSkipDays(Factory factory, QName qname) {
super(factory, qname);
}
public enum Day {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
public boolean skip(Day day) {
List<Element> days = getExtensions(RssConstants.QNAME_DAY);
for (Element d : days) {
try {
Day check = Day.valueOf(d.getText().toUpperCase());
if (d.equals(check))
return true;
} catch (Exception e) {
}
}
return false;
}
}
| 7,631 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssConstants.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.rss;
import javax.xml.namespace.QName;
public interface RssConstants {
public static final String RSS_MEDIATYPE = "application/rss+xml";
public static final String RDF_MEDIATYPE = "application/rdf+xml";
public static final String ENC_NS = "http://purl.org/rss/1.0/modules/content/";
public static final String RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
public static final String RSS1_NS = "http://purl.org/rss/1.0/";
public static final String DC_NS = "http://purl.org/dc/elements/1.1/";
public static final QName QNAME_RDF = new QName(RDF_NS, "RDF");
public static final QName QNAME_RDF_CHANNEL = new QName(RSS1_NS, "channel");
public static final QName QNAME_RDF_TITLE = new QName(RSS1_NS, "title");
public static final QName QNAME_RDF_LINK = new QName(RSS1_NS, "link");
public static final QName QNAME_RDF_DESCRIPTION = new QName(RSS1_NS, "description");
public static final QName QNAME_RDF_ITEM = new QName(RSS1_NS, "item");
public static final QName QNAME_RDF_IMAGE = new QName(RSS1_NS, "image");
public static final QName QNAME_RDF_SEQ = new QName(RDF_NS, "Seq");
public static final QName QNAME_RDF_LI = new QName(RDF_NS, "li");
public static final QName QNAME_RDF_RESOURCE = new QName(RDF_NS, "resource");
public static final QName QNAME_RDF_ABOUT = new QName(RDF_NS, "about");
public static final QName QNAME_RDF_URL = new QName(RSS1_NS, "url");
public static final QName QNAME_RDF_ITEMS = new QName(RSS1_NS, "items");
public static final QName QNAME_RSS = new QName("rss");
public static final QName QNAME_CHANNEL = new QName("channel");
public static final QName QNAME_ITEM = new QName("item");
public static final QName QNAME_LINK = new QName("link");
public static final QName QNAME_TITLE = new QName("title");
public static final QName QNAME_DESCRIPTION = new QName("description");
public static final QName QNAME_LANGUAGE = new QName("language");
public static final QName QNAME_COPYRIGHT = new QName("copyright");
public static final QName QNAME_MANAGINGEDITOR = new QName("managingEditor");
public static final QName QNAME_MANAGINGEDITOR2 = new QName("managingeditor");
public static final QName QNAME_WEBMASTER = new QName("webMaster");
public static final QName QNAME_WEBMASTER2 = new QName("webmaster");
public static final QName QNAME_PUBDATE = new QName("pubDate");
public static final QName QNAME_PUBDATE2 = new QName("pubdate");
public static final QName QNAME_LASTBUILDDATE = new QName("lastBuildDate");
public static final QName QNAME_LASTBUILDDATE2 = new QName("lastbuilddate");
public static final QName QNAME_CATEGORY = new QName("category");
public static final QName QNAME_GENERATOR = new QName("generator");
public static final QName QNAME_DOCS = new QName("docs");
public static final QName QNAME_CLOUD = new QName("cloud");
public static final QName QNAME_TTL = new QName("ttl");
public static final QName QNAME_IMAGE = new QName("image");
public static final QName QNAME_RATING = new QName("rating");
public static final QName QNAME_TEXTINPUT = new QName("textInput");
public static final QName QNAME_TEXTINPUT2 = new QName("textinput");
public static final QName QNAME_SKIPHOURS = new QName("skipHours");
public static final QName QNAME_SKIPHOURS2 = new QName("skiphours");
public static final QName QNAME_SKIPDAYS = new QName("skipDays");
public static final QName QNAME_SKIPDAYS2 = new QName("skipdays");
public static final QName QNAME_AUTHOR = new QName("author");
public static final QName QNAME_ENCLOSURE = new QName("enclosure");
public static final QName QNAME_GUID = new QName("guid");
public static final QName QNAME_COMMENTS = new QName("comments");
public static final QName QNAME_SOURCE = new QName("source");
public static final QName QNAME_URL = new QName("url");
public static final QName QNAME_WIDTH = new QName("width");
public static final QName QNAME_HEIGHT = new QName("height");
public static final QName QNAME_DAY = new QName("day");
public static final QName QNAME_HOUR = new QName("hour");
public static final QName QNAME_NAME = new QName("name");
public static final QName QNAME_CONTENT_ENCODED = new QName(ENC_NS, "encoded");
public static final QName QNAME_DC_TITLE = new QName(DC_NS, "title");
public static final QName QNAME_DC_CREATOR = new QName(DC_NS, "creator");
public static final QName QNAME_DC_SUBJECT = new QName(DC_NS, "subject");
public static final QName QNAME_DC_DESCRIPTION = new QName(DC_NS, "description");
public static final QName QNAME_DC_PUBLISHER = new QName(DC_NS, "publisher");
public static final QName QNAME_DC_CONTRIBUTOR = new QName(DC_NS, "contributor");
public static final QName QNAME_DC_DATE = new QName(DC_NS, "date");
public static final QName QNAME_DC_TYPE = new QName(DC_NS, "type");
public static final QName QNAME_DC_FORMAT = new QName(DC_NS, "format");
public static final QName QNAME_DC_IDENTIFIER = new QName(DC_NS, "identifier");
public static final QName QNAME_DC_SOURCE = new QName(DC_NS, "source");
public static final QName QNAME_DC_LANGUAGE = new QName(DC_NS, "language");
public static final QName QNAME_DC_RELATION = new QName(DC_NS, "relation");
public static final QName QNAME_DC_COVERAGE = new QName(DC_NS, "covrerage");
public static final QName QNAME_DC_RIGHTS = new QName(DC_NS, "rights");
}
| 7,632 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssGenerator.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.rss;
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;
import org.apache.abdera.model.Generator;
public class RssGenerator extends ElementWrapper implements Generator {
public RssGenerator(Element internal) {
super(internal);
}
public RssGenerator(Factory factory, QName qname) {
super(factory, qname);
}
public IRI getResolvedUri() {
return null;
}
public IRI getUri() {
return null;
}
public String getVersion() {
return null;
}
public Generator setUri(String uri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Generator setVersion(String version) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
}
| 7,633 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssSkipHours.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.rss;
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 RssSkipHours extends ExtensibleElementWrapper {
public RssSkipHours(Element internal) {
super(internal);
}
public RssSkipHours(Factory factory, QName qname) {
super(factory, qname);
}
public boolean skip(int hour) {
List<Element> hours = getExtensions(RssConstants.QNAME_HOUR);
for (Element h : hours) {
try {
int check = Integer.parseInt(h.getText());
if (check == hour)
return true;
} catch (Exception e) {
}
}
return false;
}
}
| 7,634 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssChannel.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.rss;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import org.apache.abdera.Abdera;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.DateTime;
import org.apache.abdera.model.Div;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.ExtensibleElement;
import org.apache.abdera.model.ExtensibleElementWrapper;
import org.apache.abdera.model.Generator;
import org.apache.abdera.model.IRIElement;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Person;
import org.apache.abdera.model.Text;
import org.apache.abdera.model.Text.Type;
import org.apache.abdera.parser.stax.util.FOMElementIterator;
import org.apache.abdera.parser.stax.util.FOMHelper;
import org.apache.abdera.parser.stax.util.FOMList;
import org.apache.abdera.util.Constants;
import org.apache.abdera.xpath.XPath;
import org.apache.abdera.xpath.XPathException;
public class RssChannel extends ExtensibleElementWrapper {
public RssChannel(Element internal) {
super(internal);
}
public RssChannel(Factory factory, QName qname) {
super(factory, qname);
}
public void addEntry(Entry entry) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry addEntry() {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public List<Entry> getEntries() {
QName qname = getQName();
if (qname.getNamespaceURI().equals(RssConstants.RSS1_NS) && qname.getLocalPart().equals("channel")) {
List<Entry> entries = new ArrayList<Entry>();
ExtensibleElement items = getExtension(RssConstants.QNAME_RDF_ITEMS);
if (items != null) {
ExtensibleElement se = items.getExtension(RssConstants.QNAME_RDF_SEQ);
if (se != null) {
List<Element> seq = se.getExtensions(RssConstants.QNAME_RDF_LI);
for (Element el : seq) {
String res = el.getAttributeValue("resource");
if (res != null) {
String path = "//rss:item[@rdf:about='" + res + "']";
Element entryel = null;
try {
entryel = locate(path);
} catch (Exception e) {
}
if (entryel != null) {
// TODO:fix this.. entryel should already be an RssItem
entries.add(new RssItem(entryel));
}
}
}
}
}
return entries;
} else {
return getExtensions(RssConstants.QNAME_ITEM);
}
}
public Entry getEntry(String id) {
if (id == null)
return null;
List<Entry> l = getEntries();
for (Entry e : l) {
IRI eid = e.getId();
if (eid != null && eid.equals(new IRI(id)))
return e;
}
return null;
}
public void insertEntry(Entry entry) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry insertEntry() {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void sortEntries(Comparator<Entry> comparator) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void sortEntriesByEdited(boolean new_first) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void sortEntriesByUpdated(boolean new_first) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void addAuthor(Person person) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addAuthor(String name) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addAuthor(String name, String email, String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void addCategory(Category category) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Category addCategory(String term) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Category addCategory(String scheme, String term, String label) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void addLink(Link link) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link addLink(String href) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link addLink(String href, String rel) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link addLink(String href, String rel, String type, String title, String hreflang, long length) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link getAlternateLink() {
Link link = getExtension(RssConstants.QNAME_LINK);
if (link == null)
link = getExtension(RssConstants.QNAME_RDF_LINK);
return link;
}
public Link getAlternateLink(String type, String hreflang) {
return getAlternateLink();
}
public IRI getAlternateLinkResolvedHref() {
Link link = getAlternateLink();
return (link != null) ? link.getResolvedHref() : null;
}
public IRI getAlternateLinkResolvedHref(String type, String hreflang) {
return getAlternateLinkResolvedHref();
}
public Person getAuthor() {
Person person = getExtension(RssConstants.QNAME_MANAGINGEDITOR);
if (person == null)
person = getExtension(RssConstants.QNAME_DC_CREATOR);
return person;
}
public List<Person> getAuthors() {
List<Person> people = getExtensions(RssConstants.QNAME_MANAGINGEDITOR);
if (people == null || people.size() == 0)
people = getExtensions(RssConstants.QNAME_DC_CREATOR);
return people;
}
public List<Person> getContributors() {
List<Person> people = getExtensions(RssConstants.QNAME_DC_CONTRIBUTOR);
return people;
}
public List<Category> getCategories() {
List<Category> cats = getExtensions(RssConstants.QNAME_CATEGORY);
if (cats == null || cats.size() == 0)
cats = getExtensions(RssConstants.QNAME_DC_SUBJECT);
return cats;
}
@SuppressWarnings("unchecked")
public List<Category> getCategories(String scheme) {
return (scheme != null) ? new FOMList<Category>(new FOMElementIterator(getInternal(), RssCategory.class,
new QName("domain"), scheme, null))
: getCategories();
}
public Generator getGenerator() {
return getExtension(RssConstants.QNAME_GENERATOR);
}
public IRI getIcon() {
IRIElement iri = getIconElement();
return (iri != null) ? iri.getValue() : null;
}
public IRIElement getIconElement() {
return getLogoElement();
}
public IRI getId() {
IRIElement id = getIdElement();
return (id != null) ? id.getValue() : null;
}
public IRIElement getIdElement() {
return getExtension(RssConstants.QNAME_DC_IDENTIFIER);
}
public Link getLink(String rel) {
if (rel.equals(Link.REL_ALTERNATE) || rel.equals(Link.REL_ALTERNATE_IANA)) {
RssGuid guid = (RssGuid)getIdElement();
if (guid != null && guid.isPermalink())
return guid;
return getAlternateLink();
}
List<Link> links = FOMHelper.getLinks(getInternal(), rel);
return (links != null && links.size() > 0) ? links.get(0) : null;
}
public IRI getLinkResolvedHref(String rel) {
Link link = getLink(rel);
return (link != null) ? link.getResolvedHref() : null;
}
public List<Link> getLinks() {
return getExtensions(Constants.LINK);
}
public List<Link> getLinks(String rel) {
return FOMHelper.getLinks(getInternal(), rel);
}
public List<Link> getLinks(String... rel) {
return FOMHelper.getLinks(getInternal(), rel);
}
public IRI getLogo() {
IRIElement iri = getLogoElement();
return (iri != null) ? iri.getValue() : null;
}
public IRIElement getLogoElement() {
IRIElement iri = getExtension(RssConstants.QNAME_IMAGE);
if (iri == null) {
Element image = getExtension(RssConstants.QNAME_RDF_IMAGE);
if (image != null) {
String id = image.getAttributeValue(RssConstants.QNAME_RDF_RESOURCE);
if (id != null) {
String path = "//rss:image[@rdf:about='" + id + "']";
Element res = null;
try {
res = locate(path);
} catch (Exception e) {
e.printStackTrace();
}
if (res != null) {
// TODO: Need to fix
return new RssImage(res);
}
} else {
return (IRIElement)image;
}
}
}
return iri;
}
public String getRights() {
Text text = getRightsElement();
return (text != null) ? text.getValue() : null;
}
public Text getRightsElement() {
Text text = getExtension(RssConstants.QNAME_COPYRIGHT);
if (text == null)
text = getExtension(RssConstants.QNAME_DC_RIGHTS);
return text;
}
public Type getRightsType() {
Text text = getRightsElement();
return (text != null) ? text.getTextType() : null;
}
public Link getSelfLink() {
return getLink("self");
}
public IRI getSelfLinkResolvedHref() {
Link link = getSelfLink();
return (link != null) ? link.getResolvedHref() : null;
}
public String getSubtitle() {
Text text = getSubtitleElement();
return (text != null) ? text.getValue() : null;
}
public Text getSubtitleElement() {
Text text = getExtension(RssConstants.QNAME_DESCRIPTION);
if (text == null)
text = getExtension(RssConstants.QNAME_RDF_DESCRIPTION);
if (text == null)
text = getExtension(RssConstants.QNAME_DC_DESCRIPTION);
return text;
}
public Type getSubtitleType() {
Text text = getSubtitleElement();
return (text != null) ? text.getTextType() : null;
}
public String getTitle() {
Text text = getTitleElement();
return (text != null) ? text.getValue() : null;
}
public Text getTitleElement() {
Text text = getExtension(RssConstants.QNAME_TITLE);
if (text == null)
text = getExtension(RssConstants.QNAME_RDF_TITLE);
if (text == null)
text = getExtension(RssConstants.QNAME_DC_TITLE);
return text;
}
public Type getTitleType() {
Text text = getTitleElement();
return (text != null) ? text.getTextType() : null;
}
public Date getUpdated() {
DateTime dt = getUpdatedElement();
return (dt != null) ? dt.getDate() : null;
}
public DateTime getUpdatedElement() {
DateTime dt = getExtension(RssConstants.QNAME_LASTBUILDDATE);
if (dt == null)
dt = getExtension(RssConstants.QNAME_LASTBUILDDATE2);
if (dt == null)
dt = getExtension(RssConstants.QNAME_PUBDATE);
if (dt == null)
dt = getExtension(RssConstants.QNAME_PUBDATE2);
if (dt == null)
dt = getExtension(RssConstants.QNAME_DC_DATE);
return dt;
}
public String getUpdatedString() {
DateTime dt = getUpdatedElement();
return (dt != null) ? dt.getString() : null;
}
public Date getPublished() {
DateTime dt = getPublishedElement();
return (dt != null) ? dt.getDate() : null;
}
public DateTime getPublishedElement() {
DateTime dt = getExtension(RssConstants.QNAME_PUBDATE);
if (dt == null)
dt = getExtension(RssConstants.QNAME_PUBDATE2);
if (dt == null)
dt = getExtension(RssConstants.QNAME_DC_DATE);
return dt;
}
public String getPublishedString() {
DateTime dt = getPublishedElement();
return (dt != null) ? dt.getString() : null;
}
public IRIElement newId() {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void setGenerator(Generator generator) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Generator setGenerator(String iri, String version, String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setIcon(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void setIconElement(IRIElement iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setId(String id) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setId(String id, boolean normalize) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void setIdElement(IRIElement id) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setLogo(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void setLogoElement(IRIElement iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRights(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRights(String value, Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRights(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRightsAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRightsAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void setRightsElement(Text text) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitle(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitle(String value, Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitle(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitleAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitleAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void setSubtitleElement(Text text) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitle(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitle(String value, Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitle(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitleAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitleAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void setTitleElement(Text text) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setUpdated(Date value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setUpdated(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void setUpdatedElement(DateTime dateTime) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public String getLanguage() {
String lang = getSimpleExtension(RssConstants.QNAME_LANGUAGE);
if (lang == null)
lang = getSimpleExtension(RssConstants.QNAME_DC_LANGUAGE);
return lang;
}
public <T extends Element> T setLanguage(String language) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
private Element locate(String path) throws XPathException {
Abdera abdera = this.getFactory().getAbdera();
XPath xpath = abdera.getXPath();
Map<String, String> ns = xpath.getDefaultNamespaces();
ns.put("rdf", RssConstants.RDF_NS);
ns.put("rss", RssConstants.RSS1_NS);
Element el = getDocument().getRoot();
if (el instanceof ElementWrapper) {
el = ((ElementWrapper)el).getInternal();
}
return (Element)xpath.selectSingleNode(path, el, ns);
}
}
| 7,635 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssSource.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.rss;
import java.util.Date;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.Collection;
import org.apache.abdera.model.DateTime;
import org.apache.abdera.model.Div;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ExtensibleElementWrapper;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Generator;
import org.apache.abdera.model.IRIElement;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Person;
import org.apache.abdera.model.Source;
import org.apache.abdera.model.Text;
import org.apache.abdera.model.Text.Type;
public class RssSource extends ExtensibleElementWrapper implements Source {
private Link self = null;
public RssSource(Element internal) {
super(internal);
self = new RssLink(internal);
}
public RssSource(Factory factory, QName qname) {
super(factory, qname);
self = new RssLink(factory, qname);
}
public <T extends Source> T addAuthor(Person person) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addAuthor(String name) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addAuthor(String name, String email, String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T addCategory(Category category) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Category addCategory(String term) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Category addCategory(String scheme, String term, String label) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T addContributor(Person person) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addContributor(String name) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addContributor(String name, String email, String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T addLink(Link link) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link addLink(String href) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link addLink(String href, String rel) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link addLink(String href, String rel, String type, String title, String hreflang, long length) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link getAlternateLink(String type, String hreflang) {
return getAlternateLink();
}
public IRI getAlternateLinkResolvedHref() {
Link link = getAlternateLink();
return (link != null) ? link.getResolvedHref() : null;
}
public IRI getAlternateLinkResolvedHref(String type, String hreflang) {
Link link = getAlternateLink();
return (link != null) ? link.getResolvedHref() : null;
}
public Person getAuthor() {
return null;
}
public List<Person> getAuthors() {
return null;
}
public List<Category> getCategories() {
return null;
}
public List<Category> getCategories(String scheme) {
return null;
}
public Collection getCollection() {
return null;
}
public List<Person> getContributors() {
return null;
}
public Generator getGenerator() {
return null;
}
public IRI getIcon() {
return null;
}
public IRIElement getIconElement() {
return null;
}
public IRI getId() {
return null;
}
public IRIElement getIdElement() {
return null;
}
public Link getLink(String rel) {
return null;
}
public IRI getLinkResolvedHref(String rel) {
return null;
}
public List<Link> getLinks() {
return null;
}
public List<Link> getLinks(String rel) {
return null;
}
public List<Link> getLinks(String... rel) {
return null;
}
public IRI getLogo() {
return null;
}
public IRIElement getLogoElement() {
return null;
}
public String getRights() {
return null;
}
public Text getRightsElement() {
return null;
}
public Type getRightsType() {
return null;
}
public Link getSelfLink() {
return getAlternateLink();
}
public IRI getSelfLinkResolvedHref() {
Link link = getSelfLink();
return (link != null) ? link.getResolvedHref() : null;
}
public String getSubtitle() {
return null;
}
public Text getSubtitleElement() {
return null;
}
public Type getSubtitleType() {
return null;
}
public String getTitle() {
return getText();
}
public Text getTitleElement() {
return null;
}
public Type getTitleType() {
return Type.HTML;
}
public Date getUpdated() {
return null;
}
public DateTime getUpdatedElement() {
return null;
}
public String getUpdatedString() {
return null;
}
public IRIElement newId() {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T setCollection(Collection collection) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T setGenerator(Generator generator) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Generator setGenerator(String iri, String version, String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setIcon(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T setIconElement(IRIElement iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setId(String id) {
return null;
}
public IRIElement setId(String id, boolean normalize) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T setIdElement(IRIElement id) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setLogo(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T setLogoElement(IRIElement iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRights(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRights(String value, Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRights(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRightsAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRightsAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T setRightsElement(Text text) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitle(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitle(String value, Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitle(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitleAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSubtitleAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T setSubtitleElement(Text text) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitle(String value, Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitle(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitleAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitleAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T setTitleElement(Text text) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setUpdated(Date value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setUpdated(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Source> T setUpdatedElement(DateTime dateTime) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitle(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link getAlternateLink() {
return self;
}
public Feed getAsFeed() {
throw new UnsupportedOperationException("Converting to feed is not supported");
}
}
| 7,636 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssCloud.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.rss;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
public class RssCloud extends ElementWrapper {
public RssCloud(Element internal) {
super(internal);
}
public RssCloud(Factory factory, QName qname) {
super(factory, qname);
}
public String getDomain() {
return getAttributeValue("domain");
}
public int getPort() {
String v = getAttributeValue("port");
return (v != null) ? Integer.parseInt(v) : -1;
}
public String getPath() {
return getAttributeValue("path");
}
public String getRegisterProcedure() {
return getAttributeValue("registerProcedure");
}
public String getProtocol() {
return getAttributeValue("protocol");
}
}
| 7,637 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssGuid.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.rss;
import java.util.List;
import javax.activation.MimeType;
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.ExtensibleElement;
import org.apache.abdera.model.ExtensibleElementWrapper;
import org.apache.abdera.model.IRIElement;
import org.apache.abdera.model.Link;
public class RssGuid extends ExtensibleElementWrapper implements IRIElement, Link {
public RssGuid(Element internal) {
super(internal);
}
public RssGuid(Factory factory, QName qname) {
super(factory, qname);
}
public IRI getResolvedValue() {
return getValue();
}
public IRI getValue() {
String t = getText();
return (t != null) ? new IRI(t) : null;
}
public IRIElement setNormalizedValue(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setValue(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public boolean isPermalink() {
String v = getAttributeValue("isPermaLink");
if (v == null)
getAttributeValue("ispermalink");
return (v.equalsIgnoreCase("true") || v.equalsIgnoreCase("yes"));
}
public IRI getHref() {
return getValue();
}
public String getHrefLang() {
return null;
}
public long getLength() {
return -1;
}
public MimeType getMimeType() {
return null;
}
public String getRel() {
return Link.REL_ALTERNATE;
}
public IRI getResolvedHref() {
return getValue();
}
public String getTitle() {
return null;
}
public Link setHref(String href) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setHrefLang(String lang) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setLength(long length) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setMimeType(String type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setRel(String rel) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setTitle(String title) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends ExtensibleElement> T addExtension(Element extension) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> T addExtension(QName qname) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> T addExtension(String namespace, String localPart, String prefix) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Element addSimpleExtension(QName qname, String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Element addSimpleExtension(String namespace, String localPart, String prefix, String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> T getExtension(QName qname) {
return null;
}
public <T extends Element> T getExtension(Class<T> _class) {
return null;
}
public List<Element> getExtensions() {
return null;
}
public List<Element> getExtensions(String uri) {
return null;
}
public <T extends Element> List<T> getExtensions(QName qname) {
return null;
}
public String getSimpleExtension(QName qname) {
return null;
}
public String getSimpleExtension(String namespace, String localPart, String prefix) {
return null;
}
}
| 7,638 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssDateTime.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.rss;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.AtomDate;
import org.apache.abdera.model.DateTime;
import org.apache.abdera.model.DateTimeWrapper;
import org.apache.abdera.model.Element;
public class RssDateTime extends DateTimeWrapper implements DateTime {
private static String[] masks =
{"EEE, dd MMM yyyy HH:mm:ss z", "dd MMM yyyy HH:mm z", "dd MMM yyyy", "-yy-MM-dd", "-yy-MM", "-yymm",
"yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ss.SSSz", "yyyy-MM-dd't'HH:mm:ss.SSSz", // invalid
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd't'HH:mm:ss.SSS'z'", // invalid
"yyyy-MM-dd'T'HH:mm:ssz", "yyyy-MM-dd't'HH:mm:ssz", // invalid
"yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd't'HH:mm:ss'Z'", // invalid
"yyyy-MM-dd't'HH:mm:ss'z'", // invalid
"yyyy-MM-dd'T'HH:mm:ss'z'", // invalid
"yyyy-MM-dd'T'HH:mm:ss'z'", // invalid
"yyyy-MM-dd'T'HH:mmz", // invalid
"yyyy-MM-dd't'HH:mmz", // invalid
"yyyy-MM-dd'T'HH:mm'Z'", // invalid
"yyyy-MM-dd't'HH:mm'z'", // invalid
"yyyy-MM-dd", "yyyy-MM", "yyyyMMdd", "yyMMdd", "yyyy"};
public RssDateTime(Element internal) {
super(internal);
}
public RssDateTime(Factory factory, QName qname) {
super(factory, qname);
}
@Override
public AtomDate getValue() {
return parse(getText());
}
@Override
public DateTime setCalendar(Calendar date) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
@Override
public DateTime setDate(Date date) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
@Override
public DateTime setString(String date) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
@Override
public DateTime setTime(long date) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
@Override
public DateTime setValue(AtomDate dateTime) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
private AtomDate parse(String value) {
for (String mask : masks) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(mask);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date d = sdf.parse(value);
return new AtomDate(d);
} catch (Exception e) {
}
}
return null;
}
}
| 7,639 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssTextInput.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.rss;
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.ExtensibleElementWrapper;
import org.apache.abdera.model.IRIElement;
import org.apache.abdera.model.Text;
public class RssTextInput extends ExtensibleElementWrapper {
public RssTextInput(Element internal) {
super(internal);
}
public RssTextInput(Factory factory, QName qname) {
super(factory, qname);
}
public String getTitle() {
Text text = getExtension(RssConstants.QNAME_TITLE);
return (text != null) ? text.getValue() : null;
}
public String getDescription() {
Text text = getExtension(RssConstants.QNAME_DESCRIPTION);
return (text != null) ? text.getValue() : null;
}
public String getName() {
Element el = getExtension(RssConstants.QNAME_NAME);
return (el != null) ? el.getText() : null;
}
public IRI getLink() {
IRIElement iri = getExtension(RssConstants.QNAME_LINK);
return (iri != null) ? iri.getValue() : null;
}
}
| 7,640 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssEnclosure.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.rss;
import java.util.List;
import javax.activation.MimeType;
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.ExtensibleElement;
import org.apache.abdera.model.ExtensibleElementWrapper;
import org.apache.abdera.model.Link;
public class RssEnclosure extends ExtensibleElementWrapper implements Link {
public RssEnclosure(Element internal) {
super(internal);
}
public RssEnclosure(Factory factory, QName qname) {
super(factory, qname);
}
public IRI getHref() {
String url = getAttributeValue("url");
return (url != null) ? new IRI(url) : null;
}
public String getHrefLang() {
return null;
}
public long getLength() {
String l = getAttributeValue("length");
return (l != null) ? Integer.parseInt(l) : -1;
}
public MimeType getMimeType() {
try {
String type = getAttributeValue("type");
return (type != null) ? new MimeType(type) : null;
} catch (javax.activation.MimeTypeParseException e) {
throw new org.apache.abdera.util.MimeTypeParseException(e);
}
}
public String getRel() {
return "enclosure";
}
public IRI getResolvedHref() {
return getHref();
}
public String getTitle() {
return null;
}
public Link setHref(String href) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setHrefLang(String lang) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setLength(long length) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setMimeType(String type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setRel(String rel) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link setTitle(String title) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends ExtensibleElement> T addExtension(Element extension) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> T addExtension(QName qname) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> T addExtension(String namespace, String localPart, String prefix) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Element addSimpleExtension(QName qname, String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Element addSimpleExtension(String namespace, String localPart, String prefix, String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public <T extends Element> T getExtension(QName qname) {
return null;
}
public <T extends Element> T getExtension(Class<T> _class) {
return null;
}
public List<Element> getExtensions() {
return null;
}
public List<Element> getExtensions(String uri) {
return null;
}
public <T extends Element> List<T> getExtensions(QName qname) {
return null;
}
public String getSimpleExtension(QName qname) {
return null;
}
public String getSimpleExtension(String namespace, String localPart, String prefix) {
return null;
}
}
| 7,641 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssExtensionFactory.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.rss;
import org.apache.abdera.util.AbstractExtensionFactory;
public class RssExtensionFactory extends AbstractExtensionFactory implements RssConstants {
public RssExtensionFactory() {
super("", ENC_NS, DC_NS, RDF_NS);
addMimeType(QNAME_RSS, RSS_MEDIATYPE);
addMimeType(QNAME_RDF, RDF_MEDIATYPE);
addImpl(QNAME_RSS, RssFeed.class);
addImpl(QNAME_RDF, RssFeed.class);
addImpl(QNAME_CHANNEL, RssChannel.class);
addImpl(QNAME_RDF_CHANNEL, RssChannel.class);
addImpl(QNAME_ITEM, RssItem.class);
addImpl(QNAME_RDF_ITEM, RssItem.class);
addImpl(QNAME_LINK, RssLink.class);
addImpl(QNAME_RDF_LINK, RssLink.class);
addImpl(QNAME_TITLE, RssText.class);
addImpl(QNAME_RDF_TITLE, RssText.class);
addImpl(QNAME_DC_TITLE, RssText.class);
addImpl(QNAME_DESCRIPTION, RssText.class);
addImpl(QNAME_RDF_DESCRIPTION, RssText.class);
addImpl(QNAME_DC_DESCRIPTION, RssText.class);
addImpl(QNAME_COPYRIGHT, RssText.class);
addImpl(QNAME_DC_RIGHTS, RssText.class);
addImpl(QNAME_MANAGINGEDITOR, RssPerson.class);
addImpl(QNAME_MANAGINGEDITOR2, RssPerson.class);
addImpl(QNAME_DC_CREATOR, RssPerson.class);
addImpl(QNAME_DC_CONTRIBUTOR, RssPerson.class);
addImpl(QNAME_WEBMASTER, RssPerson.class);
addImpl(QNAME_WEBMASTER2, RssPerson.class);
addImpl(QNAME_PUBDATE, RssDateTime.class);
addImpl(QNAME_PUBDATE2, RssDateTime.class);
addImpl(QNAME_LASTBUILDDATE, RssDateTime.class);
addImpl(QNAME_LASTBUILDDATE2, RssDateTime.class);
addImpl(QNAME_DC_DATE, RssDateTime.class);
addImpl(QNAME_CATEGORY, RssCategory.class);
addImpl(QNAME_DC_SUBJECT, RssCategory.class);
addImpl(QNAME_GENERATOR, RssGenerator.class);
addImpl(QNAME_DOCS, RssLink.class);
addImpl(QNAME_CLOUD, RssCloud.class);
addImpl(QNAME_TTL, RssText.class);
addImpl(QNAME_IMAGE, RssImage.class);
addImpl(QNAME_RDF_IMAGE, RssImage.class);
addImpl(QNAME_TEXTINPUT, RssTextInput.class);
addImpl(QNAME_TEXTINPUT2, RssTextInput.class);
addImpl(QNAME_SKIPHOURS, RssSkipHours.class);
addImpl(QNAME_SKIPHOURS2, RssSkipHours.class);
addImpl(QNAME_SKIPDAYS, RssSkipDays.class);
addImpl(QNAME_SKIPDAYS2, RssSkipDays.class);
addImpl(QNAME_URL, RssUriElement.class);
addImpl(QNAME_RDF_URL, RssUriElement.class);
addImpl(QNAME_AUTHOR, RssPerson.class);
addImpl(QNAME_ENCLOSURE, RssEnclosure.class);
addImpl(QNAME_GUID, RssGuid.class);
addImpl(QNAME_DC_IDENTIFIER, RssGuid.class);
addImpl(QNAME_COMMENTS, RssLink.class);
addImpl(QNAME_SOURCE, RssSource.class);
addImpl(QNAME_DC_SOURCE, RssSource.class);
addImpl(QNAME_CONTENT_ENCODED, RssContent.class);
}
}
| 7,642 |
0 | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/rss/src/main/java/org/apache/abdera/ext/rss/RssItem.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.rss;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
import javax.activation.DataHandler;
import javax.activation.MimeType;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Control;
import org.apache.abdera.model.DateTime;
import org.apache.abdera.model.Div;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.ExtensibleElementWrapper;
import org.apache.abdera.model.IRIElement;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Person;
import org.apache.abdera.model.Source;
import org.apache.abdera.model.Text;
import org.apache.abdera.model.Content.Type;
import org.apache.abdera.parser.stax.util.FOMElementIterator;
import org.apache.abdera.parser.stax.util.FOMHelper;
import org.apache.abdera.parser.stax.util.FOMList;
import org.apache.abdera.util.Constants;
public class RssItem extends ExtensibleElementWrapper implements Entry, IRIElement {
public RssItem(Element internal) {
super(internal);
}
public RssItem(Factory factory, QName qname) {
super(factory, qname);
}
public Entry addAuthor(Person person) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addAuthor(String name) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addAuthor(String name, String email, String uri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry addCategory(Category category) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Category addCategory(String term) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Category addCategory(String scheme, String term, String label) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry addContributor(Person person) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addContributor(String name) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Person addContributor(String name, String email, String uri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry addLink(Link link) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link addLink(String href) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link addLink(String href, String rel) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link addLink(String href, String rel, String type, String title, String hreflang, long length) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link getAlternateLink() {
Link link = getExtension(RssConstants.QNAME_LINK);
if (link == null)
link = getExtension(RssConstants.QNAME_RDF_LINK);
if (link == null) {
IRIElement guid = getIdElement();
if (guid != null && guid instanceof RssGuid && ((RssGuid)guid).isPermalink())
return (Link)guid;
}
return link;
}
public Link getAlternateLink(String type, String hreflang) {
return getAlternateLink();
}
public IRI getAlternateLinkResolvedHref() {
Link link = getAlternateLink();
return (link != null) ? link.getResolvedHref() : null;
}
public IRI getAlternateLinkResolvedHref(String type, String hreflang) {
return getAlternateLinkResolvedHref();
}
public Person getAuthor() {
Person person = getExtension(RssConstants.QNAME_AUTHOR);
if (person == null)
person = getExtension(RssConstants.QNAME_DC_CREATOR);
return person;
}
public List<Person> getAuthors() {
List<Person> people = getExtensions(RssConstants.QNAME_AUTHOR);
if (people == null || people.size() == 0)
people = getExtensions(RssConstants.QNAME_DC_CREATOR);
return people;
}
public List<Category> getCategories() {
List<Category> cats = getExtensions(RssConstants.QNAME_CATEGORY);
if (cats == null || cats.size() == 0)
cats = getExtensions(RssConstants.QNAME_DC_SUBJECT);
return cats;
}
@SuppressWarnings("unchecked")
public List<Category> getCategories(String scheme) {
return (scheme != null) ? new FOMList<Category>(new FOMElementIterator(getInternal(), RssCategory.class,
new QName("domain"), scheme, null))
: getCategories();
}
public String getContent() {
Content content = getContentElement();
if (content == null)
return getSummary();
return content.getValue();
}
public Content getContentElement() {
Content content = getExtension(RssConstants.QNAME_CONTENT_ENCODED);
// what else to return other than content:encoded and possibly atom:content?
if (content == null)
content = getExtension(Constants.CONTENT);
return content;
}
public MimeType getContentMimeType() {
return null;
}
public IRI getContentSrc() {
return null;
}
public InputStream getContentStream() throws IOException {
return null;
}
public Type getContentType() {
Content content = getContentElement();
if (content == null) {
Text text = getSummaryElement();
switch (text.getTextType()) {
case TEXT:
return Content.Type.TEXT;
case HTML:
return Content.Type.HTML;
case XHTML:
return Content.Type.XHTML;
default:
return Content.Type.HTML;
}
} else {
return content.getContentType();
}
}
public List<Person> getContributors() {
List<Person> people = getExtensions(RssConstants.QNAME_DC_CONTRIBUTOR);
return people;
}
public Control getControl(boolean create) {
return null;
}
public Control getControl() {
return null;
}
public Link getEditLink() {
return null;
}
public IRI getEditLinkResolvedHref() {
return null;
}
public Link getEditMediaLink() {
return null;
}
public Link getEditMediaLink(String type, String hreflang) {
return null;
}
public IRI getEditMediaLinkResolvedHref() {
return null;
}
public IRI getEditMediaLinkResolvedHref(String type, String hreflang) {
return null;
}
public Date getEdited() {
return null;
}
public DateTime getEditedElement() {
return null;
}
public Link getEnclosureLink() {
return getExtension(RssConstants.QNAME_ENCLOSURE);
}
public IRI getEnclosureLinkResolvedHref() {
Link link = getEnclosureLink();
return (link != null) ? link.getHref() : null;
}
public IRI getId() {
IRIElement iri = getIdElement();
return (iri != null) ? iri.getValue() : null;
}
public IRIElement getIdElement() {
IRIElement id = getExtension(RssConstants.QNAME_GUID);
if (id == null)
id = getExtension(RssConstants.QNAME_DC_IDENTIFIER);
if (id == null && this.getQName().equals(RssConstants.QNAME_RDF_ITEM))
return this;
return id;
}
public Link getLink(String rel) {
if (rel.equals(Link.REL_ALTERNATE) || rel.equals(Link.REL_ALTERNATE_IANA)) {
RssGuid guid = (RssGuid)getIdElement();
if (guid != null && guid.isPermalink())
return guid;
return getAlternateLink();
}
List<Link> links = FOMHelper.getLinks(getInternal(), rel);
return (links != null && links.size() > 0) ? links.get(0) : null;
}
public IRI getLinkResolvedHref(String rel) {
Link link = getLink(rel);
return (link != null) ? link.getResolvedHref() : null;
}
public List<Link> getLinks() {
return getExtensions(Constants.LINK);
}
public List<Link> getLinks(String rel) {
return FOMHelper.getLinks(getInternal(), rel);
}
public List<Link> getLinks(String... rel) {
return FOMHelper.getLinks(getInternal(), rel);
}
public Date getPublished() {
DateTime dt = getPublishedElement();
return (dt != null) ? dt.getDate() : null;
}
public DateTime getPublishedElement() {
DateTime dt = getExtension(RssConstants.QNAME_PUBDATE);
if (dt == null)
dt = getExtension(RssConstants.QNAME_PUBDATE2);
if (dt == null)
dt = getExtension(RssConstants.QNAME_DC_DATE);
return dt;
}
public String getRights() {
Text text = getRightsElement();
return (text != null) ? text.getValue() : null;
}
public Text getRightsElement() {
Element el = getParentElement();
if (el instanceof RssChannel)
return ((RssChannel)el).getRightsElement();
else if (el instanceof RssFeed)
return ((RssFeed)el).getRightsElement();
Text text = getExtension(RssConstants.QNAME_DC_RIGHTS);
return text;
}
public org.apache.abdera.model.Text.Type getRightsType() {
Text text = getRightsElement();
return (text != null) ? text.getTextType() : null;
}
public Link getSelfLink() {
return getLink("self");
}
public IRI getSelfLinkResolvedHref() {
Link link = getSelfLink();
return (link != null) ? link.getResolvedHref() : null;
}
public Source getSource() {
Source source = getExtension(RssConstants.QNAME_SOURCE);
if (source == null)
getExtension(RssConstants.QNAME_DC_SOURCE);
return source;
}
public String getSummary() {
Text text = getSummaryElement();
return (text != null) ? text.getValue() : null;
}
public Text getSummaryElement() {
Text text = getExtension(RssConstants.QNAME_DESCRIPTION);
if (text == null)
text = getExtension(RssConstants.QNAME_RDF_DESCRIPTION);
if (text == null)
text = getExtension(RssConstants.QNAME_DC_DESCRIPTION);
return text;
}
public org.apache.abdera.model.Text.Type getSummaryType() {
Text text = getSummaryElement();
return (text != null) ? text.getTextType() : null;
}
public String getTitle() {
Text text = getTitleElement();
return (text != null) ? text.getValue() : null;
}
public Text getTitleElement() {
Text text = getExtension(RssConstants.QNAME_TITLE);
if (text == null)
text = getExtension(RssConstants.QNAME_RDF_TITLE);
if (text == null)
text = getExtension(RssConstants.QNAME_DC_TITLE);
return text;
}
public org.apache.abdera.model.Text.Type getTitleType() {
Text text = getTitleElement();
return (text != null) ? text.getTextType() : null;
}
public Date getUpdated() {
return getPublished();
}
public DateTime getUpdatedElement() {
return getPublishedElement();
}
public boolean isDraft() {
return false;
}
public IRIElement newId() {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(String value, Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(Element value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(Element element, String mediaType) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(DataHandler dataHandler) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(DataHandler dataHandler, String mediatype) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(InputStream inputStream) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(InputStream inputStream, String mediatype) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(String value, String mediatype) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContent(IRI uri, String mediatype) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContentAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Content setContentAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setContentElement(Content content) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setControl(Control control) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setDraft(boolean draft) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setEdited(Date value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setEdited(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public void setEditedElement(DateTime modified) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setId(String id) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setId(String id, boolean normalize) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setIdElement(IRIElement id) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setPublished(Date value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setPublished(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setPublishedElement(DateTime dateTime) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRights(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRights(String value, org.apache.abdera.model.Text.Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRights(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRightsAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setRightsAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setRightsElement(Text text) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setSource(Source source) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSummary(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSummary(String value, org.apache.abdera.model.Text.Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSummary(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSummaryAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setSummaryAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setSummaryElement(Text text) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitle(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitle(String value, org.apache.abdera.model.Text.Type type) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitle(Div value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitleAsHtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Text setTitleAsXhtml(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setTitleElement(Text title) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setUpdated(Date value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public DateTime setUpdated(String value) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Entry setUpdatedElement(DateTime updated) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Link getComments() {
return getExtension(RssConstants.QNAME_COMMENTS);
}
public IRI getResolvedValue() {
return getValue();
}
public IRI getValue() {
String about = getAttributeValue(RssConstants.QNAME_RDF_ABOUT);
return (about != null) ? new IRI(about) : null;
}
public IRIElement setNormalizedValue(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public IRIElement setValue(String iri) {
throw new UnsupportedOperationException("Modifications are not allowed");
}
public Control addControl() {
throw new UnsupportedOperationException("Modifications are not allowed");
}
}
| 7,643 |
0 | Create_ds/abdera/extensions/features/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/features/src/test/java/org/apache/abdera/test/ext/features/FeatureTest.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.features;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.features.AcceptSelector;
import org.apache.abdera.ext.features.Feature;
import org.apache.abdera.ext.features.FeatureSelector;
import org.apache.abdera.ext.features.Features;
import org.apache.abdera.ext.features.FeaturesHelper;
import org.apache.abdera.ext.features.Selector;
import org.apache.abdera.ext.features.XPathSelector;
import org.apache.abdera.ext.features.FeaturesHelper.Status;
import org.apache.abdera.model.Collection;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Service;
import org.apache.abdera.model.Workspace;
import org.junit.Test;
public class FeatureTest {
@Test
public void testFeaturesDocument() throws Exception {
Abdera abdera = Abdera.getInstance();
Features features = FeaturesHelper.newFeatures(abdera);
assertNotNull(features);
assertNotNull(features.getDocument());
Document<Features> doc = features.getDocument();
assertTrue(doc.getRoot() instanceof Features);
}
@Test
public void testFeatures() throws Exception {
Abdera abdera = Abdera.getInstance();
Collection coll = abdera.getFactory().newCollection();
Features features = FeaturesHelper.addFeaturesElement(coll);
features.addFeature("http://example.com/features/foo", null, "foo & here");
features.addFeature("http://example.com/features/bar", null, null);
assertEquals(Status.SPECIFIED, FeaturesHelper.getFeatureStatus(coll, "http://example.com/features/foo"));
assertEquals(Status.SPECIFIED, FeaturesHelper.getFeatureStatus(coll, "http://example.com/features/bar"));
assertEquals(Status.UNSPECIFIED, FeaturesHelper.getFeatureStatus(coll, "http://example.com/features/baz"));
assertEquals(Status.UNSPECIFIED, FeaturesHelper.getFeatureStatus(coll, "http://example.com/features/pez"));
}
@Test
public void testSelectors() throws Exception {
Abdera abdera = Abdera.getInstance();
Service service = abdera.newService();
Workspace workspace = service.addWorkspace("a");
Collection collection1 = workspace.addCollection("a1", "a1");
collection1.setAcceptsEntry();
Features features = FeaturesHelper.addFeaturesElement(collection1);
features.addFeature(FeaturesHelper.FEATURE_SUPPORTS_DRAFTS);
Collection collection2 = workspace.addCollection("a2", "a2");
collection2.setAccept("image/*");
Selector s1 = new FeatureSelector(FeaturesHelper.FEATURE_SUPPORTS_DRAFTS);
Collection[] collections = FeaturesHelper.select(service, s1);
assertEquals(1, collections.length);
assertEquals(collections[0], collection1);
Selector s2 = new AcceptSelector("image/png");
collections = FeaturesHelper.select(service, s2);
assertEquals(1, collections.length);
assertEquals(collections[0], collection2);
Selector s3 = new XPathSelector("f:features/f:feature[@ref='" + FeaturesHelper.FEATURE_SUPPORTS_DRAFTS + "']");
collections = FeaturesHelper.select(service, s3);
assertEquals(1, collections.length);
assertEquals(collections[0], collection1);
}
@Test
public void testType() throws Exception {
Abdera abdera = Abdera.getInstance();
Feature feature = abdera.getFactory().newElement(FeaturesHelper.FEATURE);
feature.addType("image/jpg", "image/gif", "image/png", "image/*");
String[] types = feature.getTypes();
assertEquals(1, types.length);
assertEquals("image/*", types[0]);
}
}
| 7,644 |
0 | Create_ds/abdera/extensions/features/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/features/src/test/java/org/apache/abdera/test/ext/features/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.features;
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(FeatureTest.class);
}
}
| 7,645 |
0 | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext/features/FeatureSelector.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.features;
import java.util.ArrayList;
import java.util.List;
import org.apache.abdera.ext.features.FeaturesHelper.Status;
import org.apache.abdera.model.Collection;
public class FeatureSelector extends AbstractSelector implements Selector {
private static final long serialVersionUID = -8943638085557912175L;
private final List<String> features = new ArrayList<String>();
public FeatureSelector(String... features) {
for (String feature : features)
this.features.add(feature);
}
public boolean select(Collection collection) {
for (String feature : features) {
Status status = FeaturesHelper.getFeatureStatus(collection, feature);
if (status == Status.SPECIFIED)
return true;
}
return false;
}
public String[] getFeatures() {
return features.toArray(new String[features.size()]);
}
@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((features == null) ? 0 : features.hashCode());
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 FeatureSelector other = (FeatureSelector)obj;
if (features == null) {
if (other.features != null)
return false;
} else if (!features.equals(other.features))
return false;
return true;
}
@Override
protected Selector copy() {
return new FeatureSelector(getFeatures());
}
}
| 7,646 |
0 | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext/features/FeaturesExtensionFactory.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.features;
import org.apache.abdera.util.AbstractExtensionFactory;
public final class FeaturesExtensionFactory extends AbstractExtensionFactory {
public FeaturesExtensionFactory() {
super(FeaturesHelper.FNS);
addImpl(FeaturesHelper.FEATURE, Feature.class);
addImpl(FeaturesHelper.FEATURES, Features.class);
}
}
| 7,647 |
0 | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext/features/XPathSelector.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.features;
import java.util.Map;
import org.apache.abdera.Abdera;
import org.apache.abdera.model.Collection;
import org.apache.abdera.xpath.XPath;
/**
* Selects a collection based on a boolean XPath expression
*/
public class XPathSelector extends AbstractSelector implements Selector {
private static final long serialVersionUID = 7751803876821166591L;
private final XPath xpath;
private final Map<String, String> namespaces;
private final String path;
public XPathSelector(String path) {
this(path, (new Abdera()).getXPath());
}
public XPathSelector(String path, XPath xpath) {
this(path, xpath, xpath.getDefaultNamespaces());
}
public XPathSelector(String path, XPath xpath, Map<String, String> namespaces) {
this.path = path;
this.xpath = xpath;
this.namespaces = namespaces;
if (!this.namespaces.containsValue(FeaturesHelper.FNS)) {
int c = 0;
String p = "f";
if (!this.namespaces.containsKey(p)) {
this.namespaces.put(p, FeaturesHelper.FNS);
} else {
String s = p + c;
while (this.namespaces.containsKey(s)) {
c++;
s = p + c;
}
this.namespaces.put(s, FeaturesHelper.FNS);
}
}
}
public String getFeaturesPrefix() {
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
if (entry.getValue().equals(FeaturesHelper.FNS))
return entry.getKey();
}
return null;
}
public boolean select(Collection collection) {
if (xpath.booleanValueOf(path, collection, namespaces)) {
return true;
}
return false;
}
public void addNamespace(String prefix, String uri) {
namespaces.put(prefix, uri);
}
}
| 7,648 |
0 | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext/features/AcceptSelector.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.features;
import java.util.ArrayList;
import java.util.List;
import org.apache.abdera.model.Collection;
public class AcceptSelector extends AbstractSelector implements Selector {
private static final long serialVersionUID = -1289924342084041384L;
private final List<String> accepts = new ArrayList<String>();
public AcceptSelector(String... accepts) {
for (String accept : accepts)
this.accepts.add(accept);
}
public boolean select(Collection collection) {
for (String accept : accepts) {
if (collection.accepts(accept))
return true;
}
return false;
}
}
| 7,649 |
0 | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext/features/FeaturesHelper.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.features;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import javax.xml.namespace.QName;
import org.apache.abdera.Abdera;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Collection;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.Service;
import org.apache.abdera.model.Workspace;
import org.apache.abdera.protocol.Response.ResponseType;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
/**
* Implementation of the current APP Features Draft
* (http://www.ietf.org/internet-drafts/draft-snell-atompub-feature-08.txt)
*/
public final class FeaturesHelper {
public enum Status {
UNSPECIFIED, SPECIFIED
}
public static final String FNS = "http://purl.org/atompub/features/1.0";
public static final QName FEATURE = new QName(FNS, "feature", "f");
public static final QName FEATURES = new QName(FNS, "features", "f");
public static final QName TYPE = new QName(FNS, "type", "f");
private static final String FEATURE_BASE = "http://www.w3.org/2007/app/";
private static final String ABDERA_FEATURE_BASE = "http://abdera.apache.org/features/";
private static final String BLOG_FEATURE_BASE = "http://abdera.apache.org/features/blog/";
public static final String FEATURE_SUPPORTS_DRAFTS = FEATURE_BASE + "supportsDraft";
public static final String FEATURE_IGNORES_DRAFTS = FEATURE_BASE + "ignoresDraft";
public static final String FEATURE_SUPPORTS_XHTML_CONTENT = ABDERA_FEATURE_BASE + "supportsXhtmlContent";
public static final String FEATURE_REQUIRES_XHTML_CONTENT = ABDERA_FEATURE_BASE + "requiresXhtmlContent";
public static final String FEATURE_SUPPORTS_HTML_CONTENT = ABDERA_FEATURE_BASE + "supportsHtmlContent";
public static final String FEATURE_REQUIRES_HTML_CONTENT = ABDERA_FEATURE_BASE + "requiresHtmlContent";
public static final String FEATURE_SUPPORTS_TEXT_CONTENT = ABDERA_FEATURE_BASE + "supportsTextContent";
public static final String FEATURE_REQUIRES_TEXT_CONTENT = ABDERA_FEATURE_BASE + "requiresTextContent";
public static final String FEATURE_SUPPORTS_XML_CONTENT = ABDERA_FEATURE_BASE + "supportsXmlContent";
public static final String FEATURE_REQUIRES_XML_CONTENT = ABDERA_FEATURE_BASE + "requiresXmlContent";
public static final String FEATURE_SUPPORTS_BINARY_CONTENT = ABDERA_FEATURE_BASE + "supportsBinaryContent";
public static final String FEATURE_REQUIRES_BINARY_CONTENT = ABDERA_FEATURE_BASE + "requiresBinaryContent";
public static final String FEATURE_SUPPORTS_REF_CONTENT = ABDERA_FEATURE_BASE + "supportsRefContent";
public static final String FEATURE_REQUIRES_REF_CONTENT = ABDERA_FEATURE_BASE + "requiresRefContent";
public static final String FEATURE_SUPPORTS_XHTML_TEXT = ABDERA_FEATURE_BASE + "supportsXhtmlText";
public static final String FEATURE_REQUIRES_XHTML_TEXT = ABDERA_FEATURE_BASE + "requiresXhtmlText";
public static final String FEATURE_SUPPORTS_HTML_TEXT = ABDERA_FEATURE_BASE + "supportsHtmlText";
public static final String FEATURE_REQUIRES_HTML_TEXT = ABDERA_FEATURE_BASE + "requiresHtmlText";
public static final String FEATURE_SUPPORTS_TEXT_TEXT = ABDERA_FEATURE_BASE + "supportsTextText";
public static final String FEATURE_REQUIRES_TEXT_TEXT = ABDERA_FEATURE_BASE + "requiresTextText";
public static final String FEATURE_PRESERVES_SUMMARY = ABDERA_FEATURE_BASE + "preservesSummary";
public static final String FEATURE_IGNORES_SUMMARY = ABDERA_FEATURE_BASE + "ignoresSummary";
public static final String FEATURE_PRESERVES_RIGHTS = ABDERA_FEATURE_BASE + "preservesRights";
public static final String FEATURE_IGNORES_RIGHTS = ABDERA_FEATURE_BASE + "ignoresRights";
public static final String FEATURE_PRESERVES_AUTHORS = ABDERA_FEATURE_BASE + "preservesAuthors";
public static final String FEATURE_IGNORES_AUTHORS = ABDERA_FEATURE_BASE + "ignoresAuthors";
public static final String FEATURE_PRESERVES_CONTRIBUTORS = ABDERA_FEATURE_BASE + "preservesContributors";
public static final String FEATURE_IGNORES_CONTRIBUTORS = ABDERA_FEATURE_BASE + "ignoresContributors";
public static final String FEATURE_USES_SLUG = ABDERA_FEATURE_BASE + "usesSlug";
public static final String FEATURE_IGNORES_SLUG = ABDERA_FEATURE_BASE + "ignoresSlug";
public static final String FEATURE_PRESERVES_CATEGORIES = ABDERA_FEATURE_BASE + "preservesCategories";
public static final String FEATURE_MULTIPLE_CATEGORIES = ABDERA_FEATURE_BASE + "multipleCategories";
public static final String FEATURE_IGNORES_CATEGORIES = ABDERA_FEATURE_BASE + "ignoresCategories";
public static final String FEATURE_PRESERVES_LINKS = ABDERA_FEATURE_BASE + "preservesLinks";
public static final String FEATURE_IGNORES_LINKS = ABDERA_FEATURE_BASE + "ignoresLinks";
public static final String FEATURE_PRESERVES_INFOSET = ABDERA_FEATURE_BASE + "preservesInfoset";
public static final String FEATURE_PRESERVES_ID = ABDERA_FEATURE_BASE + "preservesId";
public static final String FEATURE_PRESERVES_DATES = ABDERA_FEATURE_BASE + "preservesDates";
public static final String FEATURE_PRESERVES_EXTENSIONS = ABDERA_FEATURE_BASE + "preservesExtensions";
public static final String FEATURE_SCHEDULED_PUBLISHING = ABDERA_FEATURE_BASE + "scheduledPublishing";
public static final String FEATURE_REQUIRES_PERSON_EMAIL = ABDERA_FEATURE_BASE + "requiresPersonEmail";
public static final String FEATURE_HIDES_PERSON_EMAIL = ABDERA_FEATURE_BASE + "hidesPersonEmail";
public static final String FEATURE_REQUIRES_PERSON_URI = ABDERA_FEATURE_BASE + "requiresPersonUri";
public static final String FEATURE_HIDES_PERSON_URI = ABDERA_FEATURE_BASE + "hidesPersonUri";
public static final String FEATURE_PRESERVES_LANGUAGE = ABDERA_FEATURE_BASE + "preservesXmlLang";
public static final String FEATURE_IGNORES_LANGUAGE = ABDERA_FEATURE_BASE + "ignoresXmlLang";
public static final String FEATURE_SUPPORTS_CONDITIONALS = ABDERA_FEATURE_BASE + "supportsConditionalUpdates";
public static final String FEATURE_REQUIRES_CONDITIONALS = ABDERA_FEATURE_BASE + "requiresConditionalUpdates";
public static final String FEATURE_PRESERVES_THREADING = ABDERA_FEATURE_BASE + "preservesThreading";
public static final String FEATURE_REQUIRES_THREADING = ABDERA_FEATURE_BASE + "requiresThreading";
public static final String FEATURE_IGNORES_THREADING = ABDERA_FEATURE_BASE + "ignoresThreading";
/**
* Indicates that the collection will preserve XML digital signatures contained in member resources
*/
public static final String FEATURE_PRESERVE_SIGNATURE = ABDERA_FEATURE_BASE + "preservesSignature";
/**
* Indicates that the collection will support XML digital signatures contained in member resources but may not
* preserve those signatures
*/
public static final String FEATURE_SUPPORTS_SIGNATURE = ABDERA_FEATURE_BASE + "supportsSignature";
/**
* Indicates that the collection will ignore XML digital signatures contained in member resources
*/
public static final String FEATURE_IGNORES_SIGNATURE = ABDERA_FEATURE_BASE + "ignoresSignature";
/**
* Indicates that the collection requires member resources to contain valid XML digital signatures
*/
public static final String FEATURE_REQUIRES_SIGNATURE = ABDERA_FEATURE_BASE + "requiresSignature";
/**
* Indicates that the collection will add it's own digital signature to the collection feed and member resources
*/
public static final String FEATURE_SIGNED_RESPONSE = ABDERA_FEATURE_BASE + "responseSignature";
/**
* Indicates that the collection supports the use of the Atom Bidi Attribute.
*/
public static final String FEATURE_SUPPORTS_BIDI = ABDERA_FEATURE_BASE + "supportsBidi";
/**
* Indicates that the collection requires the use of the Atom Bidi Attribute.
*/
public static final String FEATURE_REQUIRES_BIDI = ABDERA_FEATURE_BASE + "requiresBidi";
/**
* Indicates that the collection ignores the use of the Atom Bidi Attribute.
*/
public static final String FEATURE_IGNORES_BIDI = ABDERA_FEATURE_BASE + "ignoresBidi";
/**
* Indicates that the collection supports the use of Geo extensions (see the org.apache.abdera.ext.geo Package)
*/
public static final String FEATURE_SUPPORTS_GEO = ABDERA_FEATURE_BASE + "supportsGeo";
/**
* Indicates that the collection requires the use of Geo extensions (see the org.apache.abdera.ext.geo Package)
*/
public static final String FEATURE_REQUIRES_GEO = ABDERA_FEATURE_BASE + "requiresGeo";
/**
* Indicates that the collection ignores the use of Geo extensions (see the org.apache.abdera.ext.geo Package)
*/
public static final String FEATURE_IGNORES_GEO = ABDERA_FEATURE_BASE + "ignoresGeo";
/**
* Indicates that the collection supports the use of the Simple Sharing Extensions (see the
* org.apache.abdera.ext.sharing Package)
*/
public static final String FEATURE_SUPPORTS_SHARING = ABDERA_FEATURE_BASE + "supportsSharing";
/**
* Indicates that the collection requires the use of the Simple Sharing Extensions (see the
* org.apache.abdera.ext.sharing Package)
*/
public static final String FEATURE_REQUIRES_SHARING = ABDERA_FEATURE_BASE + "requiresSharing";
/**
* Indicates that the collection ignores the use of the Simple Sharing Extensions (see the
* org.apache.abdera.ext.sharing Package)
*/
public static final String FEATURE_IGNORES_SHARING = ABDERA_FEATURE_BASE + "ignoresSharing";
/**
* Indicates that the collection requires the GoogleLogin auth scheme (see the org.apache.abdera.ext.gdata Package)
*/
public static final String FEATURE_REQUIRES_GOOGLELOGIN = ABDERA_FEATURE_BASE + "requiresGoogleLogin";
/**
* Indicates that the collection supports the GoogleLogin auth scheme (see the org.apache.abdera.ext.gdata Package)
*/
public static final String FEATURE_SUPPORTS_GOOGLELOGIN = ABDERA_FEATURE_BASE + "supportsGoogleLogin";
/**
* Indicates that the collection requires the WSSE auth scheme (see the org.apache.abdera.ext.wsse Package)
*/
public static final String FEATURE_REQUIRES_WSSE = ABDERA_FEATURE_BASE + "requiresWsse";
/**
* Indicates that the collection supports the WSSE auth scheme (see the org.apache.abdera.ext.wsse Package)
*/
public static final String FEATURE_SUPPORTS_WSSE = ABDERA_FEATURE_BASE + "supportsWsse";
/**
* Indicates that the collection will remove markup that is considered potentially unsafe from the entry examples of
* the type of markup that would be removed include scripts and embed
*/
public static final String FEATURE_FILTERS_MARKUP = BLOG_FEATURE_BASE + "filtersUnsafeMarkup";
private FeaturesHelper() {
}
private static Map<String, Features> featuresCache =
Collections.synchronizedMap(new WeakHashMap<String, Features>());
private static Features getCachedFeatures(String iri) {
return featuresCache.get(iri);
}
private static void setCachedFeatures(String iri, Features features) {
featuresCache.put(iri, features);
}
public static void flushCachedFeatures() {
featuresCache.clear();
}
public static Features newFeatures(Abdera abdera) {
Factory factory = abdera.getFactory();
Document<Features> doc = factory.newDocument();
Features features = factory.newElement(FEATURES, doc);
doc.setRoot(features);
return features;
}
public static Features getFeaturesElement(Collection collection) {
return getFeaturesElement(collection, true);
}
public static Features getFeaturesElement(Collection collection, boolean outofline) {
Features features = collection.getExtension(FEATURES);
if (features != null && outofline) {
if (features.getHref() != null) {
String iri = features.getResolvedHref().toASCIIString();
features = getCachedFeatures(iri);
if (features == null) {
Abdera abdera = collection.getFactory().getAbdera();
AbderaClient client = new AbderaClient(abdera);
ClientResponse resp = client.get(iri);
if (resp.getType() == ResponseType.SUCCESS) {
Document<Features> doc = resp.getDocument();
features = doc.getRoot();
setCachedFeatures(iri, features);
} else {
features = null;
}
}
}
}
return features;
}
public static Feature getFeature(Collection collection, String feature) {
return getFeature(getFeaturesElement(collection), feature);
}
/**
* Returns the specified feature element or null
*/
public static Feature getFeature(Features features, String feature) {
if (features == null)
return null;
List<Element> list = features.getExtensions(FEATURE);
for (Element el : list) {
if (el.getAttributeValue("ref").equals(feature))
return (Feature)el;
}
return null;
}
public static Status getFeatureStatus(Collection collection, String feature) {
return getFeatureStatus(getFeaturesElement(collection), feature);
}
public static Status getFeatureStatus(Features features, String feature) {
if (features == null)
return Status.UNSPECIFIED;
Feature f = getFeature(features, feature);
return f != null ? Status.SPECIFIED : Status.UNSPECIFIED;
}
public static Feature[] getFeatures(Collection collection) {
Features features = getFeaturesElement(collection);
if (features == null)
return null;
List<Feature> list = features.getExtensions(FEATURE);
return list.toArray(new Feature[list.size()]);
}
public static Features addFeaturesElement(Collection collection) {
if (getFeaturesElement(collection, false) != null)
throw new IllegalArgumentException("A collection element can only contain one features element");
return collection.addExtension(FEATURES);
}
/**
* Select a Collection from the service document
*/
public static Collection[] select(Service service, Selector selector) {
return select(service, new Selector[] {selector});
}
/**
* Select a Collection from the service document
*/
public static Collection[] select(Service service, Selector... selectors) {
List<Collection> list = new ArrayList<Collection>();
for (Workspace workspace : service.getWorkspaces()) {
Collection[] collections = select(workspace, selectors);
for (Collection collection : collections)
list.add(collection);
}
return list.toArray(new Collection[list.size()]);
}
/**
* Select a Collection from the Workspace
*/
public static Collection[] select(Workspace workspace, Selector selector) {
return select(workspace, new Selector[] {selector});
}
/**
* Select a Collection from the Workspace
*/
public static Collection[] select(Workspace workspace, Selector... selectors) {
List<Collection> list = new ArrayList<Collection>();
for (Collection collection : workspace.getCollections()) {
boolean accept = true;
for (Selector selector : selectors) {
if (!selector.select(collection)) {
accept = false;
break;
}
}
if (accept)
list.add(collection);
}
return list.toArray(new Collection[list.size()]);
}
}
| 7,650 |
0 | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext/features/Selector.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.features;
import java.io.Serializable;
import org.apache.abdera.model.Collection;
public interface Selector extends Cloneable, Serializable {
boolean select(Collection collection);
Selector clone();
}
| 7,651 |
0 | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext/features/Features.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.features;
import java.util.ArrayList;
import java.util.List;
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.ExtensibleElementWrapper;
public class Features extends ExtensibleElementWrapper {
public Features(Element internal) {
super(internal);
}
public Features(Factory factory, QName qname) {
super(factory, qname);
}
public IRI getResolvedHref() {
IRI base = getResolvedBaseUri();
IRI href = getHref();
return base != null ? base.resolve(href) : href;
}
public IRI getHref() {
String href = getAttributeValue("href");
return href != null ? new IRI(href) : null;
}
public void setHref(String href) {
setAttributeValue("href", (new IRI(href)).toString());
}
public String getName() {
return getAttributeValue("name");
}
public void setName(String name) {
setAttributeValue("name", name);
}
public void addFeature(Feature feature) {
addExtension(feature);
}
public void addFeature(Feature... features) {
for (Feature feature : features)
addFeature(feature);
}
public Feature addFeature(String feature) {
Feature f = addExtension(FeaturesHelper.FEATURE);
f.setRef(feature);
return f;
}
public Feature addFeature(String feature, String href, String label) {
Feature f = addExtension(FeaturesHelper.FEATURE);
f.setRef(feature);
f.setHref(href);
f.setLabel(label);
return f;
}
public Feature[] addFeatures(String... features) {
List<Feature> list = new ArrayList<Feature>();
for (String feature : features)
list.add(addFeature(feature));
return list.toArray(new Feature[list.size()]);
}
public List<Feature> getFeatures() {
return getExtensions(FeaturesHelper.FEATURE);
}
}
| 7,652 |
0 | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext/features/AbstractSelector.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.features;
public abstract class AbstractSelector implements Selector {
public Selector clone() {
try {
return (Selector)super.clone();
} catch (CloneNotSupportedException e) {
return copy();
}
}
protected Selector copy() {
throw new RuntimeException(new CloneNotSupportedException());
}
}
| 7,653 |
0 | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/features/src/main/java/org/apache/abdera/ext/features/Feature.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.features;
import java.util.ArrayList;
import java.util.List;
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
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.ExtensibleElementWrapper;
import org.apache.abdera.util.MimeTypeHelper;
public class Feature extends ExtensibleElementWrapper {
public Feature(Element internal) {
super(internal);
}
public Feature(Factory factory) {
super(factory, FeaturesHelper.FEATURE);
}
public IRI getRef() {
String ref = getAttributeValue("ref");
return (ref != null) ? new IRI(ref) : null;
}
public IRI getHref() {
String href = getAttributeValue("href");
return (href != null) ? new IRI(href) : null;
}
public String getLabel() {
return getAttributeValue("label");
}
public void setRef(String ref) {
if (ref == null)
throw new IllegalArgumentException();
setAttributeValue("ref", (new IRI(ref)).toString());
}
public void setHref(String href) {
if (href != null)
setAttributeValue("href", (new IRI(href)).toString());
else
removeAttribute(new QName("href"));
}
public void setLabel(String label) {
if (label != null)
setAttributeValue("label", label);
else
removeAttribute(new QName("label"));
}
public void addType(String mediaRange) {
addType(new String[] {mediaRange});
}
public void addType(String... mediaRanges) {
mediaRanges = MimeTypeHelper.condense(mediaRanges);
for (String mediaRange : mediaRanges) {
try {
addSimpleExtension(FeaturesHelper.TYPE, new MimeType(mediaRange).toString());
} catch (MimeTypeParseException e) {
}
}
}
public String[] getTypes() {
List<String> list = new ArrayList<String>();
for (Element type : getExtensions(FeaturesHelper.TYPE)) {
String value = type.getText();
if (value != null) {
value = value.trim();
try {
list.add(new MimeType(value).toString());
} catch (MimeTypeParseException e) {
}
}
}
return list.toArray(new String[list.size()]);
}
}
| 7,654 |
0 | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext/geo/Polygon.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.geo;
public class Polygon extends Multiple {
private static final long serialVersionUID = 5387230171535985909L;
public Polygon() {
super();
}
public Polygon(Multiple multiple) {
super(multiple);
verify();
}
public Polygon(Point point) {
super(point);
verify();
}
public Polygon(Coordinate... coordinates) {
super(coordinates);
verify();
}
public Polygon(Coordinates coordinates) {
super(coordinates);
verify();
}
public Polygon(String value) {
super(value);
verify();
}
public Polygon(Multiple... multiples) {
super(multiples);
verify();
}
public Polygon(Point... points) {
super(points);
verify();
}
public Polygon(double... values) {
super(values);
verify();
}
@Override
public void setCoordinates(Coordinates coordinates) {
super.setCoordinates(coordinates);
verify();
}
public void verify() {
super.verify179Rule();
}
}
| 7,655 |
0 | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext/geo/Point.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.geo;
public class Point extends Position {
private static final long serialVersionUID = 7540202474168797239L;
private Coordinate coordinate;
public Point() {
}
public Point(Point point) {
this.coordinate = point.getCoordinate().clone();
}
public Point(Coordinate coordinate) {
this.coordinate = coordinate;
}
public Point(double latitude, double longitude) {
this.coordinate = new Coordinate(latitude, longitude);
}
public Point(String value) {
this.coordinate = new Coordinate(value);
}
public Coordinate getCoordinate() {
return coordinate;
}
public void setCoordinate(Coordinate coordinate) {
this.coordinate = coordinate;
}
public void setCoordinate(double latitude, double longitude) {
this.coordinate = new Coordinate(latitude, longitude);
}
public void setCoordinate(String value) {
this.coordinate = new Coordinate(value);
}
@Override
public int hashCode() {
final int PRIME = 31;
int result = super.hashCode();
result = PRIME * result + ((coordinate == null) ? 0 : coordinate.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
final Point other = (Point)obj;
if (coordinate == null) {
if (other.coordinate != null)
return false;
} else if (!coordinate.equals(other.coordinate))
return false;
return true;
}
public int compareTo(Position o) {
if (o == null || !(o instanceof Point) || equals(o))
return 0;
return coordinate.compareTo(((Point)o).coordinate);
}
}
| 7,656 |
0 | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext/geo/Position.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.geo;
import java.io.Serializable;
public abstract class Position implements Serializable, Cloneable, Comparable<Position> {
public static final String DEFAULT_FEATURE_TYPE_TAG = "location";
public static final String DEFAULT_RELATIONSHIP_TAG = "is-located-at";
protected String featureTypeTag;
protected String relationshipTag;
protected Double elevation;
protected Double floor;
protected Double radius;
public Double getElevation() {
return elevation;
}
public void setElevation(Double elevation) {
this.elevation = elevation;
}
public String getFeatureTypeTag() {
return featureTypeTag;
}
public void setFeatureTypeTag(String featureTypeTag) {
this.featureTypeTag = featureTypeTag;
}
public Double getFloor() {
return floor;
}
public void setFloor(Double floor) {
this.floor = floor;
}
public Double getRadius() {
return radius;
}
public void setRadius(Double radius) {
this.radius = radius;
}
public String getRelationshipTag() {
return relationshipTag;
}
public void setRelationshipTag(String relationshipTag) {
this.relationshipTag = relationshipTag;
}
@Override
public int hashCode() {
final int PRIME = 31;
// int result = super.hashCode();
int result = this.getClass().hashCode();
result = PRIME * result + ((elevation == null) ? 0 : elevation.hashCode());
result =
PRIME * result
+ ((featureTypeTag == null) ? DEFAULT_FEATURE_TYPE_TAG.hashCode() : featureTypeTag.hashCode());
result = PRIME * result + ((floor == null) ? 0 : floor.hashCode());
result = PRIME * result + ((radius == null) ? 0 : radius.hashCode());
result =
PRIME * result
+ ((relationshipTag == null) ? DEFAULT_RELATIONSHIP_TAG.hashCode() : relationshipTag.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (getClass() != obj.getClass())
return false;
final Position other = (Position)obj;
if (elevation == null) {
if (other.elevation != null)
return false;
} else if (!elevation.equals(other.elevation))
return false;
if (featureTypeTag == null) {
if (other.featureTypeTag != null && !other.featureTypeTag.equalsIgnoreCase(DEFAULT_FEATURE_TYPE_TAG))
return false;
} else {
String s = other.featureTypeTag != null ? other.featureTypeTag : DEFAULT_FEATURE_TYPE_TAG;
if (!featureTypeTag.equalsIgnoreCase(s))
return false;
}
if (floor == null) {
if (other.floor != null)
return false;
} else if (!floor.equals(other.floor))
return false;
if (radius == null) {
if (other.radius != null)
return false;
} else if (!radius.equals(other.radius))
return false;
if (relationshipTag == null) {
if (other.relationshipTag != null && !other.relationshipTag.equalsIgnoreCase(DEFAULT_RELATIONSHIP_TAG))
return false;
} else {
String s = other.relationshipTag != null ? other.relationshipTag : DEFAULT_RELATIONSHIP_TAG;
if (!relationshipTag.equalsIgnoreCase(s))
return false;
}
return true;
}
@SuppressWarnings("unchecked")
public <T extends Position> T clone() {
try {
return (T)super.clone();
} catch (CloneNotSupportedException e) {
return null; // should never happen
}
}
}
| 7,657 |
0 | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext/geo/Coordinates.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.geo;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class Coordinates implements Iterable<Coordinate>, Serializable, Cloneable, Comparable<Coordinates> {
private static final long serialVersionUID = 1640788106113796699L;
protected List<Coordinate> coords = new ArrayList<Coordinate>();
public Coordinates() {
}
public Coordinates(Coordinate... coordinates) {
for (Coordinate coord : coordinates)
add(coord);
}
public Coordinates(Coordinates coordinates) {
coords.addAll(coordinates.coords);
}
public Coordinates(String value) {
Coordinates cs = parse(value);
this.coords = cs.coords;
}
public synchronized Coordinate get(int n) {
return coords.get(n);
}
public synchronized void add(Coordinates coordinates) {
coords.addAll(coordinates.coords);
}
public synchronized void add(Coordinate coordinate) {
coords.add(coordinate);
}
public synchronized void add(Coordinate... coordinates) {
for (Coordinate c : coordinates)
add(c);
}
public synchronized void add(double latitude, double longitude) {
coords.add(new Coordinate(latitude, longitude));
}
public synchronized void add(String value) {
coords.add(new Coordinate(value));
}
public synchronized void remove(Coordinate coordinate) {
if (coords.contains(coordinate))
coords.remove(coordinate);
}
public synchronized void remove(Coordinate... coordinates) {
for (Coordinate c : coordinates)
remove(c);
}
public synchronized void remove(double latitude, double longitude) {
remove(new Coordinate(latitude, longitude));
}
public synchronized void remove(String value) {
remove(new Coordinate(value));
}
public synchronized boolean contains(double latitude, double longitude) {
return contains(new Coordinate(latitude, longitude));
}
public synchronized boolean contains(String value) {
return contains(new Coordinate(value));
}
public synchronized boolean contains(Coordinate coordinate) {
return coords.contains(coordinate);
}
public synchronized boolean contains(Coordinate... coordinates) {
for (Coordinate c : coordinates)
if (!coords.contains(c))
return false;
return true;
}
public Iterator<Coordinate> iterator() {
return coords.iterator();
}
public String toString() {
StringBuffer buf = new StringBuffer();
for (Coordinate coord : coords) {
if (buf.length() > 0)
buf.append(" ");
buf.append(coord);
}
return buf.toString();
}
@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((coords == null) ? 0 : coords.hashCode());
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 Coordinates other = (Coordinates)obj;
if (coords == null) {
if (other.coords != null)
return false;
} else if (!coords.equals(other.coords))
return false;
return true;
}
public static Coordinates parse(String value) {
Coordinates cs = new Coordinates();
try {
String[] points = value.trim().split("\\s+");
for (int n = 0; n < points.length; n = n + 2) {
double lat = Double.parseDouble(points[n]);
double lon = Double.parseDouble(points[n + 1]);
Coordinate c = new Coordinate(lat, lon);
cs.add(c);
}
return cs;
} catch (Throwable t) {
throw new RuntimeException("Error parsing coordinate pairs", t);
}
}
public int size() {
return coords.size();
}
public void clear() {
coords.clear();
}
public Coordinates clone() {
try {
return (Coordinates)super.clone();
} catch (CloneNotSupportedException e) {
return new Coordinates(this); // Not going to happen
}
}
public Coordinates sort() {
return sort(false);
}
public Coordinates sort(boolean reverse) {
Coordinates c = clone();
if (reverse)
Collections.sort(c.coords, Collections.reverseOrder());
else
Collections.sort(c.coords);
return c;
}
public int compareTo(Coordinates o) {
if (o == null || equals(o))
return 0;
if (size() < o.size())
return -1;
if (o.size() < size())
return 1;
for (int n = 0; n < size(); n++) {
Coordinate c1 = coords.get(n);
Coordinate c2 = o.coords.get(n);
int c = c1.compareTo(c2);
if (c != 0)
return c;
}
return 0;
}
}
| 7,658 |
0 | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext/geo/Multiple.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.geo;
import java.util.Iterator;
public abstract class Multiple extends Position implements Iterable<Coordinate> {
protected Coordinates coordinates;
public Multiple() {
}
public Multiple(Multiple... multiples) {
this.coordinates = new Coordinates();
for (Multiple m : multiples)
coordinates.add(m.getCoordinates());
}
public Multiple(Multiple multiple) {
this(multiple.getCoordinates().clone());
}
public Multiple(Point point) {
this(point.getCoordinate().clone());
}
public Multiple(Point... points) {
this.coordinates = new Coordinates();
for (Point p : points)
coordinates.add(p.getCoordinate());
}
public Multiple(Coordinates coordinates) {
this.coordinates = coordinates;
}
public Multiple(Coordinate... coordinates) {
this.coordinates = new Coordinates(coordinates);
}
public Multiple(String value) {
this.coordinates = new Coordinates(value);
}
public Multiple(double... values) {
this.coordinates = new Coordinates();
for (int n = 0; n < values.length; n = n + 2) {
Coordinate c = new Coordinate(values[n], values[n + 1]);
this.coordinates.add(c);
}
}
public Coordinates getCoordinates() {
return coordinates;
}
public void setCoordinates(Coordinates coordinates) {
this.coordinates = coordinates;
}
public Iterator<Coordinate> iterator() {
return coordinates.iterator();
}
@Override
public int hashCode() {
final int PRIME = 31;
int result = super.hashCode();
result = PRIME * result + ((coordinates == null) ? 0 : coordinates.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
final Multiple other = (Multiple)obj;
if (coordinates == null) {
if (other.coordinates != null)
return false;
} else if (!coordinates.equals(other.coordinates))
return false;
return true;
}
public int compareTo(Position o) {
if (o == null || !this.getClass().isInstance(o) || equals(o))
return 0;
return coordinates.compareTo(((Multiple)o).coordinates);
}
protected void verify179Rule() {
for (Coordinate c1 : getCoordinates()) {
for (Coordinate c2 : getCoordinates()) {
check179(c1.getLatitude(), c2.getLatitude());
check179(c1.getLongitude(), c2.getLongitude());
}
}
}
private void check179(double d1, double d2) {
if (Math.abs(Math.max(d1, d2)) - Math.abs(Math.min(d1, d2)) > 179)
throw new RuntimeException("Values are greater than 179 degrees");
}
}
| 7,659 |
0 | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext/geo/Coordinate.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.geo;
import java.io.Serializable;
public class Coordinate implements Serializable, Cloneable, Comparable<Coordinate> {
private static final long serialVersionUID = -916272885213668761L;
private double latitude = 0.0f;
private double longitude = 0.0f;
public Coordinate() {
}
public Coordinate(double latitude, double longitude) {
setLatitude(latitude);
setLongitude(longitude);
}
public Coordinate(String value) {
Coordinate c = parse(value);
setLatitude(c.latitude);
setLongitude(c.longitude);
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
if (Double.compare(longitude, 90.0d) > 0)
throw new IllegalArgumentException("Latitude > 90.0 degrees");
if (Double.compare(longitude, -90.0d) < 0)
throw new IllegalArgumentException("Latitude < 90.0 degrees");
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
if (Double.compare(longitude, 180.0d) > 0)
throw new IllegalArgumentException("Longitude > 180.0 degrees");
if (Double.compare(longitude, -180.0d) < 0)
throw new IllegalArgumentException("Longitude < 180.0 degrees");
this.longitude = longitude;
}
public String toString() {
return Double.toString(latitude) + " " + Double.toString(longitude);
}
public Coordinate clone() {
try {
return (Coordinate)super.clone();
} catch (CloneNotSupportedException e) {
return new Coordinate(latitude, longitude); // not going to happen
}
}
@Override
public int hashCode() {
final int PRIME = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(latitude);
result = PRIME * result + (int)(temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(longitude);
result = PRIME * result + (int)(temp ^ (temp >>> 32));
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 Coordinate other = (Coordinate)obj;
if (Double.doubleToLongBits(latitude) != Double.doubleToLongBits(other.latitude))
return false;
if (Double.doubleToLongBits(longitude) != Double.doubleToLongBits(other.longitude))
return false;
return true;
}
public static Coordinate parse(String value) {
try {
String[] points = value.trim().split("\\s+", 2);
double latitude = Double.parseDouble(points[0].trim());
double longitude = Double.parseDouble(points[1].trim());
return new Coordinate(latitude, longitude);
} catch (Throwable t) {
throw new RuntimeException("Error parsing coordinate pair", t);
}
}
public int compareTo(Coordinate o) {
if (o == null || equals(o))
return 0;
int l1 = Double.compare(latitude, o.latitude);
int l2 = Double.compare(longitude, o.longitude);
if (l1 < 0)
return -1;
if (l1 == 0 && l2 < -1)
return -1;
if (l1 == 0 && l2 == 0)
return 0;
return 1;
}
}
| 7,660 |
0 | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext/geo/GeoHelper.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.geo;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ExtensibleElement;
import org.apache.abdera.util.Constants;
/**
* Basic support for the GeoRSS extensions to Atom: http://georss.org/1
*/
public class GeoHelper {
public static final String W3C_GEO_NS = "http://www.w3.org/2003/01/geo/wgs84_pos#";
public static final String SIMPLE_GEO_NS = "http://www.georss.org/georss";
public static final String GML_NS = "http://www.opengis.net/gml";
public static final QName QNAME_W3C_POINT = new QName(W3C_GEO_NS, "Point", "geo");
public static final QName QNAME_W3C_LAT = new QName(W3C_GEO_NS, "lat", "geo");
public static final QName QNAME_W3C_LONG = new QName(W3C_GEO_NS, "long", "geo");
public static final QName QNAME_SIMPLE_POINT = new QName(SIMPLE_GEO_NS, "point", "georss");
public static final QName QNAME_SIMPLE_LINE = new QName(SIMPLE_GEO_NS, "line", "georss");
public static final QName QNAME_SIMPLE_POLYGON = new QName(SIMPLE_GEO_NS, "polygon", "georss");
public static final QName QNAME_SIMPLE_BOX = new QName(SIMPLE_GEO_NS, "box", "georss");
public static final QName QNAME_WHERE = new QName(SIMPLE_GEO_NS, "where", "georss");
public static final QName QNAME_GML_POINT = new QName(GML_NS, "Point", "gml");
public static final QName QNAME_GML_POS = new QName(GML_NS, "pos", "gml");
public static final QName QNAME_GML_LINESTRING = new QName(GML_NS, "LineString", "gml");
public static final QName QNAME_GML_POSLIST = new QName(GML_NS, "posList", "gml");
public static final QName QNAME_GML_POLYGON = new QName(GML_NS, "Polygon", "gml");
public static final QName QNAME_GML_EXTERIOR = new QName(GML_NS, "exterior", "gml");
public static final QName QNAME_GML_LINEARRING = new QName(GML_NS, "LinearRing", "gml");
public static final QName QNAME_GML_ENVELOPE = new QName(GML_NS, "Envelope", "gml");
public static final QName QNAME_GML_LOWERCORNER = new QName(GML_NS, "lowerCorner", "gml");
public static final QName QNAME_GML_UPPERCORNER = new QName(GML_NS, "upperCorner", "gml");
public enum Encoding {
SIMPLE, W3C, GML
}
public static void addPosition(ExtensibleElement element, Position position) {
addPosition(element, position, Encoding.SIMPLE);
}
public static void addPosition(ExtensibleElement element, Position position, Encoding encoding) {
switch (encoding) {
case SIMPLE:
addSimplePosition(element, position);
break;
case GML:
addGmlPosition(element, position);
break;
case W3C: {
addW3CPosition(element, position);
break;
}
}
}
private static void setPositionAttributes(Element pos, Position position) {
if (pos != null) {
if (position.getFeatureTypeTag() != null)
pos.setAttributeValue("featuretypetag", position.getFeatureTypeTag());
if (position.getRelationshipTag() != null)
pos.setAttributeValue("relationshiptag", position.getRelationshipTag());
if (position.getElevation() != null)
pos.setAttributeValue("elev", position.getElevation().toString());
if (position.getFloor() != null)
pos.setAttributeValue("floor", position.getFloor().toString());
if (position.getRadius() != null)
pos.setAttributeValue("radius", position.getRadius().toString());
}
}
private static void addGmlPosition(ExtensibleElement element, Position position) {
ExtensibleElement pos = element.addExtension(QNAME_WHERE);
if (position instanceof Point) {
Point point = (Point)position;
ExtensibleElement p = pos.addExtension(QNAME_GML_POINT);
p.addSimpleExtension(QNAME_GML_POS, point.getCoordinate().toString());
} else if (position instanceof Line) {
Multiple m = (Multiple)position;
ExtensibleElement p = pos.addExtension(QNAME_GML_LINESTRING);
p.addSimpleExtension(QNAME_GML_POSLIST, m.getCoordinates().toString());
} else if (position instanceof Polygon) {
Multiple m = (Multiple)position;
ExtensibleElement p = pos.addExtension(QNAME_GML_POLYGON);
p = p.addExtension(QNAME_GML_EXTERIOR);
p = p.addExtension(QNAME_GML_LINEARRING);
p.addSimpleExtension(QNAME_GML_POSLIST, m.getCoordinates().toString());
} else if (position instanceof Box) {
Box m = (Box)position;
ExtensibleElement p = pos.addExtension(QNAME_GML_ENVELOPE);
if (m.getLowerCorner() != null)
p.addSimpleExtension(QNAME_GML_LOWERCORNER, m.getLowerCorner().toString());
if (m.getUpperCorner() != null)
p.addSimpleExtension(QNAME_GML_UPPERCORNER, m.getUpperCorner().toString());
}
setPositionAttributes(pos, position);
}
private static void addSimplePosition(ExtensibleElement element, Position position) {
Element pos = null;
if (position instanceof Point) {
Point point = (Point)position;
pos = element.addSimpleExtension(QNAME_SIMPLE_POINT, point.getCoordinate().toString());
} else if (position instanceof Multiple) {
Multiple line = (Multiple)position;
QName qname =
position instanceof Line ? QNAME_SIMPLE_LINE : position instanceof Box ? QNAME_SIMPLE_BOX
: position instanceof Polygon ? QNAME_SIMPLE_POLYGON : null;
if (qname != null) {
pos = element.addSimpleExtension(qname, line.getCoordinates().toString());
}
}
setPositionAttributes(pos, position);
}
private static void addW3CPosition(ExtensibleElement element, Position position) {
if (!(position instanceof Point))
throw new IllegalArgumentException("The W3C Encoding only supports Points");
Element el = element.getExtension(QNAME_W3C_LAT);
if (el != null)
el.discard();
el = element.getExtension(QNAME_W3C_LONG);
if (el != null)
el.discard();
Point point = (Point)position;
ExtensibleElement p = element.addExtension(QNAME_W3C_POINT);
p.addSimpleExtension(QNAME_W3C_LAT, Double.toString(point.getCoordinate().getLatitude()));
p.addSimpleExtension(QNAME_W3C_LONG, Double.toString(point.getCoordinate().getLongitude()));
}
private static List<Position> _getPositions(ExtensibleElement element) {
List<Position> list = new ArrayList<Position>();
getW3CPosition(element, list);
getSimplePosition(element, list);
getGMLPosition(element, list);
return list;
}
public static boolean isGeotagged(ExtensibleElement element) {
if (element.getExtensions(QNAME_SIMPLE_POINT).size() > 0)
return true;
if (element.getExtensions(QNAME_SIMPLE_LINE).size() > 0)
return true;
if (element.getExtensions(QNAME_SIMPLE_BOX).size() > 0)
return true;
if (element.getExtensions(QNAME_SIMPLE_POLYGON).size() > 0)
return true;
if (element.getExtensions(QNAME_WHERE).size() > 0)
return true;
if (element.getExtensions(QNAME_W3C_POINT).size() > 0)
return true;
if (element.getExtensions(QNAME_W3C_LAT).size() > 0 && element.getExtensions(QNAME_W3C_LONG).size() > 0)
return true;
return false;
}
public static Iterator<Position> listPositions(ExtensibleElement element) {
return _getPositions(element).iterator();
}
public static Position getAsPosition(Element element) {
Position pos = null;
QName qname = element.getQName();
String text = element.getText();
if (qname.equals(QNAME_GML_POINT)) {
element = traverse((ExtensibleElement)element, QNAME_GML_POS);
if (element != null && text != null) {
pos = new Point(text.trim());
}
} else if (qname.equals(QNAME_GML_LINESTRING)) {
element = traverse((ExtensibleElement)element, QNAME_GML_POSLIST);
if (element != null && text != null) {
pos = new Line(text.trim());
}
} else if (qname.equals(QNAME_GML_POLYGON)) {
element = traverse((ExtensibleElement)element, QNAME_GML_EXTERIOR, QNAME_GML_LINEARRING, QNAME_GML_POSLIST);
if (element != null && text != null) {
pos = new Polygon(text.trim());
}
} else if (qname.equals(QNAME_GML_ENVELOPE)) {
String lc = ((ExtensibleElement)element).getSimpleExtension(QNAME_GML_LOWERCORNER);
String uc = ((ExtensibleElement)element).getSimpleExtension(QNAME_GML_UPPERCORNER);
if (lc != null && uc != null) {
Coordinate c1 = new Coordinate(lc);
Coordinate c2 = new Coordinate(uc);
pos = new Box(c1, c2);
}
} else if (qname.equals(QNAME_SIMPLE_POINT) && text != null) {
pos = new Point(text.trim());
} else if (qname.equals(QNAME_SIMPLE_LINE) && text != null) {
pos = new Line(text.trim());
} else if (qname.equals(QNAME_SIMPLE_BOX) && text != null) {
pos = new Box(text.trim());
} else if (qname.equals(QNAME_SIMPLE_POLYGON) && text != null) {
pos = new Polygon(text.trim());
} else if (qname.equals(QNAME_W3C_POINT) || qname.equals(Constants.ENTRY)) {
List<Position> list = new ArrayList<Position>();
getW3CPosition((ExtensibleElement)element, list);
if (list != null && list.size() > 0)
pos = list.get(0);
}
return pos;
}
public static Position[] getPositions(ExtensibleElement element) {
List<Position> positions = _getPositions(element);
return positions.toArray(new Position[positions.size()]);
}
private static void getSimplePosition(ExtensibleElement element, List<Position> list) {
List<Element> elements = element.getExtensions(SIMPLE_GEO_NS);
for (Element el : elements) {
Position pos = getAsPosition(el);
if (pos != null) {
getPositionAttributes(el, pos);
list.add(pos);
}
}
}
private static void getGMLPosition(ExtensibleElement element, List<Position> list) {
List<ExtensibleElement> elements = element.getExtensions(QNAME_WHERE);
for (ExtensibleElement where : elements) {
Position pos = null;
List<ExtensibleElement> children = where.getElements();
for (ExtensibleElement el : children) {
pos = getAsPosition(el);
if (pos != null) {
getPositionAttributes(el, pos);
list.add(pos);
}
}
}
}
private static ExtensibleElement traverse(ExtensibleElement element, QName... qnames) {
for (QName qname : qnames) {
element = element.getExtension(qname);
if (element == null)
break;
}
return element;
}
private static void getPositionAttributes(Element pos, Position position) {
if (position != null) {
String featuretypetag = pos.getAttributeValue("featuretypetag");
String relationshiptag = pos.getAttributeValue("relationshiptag");
String elevation = pos.getAttributeValue("elev");
String floor = pos.getAttributeValue("floor");
String radius = pos.getAttributeValue("radius");
if (featuretypetag != null)
position.setFeatureTypeTag(featuretypetag);
if (featuretypetag != null)
position.setRelationshipTag(relationshiptag);
if (elevation != null)
position.setElevation(Double.valueOf(elevation));
if (floor != null)
position.setFloor(Double.valueOf(floor));
if (radius != null)
position.setRadius(Double.valueOf(radius));
}
}
private static void getW3CPosition(ExtensibleElement element, List<Position> list) {
getSimpleW3CPosition(element, list);
List<ExtensibleElement> points = element.getExtensions(QNAME_W3C_POINT);
for (ExtensibleElement point : points)
getSimpleW3CPosition(point, list);
}
private static void getSimpleW3CPosition(ExtensibleElement el, List<Position> list) {
String slat = el.getSimpleExtension(QNAME_W3C_LAT);
String slong = el.getSimpleExtension(QNAME_W3C_LONG);
if (slat != null && slong != null) {
Point point = new Point(slat.trim() + " " + slong.trim());
list.add(point);
}
}
}
| 7,661 |
0 | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext/geo/Box.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.geo;
public class Box extends Multiple {
private static final String TWO_COORDINATES = "A box must have two coordinates";
private static final long serialVersionUID = 3994252648307511152L;
public Box() {
super();
}
public Box(Multiple multiple) {
super(multiple);
if (this.coordinates.size() != 2)
throw new IllegalArgumentException(TWO_COORDINATES);
}
public Box(Point lowerCorner, Point upperCorner) {
super(lowerCorner, upperCorner);
}
public Box(Coordinate... coordinates) {
super(coordinates);
if (this.coordinates.size() != 2)
throw new IllegalArgumentException(TWO_COORDINATES);
}
public Box(Coordinates coordinates) {
super(coordinates);
if (this.coordinates.size() != 2)
throw new IllegalArgumentException(TWO_COORDINATES);
}
public Box(String value) {
super(value);
if (this.coordinates.size() != 2)
throw new IllegalArgumentException(TWO_COORDINATES);
}
public Box(Multiple... multiples) {
super(multiples);
if (this.coordinates.size() != 2)
throw new IllegalArgumentException(TWO_COORDINATES);
}
public Box(Point... points) {
super(points);
if (this.coordinates.size() != 2)
throw new IllegalArgumentException(TWO_COORDINATES);
}
public Box(double... values) {
super(values);
if (this.coordinates.size() != 2)
throw new IllegalArgumentException(TWO_COORDINATES);
}
@Override
public void setCoordinates(Coordinates coordinates) {
super.setCoordinates(coordinates);
if (this.coordinates.size() > 2)
throw new IllegalArgumentException(TWO_COORDINATES);
}
public Coordinate getUpperCorner() {
return coordinates.size() > 1 ? coordinates.get(1) : null;
}
public Coordinate getLowerCorner() {
return coordinates.size() > 0 ? coordinates.get(0) : null;
}
}
| 7,662 |
0 | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/geo/src/main/java/org/apache/abdera/ext/geo/Line.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.geo;
public class Line extends Multiple {
private static final long serialVersionUID = 2852975001208906285L;
public Line() {
}
public Line(Multiple multiple) {
super(multiple);
verify();
}
public Line(Point point) {
super(point);
verify();
}
public Line(Coordinate... coordinates) {
super(coordinates);
verify();
}
public Line(Coordinates coordinates) {
super(coordinates);
verify();
}
public Line(String value) {
super(value);
verify();
}
public Line(Multiple... multiples) {
super(multiples);
verify();
}
public Line(Point... points) {
super(points);
verify();
}
public Line(double... values) {
super(values);
verify();
}
@Override
public void setCoordinates(Coordinates coordinates) {
super.setCoordinates(coordinates);
verify();
}
public void verify() {
super.verify179Rule();
}
}
| 7,663 |
0 | Create_ds/abdera/extensions/wsse/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/wsse/src/main/java/org/apache/abdera/ext/wsse/WSSEAuthScheme.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.wsse;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Date;
import org.apache.abdera.model.AtomDate;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScheme;
import org.apache.commons.httpclient.auth.AuthenticationException;
import org.apache.commons.httpclient.auth.RFC2617Scheme;
/**
* WSSE Auth Scheme implementation for use with HTTP Commons AbderaClient Some APP implementations use WSSE for
* authentication
*
* @see http://www.xml.com/pub/a/2003/12/17/dive.html
*/
public class WSSEAuthScheme extends RFC2617Scheme implements AuthScheme {
private final int NONCE_LENGTH = 16;
public static void register(AbderaClient abderaClient, boolean exclusive) {
AbderaClient.registerScheme("WSSE", WSSEAuthScheme.class);
if (exclusive)
((AbderaClient)abderaClient).setAuthenticationSchemePriority("WSSE");
else
((AbderaClient)abderaClient).setAuthenticationSchemeDefaults();
}
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
if (credentials instanceof UsernamePasswordCredentials) {
UsernamePasswordCredentials creds = (UsernamePasswordCredentials)credentials;
AtomDate now = new AtomDate(new Date());
String nonce = generateNonce();
String digest = generatePasswordDigest(creds.getPassword(), nonce, now);
String username = creds.getUserName();
String wsse =
"UsernameToken Username=\"" + username
+ "\", "
+ "PasswordDigest=\""
+ digest
+ "\", "
+ "Nonce=\""
+ nonce
+ "\", "
+ "Created=\""
+ now.getValue()
+ "\"";
if (method != null)
method.addRequestHeader("X-WSSE", wsse);
return "WSSE profile=\"UsernameToken\"";
} else {
return null;
}
}
private String generatePasswordDigest(String password, String nonce, AtomDate date) throws AuthenticationException {
String temp = nonce + date.getValue() + password;
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
return new String(Base64.encodeBase64(md.digest(temp.getBytes())));
} catch (Exception 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);
}
}
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException {
return authenticate(credentials, null);
}
public String getSchemeName() {
return "WSSE";
}
public boolean isComplete() {
return true;
}
public boolean isConnectionBased() {
return false;
}
}
| 7,664 |
0 | Create_ds/abdera/extensions/html/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlParserOptions.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.html;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.i18n.text.Localizer;
import org.apache.abdera.parser.stax.FOMException;
import org.apache.abdera.parser.stax.FOMFactory;
import org.apache.abdera.util.AbstractParserOptions;
public class HtmlParserOptions extends AbstractParserOptions {
private boolean fragment = false;
@Override
protected void checkFactory(Factory factory) {
if (!(factory instanceof FOMFactory))
throw new FOMException(Localizer.sprintf("WRONG.PARSER.INSTANCE", FOMFactory.class.getName()));
}
@Override
protected void initFactory() {
if (factory == null)
factory = new FOMFactory();
}
public boolean isHtmlFragment() {
return fragment;
}
public void setHtmlFragment(boolean fragment) {
this.fragment = fragment;
}
}
| 7,665 |
0 | Create_ds/abdera/extensions/html/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlCleaner.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.html;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.util.Arrays;
import nu.validator.htmlparser.common.XmlViolationPolicy;
import nu.validator.htmlparser.sax.HtmlSerializer;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class HtmlCleaner {
private HtmlCleaner() {
}
public static String parse(String value) {
return parse(new StringReader(value), true);
}
public static String parse(InputStream in) {
return parse(in, "UTF-8");
}
public static String parse(InputStream in, String charset) {
try {
return parse(new InputStreamReader(in, charset), true);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String parse(Reader in, boolean fragment) {
try {
nu.validator.htmlparser.sax.HtmlParser htmlParser = new nu.validator.htmlparser.sax.HtmlParser();
htmlParser.setBogusXmlnsPolicy(XmlViolationPolicy.ALTER_INFOSET);
htmlParser.setMappingLangToXmlLang(true);
htmlParser.setReportingDoctype(false);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer w = new OutputStreamWriter(out, "UTF-8");
HtmlSerializer ser = new VoidElementFixHtmlSerializer(w);
htmlParser.setContentHandler(ser);
htmlParser.setLexicalHandler(ser);
if (!fragment)
htmlParser.parse(new InputSource(in));
else
htmlParser.parseFragment(new InputSource(in), "div");
try {
w.flush();
} catch (IOException e) {
}
return new String(out.toByteArray(), "UTF-8");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
private static class VoidElementFixHtmlSerializer extends HtmlSerializer {
private static final String[] VOID_ELEMENTS =
{"area", "base", "basefont", "bgsound", "br", "col", "embed", "frame", "hr", "img", "input", "link",
"meta", "param", "spacer", "wbr"};
private final Writer writer;
public VoidElementFixHtmlSerializer(Writer out) {
super(out);
this.writer = out;
}
@Override
public void endElement(String uri, String localName, String name) throws SAXException {
if (Arrays.binarySearch(VOID_ELEMENTS, localName) > -1) {
try {
writer.write('<');
writer.write('/');
writer.write(localName);
writer.write('>');
} catch (IOException e) {
throw new SAXException(e);
}
}
super.endElement(uri, localName, name);
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
StringBuilder buf = new StringBuilder();
for (int n = start; n < (start + length); n++) {
if (ch[n] == '<')
buf.append("<");
else if (ch[n] == '>')
buf.append(">");
else if (ch[n] == '&') {
boolean isentity = false;
int i = n;
String ent = null;
for (; i < (start + length); i++) {
if (ch[i] == ';') {
ent = new String(ch, n, i - n + 1);
isentity = ent.matches("\\&[\\w]*\\;");
break;
}
}
if (isentity) {
buf.append(ent);
n = i;
} else {
buf.append("&");
}
} else
buf.append(ch[n]);
}
super.characters(buf.toString().toCharArray(), 0, buf.length());
}
}
}
| 7,666 |
0 | Create_ds/abdera/extensions/html/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlParser.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.html;
import java.io.Reader;
import javax.xml.stream.XMLStreamReader;
import org.apache.abdera.Abdera;
import org.apache.abdera.model.Div;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
import org.apache.abdera.parser.ParseException;
import org.apache.abdera.parser.ParserOptions;
import org.apache.abdera.util.AbstractNamedParser;
public class HtmlParser extends AbstractNamedParser {
public HtmlParser() {
this(null);
}
public HtmlParser(Abdera abdera) {
super(abdera, "html");
}
@Override
protected ParserOptions initDefaultParserOptions() {
return new HtmlParserOptions();
}
@SuppressWarnings("unchecked")
public <T extends Element> Document<T> parse(Reader in, String base, ParserOptions options) throws ParseException {
boolean fragment = options instanceof HtmlParserOptions ? ((HtmlParserOptions)options).isHtmlFragment() : false;
Document<T> doc = null;
if (fragment) {
Div div = HtmlHelper.parse(abdera, in);
doc = this.getFactory().newDocument();
doc.setRoot((T)div);
} else {
doc = (Document<T>)HtmlHelper.parseDocument(abdera, in);
}
if (base != null)
doc.setBaseUri(base);
return doc;
}
public <T extends Element> Document<T> parse(XMLStreamReader reader) throws ParseException {
return null;
}
public <T extends Element> Document<T> parse(XMLStreamReader reader, String base, ParserOptions options)
throws ParseException {
return null;
}
}
| 7,667 |
0 | Create_ds/abdera/extensions/html/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/html/src/main/java/org/apache/abdera/ext/html/HtmlHelper.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.html;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.abdera.Abdera;
import org.apache.abdera.model.Div;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.util.MimeTypeHelper;
import org.apache.abdera.util.XmlRestrictedCharReader;
public class HtmlHelper {
private HtmlHelper() {
}
public static Div parse(String value) {
return parse(Abdera.getInstance(), value);
}
public static Div parse(InputStream in) {
return parse(Abdera.getInstance(), in);
}
public static Div parse(InputStream in, String charset) {
return parse(Abdera.getInstance(), in, charset);
}
public static Div parse(Reader in) {
return parse(Abdera.getInstance(), in);
}
public static Div parse(Abdera abdera, String value) {
return parse(abdera, new StringReader(value));
}
public static Div parse(Abdera abdera, InputStream in) {
return parse(abdera, in, "UTF-8");
}
public static Div parse(Abdera abdera, InputStream in, String charset) {
try {
return parse(abdera, new InputStreamReader(in, charset));
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Div parse(Abdera abdera, Reader in) {
String result = null;
Div div = abdera.getFactory().newDiv();
try {
div.setValue(HtmlCleaner.parse(in, true));
return div;
} catch (Exception e) {
// this is a temporary hack. some html really
// can't be parsed successfully. in that case,
// we produce something that will likely render
// rather ugly. but there's not much else we
// can do
if (result != null)
div.setText(result);
return div;
}
}
public static Document<Element> parseDocument(Reader in) {
return parseDocument(Abdera.getInstance(), in);
}
public static Document<Element> parseDocument(Abdera abdera, Reader in) {
return abdera.getParser().parse(new StringReader(HtmlCleaner.parse(in, false)));
}
/**
* This will search the element tree for elements named "link" with a rel attribute containing the value of rel and
* a type attribute containg the value of type.
*/
public static List<Element> discoverLinks(Element base, String type, String... rel) {
List<Element> results = new ArrayList<Element>();
walkElementForLinks(results, base, rel, type);
return results;
}
private static void walkElementForLinks(List<Element> results, Element base, String[] rel, String type) {
if (checkElementForLink(base, rel, type))
results.add(base);
for (Element child : base.getElements())
walkElementForLinks(results, child, rel, type);
}
private static boolean checkElementForLink(Element base, String[] relvals, String type) {
if (base.getQName().getLocalPart().equalsIgnoreCase("link")) {
String relattr = base.getAttributeValue("rel");
String typeattr = base.getAttributeValue("type");
if (relattr != null) {
String[] rels = relattr.split("\\s+");
Arrays.sort(rels);
for (String rel : relvals) {
if (Arrays.binarySearch(rels, rel) < 0)
return false;
}
}
if (type != null && typeattr == null)
return false;
if (type == null && typeattr != null)
return true; // assume possible match
if (MimeTypeHelper.isMatch(type, typeattr))
return true;
}
return false;
}
public static List<Element> discoverLinks(String uri, String type, String... rel) throws IOException {
return discoverLinks(Abdera.getInstance(), uri, type, rel);
}
public static List<Element> discoverLinks(Abdera abdera, String uri, String type, String... rel) throws IOException {
AbderaClient client = new AbderaClient(abdera);
ClientResponse resp = client.get(uri);
InputStream in = resp.getInputStream();
InputStreamReader r = new InputStreamReader(in);
XmlRestrictedCharReader x = new XmlRestrictedCharReader(r);
Document<Element> doc = HtmlHelper.parseDocument(x);
List<Element> list = discoverLinks(doc.getRoot(), type, rel);
return list;
}
}
| 7,668 |
0 | Create_ds/abdera/extensions/gdata/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/gdata/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthScheme.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.gdata;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.Formatter;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.client.RequestOptions;
import org.apache.abdera.util.Version;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScheme;
import org.apache.commons.httpclient.auth.AuthenticationException;
import org.apache.commons.httpclient.auth.MalformedChallengeException;
import org.apache.commons.httpclient.auth.RFC2617Scheme;
import org.apache.commons.httpclient.methods.StringRequestEntity;
/**
* <p>
* Implements the GoogleLogin auth scheme used by gdata (Blogger, Google Calendar, etc). Warning: this scheme is slow!
* </p>
*
* <pre>
* GoogleLoginAuthScheme.register();
*
* AbderaClient client = new CommonsClient();
* client.addCredentials("http://beta.blogger.com", null, "GoogleLogin", new UsernamePasswordCredentials("email",
* "password"));
* </pre>
*/
public class GoogleLoginAuthScheme extends RFC2617Scheme implements AuthScheme {
public static void register(AbderaClient abderaClient, boolean exclusive) {
AbderaClient.registerScheme("GoogleLogin", GoogleLoginAuthScheme.class);
if (exclusive)
((AbderaClient)abderaClient).setAuthenticationSchemePriority("GoogleLogin");
else
((AbderaClient)abderaClient).setAuthenticationSchemeDefaults();
}
private String service = null;
@Override
public void processChallenge(String challenge) throws MalformedChallengeException {
super.processChallenge(challenge);
service = getParameter("service");
}
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException {
String auth = null;
if (credentials instanceof UsernamePasswordCredentials) {
UsernamePasswordCredentials usercreds = (UsernamePasswordCredentials)credentials;
String id = usercreds.getUserName();
String pwd = usercreds.getPassword();
auth = getAuth(id, pwd);
} else if (credentials instanceof GoogleLoginAuthCredentials) {
GoogleLoginAuthCredentials gcreds = (GoogleLoginAuthCredentials)credentials;
service = gcreds.getService();
auth = gcreds.getAuth();
} else {
throw new AuthenticationException("Cannot use credentials for GoogleLogin authentication");
}
StringBuffer buf = new StringBuffer("GoogleLogin ");
buf.append(auth);
return buf.toString();
}
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException {
return authenticate(credentials, null);
}
public String getSchemeName() {
return "GoogleLogin";
}
public boolean isComplete() {
return true;
}
public boolean isConnectionBased() {
return false;
}
protected String getAuth(String id, String pwd) {
return getAuth(id, pwd, service);
}
protected String getAuth(String id, String pwd, String service) {
try {
AbderaClient abderaClient = new AbderaClient();
Formatter f = new Formatter();
f.format("Email=%s&Passwd=%s&service=%s&source=%s", URLEncoder.encode(id, "utf-8"), URLEncoder
.encode(pwd, "utf-8"), (service != null) ? URLEncoder.encode(service, "utf-8") : "", URLEncoder
.encode(Version.APP_NAME, "utf-8"));
StringRequestEntity stringreq =
new StringRequestEntity(f.toString(), "application/x-www-form-urlencoded", "utf-8");
String uri = "https://www.google.com/accounts/ClientLogin";
RequestOptions options = abderaClient.getDefaultRequestOptions();
options.setContentType("application/x-www-form-urlencoded");
ClientResponse response = abderaClient.post(uri, stringreq, options);
InputStream in = response.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
int n = -1;
while ((n = in.read()) != -1) {
out.write(n);
}
out.flush();
response.release();
String auth = new String(out.toByteArray());
return auth.split("\n")[2].replaceAll("Auth=", "auth=");
} catch (Exception e) {
}
return null;
}
public static String getGoogleLogin(String id, String pwd, String service) {
String auth = (new GoogleLoginAuthScheme()).getAuth(id, pwd, service);
StringBuffer buf = new StringBuffer("GoogleLogin ");
buf.append(auth);
return buf.toString();
}
}
| 7,669 |
0 | Create_ds/abdera/extensions/gdata/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/gdata/src/main/java/org/apache/abdera/ext/gdata/GoogleLoginAuthCredentials.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.gdata;
import org.apache.commons.httpclient.Credentials;
/**
* <p>
* When using the GoogleLoginAuthScheme with the typical Commons AbderaClient UsernamePasswordCredentials, the
* AuthScheme implementation will request a new auth token from the Google server for every request. To make it a more
* efficient, clients can use GoogleLoginAuthCredentials which will perform the Google Auth once to get the auth token
* which will be reused for every request.
* </p>
*
* <pre>
* GoogleLoginAuthScheme.register();
*
* AbderaClient client = new CommonsClient();
*
* GoogleLoginAuthCredentials credentials = new GoogleLoginAuthCredentials("email", "password", "blogger");
* client.addCredentials("http://beta.blogger.com", null, null, credentials);
* </pre>
*/
public final class GoogleLoginAuthCredentials implements Credentials {
private final String auth;
private final String service;
public GoogleLoginAuthCredentials(String auth) {
this.auth = auth;
this.service = null;
}
public GoogleLoginAuthCredentials(String id, String pwd, String service) {
this.auth = (new GoogleLoginAuthScheme()).getAuth(id, pwd, service);
this.service = service;
}
public String getAuth() {
return auth;
}
public String getService() {
return service;
}
}
| 7,670 |
0 | Create_ds/abdera/extensions/json/src/test/java/org/apache/abdera/ext | Create_ds/abdera/extensions/json/src/test/java/org/apache/abdera/ext/json/JSONStreamTest.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.json;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import org.apache.abdera.Abdera;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Entry;
import org.apache.abdera.writer.Writer;
import org.junit.Test;
public class JSONStreamTest {
@Test
public void testJSONStreamContent() throws Exception {
Abdera abdera = new Abdera();
Entry entry = abdera.newEntry();
entry.setContent(new IRI("http://example.org/xml"), "text/xml");
Writer json = abdera.getWriterFactory().getWriter("json");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
entry.writeTo(json, outputStream);
String output = outputStream.toString();
assertTrue(output.contains("\"type\":\"text/xml\""));
assertTrue(output.contains("\"src\":\"http://example.org/xml\""));
assertTrue(output.contains("\"content\":"));
}
}
| 7,671 |
0 | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONFilter.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.json;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.abdera.Abdera;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
import org.apache.abdera.protocol.server.Filter;
import org.apache.abdera.protocol.server.FilterChain;
import org.apache.abdera.protocol.server.ProviderHelper;
import org.apache.abdera.protocol.server.RequestContext;
import org.apache.abdera.protocol.server.ResponseContext;
import org.apache.abdera.protocol.server.context.ResponseContextWrapper;
import org.apache.abdera.writer.Writer;
/**
* Filter implementation that will convert an Atom document returned by the server into a JSON document if the request
* specifies a higher preference value for JSON or explicitly requests JSON by including a format=json querystring
* parameter
*/
public class JSONFilter implements Filter {
public ResponseContext filter(RequestContext request, FilterChain chain) {
ResponseContext resp = chain.next(request);
String format = request.getParameter("format");
return (resp.getContentType() != null && jsonPreferred(request, resp.getContentType().toString())) || (format != null && format
.equalsIgnoreCase("json")) ? new JsonResponseContext(resp, request.getAbdera()) : resp;
}
private boolean jsonPreferred(RequestContext request, String type) {
return ProviderHelper.isPreferred(request, "application/json", type);
}
private class JsonResponseContext extends ResponseContextWrapper {
private final Abdera abdera;
public JsonResponseContext(ResponseContext response, Abdera abdera) {
super(response);
setContentType("application/json");
this.abdera = abdera;
}
public void writeTo(OutputStream out, Writer writer) throws IOException {
try {
toJson(out, writer);
} catch (Exception se) {
if (se instanceof RuntimeException)
throw (RuntimeException)se;
throw new RuntimeException(se);
}
}
public void writeTo(OutputStream out) throws IOException {
try {
toJson(out, null);
} catch (Exception se) {
if (se instanceof RuntimeException)
throw (RuntimeException)se;
throw new RuntimeException(se);
}
}
private void toJson(OutputStream aout, Writer writer) throws Exception {
Document<Element> doc = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
if (writer == null)
super.writeTo(out);
else
super.writeTo(out, writer);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
doc = abdera.getParser().parse(in);
} catch (Exception e) {
}
if (doc != null) {
doc.writeTo("json", aout);
} else {
throw new RuntimeException("There was an error serializing the entry to JSON");
}
}
}
}
| 7,672 |
0 | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONUtil.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.json;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.bidi.BidiHelper;
import org.apache.abdera.ext.history.FeedPagingHelper;
import org.apache.abdera.ext.html.HtmlHelper;
import org.apache.abdera.ext.thread.InReplyTo;
import org.apache.abdera.ext.thread.ThreadHelper;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.i18n.text.Bidi.Direction;
import org.apache.abdera.model.Base;
import org.apache.abdera.model.Categories;
import org.apache.abdera.model.Category;
import org.apache.abdera.model.Collection;
import org.apache.abdera.model.Content;
import org.apache.abdera.model.Control;
import org.apache.abdera.model.Div;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.ExtensibleElement;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Generator;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Person;
import org.apache.abdera.model.Service;
import org.apache.abdera.model.Source;
import org.apache.abdera.model.Text;
import org.apache.abdera.model.TextValue;
import org.apache.abdera.model.Workspace;
import org.apache.abdera.xpath.XPath;
@SuppressWarnings("unchecked")
public class JSONUtil {
public static void toJson(Base base, Writer writer) throws IOException {
JSONStream jstream = new JSONStream(writer);
if (base instanceof Document) {
toJson((Document)base, jstream);
} else if (base instanceof Element) {
toJson((Element)base, jstream);
}
}
private static boolean isSameAsParentBase(Element element) {
IRI parentbase = null;
if (element.getParentElement() != null) {
parentbase =
element instanceof Document ? ((Document)element).getBaseUri() : ((Element)element)
.getResolvedBaseUri();
}
IRI base = element.getResolvedBaseUri();
if (parentbase == null && base != null) {
return false;
}
if (parentbase == null && base == null) {
return true;
}
return parentbase.equals(element.getResolvedBaseUri());
}
private static void toJson(Element element, JSONStream jstream) throws IOException {
if (element instanceof Text) {
Text text = (Text)element;
Text.Type texttype = text.getTextType();
if (texttype.equals(Text.Type.TEXT) && !needToWriteLanguageFields(text)) {
jstream.writeQuoted(text.getValue());
} else {
jstream.startObject();
jstream.writeField("attributes");
jstream.startObject();
jstream.writeField("type", texttype.name().toLowerCase());
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element)) {
jstream.writeField("xml:base", element.getResolvedBaseUri());
}
jstream.endObject();
jstream.writeField("children");
switch (text.getTextType()) {
case TEXT:
jstream.startArray();
jstream.writeQuoted(text.getValue());
jstream.endArray();
break;
case HTML:
if (text.getValue() != null) {
Div div = HtmlHelper.parse(text.getValue());
writeElementValue(div, jstream);
} else {
jstream.writeQuoted("");
}
break;
case XHTML:
if (text.getValueElement() != null) {
writeElementValue(text.getValueElement(), jstream);
} else {
jstream.writeQuoted("");
}
break;
}
jstream.endObject();
}
} else if (element instanceof Content) {
Content content = (Content)element;
Content.Type contenttype = content.getContentType();
if (contenttype.equals(Content.Type.TEXT) && !needToWriteLanguageFields(content)) {
jstream.writeQuoted(content.getValue());
} else {
jstream.startObject();
jstream.writeField("attributes");
jstream.startObject();
switch (content.getContentType()) {
case TEXT:
case HTML:
case XHTML:
jstream.writeField("type", contenttype.name().toLowerCase());
break;
case MEDIA:
case XML:
jstream.writeField("type", content.getMimeType());
}
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element))
jstream.writeField("xml:base", element.getResolvedBaseUri());
writeLanguageFields(content, jstream);
jstream.writeField("src", content.getResolvedSrc());
jstream.endObject();
jstream.writeField("children");
switch (content.getContentType()) {
case TEXT:
jstream.startArray();
jstream.writeQuoted(content.getValue());
jstream.endArray();
break;
case HTML:
Div div = HtmlHelper.parse(content.getValue());
writeElementValue(div, jstream);
break;
case XHTML:
writeElementValue(content.getValueElement(), jstream);
break;
case MEDIA:
case XML:
jstream.startArray();
jstream.writeQuoted(content.getValue());
jstream.endArray();
}
jstream.endObject();
}
} else {
if (element instanceof Categories) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element))
jstream.writeField("xml:base", element.getResolvedBaseUri());
Categories categories = (Categories)element;
jstream.writeField("fixed", categories.isFixed() ? "true" : "false");
jstream.writeField("scheme", categories.getScheme());
writeList("categories", categories.getCategories(), jstream);
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof Category) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element))
jstream.writeField("xml:base", element.getResolvedBaseUri());
Category category = (Category)element;
jstream.writeField("term", category.getTerm());
jstream.writeField("scheme", category.getScheme());
jstream.writeField("label", category.getLabel());
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof Collection) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element))
jstream.writeField("xml:base", element.getResolvedBaseUri());
Collection collection = (Collection)element;
jstream.writeField("href", collection.getResolvedHref());
writeElement("title", collection.getTitleElement(), jstream);
String[] accepts = collection.getAccept();
if (accepts != null && accepts.length > 0) {
jstream.writeField("accept");
jstream.startArray();
for (int n = 0; n < accepts.length; n++) {
jstream.writeQuoted(accepts[n]);
if (n < accepts.length - 1)
jstream.writeSeparator();
}
jstream.endArray();
}
List<Categories> cats = collection.getCategories();
if (cats.size() > 0)
writeList("categories", collection.getCategories(), jstream);
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof Control) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element)) {
jstream.writeField("xml:base", element.getResolvedBaseUri());
}
Control control = (Control)element;
jstream.writeField("draft", control.isDraft() ? "true" : "false");
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof Entry) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element)){
jstream.writeField("xml:base", element.getResolvedBaseUri());
}
Entry entry = (Entry)element;
jstream.writeField("id", entry.getId());
writeElement("title", entry.getTitleElement(), jstream);
writeElement("summary", entry.getSummaryElement(), jstream);
writeElement("rights", entry.getRightsElement(), jstream);
writeElement("content", entry.getContentElement(), jstream);
jstream.writeField("updated", entry.getUpdated());
jstream.writeField("published", entry.getPublished());
jstream.writeField("edited", entry.getEdited());
writeElement("source", entry.getSource(), jstream);
writeList("authors", entry.getAuthors(), jstream);
writeList("contributors", entry.getContributors(), jstream);
writeList("links", entry.getLinks(), jstream);
writeList("categories", entry.getCategories(), jstream);
writeList("inreplyto", ThreadHelper.getInReplyTos(entry), jstream);
writeElement("control", entry.getControl(), jstream);
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof Generator) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element)) {
jstream.writeField("xml:base", element.getResolvedBaseUri());
}
Generator generator = (Generator)element;
jstream.writeField("version", generator.getVersion());
jstream.writeField("uri", generator.getResolvedUri());
jstream.writeField("value", generator.getText());
jstream.endObject();
} else if (element instanceof Link) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element)) {
jstream.writeField("xml:base", element.getResolvedBaseUri());
}
Link link = (Link)element;
jstream.writeField("href", link.getResolvedHref());
jstream.writeField("rel", link.getRel());
jstream.writeField("title", link.getTitle());
jstream.writeField("type", link.getMimeType());
jstream.writeField("hreflang", link.getHrefLang());
if (link.getLength() > -1) {
jstream.writeField("length", link.getLength());
}
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof Person) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element))
jstream.writeField("xml:base", element.getResolvedBaseUri());
Person person = (Person)element;
jstream.writeField("name", person.getName());
if (person.getEmail() != null)
jstream.writeField("email", person.getEmail());
if (person.getUri() != null)
jstream.writeField("uri", person.getUriElement().getResolvedValue());
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof Service) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element))
jstream.writeField("xml:base", element.getResolvedBaseUri());
Service service = (Service)element;
writeList("workspaces", service.getWorkspaces(), jstream);
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof Source) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element))
jstream.writeField("xml:base", element.getResolvedBaseUri());
Source source = (Source)element;
jstream.writeField("id", source.getId());
writeElement("title", source.getTitleElement(), jstream);
writeElement("subtitle", source.getSubtitleElement(), jstream);
writeElement("rights", source.getRightsElement(), jstream);
jstream.writeField("updated", source.getUpdated());
writeElement("generator", source.getGenerator(), jstream);
if (source.getIconElement() != null)
jstream.writeField("icon", source.getIconElement().getResolvedValue());
if (source.getLogoElement() != null)
jstream.writeField("logo", source.getLogoElement().getResolvedValue());
writeList("authors", source.getAuthors(), jstream);
writeList("contributors", source.getContributors(), jstream);
writeList("links", source.getLinks(), jstream);
writeList("categories", source.getCategories(), jstream);
if (FeedPagingHelper.isComplete(source))
jstream.writeField("complete", true);
if (FeedPagingHelper.isArchive(source))
jstream.writeField("archive", true);
if (source instanceof Feed) {
writeList("entries", ((Feed)source).getEntries(), jstream);
}
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof Workspace) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element))
jstream.writeField("xml:base", element.getResolvedBaseUri());
Workspace workspace = (Workspace)element;
writeElement("title", workspace.getTitleElement(), jstream);
writeList("collections", workspace.getCollections(), jstream);
writeExtensions((ExtensibleElement)element, jstream);
jstream.endObject();
} else if (element instanceof InReplyTo) {
jstream.startObject();
writeLanguageFields(element, jstream);
if (!isSameAsParentBase(element))
jstream.writeField("xml:base", element.getResolvedBaseUri());
InReplyTo irt = (InReplyTo)element;
jstream.writeField("ref", irt.getRef());
jstream.writeField("href", irt.getResolvedHref());
jstream.writeField("type", irt.getMimeType());
jstream.writeField("source", irt.getResolvedSource());
jstream.endObject();
} else {
writeElement(element, null, jstream);
}
}
}
private static void writeElementValue(Element element, JSONStream jstream) throws IOException {
writeElementChildren(element, jstream);
}
private static String getName(QName qname) {
String prefix = qname.getPrefix();
String name = qname.getLocalPart();
return (prefix != null && !"".equals(prefix)) ? prefix + ":" + name : name;
}
private static void writeElement(Element child, QName parentqname, JSONStream jstream) throws IOException {
QName childqname = child.getQName();
String prefix = childqname.getPrefix();
jstream.startObject();
jstream.writeField("name", getName(childqname));
jstream.writeField("attributes");
List<QName> attributes = child.getAttributes();
jstream.startObject();
if (!isSameNamespace(childqname, parentqname)) {
if (prefix != null && !"".equals(prefix))
jstream.writeField("xmlns:" + prefix);
else
jstream.writeField("xmlns");
jstream.writeQuoted(childqname.getNamespaceURI());
}
if (!isSameAsParentBase(child))
jstream.writeField("xml:base", child.getResolvedBaseUri());
writeLanguageFields(child, jstream);
for (QName attr : attributes) {
String name = getName(attr);
jstream.writeField(name);
if ("".equals(attr.getPrefix()) || "xml".equals(attr.getPrefix())) {
String val = child.getAttributeValue(attr);
if (val != null && ("href".equalsIgnoreCase(name) || "src".equalsIgnoreCase(name) || "action"
.equalsIgnoreCase(name))) {
IRI base = child.getResolvedBaseUri();
if (base != null)
val = base.resolve(val).toASCIIString();
}
jstream.writeQuoted(val);
} else {
jstream.startObject();
jstream.writeField("attributes");
jstream.startObject();
jstream.writeField("xmlns:" + attr.getPrefix());
jstream.writeQuoted(attr.getNamespaceURI());
jstream.endObject();
jstream.writeField("value");
jstream.writeQuoted(child.getAttributeValue(attr));
jstream.endObject();
}
}
jstream.endObject();
jstream.writeField("children");
writeElementChildren((Element)child, jstream);
jstream.endObject();
}
private static void writeElementChildren(Element element, JSONStream jstream) throws IOException {
jstream.startArray();
Object[] children = getChildren(element);
QName parentqname = element.getQName();
for (int n = 0; n < children.length; n++) {
Object child = children[n];
if (child instanceof Element) {
writeElement((Element)child, parentqname, jstream);
if (n < children.length - 1)
jstream.writeSeparator();
} else if (child instanceof TextValue) {
TextValue textvalue = (TextValue)child;
String value = textvalue.getText();
if (!element.getMustPreserveWhitespace()) {
if (!value.matches("\\s*")) {
jstream.writeQuoted(value.trim());
if (n < children.length - 1)
jstream.writeSeparator();
}
} else {
jstream.writeQuoted(value);
if (n < children.length - 1)
jstream.writeSeparator();
}
}
}
jstream.endArray();
}
private static void writeExtensions(ExtensibleElement element, JSONStream jstream) throws IOException {
writeExtensions(element, jstream, true);
}
private static void writeExtensions(ExtensibleElement element, JSONStream jstream, boolean startsep)
throws IOException {
List<QName> attributes = element.getExtensionAttributes();
writeList("extensions", element.getExtensions(), jstream);
if (attributes.size() > 0) {
jstream.writeField("attributes");
jstream.startObject();
for (int n = 0; n < attributes.size(); n++) {
QName qname = attributes.get(n);
jstream.writeField(getName(qname));
if ("".equals(qname.getPrefix()) || "xml".equals(qname.getPrefix())) {
jstream.writeQuoted(element.getAttributeValue(qname));
} else {
jstream.startObject();
jstream.writeField("attributes");
jstream.startObject();
jstream.writeField("xmlns:" + qname.getPrefix());
jstream.writeQuoted(qname.getNamespaceURI());
jstream.endObject();
jstream.writeField("value");
jstream.writeQuoted(element.getAttributeValue(qname));
jstream.endObject();
}
}
jstream.endObject();
}
}
private static boolean needToWriteLanguageFields(Element element) {
return needToWriteLang(element) || needToWriteDir(element);
}
private static boolean needToWriteLang(Element element) {
String parentlang = null;
if (element.getParentElement() != null) {
Base parent = element.getParentElement();
parentlang =
parent instanceof Document ? ((Document)parent).getLanguage() : ((Element)parent).getLanguage();
}
String lang = element.getLanguage();
return (parentlang == null && lang != null) || (lang != null && parentlang != null && !parentlang
.equalsIgnoreCase(lang));
}
private static boolean needToWriteDir(Element element) {
Direction parentdir = Direction.UNSPECIFIED;
Direction dir = BidiHelper.getDirection(element);
if (element.getParentElement() != null) {
Base parent = element.getParentElement();
if (parent instanceof Element)
parentdir = BidiHelper.getDirection((Element)parent);
}
return dir != Direction.UNSPECIFIED && !dir.equals(parentdir);
}
private static void writeLanguageFields(Element element, JSONStream jstream) throws IOException {
if (needToWriteLang(element)) {
String lang = element.getLanguage();
jstream.writeField("lang", lang);
}
if (needToWriteDir(element)) {
Direction dir = BidiHelper.getDirection(element);
jstream.writeField("dir", dir.name().toLowerCase());
}
}
private static void writeElement(String name, Element element, JSONStream jstream) throws IOException {
if (element != null) {
jstream.writeField(name);
toJson(element, jstream);
}
}
private static boolean writeList(String name, List list, JSONStream jstream) throws IOException {
if (list == null || list.size() == 0)
return false;
jstream.writeField(name);
jstream.startArray();
for (int n = 0; n < list.size(); n++) {
Element el = (Element)list.get(n);
if (!(el instanceof InReplyTo) && !(el instanceof Control)) {
toJson(el, jstream);
if (n < list.size() - 1)
jstream.writeSeparator();
}
}
jstream.endArray();
return true;
}
private static void toJson(Document document, JSONStream jstream) throws IOException {
jstream.startObject();
jstream.writeField("base", document.getBaseUri());
jstream.writeField("content-type", document.getContentType());
jstream.writeField("etag", document.getEntityTag());
jstream.writeField("language", document.getLanguage());
jstream.writeField("slug", document.getSlug());
jstream.writeField("last-modified", document.getLastModified());
Element root = document.getRoot();
if (root != null) {
String rootname = root.getQName().getLocalPart();
writeElement(rootname, document.getRoot(), jstream);
}
jstream.endObject();
}
private static Object[] getChildren(Element element) {
Abdera abdera = element.getFactory().getAbdera();
XPath xpath = abdera.getXPath();
List<Object> nodes = xpath.selectNodes("node()", element);
return nodes.toArray(new Object[nodes.size()]);
}
private static boolean isSameNamespace(QName q1, QName q2) {
if (q1 == null && q2 != null)
return false;
if (q1 != null && q2 == null)
return false;
String p1 = q1 == null ? "" : q1.getPrefix() != null ? q1.getPrefix() : "";
String p2 = q2 == null ? "" : q2.getPrefix() != null ? q2.getPrefix() : "";
String n1 = q1 == null ? "" : q1.getNamespaceURI() != null ? q1.getNamespaceURI() : "";
String n2 = q2 == null ? "" : q2.getNamespaceURI() != null ? q2.getNamespaceURI() : "";
return n1.equals(n2) && p1.equals(p2);
}
}
| 7,673 |
0 | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONStream.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.json;
import java.io.IOException;
import java.io.Writer;
import java.util.Date;
import java.util.Stack;
import javax.activation.MimeType;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.AtomDate;
import org.apache.abdera.util.EntityTag;
public class JSONStream {
private final Writer writer;
private int depth = 0;
private Stack<Boolean> sepstack = new Stack<Boolean>();
private void pushStack() {
sepstack.push(true);
}
private boolean isStart() {
boolean b = sepstack.peek();
if (b) {
sepstack.set(sepstack.size() - 1, false);
}
return b;
}
private void popStack() {
sepstack.pop();
}
public JSONStream(Writer writer) {
this.writer = writer;
}
private void inc() {
depth++;
}
private void dec() {
depth--;
}
private void writeIndent() throws IOException {
for (int n = 0; n < depth; n++) {
writer.write(' ');
}
}
private void writeNewLine() throws IOException {
writer.write('\n');
}
public void startObject() throws IOException {
writer.write('{');
inc();
pushStack();
}
public void endObject() throws IOException {
popStack();
dec();
writeNewLine();
writeIndent();
writer.write('}');
}
public void startArray() throws IOException {
writer.write('[');
inc();
}
public void endArray() throws IOException {
dec();
writeNewLine();
writeIndent();
writer.write(']');
}
public void writeSeparator() throws IOException {
writer.write(',');
}
private void writeColon() throws IOException {
writer.write(':');
}
public void writeQuoted(String value) throws IOException {
if (value != null) {
writer.write('"');
writer.write(escape(value));
writer.write('"');
}
}
public void writeField(String name) throws IOException {
if (!isStart()) {
writeSeparator();
}
writeNewLine();
writeIndent();
writeQuoted(name);
writeColon();
}
public void writeField(String name, Date value) throws IOException {
if (value != null) {
writeField(name, AtomDate.format(value));
}
}
public void writeField(String name, IRI value) throws IOException {
if (value != null) {
writeField(name, value.toASCIIString());
}
}
public void writeField(String name, MimeType value) throws IOException {
if (value != null) {
writeField(name, value.toString());
}
}
public void writeField(String name, EntityTag value) throws IOException {
if (value != null) {
writeField(name, value.toString());
}
}
public void writeField(String name, String value) throws IOException {
if (value != null) {
writeField(name);
writeQuoted(value);
}
}
public void writeField(String name, Number value) throws IOException {
if (value != null) {
writeField(name);
writer.write(value.toString());
}
}
public void writeField(String name, Boolean value) throws IOException {
if (value != null) {
writeField(name);
writer.write(value.toString());
}
}
private static String escape(String value) {
if (value == null)
return null;
StringBuffer buf = new StringBuffer();
char[] chars = value.toCharArray();
char b = 0;
String t = null;
for (char c : chars) {
switch (c) {
case '\\':
case '"':
buf.append('\\');
buf.append(c);
break;
case '/':
if (b == '<')
buf.append('\\');
buf.append(c);
break;
case '\b':
buf.append("\\b");
break;
case '\t':
buf.append("\\t");
break;
case '\n':
buf.append("\\n");
break;
case '\f':
buf.append("\\f");
break;
case '\r':
buf.append("\\r");
break;
default:
if (c < ' ' || c > 127) {
t = "000" + Integer.toHexString(c);
buf.append("\\u" + t.substring(t.length() - 4));
} else {
buf.append(c);
}
}
b = c;
}
return buf.toString();
}
}
| 7,674 |
0 | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONWriter.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.json;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import org.apache.abdera.model.Base;
import org.apache.abdera.util.AbstractNamedWriter;
import org.apache.abdera.util.AbstractWriterOptions;
import org.apache.abdera.writer.NamedWriter;
import org.apache.abdera.writer.WriterOptions;
public class JSONWriter extends AbstractNamedWriter implements NamedWriter {
public static final String NAME = "json";
public static final String[] FORMATS =
{"application/json", "application/javascript", "application/ecmascript", "text/javascript", "text/ecmascript"};
public JSONWriter() {
super(NAME, FORMATS);
}
@Override
protected WriterOptions initDefaultWriterOptions() {
return new AbstractWriterOptions() {
};
}
public String getName() {
return NAME;
}
public Object write(Base base, WriterOptions options) throws IOException {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writeTo(base, out, options);
return new String(out.toByteArray(), options.getCharset());
} catch (IOException i) {
throw i;
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
public void writeTo(Base base, OutputStream out, WriterOptions options) throws IOException {
writeTo(base, new OutputStreamWriter(out, options.getCharset()), options);
}
public void writeTo(Base base, java.io.Writer out, WriterOptions options) throws IOException {
try {
JSONUtil.toJson(base, out);
out.flush();
if (options.getAutoClose())
out.close();
} catch (Exception e) {
e.printStackTrace();
throw new IOException(e.getMessage());
}
}
}
| 7,675 |
0 | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/json/src/main/java/org/apache/abdera/ext/json/JSONServlet.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.json;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.abdera.Abdera;
import org.apache.abdera.model.Document;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.client.RequestOptions;
/**
* Servlet that will do an HTTP GET to retrieve an Atom document then convert that into a JSON doc. The URL pattern is
* simple: http://.../servlet/path/{url}
*/
@SuppressWarnings("unchecked")
public class JSONServlet extends HttpServlet {
private static final long serialVersionUID = 1414392196430276024L;
private Abdera getAbdera() {
ServletContext sc = getServletContext();
Abdera abdera = null;
synchronized (sc) {
abdera = (Abdera)sc.getAttribute(Abdera.class.getName());
if (abdera == null) {
abdera = new Abdera();
sc.setAttribute(Abdera.class.getName(), abdera);
}
}
return abdera;
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String url = request.getPathInfo();
if (url != null && url.length() > 1)
url = URLDecoder.decode(url, "UTF-8");
else {
response.sendError(400);
return;
}
url = url.substring(1);
Abdera abdera = getAbdera();
AbderaClient client = new AbderaClient(abdera);
RequestOptions options = client.getDefaultRequestOptions();
if (request.getHeader("If-Match") != null)
options.setIfMatch(request.getHeader("If-Match"));
if (request.getHeader("If-None-Match") != null)
options.setIfNoneMatch(request.getHeader("If-None-Match"));
if (request.getHeader("If-Modified-Since") != null)
options.setIfNoneMatch(request.getHeader("If-Modified-Since"));
if (request.getHeader("If-Unmodified-Since") != null)
options.setIfNoneMatch(request.getHeader("If-Unmodified-Since"));
ClientResponse resp = client.get(url);
switch (resp.getType()) {
case SUCCESS:
try {
Document doc = resp.getDocument();
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
if (doc.getEntityTag() != null)
response.setHeader("ETag", doc.getEntityTag().toString());
if (doc.getLanguage() != null)
response.setHeader("Content-Language", doc.getLanguage());
if (doc.getLastModified() != null)
response.setDateHeader("Last-Modified", doc.getLastModified().getTime());
OutputStream out = response.getOutputStream();
doc.writeTo("json", out);
} catch (Exception e) {
response.sendError(500);
return;
}
case CLIENT_ERROR:
case SERVER_ERROR:
response.sendError(resp.getStatus(), resp.getStatusText());
return;
}
}
}
| 7,676 |
0 | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext/license/LicenseTest.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.license;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.license.LicenseHelper;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.junit.Test;
public class LicenseTest {
@Test
public void testLicense() throws Exception {
String license = "http://example.org";
Abdera abdera = new Abdera();
Feed feed = abdera.newFeed();
Entry entry = feed.addEntry();
LicenseHelper.addLicense(feed, license);
assertTrue(LicenseHelper.hasLicense(feed, license));
assertFalse(LicenseHelper.hasLicense(entry, license, false));
assertTrue(LicenseHelper.hasLicense(entry, license, true));
assertNotNull(LicenseHelper.addUnspecifiedLicense(entry));
assertFalse(LicenseHelper.hasLicense(entry, license, true));
entry = abdera.newEntry();
entry.setSource(feed.getAsSource());
assertFalse(LicenseHelper.hasLicense(entry, license, false));
assertTrue(LicenseHelper.hasLicense(entry, license, true));
boolean died = false;
entry = abdera.newEntry();
LicenseHelper.addLicense(entry, license);
try {
// will die because the license already exists
LicenseHelper.addLicense(entry, license);
} catch (IllegalStateException e) {
died = true;
}
assertTrue(died);
died = false;
try {
// will die because another license already exists
LicenseHelper.addUnspecifiedLicense(entry);
} catch (IllegalStateException e) {
died = true;
}
assertTrue(died);
died = false;
entry = abdera.newEntry();
LicenseHelper.addUnspecifiedLicense(entry);
try {
// will die because the unspecified license already exists
LicenseHelper.addLicense(entry, license);
} catch (IllegalStateException e) {
died = true;
}
assertTrue(died);
died = false;
entry = abdera.newEntry();
LicenseHelper.addUnspecifiedLicense(entry);
try {
// will die because the unspecified license already exists
LicenseHelper.addUnspecifiedLicense(entry);
} catch (IllegalStateException e) {
died = true;
}
assertTrue(died);
}
}
| 7,677 |
0 | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext/bidi/BidiTest.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.bidi;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.bidi.BidiHelper;
import org.apache.abdera.i18n.text.Bidi.Direction;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.junit.Test;
public class BidiTest {
@Test
public void testBidi() throws Exception {
Abdera abdera = new Abdera();
Feed feed = abdera.getFactory().newFeed();
feed.setTitle("Testing");
feed.setSubtitle("Testing");
BidiHelper.setDirection(Direction.RTL, feed);
BidiHelper.setDirection(Direction.LTR, feed.getSubtitleElement());
assertNotNull(feed.getAttributeValue("dir"));
assertEquals(Direction.RTL, BidiHelper.getDirection(feed));
assertEquals(Direction.RTL, BidiHelper.getDirection(feed.getTitleElement()));
assertEquals(Direction.LTR, BidiHelper.getDirection(feed.getSubtitleElement()));
assertEquals(BidiHelper.getBidiText(Direction.RTL, "Testing"), BidiHelper.getBidiElementText(feed
.getTitleElement()));
assertEquals(BidiHelper.getBidiText(Direction.LTR, "Testing"), BidiHelper.getBidiElementText(feed
.getSubtitleElement()));
Entry entry = abdera.newEntry();
entry.setLanguage("az-arab");
assertEquals(Direction.RTL, BidiHelper.guessDirectionFromLanguage(entry));
entry.setLanguage("az-latn");
assertEquals(Direction.UNSPECIFIED, BidiHelper.guessDirectionFromLanguage(entry));
assertEquals(Direction.UNSPECIFIED, BidiHelper.guessDirectionFromEncoding(entry));
entry.getDocument().setCharset("iso-8859-6");
assertEquals(Direction.RTL, BidiHelper.guessDirectionFromEncoding(entry));
}
}
| 7,678 |
0 | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext/history/FeedPagingTest.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.history;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.xml.namespace.QName;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.history.FeedPagingHelper;
import org.apache.abdera.model.Feed;
import org.junit.Test;
public class FeedPagingTest {
@Test
public void testHistory() throws Exception {
Abdera abdera = new Abdera();
Feed feed = abdera.newFeed();
FeedPagingHelper.setComplete(feed, true);
FeedPagingHelper.setArchive(feed, true);
FeedPagingHelper.setNext(feed, "http://example.org/foo");
FeedPagingHelper.setNext(feed, "http://example.org/bar");
FeedPagingHelper.setPrevious(feed, "http://example.org/foo");
FeedPagingHelper.setPrevious(feed, "http://example.org/bar");
FeedPagingHelper.setLast(feed, "http://example.org/foo");
FeedPagingHelper.setLast(feed, "http://example.org/bar");
FeedPagingHelper.setFirst(feed, "http://example.org/foo");
FeedPagingHelper.setFirst(feed, "http://example.org/bar");
FeedPagingHelper.setPreviousArchive(feed, "http://example.org/foo");
FeedPagingHelper.setPreviousArchive(feed, "http://example.org/bar");
FeedPagingHelper.setNextArchive(feed, "http://example.org/foo");
FeedPagingHelper.setNextArchive(feed, "http://example.org/bar");
FeedPagingHelper.setCurrent(feed, "http://example.org/foo");
FeedPagingHelper.setCurrent(feed, "http://example.org/bar");
assertTrue(FeedPagingHelper.isPaged(feed));
assertTrue(FeedPagingHelper.isComplete(feed));
assertTrue(FeedPagingHelper.isArchive(feed));
assertNotNull(FeedPagingHelper.getNext(feed));
assertNotNull(FeedPagingHelper.getPrevious(feed));
assertNotNull(FeedPagingHelper.getLast(feed));
assertNotNull(FeedPagingHelper.getFirst(feed));
assertNotNull(FeedPagingHelper.getNextArchive(feed));
assertNotNull(FeedPagingHelper.getPreviousArchive(feed));
assertNotNull(FeedPagingHelper.getCurrent(feed));
assertEquals("http://example.org/bar", FeedPagingHelper.getNext(feed).toString());
}
@Test
public void testHistory2() throws Exception {
Abdera abdera = new Abdera();
Feed feed = abdera.newFeed();
QName complete = new QName(FeedPagingHelper.FHNS, "complete", "x");
feed.addExtension(complete);
assertTrue(FeedPagingHelper.isComplete(feed));
}
}
| 7,679 |
0 | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext/main/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.main;
import org.apache.abdera.test.ext.bidi.BidiTest;
import org.apache.abdera.test.ext.history.FeedPagingTest;
import org.apache.abdera.test.ext.license.LicenseTest;
import org.apache.abdera.test.ext.thread.ThreadTest;
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(BidiTest.class, FeedPagingTest.class, LicenseTest.class, ThreadTest.class);
}
}
| 7,680 |
0 | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/main/src/test/java/org/apache/abdera/test/ext/thread/ThreadTest.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.thread;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.thread.InReplyTo;
import org.apache.abdera.ext.thread.ThreadConstants;
import org.apache.abdera.ext.thread.ThreadHelper;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Entry;
import org.junit.Test;
public class ThreadTest {
@Test
public void testThread() throws Exception {
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
Entry e1 = factory.newEntry();
Entry e2 = factory.newEntry();
e1.setId("tag:example.org,2006:first");
e2.setId("tag:example.org,2006:second");
ThreadHelper.addInReplyTo(e2, e1); // e2 is a response to e1
assertNotNull(e2.getExtension(ThreadConstants.IN_REPLY_TO));
InReplyTo irt = e2.getExtension(ThreadConstants.IN_REPLY_TO);
assertEquals(e1.getId(), irt.getRef());
}
}
| 7,681 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/license/LicenseHelper.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.license;
import java.util.List;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Base;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Source;
/**
* Implementation of the Atom License Extension, RFC 4946
*/
public final class LicenseHelper {
public static final String UNSPECIFIED_LICENSE = "http://purl.org/atompub/license#unspecified";
LicenseHelper() {
}
public static List<Link> getLicense(Base base, boolean inherited) {
List<Link> links = null;
if (base instanceof Source) {
links = ((Source)base).getLinks(Link.REL_LICENSE);
} else if (base instanceof Entry) {
Entry entry = (Entry)base;
Source source = entry.getSource();
Base parent = entry.getParentElement();
links = entry.getLinks(Link.REL_LICENSE);
if (inherited && (links == null || links.size() == 0) && source != null) {
links = getLicense(source, false);
}
if (inherited && (links == null || links.size() == 0) && parent != null) {
links = getLicense(parent, false);
}
}
return links;
}
public static List<Link> getLicense(Base base) {
return getLicense(base, true);
}
public static boolean hasUnspecifiedLicense(Base base, boolean inherited) {
return hasLicense(base, UNSPECIFIED_LICENSE, inherited);
}
public static boolean hasUnspecifiedLicense(Base base) {
return hasUnspecifiedLicense(base, true);
}
public static boolean hasLicense(Base base, String iri, boolean inherited) {
List<Link> links = getLicense(base, inherited);
IRI check = new IRI(iri);
boolean answer = false;
if (links != null) {
for (Link link : links) {
if (link.getResolvedHref().equals(check)) {
answer = true;
break;
}
}
}
return answer;
}
public static boolean hasLicense(Base base, String iri) {
return hasLicense(base, iri, true);
}
public static boolean hasLicense(Base base, boolean inherited) {
List<Link> links = getLicense(base, inherited);
return (links != null && links.size() > 0);
}
public static boolean hasLicense(Base base) {
return hasLicense(base, true);
}
public static Link addUnspecifiedLicense(Base base) {
if (hasUnspecifiedLicense(base, false))
throw new IllegalStateException("Unspecified license already added");
if (hasLicense(base, false))
throw new IllegalStateException("Other licenses are already added.");
return addLicense(base, UNSPECIFIED_LICENSE);
}
public static Link addLicense(Base base, String iri) {
return addLicense(base, iri, null, null, null);
}
public static Link addLicense(Base base, String iri, String title) {
return addLicense(base, iri, null, title, null);
}
public static Link addLicense(Base base, String iri, String type, String title, String hreflang) {
if (hasLicense(base, iri, false))
throw new IllegalStateException("License '" + iri + "' has already been added");
if (hasUnspecifiedLicense(base, false))
throw new IllegalStateException("Unspecified license already added");
if (base instanceof Source) {
return ((Source)base).addLink((new IRI(iri)).toString(), Link.REL_LICENSE, type, title, hreflang, -1);
} else if (base instanceof Entry) {
return ((Entry)base).addLink((new IRI(iri)).toString(), Link.REL_LICENSE, type, title, hreflang, -1);
}
return null;
}
}
| 7,682 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/bidi/BidiHelper.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.bidi;
import java.util.Locale;
import javax.xml.namespace.QName;
import org.apache.abdera.i18n.rfc4646.Lang;
import org.apache.abdera.i18n.text.Bidi;
import org.apache.abdera.i18n.text.CharUtils;
import org.apache.abdera.i18n.text.Bidi.Direction;
import org.apache.abdera.model.Base;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;
/**
* <p>
* This is (hopefully) temporary. Ideally, this would be wrapped into the core model API so that the bidi stuff is
* handled seamlessly. There are still details being worked out on the Atom WG list and it's likely that at least one
* other impl (mozilla) will do something slightly different.
* </p>
* <p>
* Based on http://www.ietf.org/internet-drafts/draft-snell-atompub-bidi-04.txt
* </p>
* <p>
* Example:
* </p>
*
* <pre>
* <feed xmlns="http://www.w3.org/2005/Atom" dir="rtl">
* ...
* </feed>
* </pre>
* <p>
* The getBidi___ elements use the in-scope direction to wrap the text with the appropriate Unicode control characters.
* e.g. if dir="rtl", the text is wrapped with the RLE and PDF controls. If the text already contains the control chars,
* the dir attribute is ignored.
* </p>
*
* <pre>
* org.apache.abdera.Abdera abdera = new org.apache.abdera.Abdera();
* org.apache.abdera.model.Feed feed = abdera.getFactory().newFeed();
* feed.setAttributeValue("dir", "rtl");
* feed.setTitle("Testing");
* feed.addCategory("foo");
*
* System.out.println(BidiHelper.getBidiElementText(feed.getTitleElement()));
* System.out.println(BidiHelper.getBidiAttributeValue(feed.getCategories().get(0), "term"));
* </pre>
*/
public final class BidiHelper {
public static final QName DIR = new QName("dir");
BidiHelper() {
}
/**
* Set the value of dir attribute
*/
public static <T extends Element> void setDirection(Direction direction, T element) {
if (direction != Direction.UNSPECIFIED)
element.setAttributeValue(DIR, direction.toString().toLowerCase());
else if (direction == Direction.UNSPECIFIED)
element.setAttributeValue(DIR, "");
else if (direction == null)
element.removeAttribute(DIR);
}
/**
* Get the in-scope direction for an element.
*/
public static <T extends Element> Direction getDirection(T element) {
Direction direction = Direction.UNSPECIFIED;
String dir = element.getAttributeValue("dir");
if (dir != null && dir.length() > 0)
direction = Direction.valueOf(dir.toUpperCase());
else if (dir == null) {
// if the direction is unspecified on this element,
// let's see if we've inherited it
Base parent = element.getParentElement();
if (parent != null && parent instanceof Element)
direction = getDirection((Element)parent);
}
return direction;
}
/**
* Return the specified text with appropriate Unicode Control Characters given the specified Direction.
*
* @param direction The Directionality of the text
* @param text The text to wrap within Unicode Control Characters
* @return The directionally-wrapped text
*/
public static String getBidiText(Direction direction, String text) {
switch (direction) {
case LTR:
return CharUtils.wrapBidi(text, CharUtils.LRE);
case RTL:
return CharUtils.wrapBidi(text, CharUtils.RLE);
default:
return text;
}
}
/**
* Return the textual content of a child element using the in-scope directionality
*
* @param element The parent element
* @param child The XML QName of the child element
* @return The directionally-wrapped text of the child element
*/
public static <T extends Element> String getBidiChildText(T element, QName child) {
Element el = element.getFirstChild(child);
return (el != null) ? getBidiText(getDirection(el), el.getText()) : null;
}
/**
* Return the textual content of the specified element
*
* @param element An element containing directionally-sensitive text
* @return The directionally-wrapped text of the element
*/
public static <T extends Element> String getBidiElementText(T element) {
return getBidiText(getDirection(element), element.getText());
}
/**
* Return the text content of the specified attribute using the in-scope directionality
*
* @param element The parent element
* @param name the name of the attribute
* @return The directionally-wrapped text of the attribute
*/
public static <T extends Element> String getBidiAttributeValue(T element, String name) {
return getBidiText(getDirection(element), element.getAttributeValue(name));
}
/**
* Return the text content of the specified attribute using the in-scope directionality
*
* @param element The parent element
* @param name the name of the attribute
* @return The directionally-wrapped text of the attribute
*/
public static <T extends Element> String getBidiAttributeValue(T element, QName name) {
return getBidiText(getDirection(element), element.getAttributeValue(name));
}
/**
* Attempt to guess the base direction using the in-scope language. Implements the method used by Internet Explorer
* 7's feed view documented here:
* http://blogs.msdn.com/rssteam/archive/2007/05/17/reading-feeds-in-right-to-left-order.aspx. This algorithm
* differs slightly from the method documented in that the primary language tag is case insensitive. If the language
* tag is not specified, then the default Locale is used to determine the direction. If the dir attribute is
* specified, the direction will be determine using it's value instead of the language
*/
public static <T extends Element> Direction guessDirectionFromLanguage(T element) {
return guessDirectionFromLanguage(element, false);
}
/**
* Attempt to guess the base direction using the in-scope language. Implements the method used by Internet Explorer
* 7's feed view documented here:
* http://blogs.msdn.com/rssteam/archive/2007/05/17/reading-feeds-in-right-to-left-order.aspx. This algorithm
* differs slightly from the method documented in that the primary language tag is case insensitive. If the language
* tag is not specified, then the default Locale is used to determine the direction. According to the Atom Bidi
* spec, if the dir attribute is set explicitly, we should not do language guessing. This restriction can be
* bypassed by setting ignoredir to true.
*/
public static <T extends Element> Direction guessDirectionFromLanguage(T element, boolean ignoredir) {
if (!ignoredir && hasDirection(element))
return getDirection(element);
String language = element.getLanguage();
Lang lang = language != null ? new Lang(language) : new Lang(Locale.getDefault());
return Bidi.guessDirectionFromLanguage(lang);
}
/**
* Attempt to guess the base direction using the charset encoding. This is a bit of a last resort approach
*/
public static <T extends Element> Direction guessDirectionFromEncoding(T element) {
return guessDirectionFromEncoding(element, false);
}
/**
* Attempt to guess the base direction using the charset encoding. This is a bit of a last resort approach
*/
@SuppressWarnings("unchecked")
public static <T extends Element> Direction guessDirectionFromEncoding(T element, boolean ignoredir) {
if (!ignoredir && hasDirection(element))
return getDirection(element);
Document doc = element.getDocument();
if (doc == null)
return Direction.UNSPECIFIED;
return Bidi.guessDirectionFromEncoding(doc.getCharset());
}
/**
* Attempt to guess the base direction of an element using an analysis of the directional properties of the
* characters used. This is a brute-force style approach that can achieve fairly reasonable results when the element
* text consists primarily of characters with the same bidi properties. This approach is implemented by the Snarfer
* feed reader as is documented at http://www.xn--8ws00zhy3a.com/blog/2006/12/right-to-left-rss If the dir attribute
* is specified, the direction will be determine using it's value instead of the characteristics of the text
*/
public static <T extends Element> Direction guessDirectionFromTextProperties(T element) {
return guessDirectionFromTextProperties(element, false);
}
/**
* Attempt to guess the base direction of an element using an analysis of the directional properties of the
* characters used. This is a brute-force style approach that can achieve fairly reasonable results when the element
* text consists primarily of characters with the same bidi properties. This approach is implemented by the Snarfer
* feed reader as is documented at http://www.xn--8ws00zhy3a.com/blog/2006/12/right-to-left-rss According to the
* Atom Bidi spec, if the dir attribute is set explicitly, we should not do language guessing. This restriction can
* be bypassed by setting ignoredir to true.
*/
public static <T extends Element> Direction guessDirectionFromTextProperties(T element, boolean ignoredir) {
if (!ignoredir && hasDirection(element))
return getDirection(element);
return Bidi.guessDirectionFromTextProperties(element.getText());
}
/**
* Use Java's built in support for bidi text to determine the base directionality of the element's text. The
* response to this only indicates the *base* directionality, it does not indicate whether or not there are any RTL
* characters in the text. If the dir attribute is specified, the direction will be determine using it's value
* instead of the characteristics of the text
*/
public static <T extends Element> Direction guessDirectionFromJavaBidi(T element) {
return guessDirectionFromJavaBidi(element, false);
}
/**
* Use Java's built in support for bidi text to determine the base directionality of the element's text. The
* response to this only indicates the *base* directionality, it does not indicate whether or not there are any RTL
* characters in the text. According to the Atom Bidi spec, if the dir attribute is set explicitly, we should not do
* language guessing. This restriction can be bypassed by setting ignoredir to true.
*/
public static <T extends Element> Direction guessDirectionFromJavaBidi(T element, boolean ignoredir) {
if (!ignoredir && hasDirection(element))
return getDirection(element);
return Bidi.guessDirectionFromJavaBidi(element.getText());
}
private static <T extends Element> boolean hasDirection(T element) {
String dir = element.getAttributeValue("dir");
if (dir != null && dir.length() > 0)
return true;
else if (dir == null) {
// if the direction is unspecified on this element,
// let's see if we've inherited it
Base parent = element.getParentElement();
if (parent != null && parent instanceof Element)
return hasDirection((Element)parent);
}
return false;
}
}
| 7,683 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesHelper.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.tombstones;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.abdera.model.AtomDate;
import org.apache.abdera.model.Base;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
/**
* Note this is an experimental implementation of the Tombstones specification. The tombstone spec is a work-in-progress
* and will continue to evolve. This extension should only be used for experimentation or prototype development.
* http://www.ietf.org/internet-drafts/draft-snell-atompub-tombstones-04.txt
*/
public class TombstonesHelper {
public static final String TNS = "http://purl.org/atompub/tombstones/1.0";
public static final QName DELETED_ENTRY = new QName(TNS, "deleted-entry");
public static final QName BY = new QName(TNS, "by");
public static final QName COMMENT = new QName(TNS, "comment");
public static List<Tombstone> getTombstones(Feed source) {
return source.getExtensions(DELETED_ENTRY);
}
public static void addTombstone(Feed source, Tombstone tombstone) {
source.addExtension(tombstone);
}
public static Tombstone addTombstone(Feed source, Entry entry) {
Tombstone tombstone = source.getFactory().newExtensionElement(DELETED_ENTRY, source);
tombstone.setRef(entry.getId());
Base parent = entry.getParentElement();
if (parent != null && parent.equals(source))
entry.discard();
return tombstone;
}
public static Tombstone addTombstone(Feed source, Entry entry, Date when, String by, String comment) {
Tombstone ts = addTombstone(source, entry);
ts.setWhen(when);
ts.setBy(by);
ts.setComment(comment);
return ts;
}
public static Tombstone addTombstone(Feed source, Entry entry, String when, String by, String comment) {
Tombstone ts = addTombstone(source, entry);
ts.setWhen(when);
return ts;
}
public static Tombstone addTombstone(Feed source, Entry entry, Calendar when, String by, String comment) {
Tombstone ts = addTombstone(source, entry);
ts.setWhen(when);
ts.setBy(by);
ts.setComment(comment);
return ts;
}
public static Tombstone addTombstone(Feed source, Entry entry, long when, String by, String comment) {
Tombstone ts = addTombstone(source, entry);
ts.setWhen(when);
ts.setBy(by);
ts.setComment(comment);
return ts;
}
public static Tombstone addTombstone(Feed source, Entry entry, AtomDate when, String by, String comment) {
Tombstone ts = addTombstone(source, entry);
ts.setWhen(when);
ts.setBy(by);
ts.setComment(comment);
return ts;
}
public static boolean hasTombstones(Feed source) {
return source.getExtension(DELETED_ENTRY) != null;
}
public static Tombstone addTombstone(Feed source, String id) {
Tombstone tombstone = source.getFactory().newExtensionElement(DELETED_ENTRY);
tombstone.setRef(id);
return tombstone;
}
public static Tombstone addTombstone(Feed source, String id, Date when, String by, String comment) {
Tombstone ts = addTombstone(source, id);
ts.setWhen(when);
ts.setBy(by);
ts.setComment(comment);
return ts;
}
public static Tombstone addTombstone(Feed source, String id, String when, String by, String comment) {
Tombstone ts = addTombstone(source, id);
ts.setWhen(when);
return ts;
}
public static Tombstone addTombstone(Feed source, String id, Calendar when, String by, String comment) {
Tombstone ts = addTombstone(source, id);
ts.setWhen(when);
ts.setBy(by);
ts.setComment(comment);
return ts;
}
public static Tombstone addTombstone(Feed source, String id, long when, String by, String comment) {
Tombstone ts = addTombstone(source, id);
ts.setWhen(when);
ts.setBy(by);
ts.setComment(comment);
return ts;
}
public static Tombstone addTombstone(Feed source, String id, AtomDate when, String by, String comment) {
Tombstone ts = addTombstone(source, id);
ts.setWhen(when);
ts.setBy(by);
ts.setComment(comment);
return ts;
}
}
| 7,684 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/Tombstone.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.tombstones;
import java.util.Calendar;
import java.util.Date;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.AtomDate;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ExtensibleElementWrapper;
import org.apache.abdera.model.Person;
import org.apache.abdera.model.Text;
public class Tombstone extends ExtensibleElementWrapper {
public Tombstone(Element internal) {
super(internal);
}
public Tombstone(Factory factory) {
super(factory, TombstonesHelper.DELETED_ENTRY);
}
public String getRef() {
return getAttributeValue("ref");
}
public Tombstone setRef(String id) {
if (id != null) {
setAttributeValue("ref", id);
} else {
removeAttribute("ref");
}
return this;
}
public Tombstone setRef(IRI id) {
return setRef(id.toString());
}
public Date getWhen() {
String v = getAttributeValue("when");
return v != null ? AtomDate.parse(v) : null;
}
public Tombstone setWhen(Date date) {
return setWhen(AtomDate.format(date));
}
public Tombstone setWhen(String date) {
if (date != null) {
setAttributeValue("when", date);
} else {
removeAttribute("when");
}
return this;
}
public Tombstone setWhen(long date) {
return setWhen(AtomDate.valueOf(date));
}
public Tombstone setWhen(Calendar date) {
return setWhen(AtomDate.valueOf(date));
}
public Tombstone setWhen(AtomDate date) {
return setWhen(date.toString());
}
public Person getBy() {
return getExtension(TombstonesHelper.BY);
}
public Tombstone setBy(Person person) {
if (getBy() != null)
getBy().discard();
addExtension(person);
return this;
}
public Person setBy(String name) {
return setBy(name, null, null);
}
public Person setBy(String name, String email, String uri) {
if (name != null) {
Person person = getFactory().newPerson(TombstonesHelper.BY, this);
person.setName(name);
person.setEmail(email);
person.setUri(uri);
return person;
} else {
if (getBy() != null)
getBy().discard();
return null;
}
}
public Text getComment() {
return getExtension(TombstonesHelper.COMMENT);
}
public Text setComment(String comment) {
return setComment(Text.Type.TEXT, comment);
}
public Text setComment(Text.Type type, String comment) {
if (comment != null) {
Text text = getFactory().newText(TombstonesHelper.COMMENT, type, this);
text.setValue(comment);
return text;
} else {
if (getComment() != null)
getComment().discard();
return null;
}
}
}
| 7,685 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesExtensionFactory.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.tombstones;
import org.apache.abdera.util.AbstractExtensionFactory;
public final class TombstonesExtensionFactory extends AbstractExtensionFactory {
public TombstonesExtensionFactory() {
super(TombstonesHelper.TNS);
addImpl(TombstonesHelper.DELETED_ENTRY, Tombstone.class);
}
}
| 7,686 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/history/FeedPagingHelper.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.history;
import javax.xml.namespace.QName;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Source;
/**
* Initial support for Mark Nottingham's Feed Paging and Archiving draft
* (http://ietfreport.isoc.org/all-ids/draft-nottingham-atompub-feed-history-11.txt)
*/
public final class FeedPagingHelper {
public static final String FH_PREFIX = "fh";
public static final String FHNS = "http://purl.org/syndication/history/1.0";
public static final QName COMPLETE = new QName(FHNS, "complete", FH_PREFIX);
public static final QName ARCHIVE = new QName(FHNS, "archive", FH_PREFIX);
FeedPagingHelper() {
}
/**
* Returns true if the feed is "complete". According to the Feed Paging and Archiving specification, in a complete
* feed, "any entry not actually in the feed document SHOULD NOT be considered to be part of that feed."
*
* @param feed The feed to check
*/
public static boolean isComplete(Source feed) {
return (feed.getExtension(COMPLETE) != null);
}
/**
* Flag the feed as being complete. According to the Feed Paging and Archiving specification, in a complete feed,
* "any entry not actually in the feed document SHOULD NOT be considered to be part of that feed."
*
* @param feed The Feed to mark as complete
* @param complete True if the feed is complete
*/
public static void setComplete(Source feed, boolean complete) {
if (complete) {
if (!isComplete(feed))
feed.addExtension(COMPLETE);
} else {
if (isComplete(feed)) {
Element ext = feed.getExtension(COMPLETE);
ext.discard();
}
}
}
/**
* Flag the feed as being an archive.
*
* @param feed The Feed to mark as an archive
* @param archive True if the feed is an archive
*/
public static void setArchive(Source feed, boolean archive) {
if (archive) {
if (!isArchive(feed))
feed.addExtension(ARCHIVE);
} else {
if (isArchive(feed)) {
Element ext = feed.getExtension(ARCHIVE);
ext.discard();
}
}
}
/**
* Return true if the feed has been marked as an archive
*
* @param feed The feed to check
*/
public static boolean isArchive(Source feed) {
return feed.getExtension(ARCHIVE) != null;
}
/**
* Return true if the feed contains any next, previous, first or last paging link relations
*
* @param feed The feed to check
*/
public static boolean isPaged(Source feed) {
return feed.getLink("next") != null || feed.getLink("previous") != null
|| feed.getLink("first") != null
|| feed.getLink("last") != null;
}
/**
* Adds a next link relation to the feed
*
* @param feed The feed
* @param iri The IRI of the next feed document
* @return The newly created Link
*/
public static Link setNext(Source feed, String iri) {
Link link = feed.getLink("next");
if (link != null) {
link.setHref(iri);
} else {
link = feed.addLink(iri, "next");
}
return link;
}
/**
* Adds a previous link relation to the feed
*
* @param feed The feed
* @param iri The IRI of the previous feed document
* @return The newly created Link
*/
public static Link setPrevious(Source feed, String iri) {
Link link = feed.getLink("previous");
if (link != null) {
link.setHref(iri);
} else {
link = feed.addLink(iri, "previous");
}
return link;
}
/**
* Adds a first link relation to the feed
*
* @param feed The feed
* @param iri The IRI of the first feed document
* @return The newly created Link
*/
public static Link setFirst(Source feed, String iri) {
Link link = feed.getLink("first");
if (link != null) {
link.setHref(iri);
} else {
link = feed.addLink(iri, "first");
}
return link;
}
/**
* Adds a last link relation to the feed
*
* @param feed The feed
* @param iri The IRI of the last feed document
* @return The newly created Link
*/
public static Link setLast(Source feed, String iri) {
Link link = feed.getLink("last");
if (link != null) {
link.setHref(iri);
} else {
link = feed.addLink(iri, "last");
}
return link;
}
/**
* Adds a next-archive link relation to the feed
*
* @param feed The feed
* @param iri The IRI of the next archive feed document
* @return The newly created Link
*/
public static Link setNextArchive(Source feed, String iri) {
Link link = feed.getLink("next-archive");
if (link == null) { // try the full IANA URI version
link = feed.getLink(Link.IANA_BASE + "next-archive");
}
if (link != null) {
link.setHref(iri);
} else {
link = feed.addLink(iri, "next-archive");
}
return link;
}
/**
* Adds a prev-archive link relation to the feed
*
* @param feed The feed
* @param iri The IRI of the previous archive feed document
* @return The newly created Link
*/
public static Link setPreviousArchive(Source feed, String iri) {
Link link = feed.getLink("prev-archive");
if (link == null) { // try the full IANA URI version
link = feed.getLink(Link.IANA_BASE + "prev-archive");
}
if (link != null) {
link.setHref(iri);
} else {
link = feed.addLink(iri, "prev-archive");
}
return link;
}
/**
* Adds a current link relation to the feed
*
* @param feed The feed
* @param iri The IRI of the current feed document
* @return The newly created Link
*/
public static Link setCurrent(Source feed, String iri) {
Link link = feed.getLink("current");
if (link == null) { // try the full IANA URI version
link = feed.getLink(Link.IANA_BASE + "current");
}
if (link != null) {
link.setHref(iri);
} else {
link = feed.addLink(iri, "current");
}
return link;
}
/**
* Returns the IRI of the next link relation
*/
public static IRI getNext(Source feed) {
Link link = feed.getLink("next");
return (link != null) ? link.getResolvedHref() : null;
}
/**
* Returns the IRI of the previous link relation
*/
public static IRI getPrevious(Source feed) {
Link link = feed.getLink("previous");
return (link != null) ? link.getResolvedHref() : null;
}
/**
* Returns the IRI of the first link relation
*/
public static IRI getFirst(Source feed) {
Link link = feed.getLink("first");
return (link != null) ? link.getResolvedHref() : null;
}
/**
* Returns the IRI of the last link relation
*/
public static IRI getLast(Source feed) {
Link link = feed.getLink("last");
return (link != null) ? link.getResolvedHref() : null;
}
/**
* Returns the IRI of the prev-archive link relation
*/
public static IRI getPreviousArchive(Source feed) {
Link link = feed.getLink("prev-archive");
if (link == null) { // try the full IANA URI version
link = feed.getLink(Link.IANA_BASE + "prev-archive");
}
return (link != null) ? link.getResolvedHref() : null;
}
/**
* Returns the IRI of the next-archive link relation
*/
public static IRI getNextArchive(Source feed) {
Link link = feed.getLink("next-archive");
if (link == null) { // try the full IANA URI version
link = feed.getLink(Link.IANA_BASE + "next-archive");
}
return (link != null) ? link.getResolvedHref() : null;
}
/**
* Returns the IRI of the current link relation
*/
public static IRI getCurrent(Source feed) {
Link link = feed.getLink("current");
if (link == null) { // try the full IANA URI version
link = feed.getLink(Link.IANA_BASE + "current");
}
return (link != null) ? link.getResolvedHref() : null;
}
}
| 7,687 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/thread/ThreadConstants.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.thread;
import javax.xml.namespace.QName;
import org.apache.abdera.util.Constants;
public interface ThreadConstants extends Constants {
public static final String THR_NS = "http://purl.org/syndication/thread/1.0";
public static final String LN_INREPLYTO = "in-reply-to";
public static final String LN_REF = "ref";
public static final String LN_COUNT = "count";
public static final String LN_WHEN = "when";
public static final String LN_TOTAL = "total";
public static final String THR_PREFIX = "thr";
public static final QName IN_REPLY_TO = new QName(THR_NS, LN_INREPLYTO, THR_PREFIX);
public static final QName THRCOUNT = new QName(THR_NS, LN_COUNT, THR_PREFIX);
/** @deprecated Use Constants.THRUPDATED */
public static final QName THRWHEN = new QName(THR_NS, LN_WHEN, THR_PREFIX);
public static final QName THRUPDATED = new QName(THR_NS, LN_UPDATED, THR_PREFIX);
public static final QName THRTOTAL = new QName(THR_NS, LN_TOTAL, THR_PREFIX);
public static final QName THRREF = new QName(LN_REF);
public static final QName THRSOURCE = new QName(LN_SOURCE);
}
| 7,688 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/thread/ThreadExtensionFactory.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.thread;
import org.apache.abdera.util.AbstractExtensionFactory;
public final class ThreadExtensionFactory extends AbstractExtensionFactory implements ThreadConstants {
public ThreadExtensionFactory() {
super(ThreadConstants.THR_NS);
addImpl(IN_REPLY_TO, InReplyTo.class);
addImpl(THRTOTAL, Total.class);
}
}
| 7,689 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/thread/InReplyTo.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.thread;
import javax.activation.MimeType;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
import org.apache.abdera.i18n.iri.IRI;
public class InReplyTo extends ElementWrapper {
public InReplyTo(Element internal) {
super(internal);
}
public InReplyTo(Factory factory) {
super(factory, ThreadConstants.IN_REPLY_TO);
}
public IRI getHref() {
String href = getAttributeValue("href");
return (href != null) ? new IRI(href) : null;
}
public MimeType getMimeType() {
try {
String type = getAttributeValue("type");
return (type != null) ? new MimeType(type) : null;
} catch (javax.activation.MimeTypeParseException e) {
throw new org.apache.abdera.util.MimeTypeParseException(e);
}
}
public IRI getRef() {
String ref = getAttributeValue("ref");
return (ref != null) ? new IRI(ref) : null;
}
public IRI getResolvedHref() {
IRI href = getHref();
IRI base = getBaseUri();
return (base == null) ? href : (href != null) ? base.resolve(href) : null;
}
public IRI getResolvedSource() {
IRI href = getSource();
IRI base = getBaseUri();
return (base == null) ? href : (href != null) ? base.resolve(href) : null;
}
public IRI getSource() {
String source = getAttributeValue("source");
return (source != null) ? new IRI(source) : null;
}
public void setHref(IRI ref) {
setAttributeValue("href", ref.toString());
}
public void setHref(String ref) {
setAttributeValue("href", ref);
}
public void setMimeType(MimeType mimeType) {
setAttributeValue("type", mimeType.toString());
}
public void setMimeType(String mimeType) {
setAttributeValue("type", mimeType);
}
public void setRef(IRI ref) {
setAttributeValue("ref", ref.toString());
}
public void setRef(String ref) {
setAttributeValue("ref", ref);
}
public void setSource(IRI source) {
setAttributeValue("source", source.toString());
}
public void setSource(String source) {
setAttributeValue("source", source);
}
}
| 7,690 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/thread/ThreadHelper.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.thread;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.activation.MimeType;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.AtomDate;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Source;
import org.apache.abdera.i18n.iri.IRI;
public final class ThreadHelper {
ThreadHelper() {
}
public static int getCount(Link link) {
String val = link.getAttributeValue(ThreadConstants.THRCOUNT);
return (val != null) ? Integer.parseInt(val) : 0;
}
@SuppressWarnings("deprecation")
public static AtomDate getUpdated(Link link) {
String val = link.getAttributeValue(ThreadConstants.THRUPDATED);
if (val == null) // thr:when was updated to thr:updated, some old impls may still be using thr:when
val = link.getAttributeValue(ThreadConstants.THRWHEN);
return (val != null) ? AtomDate.valueOf(val) : null;
}
public static void setCount(Link link, int count) {
link.setAttributeValue(ThreadConstants.THRCOUNT, String.valueOf(count).trim());
}
public static void setUpdated(Link link, Date when) {
link.setAttributeValue(ThreadConstants.THRUPDATED, AtomDate.valueOf(when).getValue());
}
public static void setUpdated(Link link, Calendar when) {
link.setAttributeValue(ThreadConstants.THRUPDATED, AtomDate.valueOf(when).getValue());
}
public static void setUpdated(Link link, long when) {
link.setAttributeValue(ThreadConstants.THRUPDATED, AtomDate.valueOf(when).getValue());
}
public static void setUpdated(Link link, String when) {
link.setAttributeValue(ThreadConstants.THRUPDATED, AtomDate.valueOf(when).getValue());
}
public static Total addTotal(Entry entry, int total) {
Factory factory = entry.getFactory();
Total totalelement = (Total)factory.newExtensionElement(ThreadConstants.THRTOTAL, entry);
totalelement.setValue(total);
return totalelement;
}
public static Total getTotal(Entry entry) {
return entry.getFirstChild(ThreadConstants.THRTOTAL);
}
public static void addInReplyTo(Entry entry, InReplyTo replyTo) {
entry.addExtension(replyTo);
}
public static InReplyTo addInReplyTo(Entry entry) {
return entry.addExtension(ThreadConstants.IN_REPLY_TO);
}
public static InReplyTo addInReplyTo(Entry entry, Entry ref) {
if (ref.equals(entry))
return null;
InReplyTo irt = addInReplyTo(entry);
try {
irt.setRef(ref.getId());
Link altlink = ref.getAlternateLink();
if (altlink != null) {
irt.setHref(altlink.getResolvedHref());
if (altlink.getMimeType() != null)
irt.setMimeType(altlink.getMimeType());
}
Source src = ref.getSource();
if (src != null) {
Link selflink = src.getSelfLink();
if (selflink != null)
irt.setSource(selflink.getResolvedHref());
}
} catch (Exception e) {
}
return irt;
}
public static InReplyTo addInReplyTo(Entry entry, IRI ref) {
try {
if (entry.getId() != null && entry.getId().equals(ref))
return null;
} catch (Exception e) {
}
InReplyTo irt = addInReplyTo(entry);
irt.setRef(ref);
return irt;
}
public static InReplyTo addInReplyTo(Entry entry, String ref) {
return addInReplyTo(entry, new IRI(ref));
}
public static InReplyTo addInReplyTo(Entry entry, IRI ref, IRI source, IRI href, MimeType type) {
InReplyTo irt = addInReplyTo(entry, ref);
if (irt != null) {
if (source != null)
irt.setSource(source);
if (href != null)
irt.setHref(href);
if (type != null)
irt.setMimeType(type);
}
return irt;
}
public static InReplyTo addInReplyTo(Entry entry, String ref, String source, String href, String type) {
InReplyTo irt = addInReplyTo(entry, ref);
if (irt != null) {
if (source != null)
irt.setSource(source);
if (href != null)
irt.setHref(href);
if (type != null)
irt.setMimeType(type);
}
return irt;
}
public static InReplyTo getInReplyTo(Entry entry) {
return entry.getFirstChild(ThreadConstants.IN_REPLY_TO);
}
@SuppressWarnings("unchecked")
public static List<InReplyTo> getInReplyTos(Entry entry) {
List list = entry.getExtensions(ThreadConstants.IN_REPLY_TO);
return list;
}
public static InReplyTo newInReplyTo(Factory factory) {
return new InReplyTo(factory);
}
public static Total newTotal(Factory factory) {
return new Total(factory);
}
}
| 7,691 |
0 | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/main/src/main/java/org/apache/abdera/ext/thread/Total.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.thread;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
public class Total extends ElementWrapper {
public Total(Element internal) {
super(internal);
}
public Total(Factory factory) {
super(factory, ThreadConstants.THRTOTAL);
}
public int getValue() {
String val = getText();
return (val != null) ? Integer.parseInt(val) : -1;
}
public void setValue(int value) {
setText(String.valueOf(value));
}
}
| 7,692 |
0 | Create_ds/abdera/extensions/media/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/media/src/test/java/org/apache/abdera/test/ext/media/MediaTest.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.media;
import static org.apache.abdera.ext.media.MediaConstants.CONTENT;
import static org.apache.abdera.ext.media.MediaConstants.GROUP;
import static org.apache.abdera.ext.media.MediaConstants.TITLE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.List;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.media.MediaContent;
import org.apache.abdera.ext.media.MediaGroup;
import org.apache.abdera.ext.media.MediaTitle;
import org.apache.abdera.ext.media.MediaConstants.Expression;
import org.apache.abdera.ext.media.MediaConstants.Type;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.parser.Parser;
import org.junit.Test;
public class MediaTest {
@Test
public void testMedia() throws Exception {
Abdera abdera = new Abdera();
Factory factory = abdera.getFactory();
Entry entry = factory.newEntry();
MediaGroup group = entry.addExtension(GROUP);
MediaContent content = group.addExtension(CONTENT);
content.setUrl("http://example.org");
content.setBitrate(123);
content.setChannels(2);
content.setDuration(123);
content.setExpression(Expression.SAMPLE);
content.setFilesize(12345);
content.setFramerate(123);
content.setLanguage("en");
MediaTitle title = content.addExtension(TITLE);
title.setType(Type.PLAIN);
title.setText("This is a sample");
ByteArrayOutputStream out = new ByteArrayOutputStream();
entry.writeTo(out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
Parser parser = abdera.getParser();
Document<Entry> doc = parser.parse(in);
entry = doc.getRoot();
group = entry.getExtension(GROUP);
List<MediaContent> list = entry.getExtensions(CONTENT);
for (MediaContent item : list) {
assertEquals("http://example.org", item.getUrl().toString());
assertEquals(123, item.getBitrate());
assertEquals(2, item.getChannels());
assertEquals(123, item.getDuration());
assertEquals(Expression.SAMPLE, item.getExpression());
assertEquals(12345, item.getFilesize());
assertEquals(123, item.getFramerate());
assertEquals("en", item.getLang());
title = item.getExtension(TITLE);
assertNotNull(title);
assertEquals(Type.PLAIN, title.getType());
assertEquals("This is a sample", title.getText());
}
}
}
| 7,693 |
0 | Create_ds/abdera/extensions/media/src/test/java/org/apache/abdera/test/ext | Create_ds/abdera/extensions/media/src/test/java/org/apache/abdera/test/ext/media/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.media;
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(MediaTest.class);
}
}
| 7,694 |
0 | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext/media/MediaThumbnail.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.media;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
import org.apache.abdera.i18n.iri.IRI;
public class MediaThumbnail extends ElementWrapper {
public MediaThumbnail(Element internal) {
super(internal);
}
public MediaThumbnail(Factory factory) {
super(factory, MediaConstants.THUMBNAIL);
}
public IRI getUrl() {
String url = getAttributeValue("url");
return (url != null) ? new IRI(url) : null;
}
public void setUrl(String url) {
if (url != null) {
setAttributeValue("url", (new IRI(url)).toString());
} else {
removeAttribute(new QName("url"));
}
}
public int getWidth() {
String width = getAttributeValue("width");
return (width != null) ? Integer.parseInt(width) : -1;
}
public void setWidth(int width) {
if (width > -1) {
setAttributeValue("width", String.valueOf(width));
} else {
removeAttribute(new QName("width"));
}
}
public int getHeight() {
String height = getAttributeValue("height");
return (height != null) ? Integer.parseInt(height) : -1;
}
public void setHeight(int height) {
if (height > -1) {
setAttributeValue("height", String.valueOf(height));
} else {
removeAttribute(new QName("height"));
}
}
public String getTime() {
return getAttributeValue("time");
}
public void setTime(String time) {
if (time != null)
setAttributeValue("time", time);
else
removeAttribute(new QName("time"));
}
}
| 7,695 |
0 | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext/media/MediaGroup.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.media;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ExtensibleElementWrapper;
public class MediaGroup extends ExtensibleElementWrapper {
public MediaGroup(Element internal) {
super(internal);
}
public MediaGroup(Factory factory) {
super(factory, MediaConstants.GROUP);
}
}
| 7,696 |
0 | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext/media/MediaCopyright.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.media;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
import org.apache.abdera.i18n.iri.IRI;
public class MediaCopyright extends ElementWrapper {
public MediaCopyright(Element internal) {
super(internal);
}
public MediaCopyright(Factory factory) {
super(factory, MediaConstants.COPYRIGHT);
}
public IRI getUrl() {
String url = getAttributeValue("url");
return (url != null) ? new IRI(url) : null;
}
public void setUrl(String url) {
if (url != null)
setAttributeValue("url", (new IRI(url)).toString());
else
removeAttribute(new QName("url"));
}
}
| 7,697 |
0 | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext/media/MediaPlayer.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.media;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
import org.apache.abdera.i18n.iri.IRI;
public class MediaPlayer extends ElementWrapper {
public MediaPlayer(Element internal) {
super(internal);
}
public MediaPlayer(Factory factory) {
super(factory, MediaConstants.PLAYER);
}
public IRI getUrl() {
String url = getAttributeValue("url");
return (url != null) ? new IRI(url) : null;
}
public void setUrl(String url) {
if (url != null) {
setAttributeValue("url", (new IRI(url)).toString());
} else {
removeAttribute(new QName("url"));
}
}
public int getWidth() {
String width = getAttributeValue("width");
return (width != null) ? Integer.parseInt(width) : -1;
}
public void setWidth(int width) {
if (width > -1) {
setAttributeValue("width", String.valueOf(width));
} else {
removeAttribute(new QName("width"));
}
}
public int getHeight() {
String height = getAttributeValue("height");
return (height != null) ? Integer.parseInt(height) : -1;
}
public void setHeight(int height) {
if (height > -1) {
setAttributeValue("height", String.valueOf(height));
} else {
removeAttribute(new QName("height"));
}
}
}
| 7,698 |
0 | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext | Create_ds/abdera/extensions/media/src/main/java/org/apache/abdera/ext/media/MediaTitle.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.media;
import javax.xml.namespace.QName;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Element;
import org.apache.abdera.model.ElementWrapper;
public class MediaTitle extends ElementWrapper {
public MediaTitle(Element internal) {
super(internal);
}
public MediaTitle(Factory factory) {
super(factory, MediaConstants.TITLE);
}
public void setType(MediaConstants.Type type) {
switch (type) {
case PLAIN:
setAttributeValue("type", "plain");
break;
case HTML:
setAttributeValue("type", "html");
break;
default:
removeAttribute(new QName("type"));
}
}
public MediaConstants.Type getType() {
String type = getAttributeValue("type");
return (type != null) ? MediaConstants.Type.valueOf(type.toUpperCase()) : null;
}
}
| 7,699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.