Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0f6f173ccd385537c1ac090470763685c1f7c191 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.ws.internal.explorer.platform.uddi.actions;

import java.io.BufferedReader;
import java.io.StringReader;
import java.text.ParseException;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Controller;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.FormToolPropertiesInterface;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.MessageQueue;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.constants.UDDIActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.CategoryModel;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.datamodel.RegistryElement;
import org.eclipse.wst.ws.internal.explorer.platform.uddi.perspective.UDDIPerspective;
import org.eclipse.wst.ws.internal.explorer.platform.util.MultipartFormDataException;
import org.eclipse.wst.ws.internal.explorer.platform.util.MultipartFormDataParser;
import org.eclipse.wst.ws.internal.explorer.platform.util.Validator;

public class UpdateRegistryAction extends UpdateAction
{
  public UpdateRegistryAction(Controller controller)
  {
    super(controller,false);
  }
  
  protected boolean processOthers(MultipartFormDataParser parser,FormToolPropertiesInterface formToolPI) throws MultipartFormDataException
  {
    String nameModifiedState = parser.getParameter(UDDIActionInputs.NAME_MODIFIED);
    String name = parser.getParameter(UDDIActionInputs.QUERY_INPUT_ADVANCED_REGISTRY_NAME);
    String[] userDefinedCategoryTModelKeys = parser.getParameterValues(UDDIActionInputs.CATEGORY_TMODEL_KEY);
    String[] userDefinedCategoryData = parser.getParameterValues(UDDIActionInputs.CATEGORY_FILENAME);
    
    boolean inputsValid = true;
    UDDIPerspective uddiPerspective = controller_.getUDDIPerspective();
    MessageQueue messageQueue = uddiPerspective.getMessageQueue();
    
    if (nameModifiedState != null && name != null)
    {
      boolean isModified = Boolean.valueOf(nameModifiedState).booleanValue();
      String newName;
      if (isModified)
        newName = name;
      else
        newName = (String)formToolPI.getProperty(UDDIActionInputs.QUERY_INPUT_ADVANCED_REGISTRY_NAME);
      propertyTable_.put(UDDIActionInputs.QUERY_INPUT_ADVANCED_REGISTRY_NAME,newName);
      if (!Validator.validateString(name))
      {
        inputsValid = false;
        formToolPI.flagError(UDDIActionInputs.QUERY_INPUT_ADVANCED_REGISTRY_NAME);
        messageQueue.addMessage(uddiPerspective.getMessage("MSG_ERROR_INVALID_NAME"));
      }
    }
    else
      removeProperty(UDDIActionInputs.QUERY_INPUT_ADVANCED_REGISTRY_NAME);
    
    if (userDefinedCategoryTModelKeys != null && userDefinedCategoryData != null)
    {
      RegistryElement regElement = (RegistryElement)regNode_.getTreeElement();
      for (int i=0;i<userDefinedCategoryTModelKeys.length;i++)
      {
        CategoryModel userDefinedCategory = regElement.getUserDefinedCategory(userDefinedCategoryTModelKeys[i]);
//      TODO: Move UDDIPreferenceContext down to org.eclipse.wst.ws 
//      UDDIPreferenceContext context = WebServicePlugin.getInstance().getUDDIPreferenceContext();        
//      userDefinedCategory.setColumnDelimiter(context.getUddiCatDataColumnDelimiter());
//      userDefinedCategory.setStringDelimiter(context.getUddiCatDataStringDelimiter());
        userDefinedCategory.setColumnDelimiter("#");
        userDefinedCategory.setStringDelimiter("\"");
        String displayName = userDefinedCategory.getDisplayName();
        if (userDefinedCategoryData[i] == null || userDefinedCategoryData[i].length() < 1)
        {
          inputsValid = false;
          messageQueue.addMessage(uddiPerspective.getMessage("MSG_ERROR_INVALID_USER_DEFINED_CATEGORY_DATA_FILE",displayName));
          formToolPI.flagRowError(UDDIActionInputs.USER_DEFINED_CATEGORIES,userDefinedCategoryTModelKeys[i]);
        }
        else
        {
          byte rc = userDefinedCategory.loadData(new BufferedReader(new StringReader(userDefinedCategoryData[i])));
          switch (rc)
          {
            case CategoryModel.OPERATION_SUCCESSFUL:
              messageQueue.addMessage(uddiPerspective.getMessage("MSG_INFO_USER_DEFINED_CATEGORY_DATA_LOADED",displayName));
              break;
            case CategoryModel.ERROR_FILE:
              inputsValid = false;
              ParseException pe = (ParseException)userDefinedCategory.getErrorException();
              String[] args1 = {String.valueOf(pe.getErrorOffset()),displayName,pe.getMessage(),userDefinedCategory.getCategoryKey()};
              messageQueue.addMessage(uddiPerspective.getMessage("MSG_ERROR_INVALID_USER_DEFINED_CATEGORY_DATA_FILE_FORMAT",args1));
              formToolPI.flagRowError(UDDIActionInputs.USER_DEFINED_CATEGORIES,userDefinedCategoryTModelKeys[i]);
              break;              
            case CategoryModel.ERROR_CATEGORY_KEY:
            default:
              inputsValid = false;
              String[] args2 = {displayName,userDefinedCategory.getErrorException().getMessage(),userDefinedCategory.getCategoryKey()};
              messageQueue.addMessage(uddiPerspective.getMessage("MSG_ERROR_INVALID_USER_DEFINED_CATEGORY_DATA_FILE_KEY",args2));
              formToolPI.flagRowError(UDDIActionInputs.USER_DEFINED_CATEGORIES,userDefinedCategoryTModelKeys[i]);              
          }
        }
      }
    }
    return inputsValid;
  }

  public final boolean refreshFromRegistry()
  {
    return true;
  }
  
  public final boolean run()
  {
    UDDIPerspective uddiPerspective = controller_.getUDDIPerspective();
    MessageQueue messageQueue = uddiPerspective.getMessageQueue();
    String name = (String)propertyTable_.get(UDDIActionInputs.QUERY_INPUT_ADVANCED_REGISTRY_NAME);
    RegistryElement regElement = (RegistryElement)regNode_.getTreeElement();
    regElement.setName(name);
    regNode_.getTreeElement().setName(name);
    messageQueue.addMessage(uddiPerspective.getMessage("MSG_INFO_REGISTRY_UPDATED",name));
    return true;
  }
}

Back to the top