@NotNull private Element serialize() { Element el = new Element("taskManager"); Element taskManagerElement = new Element(StudySerializationUtils.Xml.MAIN_ELEMENT); XmlSerializer.serializeInto(this, taskManagerElement); if (myCourse instanceof RemoteCourse) { try { Element course = new Element(REMOTE_COURSE); //noinspection RedundantCast XmlSerializer.serializeInto((RemoteCourse)myCourse, course); final Element xmlCourse = StudySerializationUtils.Xml.getChildWithName(taskManagerElement, StudySerializationUtils.COURSE); xmlCourse.removeContent(); xmlCourse.addContent(course); } catch (StudySerializationUtils.StudyUnrecognizedFormatException e) { LOG.error("Failed to serialize remote course"); } } el.addContent(taskManagerElement); return el; }
@Override public void writeExternal(Element element) throws WriteExternalException { Settings settings = new Settings(); settings.host = this.host; settings.port = this.port; settings.route = this.route; if (this.browser != null) settings.browser = this.browser.getId().toString(); else settings.browser = ""; if (this.interpreter != null) settings.interpreterName = this.interpreter.getName(); else settings.interpreterName = ""; XmlSerializer.serializeInto(settings, element, new SkipDefaultsSerializationFilter()); super.writeExternal(element); }
@Override public void readExternal(Element element) throws InvalidDataException { super.readExternal(element); String name = ProcessingRunSettings.class.getSimpleName(); Element settingsElement = element.getChild(name); if (settingsElement == null) return; ProcessingRunSettings deserializedConfig = XmlSerializer.deserialize(settingsElement, ProcessingRunSettings.class); runSettings.setModule(deserializedConfig.getModule()); runSettings.setSketchClass(deserializedConfig.getSketchClass()); runSettings.setFullscreen(deserializedConfig.isFullscreen()); runSettings.setHideStopButton(deserializedConfig.isHideStopButton()); runSettings.setJvmArguments(deserializedConfig.getJvmArguments()); runSettings.setSketchArguments(deserializedConfig.getSketchArguments()); runSettings.setWindowBackgroundColor(deserializedConfig.getWindowBackgroundColor()); runSettings.setStopButtonColor(deserializedConfig.getStopButtonColor()); runSettings.setSketchOutputPath(deserializedConfig.getSketchOutputPath()); runSettings.setLocation(deserializedConfig.getLocation()); readModule(element); }
@Nullable @Override public Element getState() { Element element = new Element("mule-sdks"); try { for (MuleSdk sdk : sdks) { final Element sdkElement = new Element("mule-sdk"); XmlSerializer.serializeInto(sdk, sdkElement, new SkipDefaultValuesSerializationFilters()); element.addContent(sdkElement); } } catch (XmlSerializationException e) { LOG.error(e); } return element; }
public void testSharedServers() throws Exception { TaskRepository repository = new YouTrackRepository(new YouTrackRepositoryType()); repository.setShared(true); ((TaskManagerImpl)myTaskManager).setRepositories(Collections.singletonList(repository)); TaskProjectConfiguration configuration = ServiceManager.getService(getProject(), TaskProjectConfiguration.class); TaskProjectConfiguration state = configuration.getState(); assertNotNull(state); assertEquals(1, state.servers.size()); Element element = XmlSerializer.serialize(state); configuration.servers.clear(); ((TaskManagerImpl)myTaskManager).setRepositories(Collections.<TaskRepository>emptyList()); configuration.loadState(XmlSerializer.deserialize(element, TaskProjectConfiguration.class)); assertEquals(1, state.servers.size()); ((TaskManagerImpl)myTaskManager).projectOpened(); TaskRepository[] repositories = myTaskManager.getAllRepositories(); assertEquals(1, repositories.length); }
private static <P extends JpsElement> void doSaveArtifact(JpsArtifact artifact, Element componentElement, ArtifactState state, JpsArtifactPropertiesSerializer<P> serializer) { state.setArtifactType(serializer.getTypeId()); state.setRootElement(savePackagingElement(artifact.getRootElement())); List<ArtifactPropertiesState> propertiesList = state.getPropertiesList(); //noinspection unchecked serializer.saveProperties((P)artifact.getProperties(), propertiesList); for (JpsModelSerializerExtension serializerExtension : JpsModelSerializerExtension.getExtensions()) { for (JpsArtifactExtensionSerializer<?> extensionSerializer : serializerExtension.getArtifactExtensionSerializers()) { JpsElement extension = artifact.getContainer().getChild(extensionSerializer.getRole()); if (extension != null) { ArtifactPropertiesState propertiesState = new ArtifactPropertiesState(); propertiesState.setId(extensionSerializer.getId()); propertiesState.setOptions(saveExtension(extensionSerializer, extension)); propertiesList.add(propertiesState); } } } componentElement.addContent(XmlSerializer.serialize(state, SERIALIZATION_FILTERS)); }
@Nullable @Override public Element getState() { Element state = XmlSerializer.serialize(this, new SkipDefaultValuesSerializationFilters()); try { DebuggerUtilsEx.writeFilters(state, "filter", mySteppingFilters); } catch (WriteExternalException e) { LOG.error(e); return null; } for (ContentState eachState : myContentStates.values()) { final Element content = new Element("content"); if (eachState.write(content)) { state.addContent(content); } } return state; }
@Override public void loadState(Element state) { XmlSerializer.deserializeInto(this, state); try { setSteppingFilters(DebuggerUtilsEx.readFilters(state.getChildren("filter"))); } catch (InvalidDataException e) { LOG.error(e); } myContentStates.clear(); for (Element content : state.getChildren("content")) { ContentState contentState = new ContentState(content); myContentStates.put(contentState.getType(), contentState); } }
@Nullable public <T> T getState(@NotNull final FacetType<?, ?> type, @NotNull final Class<T> aClass) { String id = type.getStringId(); //noinspection unchecked T state = (T)myFacetTypeStates.get(id); if (state == null) { FacetTypeStateBean bean = myBean.getFacetTypeElements().get(id); if (bean != null) { Element element = bean.getState(); if (element != null) { state = XmlSerializer.deserialize(element, aClass); } } } return state; }
private <T> PackagingElement<T> deserializeElement(Element element) throws UnknownPackagingElementTypeException { final String id = element.getAttributeValue(TYPE_ID_ATTRIBUTE); PackagingElementType<?> type = PackagingElementFactory.getInstance().findElementType(id); if (type == null) { throw new UnknownPackagingElementTypeException(id); } PackagingElement<T> packagingElement = (PackagingElement<T>)type.createEmpty(myProject); T state = packagingElement.getState(); if (state != null) { XmlSerializer.deserializeInto(state, element); packagingElement.loadState(state); } final List children = element.getChildren(PACKAGING_ELEMENT_NAME); //noinspection unchecked for (Element child : (List<? extends Element>)children) { ((CompositePackagingElement<?>)packagingElement).addOrFindChild(deserializeElement(child)); } return packagingElement; }
public void testCarriageReturnInFormat() throws Exception { TaskRepository repository = new YouTrackRepository(); String format = "foo \n bar"; repository.setCommitMessageFormat(format); ((TaskManagerImpl)myTaskManager).setRepositories(Collections.singletonList(repository)); TaskManagerImpl.Config config = ((TaskManagerImpl)myTaskManager).getState(); Element element = XmlSerializer.serialize(config); ByteArrayOutputStream stream = new ByteArrayOutputStream(); JDOMUtil.writeDocument(new Document(element), stream, "\n"); Element element1 = JDOMUtil.load(new ByteArrayInputStream(stream.toByteArray())); TaskManagerImpl.Config deserialize = XmlSerializer.deserialize(element1, TaskManagerImpl.Config.class); ((TaskManagerImpl)myTaskManager).loadState(deserialize); TaskRepository[] repositories = myTaskManager.getAllRepositories(); assertEquals(format, repositories[0].getCommitMessageFormat()); }
@Override public void writeExternal(Element element) throws WriteExternalException { ConfigurationState state = new ConfigurationState(); state.myServerName = myServerName; if (myDeploymentSource != null) { DeploymentSourceType type = myDeploymentSource.getType(); Element deploymentTag = new Element("deployment").setAttribute(DEPLOYMENT_SOURCE_TYPE_ATTRIBUTE, type.getId()); type.save(myDeploymentSource, deploymentTag); if (myDeploymentConfiguration != null) { Object configurationState = myDeploymentConfiguration.getSerializer().getState(); if (configurationState != null) { Element settingsTag = new Element(SETTINGS_ELEMENT); XmlSerializer.serializeInto(configurationState, settingsTag, SERIALIZATION_FILTERS); deploymentTag.addContent(settingsTag); } } state.myDeploymentTag = deploymentTag; } XmlSerializer.serializeInto(state, element, SERIALIZATION_FILTERS); super.writeExternal(element); }
/** * Read in settings from XML config. * Default implementation uses XmlSerializer so you may use public fields (like <code>int TOOL_OPTION</code>) * and bean-style getters/setters (like <code>int getToolOption(), void setToolOption(int)</code>) to store your options. * * @param node to read settings from. * @throws InvalidDataException if the loaded data was not valid. */ @SuppressWarnings("deprecation") public void readSettings(@NotNull Element node) throws InvalidDataException { if (useNewSerializer()) { try { XmlSerializer.deserializeInto(this, node); } catch (XmlSerializationException e) { throw new InvalidDataException(e); } } else { //noinspection UnnecessaryFullyQualifiedName com.intellij.openapi.util.DefaultJDOMExternalizer.readExternal(this, node); } }
@Deprecated public void writeExternal(Element element) throws WriteExternalException { XmlSerializer.serializeInto(getState(), element); if (USE_PROXY_PAC && USE_HTTP_PROXY && !ApplicationManager.getApplication().isDisposed()) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame(); if (frame != null) { USE_PROXY_PAC = false; Messages.showMessageDialog(frame.getComponent(), "Proxy: both 'use proxy' and 'autodetect proxy' settings were set." + "\nOnly one of these options should be selected.\nPlease re-configure.", "Proxy Setup", Messages.getWarningIcon()); editConfigurable(frame.getComponent()); } } }, ModalityState.NON_MODAL); } }
public static KnownExtensions loadExtensions() { KnownExtensions knownExtensions = ourKnownExtensions.get(); if (knownExtensions != null) return knownExtensions; try { File file = getExtensionsFile(); if (file.isFile()) { knownExtensions = XmlSerializer.deserialize(JDOMUtil.load(file), KnownExtensions.class); ourKnownExtensions = new SoftReference<KnownExtensions>(knownExtensions); return knownExtensions; } } catch (Exception e) { LOG.info(e); } return null; }
@Nullable private static Artifacts deserialize(@Nullable URL url) { if (url == null) return null; Artifacts allArtifacts = null; try { allArtifacts = XmlSerializer.deserialize(url, Artifacts.class); } catch (XmlSerializationException e) { final Throwable cause = e.getCause(); if (!(cause instanceof IOException)) { LOG.error(e); } } return allArtifacts; }
@NotNull public MavenProjectConfiguration getMavenProjectConfiguration(@NotNull File dataStorageRoot) { final File configFile = new File(dataStorageRoot, MavenProjectConfiguration.CONFIGURATION_FILE_RELATIVE_PATH); MavenProjectConfiguration config; synchronized (myLoadedConfigs) { config = myLoadedConfigs.get(configFile); if (config == null) { config = new MavenProjectConfiguration(); try { final Document document = JDOMUtil.loadDocument(configFile); XmlSerializer.deserializeInto(config, document.getRootElement()); } catch (Exception e) { LOG.info(e); } myLoadedConfigs.put(configFile, config); } } return config; }
@NotNull private GradleProjectConfiguration loadLastConfiguration(@NotNull File gradleConfigFile) { final GradleProjectConfiguration projectConfig = new GradleProjectConfiguration(); if (gradleConfigFile.exists()) { try { final Document document = JDOMUtil.loadDocument(gradleConfigFile); XmlSerializer.deserializeInto(projectConfig, document.getRootElement()); // filter orphan modules final Set<String> actualModules = myModulesConfigurationHash.keySet(); for (Iterator<Map.Entry<String, GradleModuleResourceConfiguration>> iterator = projectConfig.moduleConfigurations.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<String, GradleModuleResourceConfiguration> configurationEntry = iterator.next(); if (!actualModules.contains(configurationEntry.getKey())) { iterator.remove(); } } } catch (Exception e) { LOG.info(e); } } return projectConfig; }
@Override public SettingsState getState() { SettingsState settingsState = new SettingsState(); settingsState.setDataViewSettings(myDataViewSettings); settingsState.setGeneralSettings(myGeneralSettings); initSettings(); if (!mySettingsById.isEmpty()) { SkipDefaultValuesSerializationFilters filter = new SkipDefaultValuesSerializationFilters(); for (XDebuggerSettings<?> settings : mySettingsById.values()) { Object subState = settings.getState(); if (subState != null) { Element serializedState = XmlSerializer.serializeIfNotDefault(subState, filter); if (!JDOMUtil.isEmpty(serializedState)) { SpecificSettingsState state = new SpecificSettingsState(); state.id = settings.getId(); state.configuration = serializedState; settingsState.specificStates.add(state); } } } } return settingsState; }
public void testSerialize() throws Exception { XDebuggerSettingsManager settingsManager = XDebuggerSettingsManager.getInstanceImpl(); MyDebuggerSettings settings = MyDebuggerSettings.getInstance(); assertNotNull(settings); settings.myOption = "239"; Element element = XmlSerializer.serialize(settingsManager.getState()); //System.out.println(JDOMUtil.writeElement(element, SystemProperties.getLineSeparator())); settings.myOption = "42"; assertSame(settings, MyDebuggerSettings.getInstance()); settingsManager.loadState(XmlSerializer.deserialize(element, XDebuggerSettingsManager.SettingsState.class)); assertSame(settings, MyDebuggerSettings.getInstance()); assertEquals("239", settings.myOption); }
public void loadState(Element from) { myConflicts.clear(); List files = from.getChildren("file"); for (Object file : files) { Element element = (Element)file; String path = element.getAttributeValue("path"); if (path == null) { continue; } VirtualFile vf = LocalFileSystem.getInstance().findFileByIoFile(new File(path)); if (vf == null || myChangeListManager.getChangeList(vf) == null) { continue; } Conflict conflict = new Conflict(); conflict.ignored = Boolean.parseBoolean(element.getAttributeValue("ignored")); myConflicts.put(path, conflict); } XmlSerializer.deserializeInto(myOptions, from); }
@NotNull private static CachedConversionResult loadCachedConversionResult(File projectFile) { try { final File infoFile = getConversionInfoFile(projectFile); if (!infoFile.exists()) { return new CachedConversionResult(); } final Document document = JDOMUtil.loadDocument(infoFile); final CachedConversionResult result = XmlSerializer.deserialize(document, CachedConversionResult.class); return result != null ? result : new CachedConversionResult(); } catch (Exception e) { LOG.info(e); return new CachedConversionResult(); } }
@NotNull public Element write(@NotNull Element parentNode) { for (ViewImpl eachState : myViews.values()) { if (myLightWeightIds != null && myLightWeightIds.contains(eachState.getID())) { continue; } parentNode.addContent(XmlSerializer.serialize(eachState)); } SkipDefaultValuesSerializationFilters filter = new SkipDefaultValuesSerializationFilters(); for (TabImpl eachTab : myTabs) { if (isUsed(eachTab)) { parentNode.addContent(XmlSerializer.serialize(eachTab, filter)); } } parentNode.addContent(XmlSerializer.serialize(myGeneral, filter)); return parentNode; }
@Nullable @Override public Element getState() { CodeStyleScheme currentScheme = getCurrentScheme(); CURRENT_SCHEME_NAME = currentScheme == null ? null : currentScheme.getName(); return XmlSerializer.serialize(this, new SerializationFilter() { @Override public boolean accepts(@NotNull Accessor accessor, @NotNull Object bean) { if ("CURRENT_SCHEME_NAME".equals(accessor.getName())) { return !DEFAULT_SCHEME_NAME.equals(accessor.read(bean)); } else { return accessor.getValueClass().equals(String.class); } } }); }
@Override public TaskRepository createRepository() { Document document; try { String configFileName = myName.toLowerCase() + ".xml"; //URL resourceUrl = ResourceUtil.getResource(GenericRepositoryType.class, "connectors", configFileName); URL resourceUrl = GenericRepository.class.getResource("connectors/" + configFileName); if (resourceUrl == null) { throw new AssertionError("Repository configuration file '" + configFileName + "' not found"); } document = JDOMUtil.loadResourceDocument(resourceUrl); } catch (Exception e) { throw new AssertionError(e); } GenericRepository repository = XmlSerializer.deserialize(document.getRootElement(), GenericRepository.class); if (repository != null) { repository.setRepositoryType(GenericRepositoryType.this); repository.setSubtypeName(getName()); } return repository; }
@NotNull public GradleProjectConfiguration getGradleProjectConfiguration(@NotNull File dataStorageRoot) { final File configFile = new File(dataStorageRoot, GradleProjectConfiguration.CONFIGURATION_FILE_RELATIVE_PATH); GradleProjectConfiguration config; synchronized (myLoadedConfigs) { config = myLoadedConfigs.get(configFile); if (config == null) { config = new GradleProjectConfiguration(); try { final Document document = JDOMUtil.loadDocument(configFile); XmlSerializer.deserializeInto(config, document.getRootElement()); } catch (Exception e) { LOG.info(e); } myLoadedConfigs.put(configFile, config); } } return config; }
@Override public void readExternal(Element element) throws InvalidDataException { super.readExternal(element); Settings settings = XmlSerializer.deserialize(element, Settings.class); this.host = settings.host; this.port = settings.port; this.route = settings.route; this.browser = WebBrowserManager.getInstance().findBrowserById(settings.browser); this.interpreter = PhpInterpretersManagerImpl.getInstance(getProject()).findInterpreter(settings.interpreterName); }
private void deserialize(Element state) throws StudySerializationUtils.StudyUnrecognizedFormatException { final Element taskManagerElement = state.getChild(StudySerializationUtils.Xml.MAIN_ELEMENT); if (taskManagerElement == null) { throw new StudySerializationUtils.StudyUnrecognizedFormatException(); } XmlSerializer.deserializeInto(this, taskManagerElement); final Element xmlCourse = StudySerializationUtils.Xml.getChildWithName(taskManagerElement, StudySerializationUtils.COURSE); final Element remoteCourseElement = xmlCourse.getChild(REMOTE_COURSE); if (remoteCourseElement != null) { final RemoteCourse remoteCourse = new RemoteCourse(); XmlSerializer.deserializeInto(remoteCourse, remoteCourseElement); myCourse = remoteCourse; } }
@Override public Element getState() { if (myCourse == null) { return null; } return XmlSerializer.serialize(this); }
@Override public void loadState(Element state) { try { Element courseElement = getChildWithName(state, COURSE).getChild(COURSE_TITLED); for (Element lesson : getChildList(courseElement, LESSONS, true)) { int lessonIndex = getAsInt(lesson, INDEX); for (Element task : getChildList(lesson, TASK_LIST, true)) { int taskIndex = getAsInt(task, INDEX); Map<String, Element> taskFiles = getChildMap(task, TASK_FILES, true); for (Map.Entry<String, Element> entry : taskFiles.entrySet()) { Element taskFileElement = entry.getValue(); String name = entry.getKey(); String answerName = FileUtil.getNameWithoutExtension(name) + CCUtils.ANSWER_EXTENSION_DOTTED + FileUtilRt.getExtension(name); Document document = StudyUtils.getDocument(myProject.getBasePath(), lessonIndex, taskIndex, answerName); if (document == null) { document = StudyUtils.getDocument(myProject.getBasePath(), lessonIndex, taskIndex, name); if (document == null) { continue; } } for (Element placeholder : getChildList(taskFileElement, ANSWER_PLACEHOLDERS, true)) { Element lineElement = getChildWithName(placeholder, LINE, true); int line = lineElement != null ? Integer.valueOf(lineElement.getAttributeValue(VALUE)) : 0; Element startElement = getChildWithName(placeholder, START, true); int start = startElement != null ? Integer.valueOf(startElement.getAttributeValue(VALUE)) : 0; int offset = document.getLineStartOffset(line) + start; addChildWithName(placeholder, OFFSET, offset); addChildWithName(placeholder, "useLength", "false"); } } } } XmlSerializer.deserializeInto(this, state); } catch (StudyUnrecognizedFormatException e) { LOG.error(e); } }
@Override public void writeExternal(Element parentNode) throws WriteExternalException { super.writeExternal(parentNode); parentNode.addContent(XmlSerializer.serialize(runSettings)); writeModule(parentNode); }
@Override public void loadContext(Element fromElement) throws InvalidDataException { XDebuggerWatchesManager.WatchesManagerState state = XmlSerializer.deserialize(fromElement, XDebuggerWatchesManager.WatchesManagerState.class); myWatchesManager.loadState(state); }
@Override public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) { JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project); EclipseCompilerOptions options = XmlSerializer.deserialize(componentTag, EclipseCompilerOptions.class); if (options == null) { options = new EclipseCompilerOptions(); } configuration.setCompilerOptions(myCompilerId, options); }
@Override public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) { GreclipseSettings settings = XmlSerializer.deserialize(componentTag, GreclipseSettings.class); if (settings == null) settings = new GreclipseSettings(); GreclipseJpsCompilerSettings component = new GreclipseJpsCompilerSettings(settings); project.getContainer().setChild(GreclipseJpsCompilerSettings.ROLE, component); }
public static void loadFacets(JpsModule module, @Nullable Element facetManagerElement) { if (facetManagerElement == null) return; final FacetManagerState state = XmlSerializer.deserialize(facetManagerElement, FacetManagerState.class); if (state != null) { addFacets(module, state.getFacets(), null); } }
public static void saveFacets(JpsModule module, @NotNull Element facetManagerElement) { FacetManagerState managerState = new FacetManagerState(); for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) { for (JpsFacetConfigurationSerializer<?> serializer : extension.getFacetConfigurationSerializers()) { if (serializer.hasExtension(module)) { serializer.saveExtension(module, managerState.getFacets()); } } } XmlSerializer.serializeInto(managerState, facetManagerElement, new SkipDefaultValuesSerializationFilters()); }
public static void loadArtifacts(@NotNull JpsProject project, @Nullable Element componentElement) { JpsArtifactService service = JpsArtifactService.getInstance(); for (Element artifactElement : JDOMUtil.getChildren(componentElement, "artifact")) { ArtifactState state = XmlSerializer.deserialize(artifactElement, ArtifactState.class); if (state == null) continue; JpsArtifactPropertiesSerializer<?> serializer = getTypePropertiesSerializer(state.getArtifactType()); loadArtifact(project, service, state, serializer); } }
@Override public void readExternal(Element element) throws InvalidDataException { PathMacroManager.getInstance(getProject()).expandPaths(element); super.readExternal(element); JavaRunConfigurationExtensionManager.getInstance().readExternal(this, element); XmlSerializer.deserializeInto(myBean, element); EnvironmentVariablesComponent.readExternal(element, getEnvs()); myConfigurationModule.readExternal(element); }
@Override public void writeExternal(Element element) throws WriteExternalException { super.writeExternal(element); JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element); XmlSerializer.serializeInto(myBean, element, SERIALIZATION_FILTERS); EnvironmentVariablesComponent.writeExternal(element, getEnvs()); if (myConfigurationModule.getModule() != null) { myConfigurationModule.writeExternal(element); } }
@Override public void saveContext(Element toElement) throws WriteExternalException { XBreakpointManagerImpl.BreakpointManagerState state = myBreakpointManager.getState(); Element serialize = XmlSerializer.serialize(state, new SerializationFilter() { @Override public boolean accepts(@NotNull Accessor accessor, @NotNull Object bean) { return accessor.read(bean) != null; } }); toElement.addContent(serialize.removeContent()); }