StyleInfo doCreateStyle(StyleHandler handler, StyleType styleType, ResourceInfo resource) throws IOException { // find a new style name String styleName = generateUniqueStyleName(resource); // variable replacement String styleData = generateStyle(handler, styleType, styleName); // let's store it StyleInfo style = catalog.getFactory().createStyle(); style.setName(styleName); style.setFilename(styleName + "." + handler.getFileExtension()); style.setFormat(handler.getFormat()); if (workspace != null) { style.setWorkspace(workspace); } catalog.getResourcePool().writeStyle(style, new ByteArrayInputStream(styleData.getBytes())); return style; }
/** Keys for overriding default layer properties */ public static class StyleProperty<T> { T get(Map<StyleProperty, Object> map, T def) { return map != null && map.containsKey(this) ? (T) map.get(this) : def; } public static StyleProperty<String> FORMAT = new StyleProperty<String>(); public static StyleProperty<Version> FORMAT_VERSION = new StyleProperty<Version>(); public static StyleProperty<LegendInfo> LEGEND_INFO = new StyleProperty<LegendInfo>(); }
+ "). The style will be converted to CSS."); si.setFilename(filenameCss); si.setFormat("css"); getCatalog().save(si);
info.setFormat(styleHandler.getFormat()); info.setFormatVersion(styleHandler.version(styleFile)); info.setWorkspace(task.getStore().getWorkspace());
@Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // we need to force validation or the value won't be converted styles.processInput(); StyleInfo style = (StyleInfo) styles.getConvertedInput(); if (style != null) { try { // same here, force validation or the field won't be updated stylePage.editor.reset(); stylePage.setRawStyle(stylePage.readFile(style)); stylePage.getStyleInfo().setFormat(style.getFormat()); target.appendJavaScript( String.format( "if (document.gsEditors) { document.gsEditors.editor.setOption('mode', '%s'); }", stylePage.styleHandler().getCodeMirrorEditMode())); clearFeedbackMessages(); } catch (Exception e) { clearFeedbackMessages(); stylePage.error( "Errors occurred loading the '" + style.getName() + "' style"); LOGGER.log( Level.WARNING, "Errors occurred loading the '" + style.getName() + "' style", e); } target.add(stylePage); } } };
/** * Constructs a new StyleInfo object, given a style name and format. * * <p>Note: It is up to the caller to add this style info to the catalog. * * @param workspaceName The workspace of the style, or null for a global style * @param name The name of the style * @param handler StyleHandler, containing format information of the style * @param mimeType Declared mime type of the style * @return A new StyleInfo object, constructed from the provided data * @throws RestException if a style of the given name and workspace already exists in the * catalog. */ private StyleInfo createStyleInfo( String workspaceName, String name, StyleHandler handler, String mimeType) throws RestException { // ensure that the style does not already exist if (catalog.getStyleByName(workspaceName, name) != null) { throw new RestException("Style " + name + " already exists.", HttpStatus.FORBIDDEN); } StyleInfo sinfo = catalog.getFactory().createStyle(); sinfo.setName(name); sinfo.setFilename(name + "." + handler.getFileExtension()); sinfo.setFormat(handler.getFormat()); sinfo.setFormatVersion(handler.versionForMimeType(mimeType)); if (workspaceName != null) { sinfo.setWorkspace(catalog.getWorkspaceByName(workspaceName)); } return sinfo; }
StyleInfo style = new StyleInfoImpl(catalog); style.setName("style-Name"); style.setFormat("sld"); style.setFilename("test_style.sld"); catalog.add(style);
StyleInfo style = getStyleInfo(); String format = style.getFormat(); style.setFormat(format); Version version = Styles.handler(format).version(rawStyle); style.setFormatVersion(version);
StyleInfo si = new StyleInfoImpl(stylePage.getCatalog()); String format = stylePage.getStyleInfo().getFormat(); si.setFormat(format); String styleName = "tmp" + UUID.randomUUID().toString(); String styleFileName =
si.setFormat("SLD"); si.setFormatVersion(new Version("1.0")); si.setName(layerInfo.getName());