Java Code Examples for com.intellij.openapi.util.JDOMUtil#internStringsInElement()
The following examples show how to use
com.intellij.openapi.util.JDOMUtil#internStringsInElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageData.java From consulo with Apache License 2.0 | 5 votes |
public void load(@Nonnull Element rootElement, @Nullable PathMacroSubstitutor pathMacroSubstitutor, boolean intern) { if (pathMacroSubstitutor != null) { pathMacroSubstitutor.expandPaths(rootElement); } StringInterner interner = intern ? new StringInterner() : null; for (Iterator<Element> iterator = rootElement.getChildren(COMPONENT).iterator(); iterator.hasNext(); ) { Element element = iterator.next(); String name = getComponentNameIfValid(element); if (name == null || !(element.getAttributes().size() > 1 || !element.getChildren().isEmpty())) { continue; } iterator.remove(); if (interner != null) { JDOMUtil.internStringsInElement(element, interner); } myStates.put(name, element); if (pathMacroSubstitutor instanceof TrackingPathMacroSubstitutor) { ((TrackingPathMacroSubstitutor)pathMacroSubstitutor).addUnknownMacros(name, PathMacrosService.getInstance().getMacroNames(element)); } // remove only after "getMacroNames" - some PathMacroFilter requires element name attribute element.removeAttribute(NAME); } }
Example 2
Source File: IoDirectoryBasedStorage.java From consulo with Apache License 2.0 | 4 votes |
public void loadFrom(@Nonnull DirectoryStorageData data, @Nullable File dir, @Nullable TrackingPathMacroSubstitutor pathMacroSubstitutor) { if (dir == null || !dir.exists()) { return; } StringInterner interner = new StringInterner(); File[] files = dir.listFiles(); if (files == null) { return; } for (File file : files) { if (!isStorageFile(file)) { continue; } try { Element element = JDOMUtil.loadDocument(file).getRootElement(); String name = StorageData.getComponentNameIfValid(element); if (name == null) { continue; } if (!element.getName().equals(StorageData.COMPONENT)) { LOG.error("Incorrect root tag name (" + element.getName() + ") in " + file.getPath()); continue; } List<Element> elementChildren = element.getChildren(); if (elementChildren.isEmpty()) { continue; } Element state = (Element)elementChildren.get(0).detach(); JDOMUtil.internStringsInElement(state, interner); if (pathMacroSubstitutor != null) { pathMacroSubstitutor.expandPaths(state); pathMacroSubstitutor.addUnknownMacros(name, PathMacrosService.getInstance().getMacroNames(state)); } data.setState(name, file.getName(), state); } catch (IOException | JDOMException e) { LOG.info("Unable to load state", e); } } }
Example 3
Source File: VfsDirectoryBasedStorage.java From consulo with Apache License 2.0 | 4 votes |
public void loadFrom(@Nonnull DirectoryStorageData data, @Nullable VirtualFile dir, @Nullable TrackingPathMacroSubstitutor pathMacroSubstitutor) { if (dir == null || !dir.exists()) { return; } StringInterner interner = new StringInterner(); for (VirtualFile file : dir.getChildren()) { if (!isStorageFile(file)) { continue; } try { Element element = JDOMUtil.loadDocument(file.contentsToByteArray()).getRootElement(); String name = StorageData.getComponentNameIfValid(element); if (name == null) { continue; } if (!element.getName().equals(StorageData.COMPONENT)) { LOG.error("Incorrect root tag name (" + element.getName() + ") in " + file.getPresentableUrl()); continue; } List<Element> elementChildren = element.getChildren(); if (elementChildren.isEmpty()) { continue; } Element state = (Element)elementChildren.get(0).detach(); JDOMUtil.internStringsInElement(state, interner); if (pathMacroSubstitutor != null) { pathMacroSubstitutor.expandPaths(state); pathMacroSubstitutor.addUnknownMacros(name, PathMacrosService.getInstance().getMacroNames(state)); } data.setState(name, file.getName(), state); } catch (IOException | JDOMException e) { LOG.info("Unable to load state", e); } } }