(三十三)geoserver源码&添加新的数据存储

1.添加新的数据存储

如下图所示,为我们经常操作的添加数据存储的界面

可以看到这个代码在如下的位置。在这样的代码中实现跳转。header.add(new BookmarkablePageLink("addNew", NewDataPage.class));

public class StorePage extends GeoServerSecuredPage {
    StoreProvider provider = new StoreProvider();

    StorePanel table;

    SelectionRemovalLink removal;

    GeoServerDialog dialog;

    public StorePage() {
        // the table, and wire up selection change
        table =
                new StorePanel("table", provider, true) {
                    @Override
                    protected void onSelectionUpdate(AjaxRequestTarget target) {
                        removal.setEnabled(table.getSelection().size() > 0);
                        target.add(removal);
                    }
                };
        table.setOutputMarkupId(true);
        add(table);

        // the confirm dialog
        add(dialog = new GeoServerDialog("dialog"));
        setHeaderPanel(headerPanel());
    }

    protected Component headerPanel() {
        Fragment header = new Fragment(HEADER_PANEL, "header", this);

        // the add button
        header.add(new BookmarkablePageLink("addNew", NewDataPage.class));

        // the removal button
        header.add(removal = new SelectionRemovalLink("removeSelected", table, dialog));
        removal.setOutputMarkupId(true);
        removal.setEnabled(false);

        return header;
    }

    @Override
    protected ComponentAuthorizer getPageAuthorizer() {
        return ComponentAuthorizer.WORKSPACE_ADMIN;
    }
}

2.NewDataPage

进入到NewDataPage页面,进行初始化数据类型,分别为矢量、栅格、以及其他的数据。

    public NewDataPage() {

        final boolean thereAreWorkspaces = !getCatalog().getWorkspaces().isEmpty();

        if (!thereAreWorkspaces) {
            super.error(
                    (String) new ResourceModel("NewDataPage.noWorkspacesErrorMessage").getObject());
        }

        final Form storeForm = new Form("storeForm");
        add(storeForm);

        final ArrayList<String> sortedDsNames =
                new ArrayList<String>(getAvailableDataStores().keySet());
        Collections.sort(sortedDsNames);

        final CatalogIconFactory icons = CatalogIconFactory.get();
        final ListView dataStoreLinks =
                new ListView("vectorResources", sortedDsNames) {
                    @Override
                    protected void populateItem(ListItem item) {
                        final String dataStoreFactoryName = item.getDefaultModelObjectAsString();
                        final DataAccessFactory factory =
                                getAvailableDataStores().get(dataStoreFactoryName);
                        final String description = factory.getDescription();
                        SubmitLink link;
                        link =
                                new SubmitLink("resourcelink") {
                                    @Override
                                    public void onSubmit() {
                                        setResponsePage(
                                                new DataAccessNewPage(dataStoreFactoryName));
                                    }
                                };
                        link.setEnabled(thereAreWorkspaces);
                        link.add(new Label("resourcelabel", dataStoreFactoryName));
                        item.add(link);
                        item.add(new Label("resourceDescription", description));
                        Image icon = new Image("storeIcon", icons.getStoreIcon(factory.getClass()));
                        // TODO: icons could provide a description too to be used in alt=...
                        icon.add(new AttributeModifier("alt", new Model("")));
                        item.add(icon);
                    }
                };

        final List<String> sortedCoverageNames = new ArrayList<String>();
        sortedCoverageNames.addAll(getAvailableCoverageStores().keySet());
        Collections.sort(sortedCoverageNames);

        final ListView coverageLinks =
                new ListView("rasterResources", sortedCoverageNames) {
                    @Override
                    protected void populateItem(ListItem item) {
                        final String coverageFactoryName = item.getDefaultModelObjectAsString();
                        final Map<String, Format> coverages = getAvailableCoverageStores();
                        Format format = coverages.get(coverageFactoryName);
                        final String description = format.getDescription();
                        SubmitLink link;
                        link =
                                new SubmitLink("resourcelink") {
                                    @Override
                                    public void onSubmit() {
                                        setResponsePage(
                                                new CoverageStoreNewPage(coverageFactoryName));
                                    }
                                };
                        link.setEnabled(thereAreWorkspaces);
                        link.add(new Label("resourcelabel", coverageFactoryName));
                        item.add(link);
                        item.add(new Label("resourceDescription", description));
                        Image icon = new Image("storeIcon", icons.getStoreIcon(format.getClass()));
                        // TODO: icons could provide a description too to be used in alt=...
                        icon.add(new AttributeModifier("alt", new Model("")));
                        item.add(icon);
                    }
                };

        final List<OtherStoreDescription> otherStores = getOtherStores();

        final ListView otherStoresLinks =
                new ListView("otherStores", otherStores) {
                    @Override
                    protected void populateItem(ListItem item) {
                        final OtherStoreDescription store =
                                (OtherStoreDescription) item.getModelObject();
                        SubmitLink link;
                        link =
                                new SubmitLink("resourcelink") {
                                    @Override
                                    public void onSubmit() {
                                        setResponsePage(store.configurationPage);
                                    }
                                };
                        link.setEnabled(thereAreWorkspaces);
                        link.add(
                                new Label(
                                        "resourcelabel",
                                        new ParamResourceModel(
                                                "other." + store.key, NewDataPage.this)));
                        item.add(link);
                        item.add(
                                new Label(
                                        "resourceDescription",
                                        new ParamResourceModel(
                                                "other." + store.key + ".description",
                                                NewDataPage.this)));
                        Image icon = new Image("storeIcon", store.icon);
                        // TODO: icons could provide a description too to be used in alt=...
                        icon.add(new AttributeModifier("alt", new Model("")));
                        item.add(icon);
                    }
                };

        storeForm.add(dataStoreLinks);
        storeForm.add(coverageLinks);
        storeForm.add(otherStoresLinks);
    }

