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


    1.添加新的数据存储

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

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

    1. public class StorePage extends GeoServerSecuredPage {
    2. StoreProvider provider = new StoreProvider();
    3. StorePanel table;
    4. SelectionRemovalLink removal;
    5. GeoServerDialog dialog;
    6. public StorePage() {
    7. // the table, and wire up selection change
    8. table =
    9. new StorePanel("table", provider, true) {
    10. @Override
    11. protected void onSelectionUpdate(AjaxRequestTarget target) {
    12. removal.setEnabled(table.getSelection().size() > 0);
    13. target.add(removal);
    14. }
    15. };
    16. table.setOutputMarkupId(true);
    17. add(table);
    18. // the confirm dialog
    19. add(dialog = new GeoServerDialog("dialog"));
    20. setHeaderPanel(headerPanel());
    21. }
    22. protected Component headerPanel() {
    23. Fragment header = new Fragment(HEADER_PANEL, "header", this);
    24. // the add button
    25. header.add(new BookmarkablePageLink("addNew", NewDataPage.class));
    26. // the removal button
    27. header.add(removal = new SelectionRemovalLink("removeSelected", table, dialog));
    28. removal.setOutputMarkupId(true);
    29. removal.setEnabled(false);
    30. return header;
    31. }
    32. @Override
    33. protected ComponentAuthorizer getPageAuthorizer() {
    34. return ComponentAuthorizer.WORKSPACE_ADMIN;
    35. }
    36. }

    2.NewDataPage

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

    1. public NewDataPage() {
    2. final boolean thereAreWorkspaces = !getCatalog().getWorkspaces().isEmpty();
    3. if (!thereAreWorkspaces) {
    4. super.error(
    5. (String) new ResourceModel("NewDataPage.noWorkspacesErrorMessage").getObject());
    6. }
    7. final Form storeForm = new Form("storeForm");
    8. add(storeForm);
    9. final ArrayList sortedDsNames =
    10. new ArrayList(getAvailableDataStores().keySet());
    11. Collections.sort(sortedDsNames);
    12. final CatalogIconFactory icons = CatalogIconFactory.get();
    13. final ListView dataStoreLinks =
    14. new ListView("vectorResources", sortedDsNames) {
    15. @Override
    16. protected void populateItem(ListItem item) {
    17. final String dataStoreFactoryName = item.getDefaultModelObjectAsString();
    18. final DataAccessFactory factory =
    19. getAvailableDataStores().get(dataStoreFactoryName);
    20. final String description = factory.getDescription();
    21. SubmitLink link;
    22. link =
    23. new SubmitLink("resourcelink") {
    24. @Override
    25. public void onSubmit() {
    26. setResponsePage(
    27. new DataAccessNewPage(dataStoreFactoryName));
    28. }
    29. };
    30. link.setEnabled(thereAreWorkspaces);
    31. link.add(new Label("resourcelabel", dataStoreFactoryName));
    32. item.add(link);
    33. item.add(new Label("resourceDescription", description));
    34. Image icon = new Image("storeIcon", icons.getStoreIcon(factory.getClass()));
    35. // TODO: icons could provide a description too to be used in alt=...
    36. icon.add(new AttributeModifier("alt", new Model("")));
    37. item.add(icon);
    38. }
    39. };
    40. final List sortedCoverageNames = new ArrayList();
    41. sortedCoverageNames.addAll(getAvailableCoverageStores().keySet());
    42. Collections.sort(sortedCoverageNames);
    43. final ListView coverageLinks =
    44. new ListView("rasterResources", sortedCoverageNames) {
    45. @Override
    46. protected void populateItem(ListItem item) {
    47. final String coverageFactoryName = item.getDefaultModelObjectAsString();
    48. final Map coverages = getAvailableCoverageStores();
    49. Format format = coverages.get(coverageFactoryName);
    50. final String description = format.getDescription();
    51. SubmitLink link;
    52. link =
    53. new SubmitLink("resourcelink") {
    54. @Override
    55. public void onSubmit() {
    56. setResponsePage(
    57. new CoverageStoreNewPage(coverageFactoryName));
    58. }
    59. };
    60. link.setEnabled(thereAreWorkspaces);
    61. link.add(new Label("resourcelabel", coverageFactoryName));
    62. item.add(link);
    63. item.add(new Label("resourceDescription", description));
    64. Image icon = new Image("storeIcon", icons.getStoreIcon(format.getClass()));
    65. // TODO: icons could provide a description too to be used in alt=...
    66. icon.add(new AttributeModifier("alt", new Model("")));
    67. item.add(icon);
    68. }
    69. };
    70. final List otherStores = getOtherStores();
    71. final ListView otherStoresLinks =
    72. new ListView("otherStores", otherStores) {
    73. @Override
    74. protected void populateItem(ListItem item) {
    75. final OtherStoreDescription store =
    76. (OtherStoreDescription) item.getModelObject();
    77. SubmitLink link;
    78. link =
    79. new SubmitLink("resourcelink") {
    80. @Override
    81. public void onSubmit() {
    82. setResponsePage(store.configurationPage);
    83. }
    84. };
    85. link.setEnabled(thereAreWorkspaces);
    86. link.add(
    87. new Label(
    88. "resourcelabel",
    89. new ParamResourceModel(
    90. "other." + store.key, NewDataPage.this)));
    91. item.add(link);
    92. item.add(
    93. new Label(
    94. "resourceDescription",
    95. new ParamResourceModel(
    96. "other." + store.key + ".description",
    97. NewDataPage.this)));
    98. Image icon = new Image("storeIcon", store.icon);
    99. // TODO: icons could provide a description too to be used in alt=...
    100. icon.add(new AttributeModifier("alt", new Model("")));
    101. item.add(icon);
    102. }
    103. };
    104. storeForm.add(dataStoreLinks);
    105. storeForm.add(coverageLinks);
    106. storeForm.add(otherStoresLinks);
    107. }

    这就是我们的NewDataPage页面。

    3.DataAccessNewPage

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

    对应的代码如下所示。

    1. /** */
    2. protected void initUI(final DataStoreInfo storeInfo) throws IllegalArgumentException {
    3. if (storeInfo.getWorkspace() == null) {
    4. throw new IllegalArgumentException("Workspace not provided");
    5. }
    6. final Catalog catalog = getCatalog();
    7. final ResourcePool resourcePool = catalog.getResourcePool();
    8. DataAccessFactory dsFactory;
    9. try {
    10. dsFactory = resourcePool.getDataStoreFactory(storeInfo);
    11. } catch (IOException e) {
    12. String msg =
    13. (String)
    14. new ResourceModel("AbstractDataAccessPage.cantGetDataStoreFactory")
    15. .getObject();
    16. msg += ": " + e.getMessage();
    17. throw new IllegalArgumentException(msg);
    18. }
    19. if (dsFactory == null) {
    20. String msg =
    21. (String)
    22. new ResourceModel("AbstractDataAccessPage.cantGetDataStoreFactory")
    23. .getObject();
    24. throw new IllegalArgumentException(msg);
    25. }
    26. final IModel model = new CompoundPropertyModel(storeInfo);
    27. final Form paramsForm = new Form("dataStoreForm", model);
    28. add(paramsForm);
    29. paramsForm.add(new Label("storeType", dsFactory.getDisplayName()));
    30. paramsForm.add(new Label("storeTypeDescription", dsFactory.getDescription()));
    31. {
    32. final IModel wsModel = new PropertyModel(model, "workspace");
    33. final IModel wsLabelModel = new ResourceModel("workspace", "Workspace");
    34. workspacePanel = new WorkspacePanel("workspacePanel", wsModel, wsLabelModel, true);
    35. }
    36. paramsForm.add(workspacePanel);
    37. final TextParamPanel dataStoreNamePanel;
    38. dataStoreNamePanel =
    39. new TextParamPanel(
    40. "dataStoreNamePanel",
    41. new PropertyModel(model, "name"),
    42. new ResourceModel("AbstractDataAccessPage.dataSrcName", "Data Source Name"),
    43. true);
    44. paramsForm.add(dataStoreNamePanel);
    45. paramsForm.add(
    46. new TextParamPanel(
    47. "dataStoreDescriptionPanel",
    48. new PropertyModel(model, "description"),
    49. new ResourceModel("AbstractDataAccessPage.description", "Description"),
    50. false,
    51. (IValidator[]) null));
    52. paramsForm.add(
    53. new CheckBoxParamPanel(
    54. "dataStoreEnabledPanel",
    55. new PropertyModel(model, "enabled"),
    56. new ResourceModel("enabled", "Enabled")));
    57. {
    58. /*
    59. * Here's where the extension point is applied in order to give extensions a chance to
    60. * provide custom behavior/components for the coverage form other than the default
    61. * single "url" input field
    62. */
    63. GeoServerApplication app = getGeoServerApplication();
    64. storeEditPanel =
    65. StoreExtensionPoints.getStoreEditPanel(
    66. "parametersPanel", paramsForm, storeInfo, app);
    67. }
    68. paramsForm.add(storeEditPanel);
    69. paramsForm.add(new FeedbackPanel("feedback"));
    70. // validate the selected workspace does not already contain a store with the same name
    71. final String dataStoreInfoId = storeInfo.getId();
    72. StoreNameValidator storeNameValidator =
    73. new StoreNameValidator(
    74. workspacePanel.getFormComponent(),
    75. dataStoreNamePanel.getFormComponent(),
    76. dataStoreInfoId);
    77. paramsForm.add(storeNameValidator);
    78. paramsForm.add(new BookmarkablePageLink("cancel", StorePage.class));
    79. paramsForm.add(
    80. new AjaxSubmitLink("save", paramsForm) {
    81. private static final long serialVersionUID = 1L;
    82. @Override
    83. protected void onError(AjaxRequestTarget target, Form form) {
    84. super.onError(target, form);
    85. target.add(paramsForm);
    86. }
    87. @Override
    88. protected void onSubmit(AjaxRequestTarget target, Form form) {
    89. try {
    90. DataStoreInfo dataStore = (DataStoreInfo) form.getModelObject();
    91. onSaveDataStore(dataStore, target, true);
    92. } catch (IllegalArgumentException e) {
    93. paramsForm.error(e.getMessage());
    94. target.add(paramsForm);
    95. }
    96. }
    97. });
    98. paramsForm.add(applyLink(paramsForm));
    99. // save the namespace panel as an instance variable. Needed as per GEOS-3149
    100. makeNamespaceSyncUpWithWorkspace(paramsForm);
    101. }

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

  • 相关阅读:
    图扑智慧电力可视化大屏,赋能虚拟电厂精准减碳
    sql server算术
    20. 如何使用 ABAP 代码消费需要传递 CSRF token 的 OData 服务
    【力扣每日一题】2023.9.12 课程表Ⅳ
    大学生HTML个人网页作业作品:基于html css实现围棋网页(带报告4800字)
    DAY48
    统计字符出现次数类Counter
    【OpenCV】 人脸识别
    git clone失败
    使用.NET简单实现一个Redis的高性能克隆版(六)
  • 原文地址:https://blog.csdn.net/u010608964/article/details/110420700