=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FileController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FileController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FileController.java 2014-07-08 19:02:06 +0000 @@ -0,0 +1,130 @@ +package org.hisp.dhis.webapi.controller; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.io.IOException; +import java.io.Writer; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.hisp.dhis.setting.SystemSettingManager; +import org.hisp.dhis.webapi.utils.ContextUtils; +import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * @author Lars Helge Overland + */ +@Controller +@RequestMapping( value = FileController.RESOURCE_PATH ) +public class FileController +{ + public static final String RESOURCE_PATH = "/files"; + + private static final String KEY_CUSTOM_JS = "keyCustomJs"; + private static final String KEY_CUSTOM_CSS = "keyCustomCss"; + + @Autowired + private SystemSettingManager systemSettingManager; + + @Autowired + private ContextUtils contextUtils; + + // ------------------------------------------------------------------------- + // Custom script + // ------------------------------------------------------------------------- + + @RequestMapping( value = "/script", method = RequestMethod.GET ) + public void getCustomScript( HttpServletResponse response, Writer writer ) + throws IOException + { + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JAVASCRIPT, CacheStrategy.CACHE_TWO_WEEKS ); + + String content = (String) systemSettingManager.getSystemSetting( KEY_CUSTOM_JS, StringUtils.EMPTY ); + + writer.write( content ); + } + + @PreAuthorize( "hasRole('ALL')" ) + @RequestMapping( value = "/script", method = RequestMethod.POST, consumes = "application/javascript" ) + public void postCustomScript( @RequestBody String content, HttpServletResponse response ) + { + if ( content != null ) + { + systemSettingManager.saveSystemSetting( KEY_CUSTOM_JS, content ); + ContextUtils.okResponse( response, "Custom script created" ); + } + } + + @PreAuthorize( "hasRole('ALL')" ) + @RequestMapping( value = "/script", method = RequestMethod.DELETE ) + public void removeCustomScript( HttpServletResponse response ) + { + systemSettingManager.deleteSystemSetting( KEY_CUSTOM_JS ); + } + + // ------------------------------------------------------------------------- + // Custom style + // ------------------------------------------------------------------------- + + @RequestMapping( value = "/style", method = RequestMethod.GET ) + public void getCustomStyle( HttpServletResponse response, Writer writer ) + throws IOException + { + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSS, CacheStrategy.CACHE_TWO_WEEKS ); + + String content = (String) systemSettingManager.getSystemSetting( KEY_CUSTOM_CSS, StringUtils.EMPTY ); + + writer.write( content ); + } + + @PreAuthorize( "hasRole('ALL')" ) + @RequestMapping( value = "/style", method = RequestMethod.POST, consumes = { "text/html", "text/plain", "text/css" } ) + public void postCustomStyle( @RequestBody String content, HttpServletResponse response ) + { + if ( content != null ) + { + systemSettingManager.saveSystemSetting( KEY_CUSTOM_CSS, content ); + ContextUtils.okResponse( response, "Custom style created" ); + } + } + + @PreAuthorize( "hasRole('ALL')" ) + @RequestMapping( value = "/style", method = RequestMethod.DELETE ) + public void removeCustomStyle( HttpServletResponse response ) + { + systemSettingManager.deleteSystemSetting( KEY_CUSTOM_CSS ); + } +} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextUtils.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextUtils.java 2014-07-08 16:48:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextUtils.java 2014-07-08 19:02:06 +0000 @@ -68,6 +68,7 @@ public static final String CONTENT_TYPE_JSON = "application/json; charset=UTF-8"; public static final String CONTENT_TYPE_HTML = "text/html; charset=UTF-8"; public static final String CONTENT_TYPE_TEXT = "text/plain; charset=UTF-8"; + public static final String CONTENT_TYPE_CSS = "text/css; charset=UTF-8"; public static final String CONTENT_TYPE_XML = "application/xml; charset=UTF-8"; public static final String CONTENT_TYPE_CSV = "application/csv; charset=UTF-8"; public static final String CONTENT_TYPE_PNG = "image/png"; === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2014-06-26 14:38:54 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2014-07-08 19:02:06 +0000 @@ -18,6 +18,7 @@ #foreach ( $style in $stylesheets ) #end + - #if( $keyCalendar == "coptic" || $keyCalendar == "ethiopian" || $keyCalendar == "islamic" || $keyCalendar == "julian" || $keyCalendar == "nepali" || $keyCalendar == "thai" ) - + #end - - @@ -87,6 +85,7 @@ #foreach( $javascript in $javascripts ) #end +