Java Code Examples for org.jdom.output.Format#getPrettyFormat()

The following examples show how to use org.jdom.output.Format#getPrettyFormat() . 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: DuplocatorHashCallback.java    From consulo with Apache License 2.0 6 votes vote down vote up
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 2
Source File: EntityTypeDOM.java    From entando-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 3
Source File: DuplocatorHashCallback.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: PageModelDOM.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getXMLDocument(){
	XMLOutputter out = new XMLOutputter();
	Format format = Format.getPrettyFormat();
	format.setIndent("\t");
	out.setFormat(format);
	return out.outputString(this._doc);
}
 
Example 5
Source File: ContentWorkflowDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 6
Source File: SoapConverter.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public String toString(){
	if (doc != null && eRoot != null) {
		Format format = Format.getPrettyFormat();
		format.setEncoding("utf-8");
		XMLOutputter xmlo = new XMLOutputter(format);
		return xmlo.outputString(doc);
	}
	return null;
}
 
Example 7
Source File: XMLTool.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean writeXMLDocument(Document doc, String dest){
	try {
		FileOutputStream fout = new FileOutputStream(dest);
		OutputStreamWriter cout = new OutputStreamWriter(fout, "UTF-8");
		XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
		xout.output(doc, cout);
		cout.close();
		fout.close();
		return true;
	} catch (Exception e) {
		ExHandler.handle(e);
		return false;
	}
	
}
 
Example 8
Source File: NewsletterConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 9
Source File: TravelAccountTypeExporter.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@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 10
Source File: BTXMLManager.java    From jbt with Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
Source File: SystemParamsUtils.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String getXMLDocument(Document doc) {
    XMLOutputter out = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setIndent("\t");
    out.setFormat(format);
    return out.outputString(doc);
}
 
Example 12
Source File: AvatarConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 13
Source File: WidgetTypeDOM.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getXMLDocument(){
	XMLOutputter out = new XMLOutputter();
	Format format = Format.getPrettyFormat();
	format.setIndent("");
	out.setFormat(format);
	return out.outputString(this.getDoc());
}
 
Example 14
Source File: SystemInstallationReport.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String toXml() {
    Document doc = new Document();
    Element rootElement = new Element(ROOT_ELEMENT);
    Status status = Status.OK;
    for (ComponentInstallationReport componentReport : this.getReports()) {
        if (!componentReport.getStatus().equals(Status.OK)
                && !componentReport.getStatus().equals(Status.UNINSTALLED)) {
            status = componentReport.getStatus();
            break;
        }
    }
    rootElement.setAttribute(STATUS_ATTRIBUTE, status.toString());

    Element creationElement = new Element(CREATION_ELEMENT);
    creationElement.setText(DateConverter.getFormattedDate(this.getCreation(), DATE_FORMAT));
    rootElement.addContent(creationElement);

    Element lastUpdateElement = new Element(LAST_UPDATE_ELEMENT);
    lastUpdateElement.setText(DateConverter.getFormattedDate(this.getLastUpdate(), DATE_FORMAT));
    rootElement.addContent(lastUpdateElement);

    Element componentsElement = new Element(COMPONENTS_ELEMENT);
    rootElement.addContent(componentsElement);
    for (int i = 0; i < this.getReports().size(); i++) {
        ComponentInstallationReport singleReport = this.getReports().get(i);
        Element componentElement = singleReport.toJdomElement();
        componentsElement.addContent(componentElement);
    }
    doc.setRootElement(rootElement);
    XMLOutputter out = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setIndent("\t");
    out.setFormat(format);
    return out.outputString(doc);
}
 
Example 15
Source File: StyleCommands.java    From geoserver-shell with MIT License 5 votes vote down vote up
@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 16
Source File: PageExtraConfigDOM.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected String getXMLDocument(Document doc) {
	XMLOutputter out = new XMLOutputter();
	Format format = Format.getPrettyFormat();
	out.setFormat(format);
	return out.outputString(doc);
}
 
Example 17
Source File: ServiceExtraConfigDOM.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected String getXMLDocument() {
    XMLOutputter out = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    out.setFormat(format);
    return out.outputString(this._doc);
}
 
Example 18
Source File: DataSourceDumpReport.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String toXml() {
	try {
		Document doc = new Document();
		Element rootElement = new Element(ROOT_ELEMENT);
		this.addElement(DATE_ELEMENT, DateConverter.getFormattedDate(this.getDate(), DATE_FORMAT), rootElement);
		this.addElement(REQUIRED_TIME_ELEMENT, String.valueOf(this.getRequiredTime()), rootElement);
		this.addElement(SUBFOLDER_NAME_ELEMENT, this.getSubFolderName(), rootElement);
		Element components = new Element(COMPONENTS_HISTORY_ELEMENT);
		rootElement.addContent(components);
		List<ComponentInstallationReport> componentsHistory = this.getComponentsHistory();
		for (int i = 0; i < componentsHistory.size(); i++) {
			ComponentInstallationReport componentHistory = componentsHistory.get(i);
			Element element = componentHistory.toJdomElement();
			components.addContent(element);
		}
		List<String> dataSourceNames = new ArrayList<String>();
		dataSourceNames.addAll(this.getDataSourcesReports().keySet());
		for (int i = 0; i < dataSourceNames.size(); i++) {
			String dataSourceName = dataSourceNames.get(i);
			Element dataSourceElement = new Element(DATASOURCE_ELEMENT);
			rootElement.addContent(dataSourceElement);
			dataSourceElement.setAttribute(NAME_ATTRIBUTE, dataSourceName);
			List<TableDumpReport> tableReports = this.getDataSourcesReports().get(dataSourceName);
			BeanComparator comparator = new BeanComparator("tableName");
			Collections.sort(tableReports, comparator);
			for (int j = 0; j < tableReports.size(); j++) {
				TableDumpReport tableDumpReport = tableReports.get(j);
				dataSourceElement.addContent(tableDumpReport.toJdomElement());
			}
		}
		doc.setRootElement(rootElement);
		XMLOutputter out = new XMLOutputter();
		Format format = Format.getPrettyFormat();
		format.setIndent("\t");
		out.setFormat(format);
		return out.outputString(doc);
	} catch (Throwable t) {
		_logger.error("Error creating XML", t);
		throw new RuntimeException("Error creating XML", t);
	}
}
 
