All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.syndication.propono.atom.server.impl.FileBasedAtomService Maven / Gradle / Ivy

Go to download

The ROME Propono subproject is a Java class library that supports publishing protocols, specifically the Atom Publishing Protocol and the legacy MetaWeblog API. Propono includes an Atom client library, Atom server framework and a Blog client that supports both Atom protocol and the MetaWeblog API.

The newest version!
/*   
 * Copyright 2007 Sun Microsystems, Inc.
 * 
 * Licensed 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.
 */ 
package com.sun.syndication.propono.atom.server.impl;

import com.sun.syndication.propono.atom.common.AtomService;
import com.sun.syndication.propono.utils.Utilities;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

/**
 * File based Atom service.
 * Supports one workspace per user.
 * Collections in workspace are defined in /propono.properties, for example:
 *
 * 
 *    # Define list of collections to be offered
 *    propono.atomserver.filebased.collections=entries,gifimages
 *
 *    # Defines 'entries' collection, accepts entries
 *    propono.atomserver.filebased.collection.entries.title=Entries
 *    propono.atomserver.filebased.collection.entries.singular=entry
 *    propono.atomserver.filebased.collection.entries.plural=entries
 *    propono.atomserver.filebased.collection.entries.accept=application/atom+xml;type=entry
 *    propono.atomserver.filebased.collection.entries.categories=general,category1,category2
 *
 *    # Defines 'gifimages' collection, accepts only GIF files
 *    propono.atomserver.filebased.collection.gifimages.title=GIF Images
 *    propono.atomserver.filebased.collection.gifimages.singular=gif
 *    propono.atomserver.filebased.collection.gifimages.plural=gifs
 *    propono.atomserver.filebased.collection.gifimages.accept=image/gif
 *    propono.atomserver.filebased.collection.gifimages.categories=general,category1,category2
 * 
* * If no such properties are found, then service will fall back to two * collections: 'entries' for Atom entries and 'resources' for any content-type. * * *

URI structure used for accessing collections and entries

* *

Collection feed (URI allows GET to get collection, POST to add to it)
* [servlet-context-uri]/app/[workspace-handle]/[collection-plural] *

* *

Collection entry (URI allows GET, PUT and DELETE)
* [servlet-context-uri]/app/[workspace-handle]/[collection-singular]/[entryid] *

* *

Collection entry media (URI allows GET, PUT and DELETE)
* [servlet-context-uri]/app/[workspace-handle]/[collection-singular]/media/[entryid] *

* *

Categories URI if not using inline categories (URI allows GET)
* [servlet-context-uri]/app/[workspace-handle]/[collection-plural]/categories *

* * *

Directory structure used to store collections and entries

* *

Collection feed (kept constantly up to date)
* [servlet-context-dir]/[workspace-handle]/[collection-plural]/feed.xml *

* *

Collection entry (individual entries also stored as entry.xml files)
* [servlet-context-dir]/[workspace-handle]/[collection-plural]/id/entry.xml *

* *

Collection entry media (media file stored under entry directory)
* [servlet-context-dir]/[workspace-handle]/[collection-plural]/id/media/id *

*/ public class FileBasedAtomService extends AtomService { private Map workspaceMap = new TreeMap(); private Map collectionMap = new TreeMap(); private static Properties cacheProps = new Properties(); private boolean firstTime = true; /** * Creates a new instance of FileBasedAtomService. */ public FileBasedAtomService( String userName, String baseDir, String contextURI, String contextPath, String servletPath) throws Exception { String workspaceHandle = userName; // One workspace per user FileBasedWorkspace workspace = new FileBasedWorkspace(workspaceHandle, baseDir); workspaceMap.put(userName, workspace); if (firstTime) { synchronized(cacheProps) { InputStream is = getClass().getResourceAsStream("/propono.properties"); if (is != null) cacheProps.load(is); firstTime = false; } } // can't find propono.properties, so use system props instead if (cacheProps == null) cacheProps = System.getProperties(); String relativeURIsString = cacheProps.getProperty( "propono.atomserver.filebased.relativeURIs"); boolean relativeURIs = "true".equals(relativeURIsString); String inlineCategoriesString = cacheProps.getProperty( "propono.atomserver.filebased.inlineCategories"); boolean inlineCategories = "true".equals(inlineCategoriesString); String colnames = cacheProps.getProperty("propono.atomserver.filebased.collections"); if (colnames != null) { // collections specified in propono.properties, use those String[] colarray = Utilities.stringToStringArray(colnames,","); for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy