Search in sources :

Example 6 with SchemeImportException

use of com.intellij.openapi.options.SchemeImportException in project intellij-community by JetBrains.

the class CodeStyleSchemeXmlImporter method getSchemeName.

@NotNull
private static String getSchemeName(@NotNull Element rootElement) throws SchemeImportException {
    String rootName = rootElement.getName();
    if ("value".equals(rootElement.getName()))
        return "Project";
    if (!"code_scheme".equals(rootName)) {
        throw new SchemeImportException(ApplicationBundle.message("settings.code.style.import.xml.error.invalid.file", rootName));
    }
    Attribute schemeNameAttr = rootElement.getAttribute("name");
    if (schemeNameAttr == null) {
        throw new SchemeImportException(ApplicationBundle.message("settings.code.style.import.xml.error.missing.scheme.name"));
    }
    return schemeNameAttr.getValue();
}
Also used : Attribute(org.jdom.Attribute) SchemeImportException(com.intellij.openapi.options.SchemeImportException) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with SchemeImportException

use of com.intellij.openapi.options.SchemeImportException in project intellij-community by JetBrains.

the class EclipseCodeStyleImportWorker method importScheme.

public void importScheme(@NotNull InputStream inputStream, @Nullable final String sourceScheme, final CodeStyleScheme scheme) throws SchemeImportException {
    final CodeStyleSettings settings = scheme.getCodeStyleSettings();
    EclipseXmlProfileReader reader = new EclipseXmlProfileReader(new EclipseXmlProfileReader.OptionHandler() {

        private String myCurrScheme;

        @Override
        public void handleOption(@NotNull String eclipseKey, @NotNull String value) throws SchemeImportException {
            if (sourceScheme == null || myCurrScheme != null && myCurrScheme.equals(sourceScheme)) {
                setCodeStyleOption(settings, eclipseKey, value);
            }
        }

        @Override
        public void handleName(String name) {
            myCurrScheme = name;
        }
    });
    reader.readSettings(inputStream);
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) SchemeImportException(com.intellij.openapi.options.SchemeImportException)

Example 8 with SchemeImportException

use of com.intellij.openapi.options.SchemeImportException in project intellij-community by JetBrains.

the class EclipseColorSchemeImporter method readFromStream.

private static String readFromStream(@NotNull final VirtualFile file, @Nullable final EclipseThemeReader.OptionHandler optionHandler) throws SchemeImportException {
    InputStream inputStream = null;
    try {
        inputStream = file.getInputStream();
        EclipseThemeReader themeReader = new EclipseThemeReader(optionHandler);
        themeReader.readSettings(inputStream);
        return themeReader.getThemeName();
    } catch (IOException e) {
        throw new SchemeImportException(e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
            //
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) SchemeImportException(com.intellij.openapi.options.SchemeImportException) IOException(java.io.IOException)

Aggregations

SchemeImportException (com.intellij.openapi.options.SchemeImportException)8 IOException (java.io.IOException)3 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)2 InputStream (java.io.InputStream)2 SAXParser (javax.xml.parsers.SAXParser)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 SAXException (org.xml.sax.SAXException)2 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)1 CodeStyleSettingsLoader (com.intellij.psi.impl.source.codeStyle.CodeStyleSettingsLoader)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 Attribute (org.jdom.Attribute)1 NotNull (org.jetbrains.annotations.NotNull)1