Check map before save.

This commit is contained in:
Paulo Gustavo Veiga 2013-02-27 23:08:37 -03:00
parent 6155a70c04
commit b5a7a11920
2 changed files with 14 additions and 8 deletions

View File

@ -162,13 +162,6 @@ public class MindmapController extends BaseController {
if (xml == null) {
throw new IllegalArgumentException("Map xml can not be null");
}
// Check that what we received a valid mindmap...
xml = xml.trim();
if (!xml.startsWith("<map") || !xml.endsWith("</map>")) {
throw new IllegalArgumentException("Map seems not to be a valid mindmap:"+xml);
}
mindmap.setXmlStr(xml);
// Update map ...

View File

@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.List;
import java.util.Set;
@ -100,7 +101,19 @@ public class MindmapServiceImpl
@Override
public void updateMindmap(@NotNull Mindmap mindMap, boolean saveHistory) throws WiseMappingException {
if (mindMap.getTitle() == null || mindMap.getTitle().length() == 0) {
throw new WiseMappingException("The tile can not be empty");
throw new WiseMappingException("The title can not be empty");
}
// Check that what we received a valid mindmap...
final String xml;
try {
xml = mindMap.getXmlStr().trim();
} catch (UnsupportedEncodingException e) {
throw new WiseMappingException("Could not be decoded.",e);
}
if (!xml.startsWith("<map") || !xml.endsWith("</map>")) {
throw new WiseMappingException("Map seems not to be a valid mindmap:"+xml);
}
mindmapManager.updateMindmap(mindMap, saveHistory);