这就是我们的NewDataPage页面。

3.DataAccessNewPage

当点击进入到shp的发布界面如下所示。

对应的代码如下所示。

    /** */
    protected void initUI(final DataStoreInfo storeInfo) throws IllegalArgumentException {

        if (storeInfo.getWorkspace() == null) {
            throw new IllegalArgumentException("Workspace not provided");
        }

        final Catalog catalog = getCatalog();
        final ResourcePool resourcePool = catalog.getResourcePool();
        DataAccessFactory dsFactory;
        try {
            dsFactory = resourcePool.getDataStoreFactory(storeInfo);
        } catch (IOException e) {
            String msg =
                    (String)
                            new ResourceModel("AbstractDataAccessPage.cantGetDataStoreFactory")
                                    .getObject();
            msg += ": " + e.getMessage();
            throw new IllegalArgumentException(msg);
        }
        if (dsFactory == null) {
            String msg =
                    (String)
                            new ResourceModel("AbstractDataAccessPage.cantGetDataStoreFactory")
                                    .getObject();
            throw new IllegalArgumentException(msg);
        }

        final IModel model = new CompoundPropertyModel(storeInfo);

        final Form paramsForm = new Form("dataStoreForm", model);
        add(paramsForm);

        paramsForm.add(new Label("storeType", dsFactory.getDisplayName()));
        paramsForm.add(new Label("storeTypeDescription", dsFactory.getDescription()));

        {
            final IModel wsModel = new PropertyModel(model, "workspace");
            final IModel wsLabelModel = new ResourceModel("workspace", "Workspace");
            workspacePanel = new WorkspacePanel("workspacePanel", wsModel, wsLabelModel, true);
        }
        paramsForm.add(workspacePanel);

        final TextParamPanel dataStoreNamePanel;

        dataStoreNamePanel =
                new TextParamPanel(
                        "dataStoreNamePanel",
                        new PropertyModel(model, "name"),
                        new ResourceModel("AbstractDataAccessPage.dataSrcName", "Data Source Name"),
                        true);
        paramsForm.add(dataStoreNamePanel);

        paramsForm.add(
                new TextParamPanel(
                        "dataStoreDescriptionPanel",
                        new PropertyModel(model, "description"),
                        new ResourceModel("AbstractDataAccessPage.description", "Description"),
                        false,
                        (IValidator[]) null));

        paramsForm.add(
                new CheckBoxParamPanel(
                        "dataStoreEnabledPanel",
                        new PropertyModel(model, "enabled"),
                        new ResourceModel("enabled", "Enabled")));

        {
            /*
             * Here's where the extension point is applied in order to give extensions a chance to
             * provide custom behavior/components for the coverage form other than the default
             * single "url" input field
             */
            GeoServerApplication app = getGeoServerApplication();
            storeEditPanel =
                    StoreExtensionPoints.getStoreEditPanel(
                            "parametersPanel", paramsForm, storeInfo, app);
        }
        paramsForm.add(storeEditPanel);

        paramsForm.add(new FeedbackPanel("feedback"));

        // validate the selected workspace does not already contain a store with the same name
        final String dataStoreInfoId = storeInfo.getId();
        StoreNameValidator storeNameValidator =
                new StoreNameValidator(
                        workspacePanel.getFormComponent(),
                        dataStoreNamePanel.getFormComponent(),
                        dataStoreInfoId);
        paramsForm.add(storeNameValidator);

        paramsForm.add(new BookmarkablePageLink("cancel", StorePage.class));

        paramsForm.add(
                new AjaxSubmitLink("save", paramsForm) {
                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void onError(AjaxRequestTarget target, Form form) {
                        super.onError(target, form);
                        target.add(paramsForm);
                    }

                    @Override
                    protected void onSubmit(AjaxRequestTarget target, Form form) {
                        try {
                            DataStoreInfo dataStore = (DataStoreInfo) form.getModelObject();
                            onSaveDataStore(dataStore, target, true);
                        } catch (IllegalArgumentException e) {
                            paramsForm.error(e.getMessage());
                            target.add(paramsForm);
                        }
                    }
                });

        paramsForm.add(applyLink(paramsForm));

        // save the namespace panel as an instance variable. Needed as per GEOS-3149
        makeNamespaceSyncUpWithWorkspace(paramsForm);
    }

这里看到数据的初始化流程。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yGIS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值