org.jdom.output.Format Java Examples
The following examples show how to use
org.jdom.output.Format.
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: 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 #2
Source File: DuplocatorHashCallback.java From consulo with Apache License 2.0 | 6 votes |
@SuppressWarnings({"HardCodedStringLiteral"}) public void report(String path, final Project project) throws IOException { int[] hashCodes = myDuplicates.keys(); Element rootElement = new Element("root"); for (int hash : hashCodes) { List<List<PsiFragment>> dupList = myDuplicates.get(hash); Element hashElement = new Element("hash"); hashElement.setAttribute("val", String.valueOf(hash)); for (final List<PsiFragment> psiFragments : dupList) { writeFragments(psiFragments, hashElement, project, false); } rootElement.addContent(hashElement); } try(FileWriter fileWriter = new FileWriter(path + File.separator + "fragments.xml")) { XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); xmlOutputter.output(new org.jdom.Document(rootElement), fileWriter); } writeDuplicates(path, project, getInfo()); }
Example #3
Source File: OvalFileAggregator.java From spacewalk with GNU General Public License v2.0 | 6 votes |
/** * Finalizes processing and builds the aggregated document * @param prettyPrint pretty print XML or not * @return XML in string form * @throws IOException document output failed */ public String finish(boolean prettyPrint) throws IOException { if (!isFinished && !isEmpty()) { buildDocument(); isFinished = true; } if (isEmpty()) { return ""; } XMLOutputter out = new XMLOutputter(); if (prettyPrint) { out.setFormat(Format.getPrettyFormat()); } else { out.setFormat(Format.getCompactFormat()); } StringWriter buffer = new StringWriter(); out.output(aggregate, buffer); String retval = buffer.toString(); retval = retval.replaceAll(" xmlns:oval=\"removeme\"", ""); return retval.replaceAll(" xmlns:redhat=\"removeme\"", ""); }
Example #4
Source File: StepConfigsDOM.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
public String createConfigXml(StepsConfig stepsConfig) throws ApsSystemException { String xml = null; try { Element root = this.createConfigElement(stepsConfig); XMLOutputter out = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); Document doc = new Document(root); xml = out.outputString(doc); } catch (Throwable t) { _logger.error("Error creating xml config", t); throw new ApsSystemException("Error creating xml config", t); } return xml; }
Example #5
Source File: BlockExporter.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
public void finalizeExport() throws XChangeException{ FileDialog fd = new FileDialog(UiDesk.getTopShell(), SWT.SAVE); fd.setText(Messages.BlockContainer_Blockbeschreibung); fd.setFilterExtensions(new String[] { "*.xchange" //$NON-NLS-1$ }); fd.setFilterNames(new String[] { Messages.BlockContainer_xchangefiles }); String filename = fd.open(); if (filename != null) { Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); //$NON-NLS-1$ XMLOutputter xmlo = new XMLOutputter(format); String xmlAspect = xmlo.outputString(getDocument()); try { FileOutputStream fos = new FileOutputStream(filename); fos.write(xmlAspect.getBytes()); fos.close(); } catch (Exception ex) { ExHandler.handle(ex); throw new XChangeException("Output failed " + ex.getMessage()); } } }
Example #6
Source File: RunConfigurationSerializerTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void testRunConfigurationUnalteredBySerializationRoundTrip() throws InvalidDataException { configuration.setTarget(Label.create("//package:rule")); configuration.setKeepInSync(true); Element initialElement = runManager.getState(); Element element = RunConfigurationSerializer.writeToXml(configuration); assertThat(RunConfigurationSerializer.findExisting(getProject(), element)).isNotNull(); clearRunManager(); // remove configuration from project RunConfigurationSerializer.loadFromXmlElementIgnoreExisting(getProject(), element); Element newElement = runManager.getState(); XMLOutputter xmlOutputter = new XMLOutputter(Format.getCompactFormat()); assertThat(xmlOutputter.outputString(newElement)) .isEqualTo(xmlOutputter.outputString(initialElement)); }
Example #7
Source File: BlazeCommandRunConfigurationRunManagerImplTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void getStateElementShouldMatchAfterEditorApplyToAndResetFrom() throws ConfigurationException { final XMLOutputter xmlOutputter = new XMLOutputter(Format.getCompactFormat()); final BlazeCommandRunConfigurationSettingsEditor editor = new BlazeCommandRunConfigurationSettingsEditor(configuration); configuration.setTarget(Label.create("//package:rule")); final Element initialElement = runManager.getState(); editor.resetFrom(configuration); editor.applyEditorTo(configuration); final Element newElement = runManager.getState(); assertThat(xmlOutputter.outputString(newElement)) .isEqualTo(xmlOutputter.outputString(initialElement)); Disposer.dispose(editor); }
Example #8
Source File: BlazeCommandRunConfigurationRunManagerImplTest.java From intellij with Apache License 2.0 | 6 votes |
@Test public void loadStateAndGetStateElementShouldMatchAfterChangeAndRevert() { final XMLOutputter xmlOutputter = new XMLOutputter(Format.getCompactFormat()); final Label label = Label.create("//package:rule"); configuration.setTarget(label); final Element initialElement = runManager.getState(); runManager.loadState(initialElement); final BlazeCommandRunConfiguration modifiedConfiguration = (BlazeCommandRunConfiguration) runManager.getAllConfigurations()[0]; modifiedConfiguration.setTarget(Label.create("//new:label")); final Element modifiedElement = runManager.getState(); assertThat(xmlOutputter.outputString(modifiedElement)) .isNotEqualTo(xmlOutputter.outputString(initialElement)); runManager.loadState(modifiedElement); final BlazeCommandRunConfiguration revertedConfiguration = (BlazeCommandRunConfiguration) runManager.getAllConfigurations()[0]; revertedConfiguration.setTarget(label); final Element revertedElement = runManager.getState(); assertThat(xmlOutputter.outputString(revertedElement)) .isEqualTo(xmlOutputter.outputString(initialElement)); }
Example #9
Source File: StepConfigsDOM.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
public String createConfigXml(Map<String, StepsConfig> config) throws ApsSystemException { String xml = null; try { Element root = new Element(ROOT); Collection<StepsConfig> stepsConfigs = config.values(); if (null != stepsConfigs) { Iterator<StepsConfig> iter = stepsConfigs.iterator(); while (iter.hasNext()) { StepsConfig stepsConfig = iter.next(); Element stepsConfigElements = this.createConfigElement(stepsConfig); root.addContent(stepsConfigElements); } } XMLOutputter out = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); Document doc = new Document(root); xml = out.outputString(doc); } catch (Throwable t) { _logger.error("Error creating xml config", t); throw new ApsSystemException("Error creating xml config", t); } return xml; }
Example #10
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 #11
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 6 votes |
public static String doc2String(final Document doc) { final StringWriter sw = new StringWriter(); final Format format = Format.getRawFormat().setEncoding("UTF-8"); final XMLOutputter xmlOut = new XMLOutputter(format); String strOutput = null; if (doc != null) { try { xmlOut.output(doc, sw); strOutput = sw.toString(); } catch (final IOException e) { LOGGER.error("Unable to retrieve the xml output", e); return null; } } return strOutput; }
Example #12
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 #13
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 #14
Source File: CreoleRegisterImpl.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
private void processFullCreoleXmlTree(Plugin plugin, Document jdomDoc, CreoleAnnotationHandler annotationHandler) throws GateException, IOException, JDOMException { // now we can process any annotations on the new classes // and augment the XML definition annotationHandler.processAnnotations(jdomDoc); // debugging if(DEBUG) { XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); xmlOut.output(jdomDoc, System.out); } // finally, parse the augmented definition with the normal parser DefaultHandler handler = new CreoleXmlHandler(this, plugin); SAXOutputter outputter = new SAXOutputter(handler, handler, handler, handler); outputter.output(jdomDoc); if(DEBUG) { Out.prln("done parsing " + plugin); } }
Example #15
Source File: DuplocatorHashCallback.java From consulo with Apache License 2.0 | 6 votes |
public static void writeDuplicates(String path, Project project, DupInfo info) throws IOException { Element rootElement = new Element("root"); final int patterns = info.getPatterns(); for (int i = 0; i < patterns; i++) { Element duplicate = new Element("duplicate"); duplicate.setAttribute("cost", String.valueOf(info.getPatternCost(i))); duplicate.setAttribute("hash", String.valueOf(info.getHash(i))); writeFragments(Arrays.asList(info.getFragmentOccurences(i)), duplicate, project, true); rootElement.addContent(duplicate); } try (FileWriter fileWriter = new FileWriter(path + File.separator + "duplicates.xml")) { XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); xmlOutputter.output(new org.jdom.Document(rootElement), fileWriter); } }
Example #16
Source File: EntityTypeDOM.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
@Override public String getXml(Map<String, IApsEntity> entityTypes) throws ApsSystemException { XMLOutputter out = new XMLOutputter(); Document document = new Document(); try { Element rootElement = new Element(this.getEntityTypesRootElementName()); document.setRootElement(rootElement); List<String> entityTypeCodes = new ArrayList<>(entityTypes.keySet()); Collections.sort(entityTypeCodes); for (String entityTypeCode : entityTypeCodes) { IApsEntity currentEntityType = entityTypes.get(entityTypeCode); Element entityTypeElement = this.createTypeElement(currentEntityType); rootElement.addContent(entityTypeElement); } Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); } catch (Throwable t) { _logger.error("Error building xml", t); throw new ApsSystemException("Error building xml", t); } return out.outputString(document); }
Example #17
Source File: EntityTypeDOM.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
@Override public String getXml(IApsEntity entityType) throws ApsSystemException { XMLOutputter out = new XMLOutputter(); Document document = new Document(); try { Element entityTypeElement = this.createTypeElement(entityType); document.setRootElement(entityTypeElement); Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); } catch (Throwable t) { _logger.error("Error building xml", t); throw new ApsSystemException("Error building xml", t); } return out.outputString(document); }
Example #18
Source File: OvalFileAggregator.java From uyuni with GNU General Public License v2.0 | 6 votes |
/** * Finalizes processing and builds the aggregated document * @param prettyPrint pretty print XML or not * @return XML in string form * @throws IOException document output failed */ public String finish(boolean prettyPrint) throws IOException { if (!isFinished && !isEmpty()) { buildDocument(); isFinished = true; } if (isEmpty()) { return ""; } XMLOutputter out = new XMLOutputter(); if (prettyPrint) { out.setFormat(Format.getPrettyFormat()); } else { out.setFormat(Format.getCompactFormat()); } StringWriter buffer = new StringWriter(); out.output(aggregate, buffer); String retval = buffer.toString(); retval = retval.replaceAll(" xmlns:oval=\"removeme\"", ""); return retval.replaceAll(" xmlns:redhat=\"removeme\"", ""); }
Example #19
Source File: UserShortcutConfigDOM.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
protected static String createUserConfigXml(String[] config) throws ApsSystemException { XMLOutputter out = new XMLOutputter(); Document document = new Document(); try { Element rootElement = new Element(ROOT_ELEMENT_NAME); document.setRootElement(rootElement); for (int i = 0; i < config.length; i++) { String shortcut = config[i]; if (null != shortcut) { Element element = new Element(BOX_ELEMENT_NAME); element.setAttribute(POS_ATTRIBUTE_NAME, String.valueOf(i)); element.setText(shortcut); rootElement.addContent(element); } } } catch (Throwable t) { _logger.error("Error parsing user config", t); //ApsSystemUtils.logThrowable(t, UserShortcutConfigDOM.class, "extractUserShortcutConfig"); throw new ApsSystemException("Error parsing user config", t); } Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); return out.outputString(document); }
Example #20
Source File: XMLOutputterTest.java From consulo with Apache License 2.0 | 5 votes |
private String printElement(Element root) throws IOException { XMLOutputter xmlOutputter = JDOMUtil.createOutputter("\n"); final Format format = xmlOutputter.getFormat().setOmitDeclaration(true).setOmitEncoding(true).setExpandEmptyElements(true); xmlOutputter.setFormat(format); CharArrayWriter writer = new CharArrayWriter(); xmlOutputter.output(root, writer); String res = new String(writer.toCharArray()); return res; }
Example #21
Source File: JDOMUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static XMLOutputter createOutputter(String lineSeparator) { XMLOutputter xmlOutputter = newXmlOutputter(); Format format = Format.getCompactFormat(). setIndent(" "). setTextMode(Format.TextMode.TRIM). setEncoding(CharsetToolkit.UTF8). setOmitEncoding(false). setOmitDeclaration(false). setLineSeparator(lineSeparator); xmlOutputter.setFormat(format); return xmlOutputter; }
Example #22
Source File: CustomWalker.java From consulo with Apache License 2.0 | 5 votes |
/** * Append some text to the text-like sequence that will be treated as * CDATA. * * @param trim How to prepare the CDATA content * @param text The actual CDATA content. */ public void appendCDATA(final Trim trim, final String text) { // this resets the mtbuffer too. closeText(); String toadd = null; switch (trim) { case NONE: toadd = text; break; case BOTH: toadd = Format.trimBoth(text); break; case LEFT: toadd = Format.trimLeft(text); break; case RIGHT: toadd = Format.trimRight(text); break; case COMPACT: toadd = Format.compact(text); break; } toadd = escapeCDATA(toadd); ensurespace(); // mark this as being CDATA text mtdata[mtsize] = CDATATOKEN; mttext[mtsize++] = toadd; mtgottext = true; }
Example #23
Source File: BTXMLManager.java From jbt with Apache License 2.0 | 5 votes |
/** * Exports a {@link BT} into an XML file. */ public static void export(BT tree, FileOutputStream file) throws IOException { Document doc = createDocument(tree); XMLOutputter outputter = new XMLOutputter(); Format format = Format.getPrettyFormat(); outputter.setFormat(format); outputter.output(doc, file); file.close(); }
Example #24
Source File: StyleCommands.java From geoserver-shell with MIT License | 5 votes |
@CliCommand(value = "style sld get", help = "Get the SLD of a style.") public String getSld( @CliOption(key = "name", mandatory = true, help = "The name") String name, @CliOption(key = "workspace", mandatory = false, help = "The workspace") String workspace, @CliOption(key = "file", mandatory = false, help = "The output file") File file, @CliOption(key = "prettyprint", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether to pretty print the SLD or not") boolean prettyPrint ) throws Exception { GeoServerRESTReader reader = new GeoServerRESTReader(geoserver.getUrl(), geoserver.getUser(), geoserver.getPassword()); String sld; if (workspace == null) { sld = reader.getSLD(name); } else { sld = getSLD(name, workspace); } if (prettyPrint) { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new StringReader(sld)); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); sld = outputter.outputString(document); } if (file != null) { FileWriter writer = new FileWriter(file); writer.write(sld); writer.close(); return file.getAbsolutePath(); } else { return sld; } }
Example #25
Source File: MailConfigDOM.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
/** * Create an xml containing the jpmail configuration. * @param config The jpmail configuration. * @return The xml containing the configuration. * @throws ApsSystemException In case of errors. */ public String createConfigXml(MailConfig config) throws ApsSystemException { Element root = this.createConfigElement(config); Document doc = new Document(root); XMLOutputter out = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); return out.outputString(doc); }
Example #26
Source File: TravelAccountTypeExporter.java From rice with Educational Community License v2.0 | 5 votes |
@Override public void export(Class<?> dataObjectClass, List<? extends Object> dataObjects, String exportFormat, OutputStream outputStream) throws IOException, ExportNotSupportedException { Document document = new Document(new Element("travelAccountTypes")); for (Object dataObject : dataObjects) { Element travelAccountTypeElement = new Element("travelAccountType"); TravelAccountType travelAccountType = (TravelAccountType) dataObject; Element accountTypeCodeElement = new Element("accountTypeCode"); accountTypeCodeElement.setText(travelAccountType.getAccountTypeCode()); travelAccountTypeElement.addContent(accountTypeCodeElement); Element nameElement = new Element("name"); nameElement.setText(travelAccountType.getName()); travelAccountTypeElement.addContent(nameElement); Element activeElement = new Element("active"); activeElement.setText(Boolean.toString(travelAccountType.isActive())); travelAccountTypeElement.addContent(activeElement); document.getRootElement().addContent(travelAccountTypeElement); } XMLOutputter outputer = new XMLOutputter(Format.getPrettyFormat()); try { outputer.output(document, outputStream); } catch (IOException e) { throw new RuntimeException("Could not write XML data export.", e); } }
Example #27
Source File: AvatarConfigDOM.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
/** * Create an xml containing the jpavatar configuration. * @param config The jpavatar configuration. * @return The xml containing the configuration. * @throws ApsSystemException In case of errors. */ public String createConfigXml(AvatarConfig config) throws ApsSystemException { Element root = this.createConfigElement(config); Document doc = new Document(root); XMLOutputter out = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); return out.outputString(doc); }
Example #28
Source File: NewsletterConfigDOM.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
/** * Create an xml containing the newsletter configuration. * @param config The newsletter configuration. * @return The xml containing the configuration. * @throws ApsSystemException In case of errors. */ public String createConfigXml(NewsletterConfig config) throws ApsSystemException { Element root = this.createConfigElement(config); Document doc = new Document(root); XMLOutputter out = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); String xml = out.outputString(doc); return xml; }
Example #29
Source File: ContentWorkflowDOM.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
public String createConfigXml(Map<String, Workflow> config) throws ApsSystemException { Element root = this.createConfigElement(config); Document doc = new Document(root); XMLOutputter out = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); return out.outputString(doc); }
Example #30
Source File: PageModelDOM.java From entando-core with GNU Lesser General Public License v3.0 | 5 votes |
public String getXMLDocument(){ XMLOutputter out = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent("\t"); out.setFormat(format); return out.outputString(this._doc); }