Example 19
Source File: ConsultationExport.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
public String doExport(String dir, String stickerName){
	try {
		Query<Patient> qbe = new Query<Patient>(Patient.class);
		if (stickerName != null) {
			List<Sticker> ls =
				new Query<Sticker>(Sticker.class, Sticker.FLD_NAME, stickerName).execute();
			if (ls != null && ls.size() > 0) {
				final Sticker sticker = ls.get(0);
				
				final PatFilterImpl pf = new PatFilterImpl();
				IFilter flt = new IFilter() {
					@Override
					public boolean select(Object element){
						return pf.accept((Patient) element, sticker) == IPatFilter.ACCEPT;
					}
					
				};
				qbe.addPostQueryFilter(flt);
			} else {
				return "Sticker " + stickerName + " nicht gefunden.";
			}
		}
		for (Patient pat : qbe.execute()) {
			Element e = new Element("Patient");
			e.setAttribute("ID", pat.getId());
			e.setAttribute("Name", pat.get(Patient.FLD_NAME));
			e.setAttribute("Vorname", pat.get(Patient.FLD_FIRSTNAME));
			e.setAttribute("GebDat", pat.get(Patient.FLD_DOB));
			for (Fall fall : pat.getFaelle()) {
				Element f = new Element("Fall");
				e.addContent(f);
				f.setAttribute("ID", fall.getId());
				f.setAttribute("Bezeichnung", fall.getBezeichnung());
				f.setAttribute("BeginnDatum", fall.getBeginnDatum());
				f.setAttribute("EndDatum", fall.getEndDatum());
				f.setAttribute("Gesetz", fall.getConfiguredBillingSystemLaw().name());
				f.setAttribute("Abrechnungssystem", fall.getAbrechnungsSystem());
				Kontakt k = fall.getGarant();
				if (k != null) {
					f.setAttribute("Garant", fall.getGarant().getLabel());
				}
				Kontakt costBearer = fall.getCostBearer();
				if (costBearer != null) {
					f.setAttribute("Kostentraeger", costBearer.getLabel());
					f.setAttribute("Versicherungsnummer",
						fall.getRequiredString("Versicherungsnummer"));
				}
				for (Konsultation kons : fall.getBehandlungen(false)) {
					Element kel = new Element("Konsultation");
					f.addContent(kel);
					kel.setAttribute("ID", kons.getId());
					kel.setAttribute("Datum", kons.getDatum());
					kel.setAttribute("Label", kons.getVerboseLabel());
					Samdas samdas = new Samdas(kons.getEintrag().getHead());
					kel.setText(samdas.getRecordText());
				}
			}
			Document doc = new Document();
			doc.setRootElement(e);
			FileOutputStream fout = new FileOutputStream(new File(dir, pat.getId() + ".xml"));
			OutputStreamWriter cout = new OutputStreamWriter(fout, "UTF-8"); //$NON-NLS-1$
			XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
			xout.output(doc, cout);
			cout.close();
			fout.close();
		}
		return "ok";
	} catch (Exception ex) {
		return ex.getClass().getName() + ":" + ex.getMessage();
	}
}
 
Example 20
Source File: KeelToXml.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Method that creates the output file with XML format given as parameter 
 * using all the structures built by the start method of the Exporter class.  
 * @param pathnameOutput XML file path to generate.
 * @throws Exception if the file can not be written.
 */
public void Save(String pathnameOutput) throws Exception {
    int i;
    int j;
    int k;
    String value = new String();
    String filename = new String();
    String nameElement = new String();
    String vowel[] = {"a", "e", "i", "o", "u", "A", "E", "I", "O", "U"};
    String vowel_accent[] = {"á", "é", "í", "ó", "ú", "Á", "É", "Í", "Ó", "Ú"};

    /* Comprobamos si el nombre del fichero tiene la extensión .xml, si no la tiene
     * se la ponemos */
    if (pathnameOutput.endsWith(".xml")) {
        filename = pathnameOutput;
    } else {
        filename = pathnameOutput.concat(".xml");
    }
    Element root = new Element("root");
    Document myDocument = new Document(root);

    for (i = 0; i < data[0].size(); i++) {
        nameRelation = NameLabelValid(nameRelation);

        if (nameRelation.equals("")) {
            nameRelation = "root";
        }
        Element childrenRoot = new Element(nameRelation);

        for (j = 0; j < numAttributes; j++) {
            nameElement = attribute[j].getName();

            nameElement = NameLabelValid(nameElement);

            if (nameElement.equals("?") || nameElement.equals("<null>")) {
                nameElement = "ATTRIBUTE_" + (j + 1) + "";
            }
            value = (String) data[j].elementAt(i);

            value = value.replace("\"", "");

            for (k = 0; k < vowel.length; k++) {
                value = value.replace(vowel_accent[k], "&" + vowel[k] + "acute;");
            }
            Element children = new Element(nameElement).addContent(value);

            childrenRoot.addContent(children);
        }
        root.addContent(childrenRoot);
    }

    try {


        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());

        outputter.output(myDocument, new FileWriter(pathnameOutput));

    } catch (java.io.IOException e) {
        e.printStackTrace();
    }


    File f = new File(filename);


    System.out.println("Fichero " + f.getName() + " creado correctamente");


}