本文整理汇总了Java中org.openide.xml.XMLUtil.write方法的典型用法代码示例。如果您正苦于以下问题:Java XMLUtil.write方法的具体用法?Java XMLUtil.write怎么用?Java XMLUtil.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.xml.XMLUtil
的用法示例。
在下文中一共展示了XMLUtil.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
static void write(
@NonNull final OutputStream out,
@NonNull final RemotePlatform platform) throws IOException {
Parameters.notNull("out", out); //NOI18N
Parameters.notNull("platform", platform); //NOI18N
final Document doc = XMLUtil.createDocument(
ELM_PLATFORM,
null,
REMOTE_PLATFORM_DTD_ID,
REMOTE_PLATFORM_SYSTEM_ID);
final Element platformElement = doc.getDocumentElement();
platformElement.setAttribute(ATTR_NAME, platform.getDisplayName());
final Map<String,String> props = platform.getProperties();
final Element propsElement = doc.createElement(ELM_PROPERTIES);
writeProperties(props, propsElement, doc);
platformElement.appendChild(propsElement);
final Map<String,String> sysProps = platform.getSystemProperties();
final Element sysPropsElement = doc.createElement(ELM_SYSPROPERTIES);
writeProperties(sysProps, sysPropsElement, doc);
platformElement.appendChild(sysPropsElement);
XMLUtil.write(doc, out, "UTF8");
}
示例2: writeCustomScript
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Write a script with a new or modified document.
* @param scriptPath e.g. {@link #FILE_SCRIPT_PATH} or {@link #GENERAL_SCRIPT_PATH}
*/
void writeCustomScript(Document doc, String scriptPath) throws IOException {
FileObject script = helper.getProjectDirectory().getFileObject(scriptPath);
if (script == null) {
script = FileUtil.createData(helper.getProjectDirectory(), scriptPath);
}
FileLock lock = script.lock();
try {
OutputStream os = script.getOutputStream(lock);
try {
XMLUtil.write(doc, os, "UTF-8"); // NOI18N
} finally {
os.close();
}
} finally {
lock.releaseLock();
}
}
示例3: upgradeSchemaTestImpl
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private void upgradeSchemaTestImpl(String from, String to) throws Exception {
// Formatting has to be the same as Xerces' formatter produces for this test to pass:
String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<java-data xmlns=\""+from+"\">\n" +
" <!-- Hello there. -->\n" +
" <foo bar=\"baz\" quux=\"whatever\">hello</foo>\n" +
" <x>OK</x>\n" +
"</java-data>\n";
String xml2expected = xml1.replaceAll(from, to);
Document doc1 = XMLUtil.parse(new InputSource(new StringReader(xml1)), false, true, null, null);
Element el1 = doc1.getDocumentElement();
Element el2 = LookupProviderImpl.upgradeSchema(el1,to);
Document doc2 = XMLUtil.createDocument(JavaProjectNature.EL_JAVA, to, null, null);
doc2.removeChild(doc2.getDocumentElement());
doc2.appendChild(doc2.importNode(el2, true));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLUtil.write(doc2, baos, "UTF-8");
String xml2actual = baos.toString("UTF-8").replaceAll(System.getProperty("line.separator"), "\n");
assertEquals("Correct upgrade result", xml2expected, xml2actual);
}
示例4: write
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/** Write object described by DOM document filled by {@link #writeElement}
* @param w stream into which inst is written
* @param inst the setting object to be written
* @exception IOException if the object cannot be written
* @since 1.1
*/
public final void write(java.io.Writer w, Object inst) throws java.io.IOException {
Document doc = null;
try {
doc = XMLUtil.createDocument(rootElement, null, publicID, systemID);
setDocumentContext(doc, findContext(w));
writeElement(doc, doc.getDocumentElement(), inst);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(1024);
XMLUtil.write(doc, baos, "UTF-8"); // NOI18N
w.write(baos.toString("UTF-8")); // NOI18N
} catch (org.w3c.dom.DOMException ex) {
IOException e = new IOException(ex.getLocalizedMessage());
e.initCause(ex);
throw e;
} finally {
if (doc != null) {
clearCashesForDocument(doc);
}
}
}
示例5: testForFolder
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public void testForFolder() throws Exception {
TestFileUtils.writeFile(new File(getWorkDir(), ".git/config"),
"[core]\n"
+ "\trepositoryformatversion = 0\n"
+ "[remote \"origin\"]\n"
+ "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
+ "\turl = [email protected]:x/y.git\n"
+ "[branch \"master\"]\n"
+ "\tremote = origin\n"
+ "\tmerge = refs/heads/master\n");
// ref: http://www.kernel.org/pub/software/scm/git/docs/git-clone.html#_git_urls_a_id_urls_a
assertEquals("ssh://[email protected]/x/y.git", String.valueOf(HudsonGitSCM.getRemoteOrigin(Utilities.toURI(getWorkDir()), null)));
HudsonSCM.Configuration cfg = new HudsonGitSCM().forFolder(getWorkDir());
assertNotNull(cfg);
Document doc = XMLUtil.createDocument("whatever", null, null, null);
cfg.configure(doc);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLUtil.write(doc, baos, "UTF-8");
String text = baos.toString("UTF-8");
assertTrue(text, text.contains("x/y.git"));
}
示例6: generateContents
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Create XML contents of the shortcut to be generated, based on current data.
*/
private String generateContents() {
try {
Document doc = XMLUtil.createDocument("project", null, null, null); // NOI18N
Element pel = doc.getDocumentElement();
String displayName = (String)getProperty(PROP_DISPLAY_NAME);
if (displayName != null && displayName.length() > 0) {
pel.setAttribute("name", displayName); // NOI18N
}
pel.setAttribute("default", "run"); // NOI18N
Element tel = doc.createElement("target"); // NOI18N
tel.setAttribute("name", "run"); // NOI18N
Element ael = doc.createElement("ant"); // NOI18N
ael.setAttribute("antfile", project.getFile().getAbsolutePath()); // NOI18N
// #34802: let the child project decide on the basedir:
ael.setAttribute("inheritall", "false"); // NOI18N
ael.setAttribute("target", target.getAttribute("name")); // NOI18N
tel.appendChild(ael);
pel.appendChild(tel);
ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
XMLUtil.write(doc, baos, "UTF-8"); // NOI18N
return baos.toString("UTF-8"); // NOI18N
} catch (IOException e) {
AntModule.err.notify(e);
return ""; // NOI18N
}
}
示例7: safelyWrite
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private static void safelyWrite(FileObject projectXml, Document prjDoc) throws IOException {
OutputStream os = projectXml.getOutputStream();
try {
XMLUtil.write(prjDoc, os, "UTF-8"); // NOI18N
} finally {
os.close();
}
}
示例8: testSVNDir
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public void testSVNDir() throws Exception {
HudsonSCM scm = new HudsonSubversionSCM();
File dir = getWorkDir();
File dotSvn = new File(dir, ".svn");
dotSvn.mkdir();
OutputStream os = new FileOutputStream(new File(dotSvn, "entries"));
InputStream is = HudsonSubversionSCMTest.class.getResourceAsStream("sample-entries-file");
int c;
while ((c = is.read()) != -1) {
os.write(c);
}
is.close();
os.close();
HudsonSCM.Configuration cfg = scm.forFolder(dir);
assertNotNull(cfg);
Document doc = XMLUtil.createDocument("root", null, null, null);
cfg.configure(doc);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLUtil.write(doc, baos, "UTF-8");
assertEquals("<?xml version='1.0' encoding='UTF-8'?>" +
"<root>" +
"<scm class='hudson.scm.SubversionSCM'>" +
"<locations>" +
"<hudson.scm.SubversionSCM_-ModuleLocation>" +
"<remote>https://sezpoz.dev.java.net/svn/sezpoz/trunk</remote>" +
"<local>.</local>" +
"</hudson.scm.SubversionSCM_-ModuleLocation>" +
"</locations>" +
"<useUpdate>false</useUpdate>" +
"</scm>" +
"<triggers>" +
"<hudson.triggers.SCMTrigger>" +
"<spec>@hourly</spec>" +
"</hudson.triggers.SCMTrigger>" +
"</triggers>" +
"</root>",
baos.toString("UTF-8").replace('"', '\'').replaceAll("\n *", "").replaceAll("\r|\n", ""));
}
示例9: save
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public void save() {
synchronized (this) {
if (lastSave >= modificationCount) return ; //already saved
lastSave = modificationCount;
}
File file = Utilities.toFile(settings); //XXX: non-file:// scheme
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
XMLUtil.write(doc, out, "UTF-8");
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
示例10: xmlToString
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Format XML as a string. Assumes Xerces serializer in current impl.
* Collapse all comments to no body.
*/
private static String xmlToString(Element el) throws Exception {
Document doc = XMLUtil.createDocument("fake", null, null, null);
doc.removeChild(doc.getDocumentElement());
doc.appendChild(doc.importNode(el, true));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLUtil.write(doc, baos, "UTF-8");
return baos.toString("UTF-8").replaceAll("<!--([^-]|-[^-])*-->", "<!---->").replaceAll(System.getProperty("line.separator"), "\n");
}
示例11: create
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private static void create(File root, int val, final BoundedRangeModel progress) throws IOException {
for (int i = 0; i < val; i++) {
final int progval = i;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progress.setValue(progval);
}
});
boolean xml = i % 5 > 2;
String fname = "file" + i + (xml ? ".xml" : ".txt");
int bit = 0;
int x = i;
while (x > 0) {
if (x % 3 == 0) {
fname = "dir" + bit + File.separatorChar + fname;
}
bit++;
x /= 3;
}
File tomake = new File(root, "test" + File.separatorChar + fname);
tomake.getParentFile().mkdirs();
if (tomake.createNewFile()) {
OutputStream os = new FileOutputStream(tomake);
try {
if (xml) {
Document doc = createXML(i);
XMLUtil.write(doc, os, "UTF-8");
} else {
PrintStream ps = new PrintStream(os);
ps.println("Sample data for file #" + i);
ps.close();
}
} finally {
os.close();
}
}
}
}
示例12: writeXMLDocumentToFile
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private static void writeXMLDocumentToFile (Document doc, File dest) {
doc.getDocumentElement ().normalize ();
dest.getParentFile ().mkdirs ();
InputStream is = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream ();
OutputStream fos = null;
try {
try {
XMLUtil.write (doc, bos, "UTF-8"); // NOI18N
bos.close ();
fos = new FileOutputStream (dest);
is = new ByteArrayInputStream (bos.toByteArray ());
FileUtil.copy (is, fos);
} finally {
if (is != null) {
is.close ();
}
if (fos != null) {
fos.close ();
}
bos.close ();
}
} catch (java.io.FileNotFoundException fnfe) {
Exceptions.printStackTrace (fnfe);
} catch (java.io.IOException ioe) {
Exceptions.printStackTrace (ioe);
} finally {
try {
bos.close ();
} catch (IOException x) {
Exceptions.printStackTrace (x);
}
}
}
示例13: saveXml
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Save an XML config file to a named path.
* If the file does not yet exist, it is created.
*/
private static void saveXml(Document doc, FileObject dir, String path) throws IOException {
FileObject xml = FileUtil.createData(dir, path);
FileLock lock = xml.lock();
try {
OutputStream os = xml.getOutputStream(lock);
try {
XMLUtil.write(doc, os, "UTF-8"); // NOI18N
} finally {
os.close();
}
} finally {
lock.releaseLock();
}
}
示例14: filterProjectXML
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private static void filterProjectXML(FileObject fo, ZipInputStream str, String name) throws IOException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileUtil.copy(str, baos);
Document doc = XMLUtil.parse(new InputSource(new ByteArrayInputStream(baos.toByteArray())), false, false, null, null);
NodeList nl = doc.getDocumentElement().getElementsByTagName("name");
if (nl != null) {
for (int i = 0; i < nl.getLength(); i++) {
Element el = (Element) nl.item(i);
if (el.getParentNode() != null && "data".equals(el.getParentNode().getNodeName())) {
NodeList nl2 = el.getChildNodes();
if (nl2.getLength() > 0) {
nl2.item(0).setNodeValue(name);
}
break;
}
}
}
OutputStream out = fo.getOutputStream();
try {
XMLUtil.write(doc, out, "UTF-8");
} finally {
out.close();
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
writeFile(str, fo);
}
}
示例15: xmlSimplified
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private static String xmlSimplified(Element e) throws Exception {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
doc.appendChild(doc.importNode(e, true));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLUtil.write(doc, baos, "UTF-8");
return xmlSimplified(baos.toString("UTF-8"));
}