本文整理汇总了Java中org.jdom2.output.XMLOutputter.setFormat方法的典型用法代码示例。如果您正苦于以下问题:Java XMLOutputter.setFormat方法的具体用法?Java XMLOutputter.setFormat怎么用?Java XMLOutputter.setFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom2.output.XMLOutputter
的用法示例。
在下文中一共展示了XMLOutputter.setFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public void exportXML(ArrayList<Pokemon> pokemons,String tipo){
try {
Element pokemon = new Element("pokemon");
Document doc = new Document(pokemon);
for(Pokemon p:pokemons) {
Element poke = new Element("pokemon");
poke.addContent(new Element("nombre").setText(p.getName()));
poke.addContent(new Element("peso").setText(String.valueOf(p.getWeight())));
poke.addContent(new Element("altura").setText(String.valueOf(p.getHeight())));
poke.addContent(new Element("base_experience").setText(String.valueOf(p.getBaseExperience())));
doc.getRootElement().addContent(poke);
}
XMLOutputter output = new XMLOutputter();
output.setFormat(Format.getPrettyFormat());
output.output(doc, new FileWriter("pokemons-tipo-"+tipo+".xml"));
}catch(Exception e) {
System.out.println("Ocurri� alg�n error");
}
}
示例2: getStringFromElement
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
*
* @param element
* @param encoding
* @return
*/
public static String getStringFromElement(Element element, String encoding) {
if (element == null) {
throw new IllegalArgumentException("element may not be null");
}
if (encoding == null) {
encoding = DEFAULT_ENCODING;
}
Format format = Format.getRawFormat();
XMLOutputter outputter = new XMLOutputter(format);
Format xmlFormat = outputter.getFormat();
if (StringUtils.isNotEmpty(encoding)) {
xmlFormat.setEncoding(encoding);
}
xmlFormat.setExpandEmptyElements(true);
outputter.setFormat(xmlFormat);
String docString = outputter.outputString(element);
return docString;
}
示例3: updateXMLValue
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* This method updates XML values from the Health Check GUI.
* Not all items are supported. If it can't find the XML file,
* it will print the error message. Could cause errors if the structure
* of the XML file has been modified.
*/
public void updateXMLValue(String item, String value) {
if (item.equals("jss_url")){
this.root.getChildren().get(0).setText(value);
} else if (item.equals("jss_username")){
this.root.getChildren().get(1).setText(value);
} else if (item.equals("jss_password")){
this.root.getChildren().get(2).setText(value);
} else if (item.equals("smart_groups")){
this.root.getChildren().get(5).getChildren().get(1).setText(value);
} else if (item.equals("extension_attributes")){
this.root.getChildren().get(5).getChildren().get(2).getChildren().get(0).setText(value);
this.root.getChildren().get(5).getChildren().get(2).getChildren().get(1).setText(value);
}
try {
XMLOutputter o = new XMLOutputter();
o.setFormat(Format.getPrettyFormat());
o.output(this.root, new FileWriter(getConfigurationPath()));
} catch (Exception e) {
LOGGER.error("Unable to update XML file.", e);
}
}
示例4: doGetPost
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
@Override
protected void doGetPost(MCRServletJob job) throws Exception {
HttpServletRequest request = job.getRequest();
// get base url
if (this.myBaseURL == null) {
this.myBaseURL = MCRFrontendUtil.getBaseURL() + request.getServletPath().substring(1);
}
logRequest(request);
// create new oai request
OAIRequest oaiRequest = new OAIRequest(fixParameterMap(request.getParameterMap()));
// create new oai provider
OAIXMLProvider oaiProvider = new JAXBOAIProvider(getOAIAdapter());
// handle request
OAIResponse oaiResponse = oaiProvider.handleRequest(oaiRequest);
// build response
Element xmlRespone = oaiResponse.toXML();
// fire
job.getResponse().setContentType("text/xml; charset=UTF-8");
XMLOutputter xout = new XMLOutputter();
xout.setFormat(Format.getPrettyFormat().setEncoding("UTF-8"));
xout.output(addXSLStyle(new Document(xmlRespone)), job.getResponse().getOutputStream());
}
示例5: write
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Write the root Element to a writer.
*
* @param root
* Root Element to write.
* @param writer
* Writer to write to.
* @throws IOException
* if the writer fails to write.
*/
@SuppressWarnings("unchecked")
protected void write(Element root, Writer writer) throws IOException {
XMLOutputter outputter = new XMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
Document document = new Document(root);
if (stylesheetURL != null) {
Map<String, String> instructionMap = new HashMap<String, String>(2);
instructionMap.put("type", "text/xsl");
instructionMap.put("href", stylesheetURL);
ProcessingInstruction pi = new ProcessingInstruction(
"xml-stylesheet", instructionMap);
document.getContent().add(0, pi);
}
outputter.output(document, writer);
}
示例6: repair
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static String repair(String originalHtml)
{
String content = null;
try
{
HtmlCleaner cleaner = createHtmlCleaner();
//wir probieren es erstmal mit UTF-8
TagNode rootNode = cleaner.clean(originalHtml);
Document jdomDocument = new JDomSerializer(cleaner.getProperties(), false).createJDom(rootNode);
jdomDocument.setDocType(Constants.DOCTYPE_XHTML.clone());
XMLOutputter outputter = new XMLOutputter();
Format xmlFormat = Format.getPrettyFormat();
outputter.setFormat(xmlFormat);
outputter.setXMLOutputProcessor(new XHTMLOutputProcessor());
content = outputter.outputString(jdomDocument);
}
catch (IllegalAddException e)
{
logger.error("", e);
}
return content;
}
示例7: createOPFContent
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static byte[] createOPFContent(Book book) throws IllegalArgumentException, IllegalStateException
{
Document opfDocument = write(book);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLOutputter outputter = new XMLOutputter();
Format xmlFormat = Format.getPrettyFormat();
outputter.setFormat(xmlFormat);
try
{
outputter.output(opfDocument, baos);
}
catch (IOException e)
{
logger.error("", e);
}
return baos.toByteArray();
}
示例8: outputXHTMLDocument
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static byte[] outputXHTMLDocument(Document document)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
document.setDocType(Constants.DOCTYPE_XHTML.clone());
XMLOutputter outputter = new XMLOutputter();
Format xmlFormat = Format.getPrettyFormat();
outputter.setFormat(xmlFormat);
outputter.setXMLOutputProcessor(new XHTMLOutputProcessor());
outputter.output(document, baos);
}
catch (IOException e)
{
logger.error("", e);
}
return baos.toByteArray();
}
示例9: createXml
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
private void createXml(ISendMessageCallback callback) {
Document generatedXml = new Document();
Stack<DocElement> parentStack = new Stack<DocElement>();
ArrayList<String> outboundPayload = new ArrayList<String>();
for (Message msg : messagesToProcess) {
processMsgEntities(parentStack, msg, generatedXml);
}
XMLOutputter xmlOutputter = new XMLOutputter();
Format format = null;
if (xmlFormat.equals(COMPACT_FORMAT)) {
format = Format.getCompactFormat();
} else if (xmlFormat.equals(RAW_FORMAT)) {
format = Format.getRawFormat();
} else {
format = Format.getPrettyFormat();
}
xmlOutputter.setFormat(format);
outboundPayload.add(xmlOutputter.outputString(generatedXml));
callback.sendTextMessage(null, outboundPayload);
}
示例10: removeElement
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public void removeElement(String cityName) {
try {
SAXBuilder builder = new SAXBuilder();
Document doc = (Document) builder.build(xmlFile);
Element costCalculator = doc.getRootElement();
Iterator<Element> cities = costCalculator.getChildren("city").iterator();
while (cities.hasNext()) {
Element city = (Element) cities.next();
if (cityName.equals(city.getAttribute("name").getValue())) {
cities.remove();
}
}
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(doc, new FileWriter(xmlFile));
} catch (JDOMException | IOException e) {
e.printStackTrace();
}
}
示例11: initialize
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
@Override
public void initialize(UimaContext context)
throws ResourceInitializationException {
inputDir = CORPORA_BASE + "USC_TTE_corpus";
// inputDir = CORPORA_HOME + "src/test/resources/corpus/USC_TTE_corpus";
docCnt = 1;
super.initialize(context);
try {
File corpusDir = new File(inputDir);
checkArgument(corpusDir.exists());
// duplicating code from AbstractFileReader to add "xml" filtering
fileIterator = DirectoryIterator.get(directoryIterator, corpusDir,
"xml", false);
builder = new SAXBuilder();
xo = new XMLOutputter();
xo.setFormat(Format.getRawFormat());
sentenceXPath = XPathFactory.instance().compile("//S");
} catch (Exception e) {
throw new ResourceInitializationException(
ResourceInitializationException.NO_RESOURCE_FOR_PARAMETERS,
new Object[] { inputDir });
}
}
示例12: generateConfigXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static void generateConfigXML(DynamicAspect aspect, String filepath) {
try {
Element root = generateRootElement();
Document doc = new Document(root);
generateBeans(doc, aspect);
Element config = new Element(AOP_CONFIG, aop);
generatePointcuts(config, aspect);
generateAdvisors(config, aspect);
doc.getRootElement().addContent(config);
// new XMLOutputter().output(doc, System.out);
XMLOutputter xmlOutput = new XMLOutputter();
// display nice nice
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(doc, new FileWriter(filepath)); // filepath example: "c:\\file.xml"
} catch (IOException io) {
String desc = "Error generating xml configuration file. IOException.";
DeploymentStatusSingleton.getStatus().addError(desc, Module.ASPECT_WEAVER, Type.SPRING_AOP_WEAVER);
io.printStackTrace();
}
}
示例13: save
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public boolean save(File file) {
XMLOutputter out = new XMLOutputter();
out.setFormat(Format.getPrettyFormat());
try {
if (file.createNewFile()) {
Cardinal.getInstance().getLogger().info("Database file not found, creating...");
out.output(document, new FileWriter(file));
return true;
} else {
out.output(document, new FileWriter(file));
return true;
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
示例14: save
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public void save(String filepath) throws IOException {
Document xml = new Document(new Element("root"));
Element root = xml.getRootElement();
serialize(root);
XMLOutputter xout = new XMLOutputter();
xout.setFormat(Format.getPrettyFormat());
FileOutputStream ostream = null;
try {
ostream = new FileOutputStream(filepath);
xout.output(xml, ostream);
} finally {
if (ostream != null) {
ostream.close();
}
}
}
示例15: actionPerformed
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent actionEvent) {
File file = new File(WASRFrame.getInstance().getCurrentReport().getReportFolder(), "report.xml");
Document wasrDoc = WASRFrame.getInstance().getCurrentReport().getReportDOM();
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
XMLOutputter outputter = new XMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
outputter.output(wasrDoc, bos);
bos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace(); // TODO: push save errors up to UI.
}
}