[200441] Create XML File, New WSDL File, and Create XML Schema wizards overwrite linked files w/o confirmation
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java index f4a929a..6552d9c 100644 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java +++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2012 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 @@ -121,36 +121,37 @@ // if there was problem with creating file, it will be null, so make // sure to check if (file != null) { - // put template contents into file - String templateString = fNewFileTemplatesPage.getTemplateString(); - if (templateString != null) { - templateString = applyLineDelimiter(file, templateString); - // determine the encoding for the new file - Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences(); - String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - OutputStreamWriter outputStreamWriter = null; - if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ - // just use default encoding - outputStreamWriter = new OutputStreamWriter(outputStream); + if (!file.isLinked()) { + // put template contents into file + String templateString = fNewFileTemplatesPage.getTemplateString(); + if (templateString != null) { + templateString = applyLineDelimiter(file, templateString); + // determine the encoding for the new file + Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences(); + String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); + + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = null; + if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ + // just use default encoding + outputStreamWriter = new OutputStreamWriter(outputStream); + } + else { + outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + } + outputStreamWriter.write(templateString); + outputStreamWriter.flush(); + outputStreamWriter.close(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + file.setContents(inputStream, true, false, null); + inputStream.close(); } - else { - outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + catch (Exception e) { + Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new JSP file", e); //$NON-NLS-1$ } - outputStreamWriter.write(templateString); - outputStreamWriter.flush(); - outputStreamWriter.close(); - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - file.setContents(inputStream, true, false, null); - inputStream.close(); - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new JSP file", e); //$NON-NLS-1$ } } - // open the file in editor if (fShouldOpenEditorOnFinish) openEditor(file);
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewTagWizard.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewTagWizard.java index 382714c..20fed11 100644 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewTagWizard.java +++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewTagWizard.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. + * Copyright (c) 2005, 2012 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 @@ -104,36 +104,37 @@ // if there was problem with creating file, it will be null, so make // sure to check if (file != null) { - // put template contents into file - String templateString = fNewFileTemplatesPage.getTemplateString(); - if (templateString != null) { - templateString = applyLineDelimiter(file, templateString); - // determine the encoding for the new file - Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences(); - String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - OutputStreamWriter outputStreamWriter = null; - if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ - // just use default encoding - outputStreamWriter = new OutputStreamWriter(outputStream); + if (!file.isLinked()) { + // put template contents into file + String templateString = fNewFileTemplatesPage.getTemplateString(); + if (templateString != null) { + templateString = applyLineDelimiter(file, templateString); + // determine the encoding for the new file + Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences(); + String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); + + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = null; + if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ + // just use default encoding + outputStreamWriter = new OutputStreamWriter(outputStream); + } + else { + outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + } + outputStreamWriter.write(templateString); + outputStreamWriter.flush(); + outputStreamWriter.close(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + file.setContents(inputStream, true, false, null); + inputStream.close(); } - else { - outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + catch (Exception e) { + Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new Tag file", e); //$NON-NLS-1$ } - outputStreamWriter.write(templateString); - outputStreamWriter.flush(); - outputStreamWriter.close(); - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - file.setContents(inputStream, true, false, null); - inputStream.close(); - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new Tag file", e); //$NON-NLS-1$ } } - // open the file in editor openEditor(file);
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java index 62b456d..8ab0d4a 100644 --- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java +++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. + * Copyright (c) 2005, 2012 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 @@ -104,33 +104,35 @@ // if there was problem with creating file, it will be null, so make // sure to check if (file != null) { - // put template contents into file - String templateString = fNewFileTemplatesPage.getTemplateString(); - if (templateString != null) { - templateString = applyLineDelimiter(file, templateString); - // determine the encoding for the new file - Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences(); - String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - OutputStreamWriter outputStreamWriter = null; - if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ - // just use default encoding - outputStreamWriter = new OutputStreamWriter(outputStream); + if (!file.isLinked()) { + // put template contents into file + String templateString = fNewFileTemplatesPage.getTemplateString(); + if (templateString != null) { + templateString = applyLineDelimiter(file, templateString); + // determine the encoding for the new file + Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences(); + String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); + + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = null; + if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ + // just use default encoding + outputStreamWriter = new OutputStreamWriter(outputStream); + } + else { + outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + } + outputStreamWriter.write(templateString); + outputStreamWriter.flush(); + outputStreamWriter.close(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + file.setContents(inputStream, true, false, null); + inputStream.close(); } - else { - outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + catch (Exception e) { + Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new CSS file", e); //$NON-NLS-1$ } - outputStreamWriter.write(templateString); - outputStreamWriter.flush(); - outputStreamWriter.close(); - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - file.setContents(inputStream, true, false, null); - inputStream.close(); - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new CSS file", e); //$NON-NLS-1$ } } // open the file in editor
diff --git a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/wizard/NewDTDWizard.java b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/wizard/NewDTDWizard.java index 637811c..c73a603 100644 --- a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/wizard/NewDTDWizard.java +++ b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/wizard/NewDTDWizard.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2012 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 @@ -249,35 +249,36 @@ // if there was problem with creating file, it will be null, so make // sure to check if (file != null) { - // put template contents into file - String templateString = fNewFileTemplatesPage.getTemplateString(); - if (templateString != null) { - templateString = applyLineDelimiter(file, templateString); - // determine the encoding for the new file - String charSet = getAppropriateCharset(); - - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - OutputStreamWriter outputStreamWriter = null; - if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ - // just use default encoding - outputStreamWriter = new OutputStreamWriter(outputStream); + if (!file.isLinked()) { + // put template contents into file + String templateString = fNewFileTemplatesPage.getTemplateString(); + if (templateString != null) { + templateString = applyLineDelimiter(file, templateString); + // determine the encoding for the new file + String charSet = getAppropriateCharset(); + + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = null; + if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ + // just use default encoding + outputStreamWriter = new OutputStreamWriter(outputStream); + } + else { + outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + } + outputStreamWriter.write(templateString); + outputStreamWriter.flush(); + outputStreamWriter.close(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + file.setContents(inputStream, true, false, null); + inputStream.close(); } - else { - outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + catch (Exception e) { + Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new DTD file", e); //$NON-NLS-1$ } - outputStreamWriter.write(templateString); - outputStreamWriter.flush(); - outputStreamWriter.close(); - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - file.setContents(inputStream, true, false, null); - inputStream.close(); - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new DTD file", e); //$NON-NLS-1$ } } - // open the file in editor openEditor(file);
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java index 77c52f1..d05cca3 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java
@@ -104,36 +104,37 @@ // if there was problem with creating file, it will be null, so make // sure to check if (file != null) { - // put template contents into file - String templateString = fNewFileTemplatesPage.getTemplateString(); - if (templateString != null) { - templateString = applyLineDelimiter(file, templateString); - // determine the encoding for the new file - Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences(); - String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - OutputStreamWriter outputStreamWriter = null; - if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ - // just use default encoding - outputStreamWriter = new OutputStreamWriter(outputStream); + if (!file.isLinked()) { + // put template contents into file + String templateString = fNewFileTemplatesPage.getTemplateString(); + if (templateString != null) { + templateString = applyLineDelimiter(file, templateString); + // determine the encoding for the new file + Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences(); + String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); + + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + OutputStreamWriter outputStreamWriter = null; + if (charSet == null || charSet.trim().equals("")) { //$NON-NLS-1$ + // just use default encoding + outputStreamWriter = new OutputStreamWriter(outputStream); + } + else { + outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + } + outputStreamWriter.write(templateString); + outputStreamWriter.flush(); + outputStreamWriter.close(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); + file.setContents(inputStream, true, false, null); + inputStream.close(); } - else { - outputStreamWriter = new OutputStreamWriter(outputStream, charSet); + catch (Exception e) { + Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new HTML file", e); //$NON-NLS-1$ } - outputStreamWriter.write(templateString); - outputStreamWriter.flush(); - outputStreamWriter.close(); - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - file.setContents(inputStream, true, false, null); - inputStream.close(); - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, "Could not create contents for new HTML file", e); //$NON-NLS-1$ } } - // open the file in editor openEditor(file);
diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java index bc77849..72c6a3e 100644 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java +++ b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2008 IBM Corporation and others. + * Copyright (c) 2001, 2012 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 @@ -299,32 +299,34 @@ } final IFile newFile = newFilePage.createNewFile(); - final String xmlFileName = newFile.getLocation().toOSString(); - final String grammarFileName = fileName; - - if (getContainer().getCurrentPage() == selectRootElementPage) { - - int limit = selectRootElementPage.getOptionalElementDepthLimit(); - generator.setOptionalElementDepthLimit(limit); - setNeedsProgressMonitor(true); - getContainer().run(true, false, new IRunnableWithProgress(){ - public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException { - progressMonitor.beginTask(XMLWizardsMessages._UI_WIZARD_GENERATING_XML_DOCUMENT, IProgressMonitor.UNKNOWN); - try { - generator.createXMLDocument(newFile, xmlFileName); - } catch (Exception exception) { - Logger.logException("Exception completing New XML wizard " + grammarFileName, exception); //$NON-NLS-1$ + if (!newFile.isLinked()) { + final String xmlFileName = newFile.getLocation().toOSString(); + final String grammarFileName = fileName; + + if (getContainer().getCurrentPage() == selectRootElementPage) { + + int limit = selectRootElementPage.getOptionalElementDepthLimit(); + generator.setOptionalElementDepthLimit(limit); + setNeedsProgressMonitor(true); + getContainer().run(true, false, new IRunnableWithProgress(){ + public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException { + progressMonitor.beginTask(XMLWizardsMessages._UI_WIZARD_GENERATING_XML_DOCUMENT, IProgressMonitor.UNKNOWN); + try { + generator.createXMLDocument(newFile, xmlFileName); + } catch (Exception exception) { + Logger.logException("Exception completing New XML wizard " + grammarFileName, exception); //$NON-NLS-1$ + } + progressMonitor.done(); } - progressMonitor.done(); - } - }); + }); + } + else { + // put template contents into file + String templateString = fNewXMLTemplatesWizardPage.getTemplateString(); + generator.createTemplateXMLDocument(newFile, templateString); + } + newFile.refreshLocal(IResource.DEPTH_ONE, null); } - else { - // put template contents into file - String templateString = fNewXMLTemplatesWizardPage.getTemplateString(); - generator.createTemplateXMLDocument(newFile, templateString); - } - newFile.refreshLocal(IResource.DEPTH_ONE, null); IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); BasicNewResourceWizard.selectAndReveal(newFile, workbenchWindow); openEditor(newFile);