Skip to content

Commit

Permalink
TEIIDDES-2141 removed connection check for updateState() and replaced…
Browse files Browse the repository at this point in the history
… with simple URL validation
  • Loading branch information
blafond committed May 6, 2014
1 parent cae066b commit 1d25b22
Showing 1 changed file with 34 additions and 37 deletions.
Expand Up @@ -9,11 +9,12 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -43,7 +44,6 @@
import org.eclipse.ui.progress.UIJob;
import org.teiid.designer.datatools.ui.DatatoolsUiConstants;
import org.teiid.designer.ui.common.util.WidgetFactory;
import org.teiid.designer.ui.common.viewsupport.UiBusyIndicator;


public class XmlUrlProfileDetailsWizardPage extends ConnectionProfileDetailsPage
Expand All @@ -58,12 +58,16 @@ public class XmlUrlProfileDetailsWizardPage extends ConnectionProfileDetailsPag
private Text descriptionText;
private Label urlLabel;
private Text urlText;

private URLValidator urlValidator;
/**
* @param wizardPageName
*/
public XmlUrlProfileDetailsWizardPage( String pageName ) {
super(pageName, UTIL.getString("XmlUrlProfileDetailsWizardPage.Name"), //$NON-NLS-1$
AbstractUIPlugin.imageDescriptorFromPlugin(DatatoolsUiConstants.PLUGIN_ID, "icons/ldap.gif")); //$NON-NLS-1$

this.urlValidator = new URLValidator();
}

@Override
Expand Down Expand Up @@ -183,42 +187,34 @@ void updateState() {
setErrorMessage(UTIL.getString("Common.URL.Error.Message")); //$NON-NLS-1$
return;
}
setErrorMessage(null);

final Display display = getControl().getDisplay();
UiBusyIndicator.showWhile(display, new Runnable() {

@Override
public void run() {
// Check to see if URL is a parseable xml file, regardless of extension
final String urlString = properties.get(IXmlProfileConstants.URL_PROP_ID).toString();
final String[] errorMessage = new String[1];
// Check URL
String urlStatus = this.urlValidator.isValidValue(this.urlText.getText());
if( urlStatus != null ) {
this.setErrorMessage(urlStatus);
return;
}

try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
dBuilder.parse(new URL(urlString).openStream());
} catch (Exception ex) {
errorMessage[0] = UTIL.getString("XmlUrlProfileDetailsWizardPage.InvalidXml.Message", urlString, ex.getMessage()); //$NON-NLS-1$
}

setPingButtonEnabled(true);
setErrorMessage(null);
setPageComplete(true);
setMessage(UTIL.getString("Click.Next.or.Finish")); //$NON-NLS-1$
}

class URLValidator implements Serializable {
/**
*/
private static final long serialVersionUID = -4756137226908808631L;

display.syncExec(new Runnable() {
@Override
public void run() {
setPingButtonEnabled(true);

if(errorMessage[0] != null) {
setErrorMessage(errorMessage[0]);
return;
}

setErrorMessage(null);
setPageComplete(true);
setMessage(UTIL.getString("Click.Next.or.Finish")); //$NON-NLS-1$
}
});
public String isValidValue( String value ) {
try {
new URL(value.toString());
} catch (MalformedURLException e) {
return e.getMessage();
}
});
return null;
}
}

/**
Expand Down Expand Up @@ -252,7 +248,8 @@ private boolean internalComplete(boolean complete) {
*
* @see org.eclipse.datatools.connectivity.internal.ui.wizards.BaseWizardPage#getSummaryData()
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public List getSummaryData() {
List result = super.getSummaryData();
result.add(new String[] {UTIL.getString("Common.URL.Label"), urlText.getText()}); //$NON-NLS-1$
Expand Down Expand Up @@ -319,7 +316,7 @@ protected IStatus run( IProgressMonitor monitor ) {
return Status.OK_STATUS;
}

public Exception testXmlUrlConnection( IConnectionProfile icp ) {
public Exception testXmlUrlConnection( IConnectionProfile icp ) {
Properties connProperties = icp.getBaseProperties();
//InputStream not provided, check XML file
String xmlFile = connProperties == null ? null :(String) connProperties.get( IXmlProfileConstants.URL_PROP_ID );
Expand Down

0 comments on commit 1d25b22

Please sign in to comment.