Package org.vfny.geoserver.config

Examples of org.vfny.geoserver.config.DataConfig


                || action.startsWith("Remove") || action.equals(BBOX)) {
            return errors;
        }

        // Check selected style exists
        DataConfig data = ConfigRequests.getDataConfig(request);

        if (!(data.getStyles().containsKey(styleId) || "".equals(styleId))) {
            errors.add("styleId",
                new ActionError("error.styleId.notFound", styleId));
        }

        // check name exists in current DataStore?
View Full Code Here


        HttpServletResponse response) throws IOException {
       
        DataFeatureTypesNewForm form = (DataFeatureTypesNewForm) incomingForm;
        String selectedNewFeatureType = form.getSelectedNewFeatureType();

        DataConfig dataConfig = (DataConfig) request.getSession()
                                                    .getServletContext()
                                                    .getAttribute(DataConfig.CONFIG_KEY);
        int index = selectedNewFeatureType.indexOf(DataConfig.SEPARATOR);
        String dataStoreID = selectedNewFeatureType.substring(0, index);
        String featureTypeName = selectedNewFeatureType.substring(index
                + DataConfig.SEPARATOR.length());

        DataStoreConfig dsConfig = dataConfig.getDataStore(dataStoreID);
        DataStore dataStore = dsConfig.findDataStore(request.getSession().getServletContext());

        FeatureTypeConfig ftConfig;
        //JD: GEOS-399, wrap rest of method in try catch block in order to
        // report back nicely to app
View Full Code Here

        DataFeatureTypesSelectForm form = (DataFeatureTypesSelectForm) incomingForm;

        String selectedFeatureType = form.getSelectedFeatureTypeName();
        String buttonAction = form.getButtonAction();

        DataConfig dataConfig = (DataConfig) getServlet().getServletContext()
                                                 .getAttribute(DataConfig.CONFIG_KEY);
       
        FeatureTypeConfig ftConfig = dataConfig.getFeatureTypeConfig(selectedFeatureType);
        request.getSession().removeAttribute(DataConfig.SELECTED_ATTRIBUTE_TYPE);
       
        Locale locale = (Locale) request.getLocale();
        MessageResources messages = servlet.getResources();
        String edit = messages.getMessage(locale, "label.edit");
        String delete = messages.getMessage(locale, "label.delete");

        if (edit.equals(buttonAction)) {
            request.getSession().setAttribute(DataConfig.SELECTED_FEATURE_TYPE,
                ftConfig);
           
            user.setFeatureTypeConfig( ftConfig );                      
      LOGGER.info("setting session and user ftConfig to : " + ftConfig);
            return mapping.findForward("config.data.type.editor");
        } else if (delete.equals(buttonAction)) {
            dataConfig.removeFeatureType(selectedFeatureType);
            request.getSession().removeAttribute(DataConfig.SELECTED_FEATURE_TYPE);
            getApplicationState().notifyConfigChanged();

            return mapping.findForward("config.data.type");
        }
View Full Code Here

            HttpServletRequest request,
            HttpServletResponse response)
    throws IOException, ServletException {

        FeatureTypeConfig ftConfig = (FeatureTypeConfig) request.getSession().getAttribute(DataConfig.SELECTED_FEATURE_TYPE);
        DataConfig dataConfig = getDataConfig();
        DataStoreConfig dsConfig = dataConfig.getDataStore(ftConfig.getDataStoreId());
        DataStore dataStore = dsConfig.findDataStore(request.getSession().getServletContext());
        FeatureType featureType = dataStore.getSchema(ftConfig.getName());
        FeatureSource fs = dataStore.getFeatureSource(featureType.getTypeName());
       
        ftConfig.setLatLongBBox(DataStoreUtils.getBoundingBoxEnvelope(fs));
View Full Code Here

*/
public class StylesEditorAction extends ConfigAction {
    public ActionForward execute(ActionMapping mapping, ActionForm form,
        UserContainer user, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {
        DataConfig config = (DataConfig) getDataConfig();
        StylesEditorForm stylesForm = (StylesEditorForm) form;
        FormFile file = stylesForm.getSldFile();
        final String filename = file.getFileName();
        final String styleID = stylesForm.getStyleID();

        StyleConfig style = user.getStyle();
       

       
        boolean doFullValidation = stylesForm.getFullyValidate();
        if (stylesForm.getFullyValidateChecked() == false) {
          doFullValidation = false;
        }
       
        if (doFullValidation)
        {
          List l = getSchemaExceptions(file,request);
          if (l.size() !=0)
          {
            handleValidationErrors(l,file,stylesForm);           
            return mapping.findForward("schemaErrors");
          }
        }

        if (style == null) {
            // Must of bookmarked? Redirect so they can select           
            return mapping.findForward("config.data.style");
        }

 
  ServletContext sc = getServlet().getServletContext();
        //DJB: changed for geoserver_data_dir
        //File rootDir = new File(getServlet().getServletContext().getRealPath("/"));
        File rootDir = GeoserverDataDirectory.getGeoserverDataDirectory(sc);
 
  File styleDir;
  try {
      styleDir = GeoserverDataDirectory.findConfigDir(rootDir, "styles");
  } catch (ConfigurationException cfe) {
            LOGGER.warning("no style dir found, creating new one");
            //if for some bizarre reason we don't fine the dir, make a new one.
            styleDir = new File(rootDir, "styles");
  }
        // send content of FormFile to /styles :
        // there nothing to keep the styles in memory for XMLConfigWriter.store()
        InputStreamReader isr = new InputStreamReader(file.getInputStream());
        File newSldFile = new File(styleDir, filename);

        //here we do a check to see if the file we are trying to upload is
        //overwriting another style file.
        LOGGER.fine("new sld file is: " + newSldFile + ", exists: "
            + newSldFile.exists());

        if (newSldFile.exists()) {
            StyleConfig styleForID = config.getStyle(styleID);

            if (styleForID == null) {
                //if there is already a file at the location (file.exists()), and
                //the system does not have a record of this styleId then it means
                //we are trying to add a new sld at a location that would overwrite
                //another's sld file.
                doFileExistsError(newSldFile, request);

                return mapping.findForward("config.data.style.editor");
            } else {
                //if the system has a record of the file, then we need to check if this
                //update is being performed on the correct style id, so we see if the
                //file in the system is the same as this one. 
                File oldFile = styleForID.getFilename();
                LOGGER.fine("old file: " + oldFile + ", newFile: " + newSldFile);

                if (!oldFile.equals(newSldFile)) {
                    doFileExistsError(newSldFile, request);

                    return mapping.findForward("config.data.style.editor");
                }
            }
        }

        //When we have time we should put this in a temp file, to be safe, before
        //we do the validation, and only write to the real style directory when we
        //have things set.  If only java had a nice file copy utility.
        FileWriter fw = new FileWriter(newSldFile);
        char[] tampon = new char[1024];
        int charsRead;

        while ((charsRead = isr.read(tampon, 0, 1024)) != -1) {
            fw.write(tampon, 0, charsRead);
        }

        fw.flush();
        fw.close();
        isr.close();
        style.setFilename(new File(styleDir, filename));

        style.setId(styleID);

        StyleFactory factory = StyleFactory.createStyleFactory();
        SLDParser styleReader = new SLDParser(factory, newSldFile.toURL());
        Style[] readStyles = null;
        Style newStyle;

        try {
            readStyles = styleReader.readXML();

            if (readStyles.length == 0) {
                //I think our style parser does pretty much no error reporting.
                //This is one of the many reasons we need a new SLD parser.
                //We could add new exceptions to it, but it's really just
                //patching a sinking ship.  One option that we could do
                //here is do a xerces validating parse, to make sure the
                //sld matches the schema before we try to pass it to our
                //crappy parser.
                String message = "The xml was valid, but couldn't get a Style"
                    + " from it.  Make sure your style validates against "
                    + " the SLD schema";
                doStyleParseError(message, newSldFile, request);

                return mapping.findForward("config.data.style.editor");
            }

            newStyle = readStyles[0];
            LOGGER.fine("sld is " + newStyle);
        } catch (Exception e) {
            e.printStackTrace();

            String message = (e.getCause() == null) ? e.getLocalizedMessage()
                                                    : e.getCause()
                                                       .getLocalizedMessage();
            doStyleParseError(message, newSldFile, request);

            return mapping.findForward("config.data.style.editor");
        }

        if (newStyle == null) {
            throw new RuntimeException("new style equals null"); //I don't

            //think this will ever happen, our SLD parser won't return a null.
        }

        // Do configuration parameters here
        config.addStyle(style.getId(), style);
        getApplicationState().notifyConfigChanged();

        return mapping.findForward("config.data.style");
    }
View Full Code Here

TOP

Related Classes of org.vfny.geoserver.config.DataConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.