本文整理汇总了Java中org.openide.xml.XMLUtil.createDocument方法的典型用法代码示例。如果您正苦于以下问题:Java XMLUtil.createDocument方法的具体用法?Java XMLUtil.createDocument怎么用?Java XMLUtil.createDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.xml.XMLUtil
的用法示例。
在下文中一共展示了XMLUtil.createDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: testCreatePathLikeElem
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public void testCreatePathLikeElem() throws Exception {
Document doc = XMLUtil.createDocument("testdoc", null, null, null);
Element pathElem = ja.createPathLikeElem(doc, "path", "id",
new String[] {"lib/File.jar;lib/File2.jar", "testlib/Lib1.jar;testlib/Lib2"},
new String[] {"c:\\workfiles\\library.jar", "/workfiles/library2.jar"},
"refid", "comment");
String expectedXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<path id=\"id\" refid=\"refid\">\n" +
" <!---->\n" +
" <pathelement path=\"lib/File.jar;lib/File2.jar\"/>\n" +
" <pathelement path=\"testlib/Lib1.jar;testlib/Lib2\"/>\n" +
" <pathelement location=\"c:\\workfiles\\library.jar\"/>\n" +
" <pathelement location=\"/workfiles/library2.jar\"/>\n" +
"</path>\n";
assertEquals(expectedXml, xmlToString(pathElem));
pathElem = ja.createPathLikeElem(doc, "classpath", null, null, null, null, "comment");
expectedXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<classpath>\n" +
" <!---->\n" +
"</classpath>\n";
assertEquals(expectedXml, xmlToString(pathElem));
}
示例3: testCreateRunSingleTargetElem
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public void testCreateRunSingleTargetElem() throws Exception {
Document doc = XMLUtil.createDocument("project", null, null, null);
Lookup context = contextDO(new FileObject[] {myAppJava});
JavaActions.AntLocation root = ja.findPackageRoot(context);
Element targetElem = ja.createRunSingleTargetElem(doc, "run-single-test-target", "test.class", root);
doc.getDocumentElement().appendChild(targetElem);
String expectedXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<project>\n" +
" <target name=\"run-single-test-target\">\n" +
" <fail unless=\"test.class\">Must set property 'test.class'</fail>\n" +
" <ant antfile=\"build.xml\" inheritall=\"false\" target=\"jar\"/>\n" +
" <java classname=\"${test.class}\" failonerror=\"true\" fork=\"true\">\n" +
" <classpath>\n" +
" <pathelement path=\"${src.cp}\"/>\n" +
" <pathelement location=\"${classes.dir}\"/>\n" +
" <pathelement location=\"${main.jar}\"/>\n" +
" </classpath>\n" +
" </java>\n" +
" </target>\n" +
"</project>\n";
assertEquals(expectedXml, xmlToString(doc.getDocumentElement()));
}
示例4: 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
}
}
示例5: generateLibraryModuleTemplate
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Create a library wrapper project.xml.
*
* @param publicPackages set of <code>String</code>s representing the packages
* @param extensions <key=runtime path(String), value=binary path (String)>
*/
static void generateLibraryModuleTemplate(FileObject projectXml, String cnb,
NbModuleType moduleType, Set<String> publicPackages, Map<String,String> extensions) throws IOException {
Document prjDoc = XMLUtil.createDocument("project", PROJECT_NS, null, null); // NOI18N
// generate general project elements
Element typeEl = prjDoc.createElementNS(PROJECT_NS, "type"); // NOI18N
typeEl.appendChild(prjDoc.createTextNode(NbModuleProject.TYPE));
prjDoc.getDocumentElement().appendChild(typeEl);
Element confEl = prjDoc.createElementNS(PROJECT_NS, "configuration"); // NOI18N
prjDoc.getDocumentElement().appendChild(confEl);
// generate NB Module project type specific elements
Element dataEl = createModuleElement(confEl.getOwnerDocument(), DATA);
confEl.appendChild(dataEl);
Document dataDoc = dataEl.getOwnerDocument();
dataEl.appendChild(createModuleElement(dataDoc, CODE_NAME_BASE, cnb));
Element moduleTypeEl = createTypeElement(dataDoc, moduleType);
if (moduleTypeEl != null) {
dataEl.appendChild(moduleTypeEl);
}
dataEl.appendChild(createModuleElement(dataDoc, MODULE_DEPENDENCIES));
Element packages = createModuleElement(dataDoc, PUBLIC_PACKAGES);
dataEl.appendChild(packages);
for (String pkg : publicPackages) {
packages.appendChild(createModuleElement(dataDoc, PACKAGE, pkg));
}
for (Map.Entry<String,String> entry : extensions.entrySet()) {
Element cp = createModuleElement(dataDoc, CLASS_PATH_EXTENSION);
dataEl.appendChild(cp);
cp.appendChild(createModuleElement(dataDoc, CLASS_PATH_RUNTIME_PATH, entry.getKey()));
cp.appendChild(createModuleElement(dataDoc, CLASS_PATH_BINARY_ORIGIN, entry.getValue()));
}
// store document to disk
ProjectXMLManager.safelyWrite(projectXml, prjDoc);
}
示例6: createNetBeansOrgBuildXML
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Creates basic <em>build.xml</em> or whatever
* <code>GeneratedFilesHelper.BUILD_XML_PATH</code> is pointing to.
*/
private static void createNetBeansOrgBuildXML(FileObject projectDir, String cnb,
File nborg) throws IOException {
FileObject buildScript = NbModuleProjectGenerator.createFileObject(
projectDir, GeneratedFilesHelper.BUILD_XML_PATH);
Document prjDoc = XMLUtil.createDocument("project", null, null, null); // NOI18N
Element prjEl = prjDoc.getDocumentElement();
prjEl.setAttribute("name", PropertyUtils.relativizeFile(nborg, // NOI18N
FileUtil.toFile(projectDir)));
prjEl.setAttribute("default", "netbeans"); // NOI18N
prjEl.setAttribute("basedir", "."); // NOI18N
Element el = prjDoc.createElement("description"); // NOI18N
el.appendChild(prjDoc.createTextNode("Builds, tests, and runs the " + // NOI18N
"project " + cnb)); // NOI18N
prjEl.appendChild(el);
el = prjDoc.createElement("import"); // NOI18N
el.setAttribute("file", PropertyUtils.relativizeFile(FileUtil.toFile(projectDir), // NOI18N
new File(nborg, "nbbuild/templates/projectized.xml"))); // NOI18N
prjEl.appendChild(el);
// store document to disk
OutputStream os = buildScript.getOutputStream();
try {
XMLUtil.write(prjDoc, os, "UTF-8"); // NOI18N
} finally {
os.close();
}
}
示例7: createLibraryDefinition1
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private static Document createLibraryDefinition1(
final @NonNull LibraryImplementation library,
final @NonNull LibraryTypeProvider libraryTypeProvider) {
final Document doc = XMLUtil.createDocument(LIBRARY, null,
LIBRARY_DEF_1,
LIBRARY_DTD_1);
final Element libraryE = doc.getDocumentElement();
libraryE.setAttribute(VERSION, VER_1); // NOI18N
libraryE.appendChild(doc.createElement(NAME)).appendChild(doc.createTextNode(library.getName())); // NOI18N
libraryE.appendChild(doc.createElement(TYPE)).appendChild(doc.createTextNode(library.getType())); // NOI18N
String description = library.getDescription();
if (description != null && description.length() > 0) {
libraryE.appendChild(doc.createElement(DESCRIPTION)).appendChild(doc.createTextNode(description)); // NOI18N
}
String localizingBundle = library.getLocalizingBundle();
if (localizingBundle != null && localizingBundle.length() > 0) {
libraryE.appendChild(doc.createElement(BUNDLE)).appendChild(doc.createTextNode(localizingBundle)); // NOI18N
}
String displayname = LibrariesSupport.getDisplayName(library);
if (displayname != null) {
libraryE.appendChild(doc.createElement(DISPLAY_NAME)).appendChild(doc.createTextNode(displayname)); // NOI18N
}
for (String vtype : libraryTypeProvider.getSupportedVolumeTypes()) {
Element volumeE = (Element) libraryE.appendChild(doc.createElement(VOLUME)); // NOI18N
volumeE.appendChild(doc.createElement(TYPE)).appendChild(doc.createTextNode(vtype)); // NOI18N
List<URL> volume = library.getContent(vtype);
if (volume != null) {
//If null -> broken library, repair it.
for (URL url : volume) {
volumeE.appendChild(doc.createElement(RESOURCE)).appendChild(doc.createTextNode(url.toString())); // NOI18N
}
}
}
return doc;
}
示例8: createLibraryDefinition2
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private static Document createLibraryDefinition2(
final @NonNull LibraryImplementation library,
final @NonNull LibraryTypeProvider libraryTypeProvider) {
final Document doc = XMLUtil.createDocument(LIBRARY, LIBRARY_NS2, null, null);
final Element libraryE = doc.getDocumentElement();
libraryE.setAttribute(VERSION, VER_2); // NOI18N
libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, NAME)).appendChild(doc.createTextNode(library.getName())); // NOI18N
libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, TYPE)).appendChild(doc.createTextNode(library.getType())); // NOI18N
String description = library.getDescription();
if (description != null && description.length() > 0) {
libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, DESCRIPTION)).appendChild(doc.createTextNode(description)); // NOI18N
}
String localizingBundle = library.getLocalizingBundle();
if (localizingBundle != null && localizingBundle.length() > 0) {
libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, BUNDLE)).appendChild(doc.createTextNode(localizingBundle)); // NOI18N
}
String displayname = LibrariesSupport.getDisplayName(library);
if (displayname != null) {
libraryE.appendChild(doc.createElementNS(LIBRARY_NS2, DISPLAY_NAME)).appendChild(doc.createTextNode(displayname)); // NOI18N
}
for (String vtype : libraryTypeProvider.getSupportedVolumeTypes()) {
Element volumeE = (Element) libraryE.appendChild(doc.createElementNS(LIBRARY_NS2,VOLUME)); // NOI18N
volumeE.appendChild(doc.createElementNS(LIBRARY_NS2, TYPE)).appendChild(doc.createTextNode(vtype)); // NOI18N
List<URL> volume = library.getContent(vtype);
if (volume != null) {
for (URL url : volume) {
volumeE.appendChild(doc.createElementNS(LIBRARY_NS2, RESOURCE)).appendChild(doc.createTextNode(url.toString())); // NOI18N
}
}
}
return doc;
}
示例9: createNewSharedDocument
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private Document createNewSharedDocument() throws DOMException {
String element = "project-shared-configuration";
Document doc = XMLUtil.createDocument(element, null, null, null);
doc.getDocumentElement().appendChild(doc.createComment(
"\nThis file contains additional configuration written by modules in the NetBeans IDE.\n" +
"The configuration is intended to be shared among all the users of project and\n" +
"therefore it is assumed to be part of version control checkout.\n" +
"Without this configuration present, some functionality in the IDE may be limited or fail altogether.\n"));
return doc;
}
示例10: disableProfile
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public @Override void disableProfile(String id, boolean shared) {
lazyInit();
Element element = ac.getConfigurationFragment(PROFILES, NAMESPACE, shared);
if (element == null) {
String root = "project-private"; // NOI18N"
Document doc = XMLUtil.createDocument(root, NAMESPACE, null, null);
element = doc.createElementNS(NAMESPACE, PROFILES);
}
String activeProfiles = element.getAttributeNS(NAMESPACE, ACTIVEPROFILES);
if (activeProfiles != null && activeProfiles.length() > 0) {
StringTokenizer tokenizer = new StringTokenizer(activeProfiles, SEPARATOR);
Set<String> set = new HashSet<String>(tokenizer.countTokens());
while (tokenizer.hasMoreTokens()) {
set.add(tokenizer.nextToken());
}
set.remove(id);
StringBuilder buffer = new StringBuilder();
for (String profle : set) {
buffer.append(profle).append(SEPARATOR);
}
element.setAttributeNS(NAMESPACE, ACTIVEPROFILES, buffer.toString().trim());
}
ac.putConfigurationFragment(element, shared);
if(shared){
sharedProfiles.remove(id);
}else{
privateProfiles.remove(id);
}
}
示例11: storeDefs
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private static void storeDefs(Project project, String... definitions) throws IOException {
Document doc = XMLUtil.createDocument("x", null, null, null);
Element libraries = doc.createElementNS("http://www.netbeans.org/ns/ant-project-libraries/1", "libraries");
for (String def : definitions) {
libraries.appendChild(doc.createElementNS("http://www.netbeans.org/ns/ant-project-libraries/1", "definitions")).appendChild(doc.createTextNode(def));
}
project.getLookup().lookup(AuxiliaryConfiguration.class).putConfigurationFragment(libraries, true);
ProjectManager.getDefault().saveProject(project); // to assist in debugging
}
示例12: createNbjdkXmlSkeleton
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private Document createNbjdkXmlSkeleton() {
Document nbjdkDoc = XMLUtil.createDocument("project", null, null, null); // NOI18N
Element projectE = nbjdkDoc.getDocumentElement();
// XXX for better fidelity would use ${ant.script}#/project[@name]
projectE.setAttribute("name", ProjectUtils.getInformation(project).getName()); // NOI18N
projectE.setAttribute("basedir", ".."); // NOI18N
insertJdkXmlImport(nbjdkDoc);
return nbjdkDoc;
}
示例13: 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", ""));
}
示例14: testCreateCompileSingleTarget
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public void testCreateCompileSingleTarget() throws Exception {
Document doc = XMLUtil.createDocument("fake", null, null, null);
Lookup context = context(new FileObject[] {someFileJava});
Element target = ja.createCompileSingleTarget(doc, context, "files", new JavaActions.AntLocation("${src.dir}", src));
String expectedXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<target name=\"compile-selected-files-in-src\">\n" +
" <fail unless=\"files\">Must set property 'files'</fail>\n" +
" <mkdir dir=\"${classes.dir}\"/>\n" +
" <javac destdir=\"${classes.dir}\" includes=\"${files}\" source=\"1.4\" srcdir=\"${src.dir}\">\n" +
" <classpath path=\"${src.cp}\"/>\n" +
" </javac>\n" +
"</target>\n";
assertEquals(expectedXml, xmlToString(target));
}
示例15: testEnsurePropertiesCopied
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public void testEnsurePropertiesCopied() throws Exception {
Document doc = XMLUtil.createDocument("project", null, null, null);
Element root = doc.getDocumentElement();
ja.ensurePropertiesCopied(root);
String expectedXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<project basedir=\"..\">\n" +
" <property name=\"build.properties\" value=\"build.properties\"/>\n" +
" <property file=\"${build.properties}\"/>\n" +
"</project>\n";
assertEquals("Correct code generated", expectedXml, xmlToString(root));
ja.ensurePropertiesCopied(root);
assertEquals("Idempotent", expectedXml, xmlToString(root));
}