Skip to content

Commit aecadc6

Browse files
mmoquiNicolasEYSSERIC
authored andcommitted
bug #4737 : When updating a page name, the extension of the file isn't taken into account and it is added to the updated file name
1 parent 766459c commit aecadc6

File tree

4 files changed

+123
-161
lines changed

4 files changed

+123
-161
lines changed

websites/websites-war/src/main/java/com/stratelia/webactiv/webSites/control/WebSiteSessionController.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import javax.ejb.EJBException;
6868
import javax.xml.bind.JAXBException;
6969
import org.apache.commons.fileupload.FileItem;
70+
import org.apache.commons.io.FilenameUtils;
7071

7172
import static com.silverpeas.pdc.model.PdcClassification.aPdcClassificationOfContent;
7273

@@ -128,7 +129,7 @@ public boolean isSortedTopicsEnabled() {
128129
*/
129130
/* WebSite - Gestion des objets session */
130131
/**
131-
* ***********************************************************************************
132+
* **********************************************************************************
132133
*/
133134
public synchronized void setSessionTopic(FolderDetail topicDetail) {
134135
this.sessionTopic = topicDetail;
@@ -712,7 +713,14 @@ public synchronized void renameFile(String rep, String name, String newName)
712713
throws WebSitesException {
713714
/* chemin = c:\\j2sdk\\public_html\\WAUploads\\WA0webSite10\\nomSite\\Folder */
714715
try {
715-
FileFolderManager.renameFile(getFullPath(rep), name, newName);
716+
String extension = FilenameUtils.getExtension(name);
717+
String newExtension = FilenameUtils.getExtension(newName);
718+
if (extension.equals(newExtension)) {
719+
FileFolderManager.renameFile(getFullPath(rep), name, newName);
720+
} else {
721+
throw new IllegalArgumentException(
722+
"the new and the old file names must have the same extension: " + extension);
723+
}
716724
} catch (Exception e) {
717725
throw new WebSitesException("WebSiteSessionController.renameFile()",
718726
SilverpeasException.ERROR, "webSites.EX_RENAME_FILE_FAIL", e);
@@ -974,7 +982,7 @@ private boolean isInWhiteList(File file) {
974982
List<String> whiteList = Arrays.asList(authorizedMimeTypes.split(" "));
975983
String mimeType = FileUtil.getMimeType(file.getPath());
976984
for (String whiteMiteType : whiteList) {
977-
if (mimeType.matches(whiteMiteType.replace("*", ".*"))) {
985+
if (mimeType.matches(whiteMiteType.replace("*", ".*").replace("+", "\\+"))) {
978986
return true;
979987
}
980988
}

websites/websites-war/src/main/webapp/webSites/jsp/checkScc.jsp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
String componentLabel = browseContext[1];
106106
String spaceId = browseContext[2];
107107
String componentId = browseContext[3];
108+
109+
pageContext.setAttribute("componentLabel", componentLabel);
108110
109111
boolean bookmarkMode = componentId.startsWith("bookmark");
110112
%>

websites/websites-war/src/main/webapp/webSites/jsp/updatePage.jsp

Lines changed: 89 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
along with this program. If not, see <http://www.gnu.org/licenses/>.
2424
2525
--%>
26-
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
26+
<%@page import="com.silverpeas.util.StringUtil"%>
27+
<%@page import="org.apache.commons.io.FilenameUtils"%>
28+
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
29+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
30+
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
31+
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
32+
<%@ taglib uri="http://www.silverpeas.com/tld/viewGenerator" prefix="view"%>
2733

28-
<%
29-
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
30-
response.setHeader("Pragma","no-cache"); //HTTP 1.0
31-
response.setDateHeader ("Expires",-1); //prevents caching at the proxy server
32-
%>
3334
<%@ page import="javax.servlet.*"%>
3435
<%@ page import="javax.servlet.http.*"%>
3536
<%@ page import="javax.servlet.jsp.*"%>
@@ -54,55 +55,44 @@ response.setDateHeader ("Expires",-1); //prevents caching at the proxy server
5455

5556
<%@ include file="checkScc.jsp" %>
5657

57-
<%
58-
59-
//R�cup�ration des param�tres
60-
String fatherId = (String) request.getParameter("Id");
61-
String path = (String) request.getParameter("Path");
62-
String name = (String) request.getParameter("Name"); //ancien nom
63-
String action = (String) request.getParameter("Action");
64-
65-
String type = "";
66-
if (name != null) {
67-
int index = name.lastIndexOf(".");
68-
if (index != -1)
69-
type = name.substring(index + 1);
70-
}
71-
72-
//Icons
73-
String mandatoryField = m_context + "/util/icons/mandatoryField.gif";
74-
75-
Button cancelButton = (Button) gef.getFormButton(resources.getString("GML.cancel"), "javascript:onClick=window.close();", false);
76-
Button validateButton = (Button) gef.getFormButton(resources.getString("GML.validate"), "javascript:onClick=sendData('"+type+"')", false);
77-
78-
%>
79-
80-
<!-- updatePage -->
81-
82-
<%
83-
if (action.equals("View")) {
84-
%>
58+
<fmt:setLocale value="${sessionScope['SilverSessionController'].favoriteLanguage}" />
59+
<view:setBundle basename="com.silverpeas.selection.multilang.selectionBundle" />
60+
61+
<c:url var="checkformjs" value="/util/javaScript/checkForm.js"/>
62+
<c:url var="mandatoryField" value="/util/icons/mandatoryField.gif"/>
63+
64+
<c:set var="action" value="${param.Action}"/>
65+
<c:set var="name" value="${param.Name}"/>
66+
<c:set var="fatherId" value="${param.Id}"/>
67+
<c:set var="path" value="${param.Path}"/>
68+
69+
<fmt:message var="pageUpdateTitle" key="PageUpdateTitle"/>
70+
<fmt:message var="cancelLabel" key="GML.cancel"/>
71+
<fmt:message var="okLabel" key="GML.validate"/>
72+
<fmt:message var="theFieldTxt" key="GML.theField"/>
73+
<fmt:message var="nameTxt" key="GML.name"/>
74+
<fmt:message var="mustBeFilledTxt" key="GML.MustBeFilled"/>
75+
<fmt:message var="mustNotContainSpecialCharTxt" key="MustNotContainSpecialChar"/>
76+
<fmt:message var="mustContainFileNameTxt" key="MustContainFileName"/>
77+
<fmt:message var="thisFormContainsTxt" key="GML.ThisFormContains"/>
78+
<fmt:message var="errorsTxt" key="GML.errors"/>
79+
80+
<c:choose>
81+
<c:when test="${action == 'View'}">
82+
<%
83+
String nameToChange = (String) pageContext.getAttribute("name");
84+
String extension = FilenameUtils.getExtension(nameToChange);
85+
if (StringUtil.isDefined(extension)) {
86+
nameToChange = nameToChange.replace("." + extension, "");
87+
}
88+
pageContext.setAttribute("nameToChange", nameToChange);
89+
%>
8590
<HTML>
8691
<HEAD>
87-
<TITLE><%=resources.getString("GML.popupTitle")%></TITLE>
88-
<%
89-
out.println(gef.getLookStyleSheet());
90-
%>
91-
92-
<script type="text/javascript" src="<%=m_context%>/util/javaScript/checkForm.js"></script>
93-
<script LANGUAGE="JavaScript" TYPE="text/javascript">
94-
95-
96-
97-
function isCorrectName(nom) {
98-
99-
if (nom.indexOf(".") == 0) {
100-
return false;
101-
}
102-
103-
return true;
104-
105-
}
92+
<TITLE><fmt:message key="GML.popupTitle"/></TITLE>
93+
<view:looknfeel/>
94+
<script type="text/javascript" src="${checkformjs}"></script>
95+
<script type="text/javascript">
10696
10797
/************************************************************************************/
10898
@@ -128,37 +118,32 @@ function isCorrect(nom) {
128118
/************************************************************************************/
129119
130120
131-
function isCorrectForm() {
121+
function isCorrectForm(title) {
122+
var result;
132123
var errorMsg = "";
133124
var errorNb = 0;
134-
var title = stripInitialWhitespace(document.topicForm.Name.value);
135125
136126
if (isWhitespace(title)) {
137-
errorMsg+=" - <%=resources.getString("GML.theField")%> '<%=resources.getString("GML.name")%>' <%=resources.getString("GML.MustBeFilled")%>\n";
127+
errorMsg+=" - ${theFieldTxt} '${nameTxt}' ${mustBeFilledTxt}\n";
138128
errorNb++;
139129
}
140130
141131
if (! isCorrect(title)) {
142-
errorMsg+=" - <%=resources.getString("GML.theField")%> '<%=resources.getString("GML.name")%>' <%=resources.getString("MustNotContainSpecialChar")%>\n<%=Encode.javaStringToJsString(resources.getString("Char5"))%>\n";
132+
errorMsg+=" - ${theFieldTxt} '${nameTxt}' ${mustNotContainSpecialCharTxt}\n<%=EncodeHelper.javaStringToJsString(resources.getString("Char5"))%>\n";
143133
errorNb++;
144-
}
145-
146-
if (! isCorrectName(title)) {
147-
errorMsg+=" - <%=resources.getString("GML.theField")%> '<%=resources.getString("GML.name")%>' <%=resources.getString("MustContainFileName")%>\n";
148-
errorNb++;
149-
}
134+
}
150135
151136
switch(errorNb) {
152137
case 0 :
153138
result = true;
154139
break;
155140
case 1 :
156-
errorMsg = "<%=resources.getString("GML.ThisFormContains")%> 1 <%=resources.getString("GML.error")%> : \n" + errorMsg;
141+
errorMsg = "${thisFormContainsTxt} 1 ${errorsTxt} : \n" + errorMsg;
157142
window.alert(errorMsg);
158143
result = false;
159144
break;
160145
default :
161-
errorMsg = "<%=resources.getString("GML.ThisFormContains")%> " + errorNb + " <%=resources.getString("GML.errors")%> :\n" + errorMsg;
146+
errorMsg = "${thisFormContainsTxt} " + errorNb + " ${errorsTxt} :\n" + errorMsg;
162147
window.alert(errorMsg);
163148
result = false;
164149
break;
@@ -168,20 +153,10 @@ function isCorrectForm() {
168153
169154
/************************************************************************************/
170155
171-
function sendData(type) {
172-
if (isCorrectForm()) {
156+
function sendData() {
157+
var nameFile = stripInitialWhitespace(document.topicForm.Name.value);
158+
if (isCorrectForm(nameFile)) {
173159
document.topicDetailForm.Action.value = "Update";
174-
175-
var nameFile = stripInitialWhitespace(document.topicForm.Name.value);
176-
177-
if ( (type == "html") || (type == "htm") || (type == "HTML") || (type == "HTM") ) {
178-
179-
var indexPoint = nameFile.lastIndexOf(".");
180-
var ext = nameFile.substring(indexPoint + 1);
181-
if ( (ext != "html") && (ext != "htm") && (ext != "HTML") && (ext != "HTM") )
182-
nameFile = nameFile + ".html";
183-
}
184-
185160
document.topicDetailForm.NewName.value = nameFile;
186161
document.topicDetailForm.submit();
187162
}
@@ -191,74 +166,45 @@ function sendData(type) {
191166
</HEAD>
192167

193168
<BODY bgcolor="white" topmargin="15" leftmargin="20" onload="document.topicForm.Name.focus()">
194-
<%
195-
Window window = gef.getWindow();
196-
BrowseBar browseBar = window.getBrowseBar();
197-
browseBar.setDomainName(spaceLabel);
198-
browseBar.setComponentName(componentLabel);
199-
browseBar.setPath(resources.getString("PageUpdateTitle"));
200-
201-
//Le cadre
202-
Frame frame = gef.getFrame();
203-
204-
//Le board
205-
Board board = gef.getBoard();
169+
<view:window>
170+
<view:browseBar componentId="${componentLabel}" path="${pageUpdateTitle}"/>
171+
<view:frame>
172+
<view:board>
206173

207-
//D�but code
208-
out.println(window.printBefore());
209-
out.println(frame.printBefore());
210-
out.print(board.printBefore());
211-
%>
212-
213-
<TABLE ALIGN=CENTER CELLPADDING=5 CELLSPACING=0 BORDER=0 WIDTH="100%" CLASS=intfdcolor4>
214-
<FORM NAME="topicForm">
174+
<TABLE ALIGN=CENTER CELLPADDING=5 CELLSPACING=0 BORDER=0 WIDTH="100%" CLASS=intfdcolor4>
175+
<FORM NAME="topicForm">
215176
<TR>
216-
<TD class="txtlibform"><%=resources.getString("GML.name")%> : </TD>
217-
<TD valign="top"><input type="text" name="Name" value="<%=Encode.javaStringToHtmlString(name)%>" size="60" maxlength="50">&nbsp;<img border="0" src="<%=mandatoryField%>" width="5" height="5"></TD>
218-
</TR>
219-
<TR>
220-
<TD colspan="2">(<img border="0" src="<%=mandatoryField%>" width="5" height="5">
221-
: <%=resources.getString("GML.requiredField")%>)</TD>
222-
</TR>
223-
</FORM>
224-
</TABLE>
225-
226-
<%
227-
//fin du code
228-
out.print(board.printAfter());
229-
out.println(frame.printMiddle());
230-
231-
ButtonPane buttonPane = gef.getButtonPane();
232-
buttonPane.addButton(validateButton);
233-
buttonPane.addButton(cancelButton);
234-
235-
out.println("<br><center>"+buttonPane.print()+"</center><br>");
236-
237-
out.println(frame.printAfter());
238-
out.println(window.printAfter());
239-
240-
%>
241-
177+
<TD class="txtlibform">${nameTxt} : </TD>
178+
<TD valign="top"><input type="text" name="Name" value="<c:out value='${nameToChange}'/>" size="60" maxlength="50">&nbsp;<img border="0" src="${mandatoryField}" width="5" height="5"></TD>
179+
</TR>
180+
<TR>
181+
<TD colspan="2">(<img border="0" src="${mandatoryField}" width="5" height="5"> : <fmt:message key="GML.requiredField"/>)</TD>
182+
</TR>
183+
</FORM>
184+
</TABLE>
185+
<view:buttonPane verticalPosition="center">
186+
<view:button action="javascript:onClick=window.close();" label="${cancelLabel}" disabled="false"/>
187+
<view:button action="javascript:onClick=sendData();" label="${okLabel}" disabled="false"/>
188+
</view:buttonPane>
189+
190+
</view:board>
191+
</view:frame>
192+
</view:window>
193+
242194
<FORM NAME="topicDetailForm" ACTION="updatePage.jsp" METHOD=POST>
243195
<input type="hidden" name="Action">
244-
<input type="hidden" name="Id" value="<%=fatherId%>">
245-
<input type="hidden" name="Path" value="<%=path%>">
246-
<input type="hidden" name="Name" value="<%=name%>">
196+
<input type="hidden" name="Id" value="${fatherId}">
197+
<input type="hidden" name="Path" value="${path}">
198+
<input type="hidden" name="Name" value="${name}">
247199
<input type="hidden" name="NewName">
248200
</FORM>
249-
201+
250202
</BODY>
251203
</HTML>
252204

253-
<% } //End View
254-
255-
256-
257-
else if (action.equals("Update")) {
258-
259-
//VERIFICATION COTE SERVEUR
260-
String newName = (String) request.getParameter("NewName"); //nouveau nom
261-
%>
205+
</c:when>
206+
<c:when test="${action == 'Update'}">
207+
<c:set var="newName" value="${param.NewName}"/>
262208

263209
<HTML>
264210
<HEAD>
@@ -270,15 +216,12 @@ else if (action.equals("Update")) {
270216
</script>
271217
</HEAD>
272218

273-
<BODY onLoad="verifServer('<%=fatherId%>',
274-
'<%=Encode.javaStringToJsString(path)%>',
275-
'<%=Encode.javaStringToJsString(name)%>',
276-
'<%=Encode.javaStringToJsString(newName)%>')">
219+
<BODY onLoad="verifServer('${fatherId}',
220+
'<%=EncodeHelper.javaStringToJsString((String) pageContext.getAttribute("path"))%>',
221+
'<%=EncodeHelper.javaStringToJsString((String) pageContext.getAttribute("name"))%>',
222+
'<%=EncodeHelper.javaStringToJsString((String) pageContext.getAttribute("newName"))%>')">
277223
</BODY>
278224
</HTML>
279-
<%
280-
281-
}
282-
283-
%>
284225

226+
</c:when>
227+
</c:choose>

0 commit comments

Comments
 (0)