use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class CleanupProcessorXML method cleanupModel.
public void cleanupModel(IStructuredModel structuredModel) {
Preferences preferences = getModelPreferences();
if (preferences != null && preferences.getBoolean(XMLCorePreferenceNames.FIX_XML_DECLARATION)) {
IDOMDocument document = ((DOMModelImpl) structuredModel).getDocument();
if (!fixExistingXmlDecl(document)) {
String encoding = preferences.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Node xml = document.createProcessingInstruction("xml", "version=\"1.0\" " + "encoding=\"" + encoding + "\"");
document.insertBefore(xml, document.getFirstChild());
}
}
super.cleanupModel(structuredModel);
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class NodeCleanupHandler method getCleanupPreferences.
public IStructuredCleanupPreferences getCleanupPreferences() {
if (fCleanupPreferences == null) {
fCleanupPreferences = new StructuredCleanupPreferences();
Preferences preferences = getModelPreferences();
if (preferences != null) {
fCleanupPreferences.setCompressEmptyElementTags(preferences.getBoolean(XMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS));
fCleanupPreferences.setInsertRequiredAttrs(preferences.getBoolean(XMLCorePreferenceNames.INSERT_REQUIRED_ATTRS));
fCleanupPreferences.setInsertMissingTags(preferences.getBoolean(XMLCorePreferenceNames.INSERT_MISSING_TAGS));
fCleanupPreferences.setQuoteAttrValues(preferences.getBoolean(XMLCorePreferenceNames.QUOTE_ATTR_VALUES));
fCleanupPreferences.setFormatSource(preferences.getBoolean(XMLCorePreferenceNames.FORMAT_SOURCE));
fCleanupPreferences.setConvertEOLCodes(preferences.getBoolean(XMLCorePreferenceNames.CONVERT_EOL_CODES));
fCleanupPreferences.setEOLCode(preferences.getString(XMLCorePreferenceNames.CLEANUP_EOL_CODE));
}
}
return fCleanupPreferences;
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class BaseCommand method getXMLDeclaration.
private static ProcessingInstruction getXMLDeclaration(Document document) {
Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences();
String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
if (charSet == null || charSet.trim().equals("")) {
charSet = "UTF-8";
}
ProcessingInstruction xmlDeclaration = document.createProcessingInstruction(XML, "version=\"1.0\" encoding=\"" + charSet + "\"");
return xmlDeclaration;
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class NodeFormatter method getFormatPreferences.
public IStructuredFormatPreferences getFormatPreferences() {
if (fFormatPreferences == null) {
fFormatPreferences = new StructuredFormatPreferencesXML();
Preferences preferences = getModelPreferences();
if (preferences != null) {
fFormatPreferences.setLineWidth(preferences.getInt(XMLCorePreferenceNames.LINE_WIDTH));
((StructuredFormatPreferencesXML) fFormatPreferences).setSplitMultiAttrs(preferences.getBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS));
((StructuredFormatPreferencesXML) fFormatPreferences).setAlignEndBracket(preferences.getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET));
((StructuredFormatPreferencesXML) fFormatPreferences).setPreservePCDATAContent(preferences.getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT));
fFormatPreferences.setClearAllBlankLines(preferences.getBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES));
char indentChar = ' ';
String indentCharPref = preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR);
if (XMLCorePreferenceNames.TAB.equals(indentCharPref)) {
indentChar = '\t';
}
int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE);
StringBuffer indent = new StringBuffer();
for (int i = 0; i < indentationWidth; i++) {
indent.append(indentChar);
}
fFormatPreferences.setIndent(indent.toString());
}
}
return fFormatPreferences;
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class NewXSDWizard method performFinish.
public boolean performFinish() {
IFile file = newFilePage.createNewFile();
//
// Get the xsd schema name from the full path name
// e.g. f:/b2b/po.xsd => schema name = po
//
IPath iPath = file.getFullPath().removeFileExtension();
// String schemaName = iPath.lastSegment();
String schemaName = iPath.lastSegment();
String schemaPrefix = "tns";
String prefixForSchemaNamespace = "";
String schemaNamespaceAttribute = "xmlns";
if (XSDEditorPlugin.getPlugin().isQualifyXMLSchemaLanguage()) {
// Can take this out. See also XSDEditor
if (XSDEditorPlugin.getPlugin().getXMLSchemaPrefix().trim().length() > 0) {
prefixForSchemaNamespace = XSDEditorPlugin.getPlugin().getXMLSchemaPrefix() + ":";
schemaNamespaceAttribute += ":" + XSDEditorPlugin.getPlugin().getXMLSchemaPrefix();
}
}
Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences();
String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
if (charSet == null || charSet.trim().equals("")) {
charSet = "UTF-8";
}
String newContents = "<?xml version=\"1.0\" encoding=\"" + charSet + "\"?>\n";
String defaultTargetURI = XSDEditorPlugin.getPlugin().getXMLSchemaTargetNamespace();
newContents += "<" + prefixForSchemaNamespace + "schema " + schemaNamespaceAttribute + "=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"" + defaultTargetURI + schemaName + "\" xmlns:" + schemaPrefix + "=\"" + defaultTargetURI + schemaName + "\" elementFormDefault=\"qualified\">\n</" + prefixForSchemaNamespace + "schema>";
try {
byte[] bytes = newContents.getBytes(charSet);
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
file.setContents(inputStream, true, false, null);
inputStream.close();
} catch (Exception e) {
// XSDEditorPlugin.getPlugin().getMsgLogger().write("Error writing
// default content:\n" + newContents);
// XSDEditorPlugin.getPlugin().getMsgLogger().write(e);
}
if (file != null) {
revealSelection(new StructuredSelection(file));
}
openEditor(file);
return true;
}
Aggregations