r870 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication
Author: mfortun Date: 2011-05-09 16:05:52 +0200 (Mon, 09 May 2011) New Revision: 870 Url: http://nuiton.org/repositories/revision/wikitty/870 Log: * remove old file/action Removed: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionRaw.java trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationServlet.java Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionRaw.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionRaw.java 2011-05-09 12:39:54 UTC (rev 869) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/ActionRaw.java 2011-05-09 14:05:52 UTC (rev 870) @@ -1,123 +0,0 @@ -/* - * #%L - * Wikitty :: publication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 CodeLutin, Benjamin Poussin, Benjamin Poussin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.wikitty.publication; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.ApplicationConfig; -import org.nuiton.wikitty.WikittyProxy; -import org.nuiton.wikitty.entities.Wikitty; -import org.nuiton.wikitty.entities.WikittyExtension; -import org.nuiton.wikitty.search.Criteria; - -/** - * Action permettant de retourner la valeur d'un champs d'un object. - * Elle peut-etre utilisee pour retourner une image ou un document stocke dans - * un champs d'un wikitty - * - * Cette action prend deux arguments obligatoires (si pas WikittyPub(Text|Data) - * <li> l'argument de recherche du wikitty - * <li> le champs qu'il faut retourner en raw - * - * et un argument optionnel - * <li> le type mime du contenu qui peut-etre un champs de l'objet - * - * exemple - * <pre> - * ram/WikittyPubData.name=MonImage.jpg - * ram/WikittyPubText.name=Tuto - * ram/WikittyPubData.name=MonImage.jpg/WikittyPubData.content?mimetype=WikittyPubData.mimetype - * ram/WikittyPubData.name=MonImage.jpg/WikittyPubData.mimetype?mimetype=text/plain - * ram/WikittyPubText.name=Tuto/WikittyPubText.content?mimetype=WikittyPubText.mimetype - * ram/WikittyUser.login=admin/WikittyUser.password?mimetype=text/plain - * </pre> - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class ActionRaw extends AbstractActionOnWikitty { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(ActionError.class); - - static final protected String exampleUsage = - "ram/WikittyPubData.name=MonImage.jpg/WikittyPubData.content?mimetype=WikittyPubData.mimetype\n" - + "ram/Tuto\n" - + "ram/Tuto/WikittyPubText.content\n" - + "ram/WikittyPubText.name=Tuto/WikittyPubText.content\n" - + "ram/WikittyPubText.name=Tuto/WikittyPubText.content?mimetype=WikittyPubText.mimetype\n" - + "ram/WikittyUser.login=admin/WikittyUser.password?mimetype=text/plain\n"; - - protected ApplicationConfig appConfig; - - public ActionRaw(ApplicationConfig appConfig) { - this.appConfig = appConfig; - } - - protected String getExampleUsage() { - return exampleUsage; - } - - @Override - public Object doAction(WikittyPublicationContext context) { - - log.info("args " + context.getMandatoryArguments()); - - Object result; - Criteria criteria = searchCriteria(context.getMandatoryArguments()); - - if (criteria == null) { - result = getError(context); - } else { - WikittyProxy proxy = context.getWikittyProxy(); - Wikitty w = proxy.findByCriteria(criteria); - - if (w == null) { - context.setContentType("text/plain"); - result = String.format( - "no data found for criteria %s", criteria); - } else { - String contentField = getContentFieldName(context, criteria.getName(), w); - - if (contentField == null) { - result = getError(context); - } else { - String extName = WikittyExtension.extractExtensionName(contentField); - String fieldName = WikittyExtension.extractFieldName(contentField); - - String mimetype = getMimeType(context, criteria.getName(), w); - context.setContentType(mimetype); - result = w.getFieldAsObject(extName, fieldName); - } - } - } - - return result; - } - -} Deleted: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationServlet.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationServlet.java 2011-05-09 12:39:54 UTC (rev 869) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/WikittyPublicationServlet.java 2011-05-09 14:05:52 UTC (rev 870) @@ -1,131 +0,0 @@ -/* - * #%L - * Wikitty :: publication - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 CodeLutin, Benjamin Poussin, Benjamin Poussin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.wikitty.publication; - - -import java.io.IOException; -import java.io.PrintWriter; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.ApplicationConfig; -import org.nuiton.util.ArgumentsParserException; - -/** - * url: - * <pre> - * /[context]/[action]/[action argument]?[action argument]#[fragment] - * </pre> - * - * example: - * <pre> - * /codelutin/raw/WikittyPubData.name=lutin.jpg/WikittyPubData.content?mimetype=WikittyPubData.mimetype - * </pre> - * - * <li>la config du WikittyService sera lu dans la config - * wikitty.publication.config.pattern en remplacant %s par 'default' - * la valeur de 'wikitty.data.directory' est modifier pour lui ajouter le - * context par defaut en plus, puis le fichier de config specifique au context est lu - * qui peut alors ecraser 'wikitty.data.directory' et toutes les autres valeurs - * par defaut - * <li>l'action executee sera 'raw' la classe associee sera trouve dans le fichier - * de config WikittyPublication. - * <li> le reste sont des arguments specifique a l'action que l'action pourra - * trouver dans: {@link WikittyPublicationContext#getMandatoryArguments()} et - * {@link WikittyPublicationContext#getArguments()}. - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class WikittyPublicationServlet extends HttpServlet { - - static public ApplicationConfig appConfig; - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(WikittyPublicationServlet.class); - - public void init() throws ServletException { - try { - appConfig = new ApplicationConfig(); - appConfig.setConfigFileName("wikitty-publication.properties"); - appConfig.parse(null); - } catch(ArgumentsParserException eee) { - throw new ServletException("Can't get filename config prefix", eee); - } - } - - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - doPost(req, resp); - } - - protected void doPost(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - - Object result; - WikittyPublicationContext context = new WikittyPublicationContext(appConfig); - try { - context.parse(req, resp); - - if ("true".equals(context.getArguments().get("debug"))) { - // debug asked, not do action, but show context - result = context.toString(); - context.setContentType("text/plain"); - } else { - WikittyPublicationAction action = context.getAction(); - result = action.doAction(context); - } - } catch (Throwable eee) { - WikittyPublicationAction action = new ActionError(eee); - result = action.doAction(context); - } - - String contentType = context.getContentType(); - if (contentType != null && contentType.startsWith("forward")) { - req.getRequestDispatcher(String.valueOf(result)).forward(req, resp); - } else { - if (contentType != null) { - resp.setContentType(contentType); - } - if (result instanceof byte[]) { - ServletOutputStream out = resp.getOutputStream(); - out.write((byte[]) result); - out.flush(); - } else { - PrintWriter out = resp.getWriter(); - out.write(String.valueOf(result)); - out.flush(); - } - } - } - -}
participants (1)
-
mfortun@users.nuiton.org