r916 - in trunk/wikitty-publication/src/main: java/org/nuiton/wikitty/publication/action webapp/WEB-INF/jsp
Author: mfortun Date: 2011-05-24 17:01:48 +0200 (Tue, 24 May 2011) New Revision: 916 Url: http://nuiton.org/repositories/revision/wikitty/916 Log: * correct edit page struts migration finished #1500 Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEdit.java trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/edit.jsp Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEdit.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEdit.java 2011-05-24 09:43:17 UTC (rev 915) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/action/PublicationActionEdit.java 2011-05-24 15:01:48 UTC (rev 916) @@ -32,14 +32,19 @@ */ private static final long serialVersionUID = -590087371230933701L; - protected String newExtension; - protected Wikitty wikitty; private HashMap<String, Object> wikittyFieldMap; - protected File upload;// The actual file + protected WikittyProxy proxy; + protected boolean isDelete = false; + protected boolean isStore = false; + protected String wikittyId = ""; + protected String version = ""; + + protected File uploadedFile; + static public PublicationActionEdit getAction() { return (PublicationActionEdit) ActionContext.getContext().get( CONTEXT_ACTION_KEY); @@ -48,28 +53,36 @@ @Override public String execute() throws Exception { - doAction(); + proxy = getWikittyPublicationProxy(); + Map<String, Object> param = ActionContext.getContext().getParameters(); + this.formatArgs(param); - return SUCCESS; - } + isDelete = param.containsKey("delete"); + isStore = param.containsKey("store"); - public void doAction() { + wikittyId = getArgument("id", ""); + version = getArgument("version", ""); - WikittyProxy proxy = getWikittyPublicationProxy(); + - Object context; + putIdArgs(wikitty.getId()); - Map<String, Object> param = ActionContext.getContext().getParameters(); + return SUCCESS; + } - if (param.containsKey("delete")) { + public void doAction() { + + if (isDelete) { // on nous demande supprimer le wikitty, on l'efface et on // affichera un wikitty vide - String id = getArgument("id", ""); + String id = this.wikittyId; proxy.delete(id); // apres un effacement on reprend l'edition d'un tout nouveau // wikitty wikitty = new WikittyImpl(); + } else { + List<String> argsString = new ArrayList<String>(); String args = ActionContext.getContext().getParameters() .get(ARGS_KEY).toString(); @@ -81,26 +94,20 @@ // recherche du Wikitty a editer ou creation d'un nouveau si // necessaire Criteria criteria = searchCriteria(argsString); + if (criteria == null) { wikitty = new WikittyImpl(); - ActionContext.getContext().getParameters() - .put(ARGS_KEY, Element.ELT_ID + ":" + wikitty.getId()); - } else { wikitty = proxy.findByCriteria(criteria); } // si on ne retrouve pas le wikitty, mais qu'il vient d'etre cree // pour l'edition, on recree un wikitty avec ce meme identifiant - if (wikitty == null && "0.0".equals(getArgument("version", ""))) { + if (wikitty == null && "0.0".equals(version)) { // c'est un nouvel objet, il n'a pas encore ete sauve, mais on // veut le faire - String id = getArgument("id", ""); - ; + String id = this.wikittyId; wikitty = new WikittyImpl(id); - ActionContext.getContext().getParameters() - .put(ARGS_KEY, Element.ELT_ID + ":" + wikitty.getId()); - } if (wikitty == null) { @@ -108,21 +115,20 @@ // cela signifie qu'on ne retrouve pas le wikitty a editer // on creer un nouveau wikitty vide que l'on editera wikitty = new WikittyImpl(); - ActionContext.getContext().getParameters() - .put(ARGS_KEY, Element.ELT_ID + ":" + wikitty.getId()); - } else { // on met a jour le wikitty avec les infos trouvees dans les // arguments // ajout des extensions deja existante si necessaire String extensions = getArgument("extensions", null); + if (extensions != null) { String[] exts = StringUtil.split(extensions .replace("[", "").replace("]", ""), ","); for (String extName : exts) { + WikittyExtension ext = proxy - .restoreExtensionLastVersion(extName); + .restoreExtensionLastVersion(extName.trim()); if (ext != null) { wikitty.addExtension(ext); } @@ -139,9 +145,8 @@ } } - Map<String, Object> args1 = new HashMap<String, Object>(); - args1.putAll(getFieldArguments()); - for (Map.Entry<String, Object> field : args1.entrySet()) { + for (Map.Entry<String, Object> field : wikittyFieldMap + .entrySet()) { String key = field.getKey(); Object value = null; if (key.contains(WikittyUtil.FQ_FIELD_NAME_SEPARATOR)) { @@ -158,6 +163,7 @@ FieldType extFieldType = wikitty.getExtension(ext) .getFieldType(fieldName); + // allow collection string to be parse and save if (extFieldType.isCollection() && extFieldType.getType() == TYPE.STRING && value != null) { @@ -181,6 +187,7 @@ } else { wikitty.setField(ext, fieldName, value); } + // si w est un WikittyPubData on essai de mettre a // jour si besoin les champs mimetype et name if (ext.equals(WikittyPubData.EXT_WIKITTYPUBDATA) @@ -188,43 +195,38 @@ .equals(WikittyPubData.FIELD_WIKITTYPUBDATA_CONTENT)) { if (null == WikittyPubDataHelper .getName(wikitty)) { - WikittyPubDataHelper.setName( - wikitty, - String.valueOf(args1.get(key - + "-filename"))); + WikittyPubDataHelper.setName(wikitty, + String.valueOf(wikittyFieldMap + .get(key + "-filename"))); } if (null == WikittyPubDataHelper .getMimeType(wikitty)) { - WikittyPubDataHelper.setMimeType( - wikitty, - String.valueOf(args1.get(key - + "-contentType"))); + WikittyPubDataHelper + .setMimeType( + wikitty, + String.valueOf(wikittyFieldMap + .get(key + + "-contentType"))); } } } } } - if (param.containsKey("store")) { + if (isStore) { // on nous demande la sauvegarde proxy.store(wikitty); } } } - } - public File getUpload() { - return upload; } + public void setFile(File upload) { - this.upload = upload; + this.uploadedFile = upload; } - public void setUpload(File upload) { - this.upload = upload; - } - public Wikitty getWikitty() { return wikitty; } @@ -233,35 +235,14 @@ this.wikitty = wikitty; } - public List<String> getWikittyExtentionAviable() { - List<String> result = new ArrayList<String>(); - result.add("ponay"); - result.add("machin"); - - return result; - } - - public String getNewExtension() { - return newExtension; - } - - /* - * <s:combobox list="wikittyExtentionAviable" label="test" - * name="newExtension" /> - */ - public void setNewExtension(String newExtension) { - this.newExtension = newExtension; - } - public String getPostUrl() { return this.getArgument(ARGS_KEY, "") + ".action"; } - protected Map<String, Object> getFieldArguments() { + protected Map<String, Object> formatArgs(Map<String, Object> args) { wikittyFieldMap = new HashMap<String, Object>(); - for (Entry<String, Object> en : ActionContext.getContext() - .getParameters().entrySet()) { + for (Entry<String, Object> en : args.entrySet()) { if (en.getKey().startsWith("Wikitty")) { @@ -275,11 +256,11 @@ value = String.valueOf(en.getValue()); } - if ("BINARY".equals(value) && upload != null) { + if ("BINARY".equals(value) && uploadedFile != null) { try { wikittyFieldMap.put(en.getKey(), - FileUtil.fileToByte(upload)); - upload.deleteOnExit(); + FileUtil.fileToByte(uploadedFile)); + uploadedFile.deleteOnExit(); } catch (IOException e) { // TODO mfortun-2011-05-24 really handle exception e.printStackTrace(); @@ -293,4 +274,10 @@ } return wikittyFieldMap; } + + protected void putIdArgs(String id) { + ActionContext.getContext().getParameters() + .put(ARGS_KEY, Element.ELT_ID + ":" + id); + } + } Modified: trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/edit.jsp =================================================================== --- trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/edit.jsp 2011-05-24 09:43:17 UTC (rev 915) +++ trunk/wikitty-publication/src/main/webapp/WEB-INF/jsp/edit.jsp 2011-05-24 15:01:48 UTC (rev 916) @@ -98,8 +98,8 @@ case BINARY: %> - <input type="hidden" name="<%=extName%>.<%=fieldName%>" value="BINARY" /> - <input type="file" name="File" label ="File"/> + <input type="hidden" name="<%=extName%>.<%=fieldName%>" value="BINARY" /> + <input type="file" name="File" label ="File"/> <%
participants (1)
-
mfortun@users.nuiton.org