Search in sources :

Example 1 with XMLDocumentLoader

use of org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader in project webtools.sourceediting by eclipse.

the class TestXMLDocumentLoader method testCreateNewStructuredDocumentFromInputStream.

public void testCreateNewStructuredDocumentFromInputStream() {
    String fileLocation = "/files/simple.xml";
    String absoluteFileLocation = Platform.getInstanceLocation() + fProjectName + fileLocation;
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fProjectName + "/files/simple.xml"));
    XMLDocumentLoader xmlDocumentLoader = new XMLDocumentLoader();
    IDocument document = null;
    try {
        document = xmlDocumentLoader.createNewStructuredDocument(absoluteFileLocation, file.getContents());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (CoreException e) {
        e.printStackTrace();
    }
    assertNotNull("failed to create document from InputStream", document);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) XMLDocumentLoader(org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader) IOException(java.io.IOException) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with XMLDocumentLoader

use of org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader in project webtools.sourceediting by eclipse.

the class TestXMLDocumentLoader method testCreateNewStructuredDocumentFromFile.

public void testCreateNewStructuredDocumentFromFile() {
    // from a file
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fProjectName + "/files/simple.xml"));
    XMLDocumentLoader xmlDocumentLoader = new XMLDocumentLoader();
    IDocument document = null;
    try {
        document = xmlDocumentLoader.createNewStructuredDocument(file);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (CoreException e) {
        e.printStackTrace();
    }
    assertNotNull("failed to create document from IFile", document);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) XMLDocumentLoader(org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader) IOException(java.io.IOException) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with XMLDocumentLoader

use of org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader in project webtools.sourceediting by eclipse.

the class TestXMLDocumentLoader method testCreateNewEmptyStructuredDocument.

public void testCreateNewEmptyStructuredDocument() {
    XMLDocumentLoader xmlDocumentLoader = new XMLDocumentLoader();
    IDocument document = null;
    document = xmlDocumentLoader.createNewStructuredDocument();
    assertNotNull("failed to create Empty document", document);
}
Also used : XMLDocumentLoader(org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with XMLDocumentLoader

use of org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader in project webtools.sourceediting by eclipse.

the class TestXMLDocumentLoader method testCreateNewDocumentFromReaderWithEncodingRule.

public void testCreateNewDocumentFromReaderWithEncodingRule() {
    String fileLocation = "/files/simple.xml";
    String absoluteFileLocation = Platform.getInstanceLocation().getURL().getPath().toString() + fProjectName + fileLocation;
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fProjectName + "/files/simple.xml"));
    XMLDocumentLoader xmlDocumentLoader = new XMLDocumentLoader();
    IDocument document = null;
    try {
        document = xmlDocumentLoader.createNewStructuredDocument(absoluteFileLocation, file.getContents());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (CoreException e) {
        e.printStackTrace();
    }
    assertNotNull("failed to create document from InputStream with EncodingRule", document);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) XMLDocumentLoader(org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader) IOException(java.io.IOException) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with XMLDocumentLoader

use of org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader in project webtools.sourceediting by eclipse.

the class XMLCorePreferencesTest method testDelimiterPreferences.

/**
 * Tests line delimiter preferences by making sure document created
 * follows line delimiter preference.
 */
public void testDelimiterPreferences() {
    // check if content type preferences match
    String preferredDelimiter = ContentTypeEncodingPreferences.getPreferredNewLineDelimiter(ContentTypeIdForXML.ContentTypeID_XML);
    Preferences prefs = ContentBasedPreferenceGateway.getPreferences(ContentTypeIdForXML.ContentTypeID_XML);
    String gatewayDelimiter = prefs.get(CommonEncodingPreferenceNames.END_OF_LINE_CODE, null);
    assertEquals("ContentTypeEncodingPreferences and ContentBasedPreferenceGateway preferences do not match", gatewayDelimiter, preferredDelimiter);
    // set a particular line delimiter
    prefs.put(CommonEncodingPreferenceNames.END_OF_LINE_CODE, CommonEncodingPreferenceNames.LF);
    // create document
    XMLDocumentLoader loader = new XMLDocumentLoader();
    IEncodedDocument document = loader.createNewStructuredDocument();
    String documentDelimiter = document.getPreferredLineDelimiter();
    // verify delimiter in document matches preference
    assertEquals("Delimiter in document does not match preference", CommonEncodingPreferenceNames.STRING_LF, documentDelimiter);
    // return to original preference
    prefs.remove(CommonEncodingPreferenceNames.END_OF_LINE_CODE);
}
Also used : XMLDocumentLoader(org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader) ContentTypeEncodingPreferences(org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Aggregations

XMLDocumentLoader (org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader)5 IDocument (org.eclipse.jface.text.IDocument)4 IOException (java.io.IOException)3 IFile (org.eclipse.core.resources.IFile)3 CoreException (org.eclipse.core.runtime.CoreException)3 Path (org.eclipse.core.runtime.Path)3 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 ContentTypeEncodingPreferences (org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences)1 IEncodedDocument (org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)1 Preferences (org.osgi.service.prefs.Preferences)1