Java Code Examples for org.jdom.Element#clone()
The following examples show how to use
org.jdom.Element#clone() .
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: DesktopPsiAwareTextEditorProvider.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nonnull public FileEditorState readState(@Nonnull final Element element, @Nonnull final Project project, @Nonnull final VirtualFile file) { final TextEditorState state = (TextEditorState)super.readState(element, project, file); // Foldings Element child = element.getChild(FOLDING_ELEMENT); Document document = FileDocumentManager.getInstance().getCachedDocument(file); if (child != null) { if (document == null) { final Element detachedStateCopy = child.clone(); state.setDelayedFoldState(() -> { Document document1 = FileDocumentManager.getInstance().getCachedDocument(file); return document1 == null ? null : CodeFoldingManager.getInstance(project).readFoldingState(detachedStateCopy, document1); }); } else { //PsiDocumentManager.getInstance(project).commitDocument(document); state.setFoldingState(CodeFoldingManager.getInstance(project).readFoldingState(child, document)); } } return state; }
Example 2
Source File: BlazeAndroidBinaryRunConfigurationStateTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void repeatedWriteShouldNotChangeElement() throws WriteExternalException { final XMLOutputter xmlOutputter = new XMLOutputter(Format.getCompactFormat()); BlazeAndroidRunConfigurationCommonState commonState = state.getCommonState(); commonState.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2")); commonState.setNativeDebuggingEnabled(true); state.setActivityClass("com.example.TestActivity"); state.setMode(BlazeAndroidBinaryRunConfigurationState.LAUNCH_SPECIFIC_ACTIVITY); state.setLaunchMethod(AndroidBinaryLaunchMethod.MOBILE_INSTALL); state.setUseSplitApksIfPossible(false); state.setUseWorkProfileIfPresent(true); state.setUserId(2); state.setShowLogcatAutomatically(true); state.setDeepLink("http://deeplink"); Element firstWrite = new Element("test"); state.writeExternal(firstWrite); Element secondWrite = firstWrite.clone(); state.writeExternal(secondWrite); assertThat(xmlOutputter.outputString(secondWrite)) .isEqualTo(xmlOutputter.outputString(firstWrite)); }
Example 3
Source File: BlazeAndroidTestRunConfigurationStateTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void repeatedWriteShouldNotChangeElement() throws WriteExternalException { final XMLOutputter xmlOutputter = new XMLOutputter(Format.getCompactFormat()); BlazeAndroidRunConfigurationCommonState commonState = state.getCommonState(); commonState.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2")); commonState.setNativeDebuggingEnabled(true); state.setTestingType(BlazeAndroidTestRunConfigurationState.TEST_METHOD); state.setInstrumentationRunnerClass("com.example.TestRunner"); state.setMethodName("fooMethod"); state.setClassName("BarClass"); state.setPackageName("com.test.package.name"); state.setLaunchMethod(AndroidTestLaunchMethod.MOBILE_INSTALL); state.setExtraOptions("--option"); Element firstWrite = new Element("test"); state.writeExternal(firstWrite); Element secondWrite = firstWrite.clone(); state.writeExternal(secondWrite); assertThat(xmlOutputter.outputString(secondWrite)) .isEqualTo(xmlOutputter.outputString(firstWrite)); }
Example 4
Source File: BlazeAndroidRunConfigurationCommonStateTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void repeatedWriteShouldNotChangeElement() throws WriteExternalException { final XMLOutputter xmlOutputter = new XMLOutputter(Format.getCompactFormat()); state.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2")); state.getExeFlagsState().setRawFlags(ImmutableList.of("--exe1", "--exe2")); state.setNativeDebuggingEnabled(true); Element firstWrite = new Element("test"); state.writeExternal(firstWrite); Element secondWrite = firstWrite.clone(); state.writeExternal(secondWrite); assertThat(xmlOutputter.outputString(secondWrite)) .isEqualTo(xmlOutputter.outputString(firstWrite)); }
Example 5
Source File: BlazeCommandRunConfigurationCommonStateTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void repeatedWriteShouldNotChangeElement() throws Exception { final XMLOutputter xmlOutputter = new XMLOutputter(Format.getCompactFormat()); state.getCommandState().setCommand(COMMAND); state.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2")); state.getExeFlagsState().setRawFlags(ImmutableList.of("--exeFlag1")); state.getBlazeBinaryState().setBlazeBinary("/usr/bin/blaze"); Element firstWrite = new Element("test"); state.writeExternal(firstWrite); Element secondWrite = firstWrite.clone(); state.writeExternal(secondWrite); assertThat(xmlOutputter.outputString(secondWrite)) .isEqualTo(xmlOutputter.outputString(firstWrite)); }
Example 6
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static void writeElementToStream(final Element e, final OutputStream os) { try { final BufferedOutputStream bos = new BufferedOutputStream(os); final Document document = new Document((Element) e.clone()); final XMLOutputter outputter = new XMLOutputter(); outputter.output(document, bos); bos.flush(); } catch (final IOException ioe) { LOGGER.info("write error", ioe); } }
Example 7
Source File: InspectionProfileImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void readExternal(@Nonnull Element element) throws InvalidDataException { super.readExternal(element); if (!ApplicationManager.getApplication().isUnitTestMode() || myBaseProfile == null) { // todo remove this strange side effect myBaseProfile = getDefaultProfile(); } final String version = element.getAttributeValue(VERSION_TAG); if (version == null || !version.equals(VALID_VERSION)) { element = InspectionProfileConvertor.convertToNewFormat(element, this); } final Element highlightElement = element.getChild(USED_LEVELS); if (highlightElement != null) { // from old profiles ((SeverityProvider)getProfileManager()).getOwnSeverityRegistrar().readExternal(highlightElement); } StringInterner interner = new StringInterner(); for (Element toolElement : element.getChildren(INSPECTION_TOOL_TAG)) { // make clone to avoid retaining memory via o.parent pointers toolElement = toolElement.clone(); JDOMUtil.internStringsInElement(toolElement, interner); myUninstalledInspectionsSettings.put(toolElement.getAttributeValue(CLASS_TAG), toolElement); } }
Example 8
Source File: XmlElementStorageTest.java From consulo with Apache License 2.0 | 5 votes |
@Override protected XmlElementStorageSaveSession createSaveSession(@Nonnull StorageData storageData) { return new XmlElementStorageSaveSession(storageData) { @Override protected void doSave(@Nullable Element element) { mySavedElement = element == null ? null : element.clone(); } }; }
Example 9
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static void writeElementToWriter(final Element e, final Writer writer) { try { final Document document = new Document((Element) e.clone()); final XMLOutputter outputter = new XMLOutputter(); outputter.output(document, writer); } catch (final IOException ioe) { LOGGER.info("write error", ioe); } }
Example 10
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static String writeElementToString(final Element e) { try { final StringWriter sw = new StringWriter(); final Document document = new Document((Element) e.clone()); final XMLOutputter outputter = new XMLOutputter(); outputter.output(document, sw); return sw.getBuffer().toString(); } catch (final IOException ioe) { LOGGER.info("write error", ioe); } return null; }
Example 11
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static void writeElementToStreamPretty(final Element e, final OutputStream os) { try { final BufferedOutputStream bos = new BufferedOutputStream(os); final Document document = new Document((Element) e.clone()); final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(document, bos); bos.flush(); } catch (final IOException ioe) { LOGGER.info("write error", ioe); } }
Example 12
Source File: SaveState.java From ghidra with Apache License 2.0 | 5 votes |
protected Element createElementFromElement(String internalKey, Element internalElement) { Element newElement = new Element("XML"); newElement.setAttribute("NAME", internalKey); Element internalElementClone = (Element) internalElement.clone(); newElement.addContent(internalElementClone); return newElement; }
Example 13
Source File: BlazeCommandRunConfiguration.java From intellij with Apache License 2.0 | 5 votes |
private static Element getBlazeSettingsCopy(Element element) { Element blazeSettings = element.getChild(BLAZE_SETTINGS_TAG); if (blazeSettings != null) { return blazeSettings.clone(); } // migrate an old-style run configuration blazeSettings = element.clone(); blazeSettings.setName(BLAZE_SETTINGS_TAG); for (String common : COMMON_SETTINGS) { blazeSettings.removeChildren(common); blazeSettings.removeAttribute(common); } return blazeSettings; }
Example 14
Source File: SEDMLutilities.java From iBioSim with Apache License 2.0 | 5 votes |
public static void copyAnnotation(SEDBase sedBase1,SEDBase sedBase2) { Annotation annotation = sedBase1.getAnnotation(); if (annotation!=null) { List<Element> elements = annotation.getAnnotationElementsList(); for (Element element : elements) { if (!element.getName().equals("sbsi-editor")) { Annotation newAnnotation = new Annotation((Element)element.clone()); sedBase2.setAnnotation(newAnnotation); // TODO: only copying first element break; } } } }
Example 15
Source File: LoggingConfigurator.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public void addHtmlAppender(String name) { // Check appender existence if (xml.getChild("appender", "name", name) != null) return; // Get the DMS_WEB appender and use it as a model Element model = xml.getChild("appender", "name", "DMS_WEB"); // Clone the model and add to the root Element newAppender = (Element) model.clone(); List appenders = xml.getRootElement().getChildren("appender"); xml.getRootElement().addContent(0, newAppender); // Setup the appender name newAppender.setAttribute("name", name); // Now setup the file name Iterator params = newAppender.getChildren("param").iterator(); while (params.hasNext()) { Element child = (Element) params.next(); if (child.getAttributeValue("name").equals("File")) { String logfile = name.trim().toLowerCase() + ".log.html"; child.setAttribute("value", child.getAttributeValue("value").replaceAll("dms.log.html", logfile)); break; } } }
Example 16
Source File: LoggingConfigurator.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public void addTextAppender(String name) { // Check appender existence if (xml.getChild("appender", "name", name) != null) return; // Get the DMS appender and use it as a model Element model = xml.getChild("appender", "name", "DMS"); // Clone the model and add to the root Element newAppender = (Element) model.clone(); List appenders = xml.getRootElement().getChildren("appender"); xml.getRootElement().addContent(0, newAppender); // Setup the appender name newAppender.setAttribute("name", name); // Now setup the file name Iterator params = newAppender.getChildren("param").iterator(); while (params.hasNext()) { Element child = (Element) params.next(); if (child.getAttributeValue("name").equals("File")) { String logfile = name.trim().toLowerCase() + ".log"; child.setAttribute("value", child.getAttributeValue("value").replaceAll("dms.log", logfile)); break; } } }
Example 17
Source File: DefaultProjectStoreImpl.java From consulo with Apache License 2.0 | 4 votes |
@Nullable Element getStateCopy() { final Element element = getProject().getStateElement(); return element != null ? element.clone() : null; }
Example 18
Source File: UnknownRunConfiguration.java From consulo with Apache License 2.0 | 4 votes |
@Override public void readExternal(final Element element) throws InvalidDataException { myStoredElement = (Element) element.clone(); }