Java Code Examples for org.openide.xml.XMLUtil#appendChildElement()
The following examples show how to use
org.openide.xml.XMLUtil#appendChildElement() .
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: JavaProjectGenerator.java From netbeans with Apache License 2.0 | 6 votes |
/** * Update subprojects of the project. * Project is left modified and you must save it explicitely. * @param helper AntProjectHelper instance * @param subprojects list of paths to subprojects */ public static void putSubprojects(AntProjectHelper helper, List<String> subprojects) { //assert ProjectManager.mutex().isWriteAccess(); Element data = Util.getPrimaryConfigurationData(helper); Document doc = data.getOwnerDocument(); Element subproject = XMLUtil.findElement(data, "subprojects", Util.NAMESPACE); // NOI18N if (subproject != null) { data.removeChild(subproject); } subproject = doc.createElementNS(Util.NAMESPACE, "subprojects"); // NOI18N XMLUtil.appendChildElement(data, subproject, rootElementsOrder); for (String proj : subprojects) { Element projEl = doc.createElementNS(Util.NAMESPACE, "project"); // NOI18N projEl.appendChild(doc.createTextNode(proj)); subproject.appendChild(projEl); } Util.putPrimaryConfigurationData(helper, data); }
Example 2
Source File: FreeformProjectGenerator.java From netbeans with Apache License 2.0 | 6 votes |
private static void putBuildXMLSourceFile(AntProjectHelper helper, String antPath) { Element data = Util.getPrimaryConfigurationData(helper); Document doc = data.getOwnerDocument(); Element viewEl = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N if (viewEl == null) { viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N XMLUtil.appendChildElement(data, viewEl, rootElementsOrder); } Element itemsEl = XMLUtil.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N if (itemsEl == null) { itemsEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "items"); // NOI18N XMLUtil.appendChildElement(viewEl, itemsEl, viewElementsOrder); } Element fileEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "source-file"); // NOI18N Element el = doc.createElementNS(FreeformProjectType.NS_GENERAL, "location"); // NOI18N el.appendChild(doc.createTextNode(antPath)); // NOI18N fileEl.appendChild(el); XMLUtil.appendChildElement(itemsEl, fileEl, viewItemElementsOrder); Util.putPrimaryConfigurationData(helper, data); }
Example 3
Source File: FreeformProjectGenerator.java From netbeans with Apache License 2.0 | 5 votes |
/** * Update context menu actions. Project is left modified and * you must save it explicitely. This method stores all IDE actions * before the custom actions what means that user's customization by hand * (e.g. order of items) is lost. * @param helper AntProjectHelper instance * @param mappings list of <TargetMapping> instances for which the context * menu actions will be created */ public static void putContextMenuAction(AntProjectHelper helper, List<TargetMapping> mappings) { //assert ProjectManager.mutex().isWriteAccess(); Element data = Util.getPrimaryConfigurationData(helper); Document doc = data.getOwnerDocument(); Element viewEl = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N if (viewEl == null) { viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N XMLUtil.appendChildElement(data, viewEl, rootElementsOrder); } Element contextMenuEl = XMLUtil.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N if (contextMenuEl == null) { contextMenuEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "context-menu"); // NOI18N XMLUtil.appendChildElement(viewEl, contextMenuEl, viewElementsOrder); } for (Element ideActionEl : XMLUtil.findSubElements(contextMenuEl)) { if (!ideActionEl.getLocalName().equals("ide-action")) { // NOI18N continue; } contextMenuEl.removeChild(ideActionEl); } for (TargetMapping tm : sortMappings(mappings)) { if (tm.context != null) { // ignore context sensitive actions continue; } Element ideAction = doc.createElementNS(FreeformProjectType.NS_GENERAL, "ide-action"); //NOI18N ideAction.setAttribute("name", tm.name); // NOI18N XMLUtil.appendChildElement(contextMenuEl, ideAction, contextMenuElementsOrder); } Util.putPrimaryConfigurationData(helper, data); }
Example 4
Source File: ProjectXMLManager.java From netbeans with Apache License 2.0 | 5 votes |
/** * Replaces all original dependencies with the given <code>newDeps</code>. * * Checks for dependency cycles, throws {@link CyclicDependencyException} if new dependencies * introduce dependency cycle and leaves current dependencies untouched. */ public void replaceDependencies(final Set<ModuleDependency> newDeps) throws CyclicDependencyException { Set<ModuleDependency> addedDeps = new HashSet<ModuleDependency>(newDeps); try { SortedSet<ModuleDependency> currentDeps = getDirectDependencies(); addedDeps.removeAll(currentDeps); String warning = getDependencyCycleWarning(addedDeps); if (warning != null) { throw new CyclicDependencyException(warning); } } catch (IOException x) { // getDirectDependencies LOG.log(Level.INFO, null, x); // and skip check } Element _confData = getConfData(); Document doc = _confData.getOwnerDocument(); Element moduleDependencies = findModuleDependencies(_confData); _confData.removeChild(moduleDependencies); moduleDependencies = createModuleElement(doc, ProjectXMLManager.MODULE_DEPENDENCIES); XMLUtil.appendChildElement(_confData, moduleDependencies, ORDER); SortedSet<ModuleDependency> sortedDeps = new TreeSet<ModuleDependency>(newDeps); for (ModuleDependency md : sortedDeps) { createModuleDependencyElement(moduleDependencies, md, null); } project.putPrimaryConfigurationData(_confData); this.directDeps = sortedDeps; }
Example 5
Source File: WebProjectGenerator.java From netbeans with Apache License 2.0 | 5 votes |
private static void insertWebInfElement(Element itemsEl, Node firstNode, Element sourceFolderEl) { Node secondNode = firstNode.getNextSibling(); if (secondNode != null) { itemsEl.insertBefore(sourceFolderEl, secondNode); } else { XMLUtil.appendChildElement(itemsEl, sourceFolderEl, viewItemElementsOrder); } }
Example 6
Source File: JavaProjectGenerator.java From netbeans with Apache License 2.0 | 4 votes |
/** * Update source views of the project. * This method should be called always after the putSourceFolders method * to keep views and folders in sync. * Project is left modified and you must save it explicitely. * @param helper AntProjectHelper instance * @param sources list of SourceFolder instances * @param style style of source views to update. * Can be null in which case all styles will be overriden. * Useful for overriding just one style of source view. */ public static void putSourceViews(AntProjectHelper helper, List<SourceFolder> sources, String style) { //assert ProjectManager.mutex().isWriteAccess(); Element data = Util.getPrimaryConfigurationData(helper); Document doc = data.getOwnerDocument(); Element viewEl = XMLUtil.findElement(data, "view", Util.NAMESPACE); // NOI18N if (viewEl == null) { viewEl = doc.createElementNS(Util.NAMESPACE, "view"); // NOI18N XMLUtil.appendChildElement(data, viewEl, rootElementsOrder); } Element itemsEl = XMLUtil.findElement(viewEl, "items", Util.NAMESPACE); // NOI18N if (itemsEl == null) { itemsEl = doc.createElementNS(Util.NAMESPACE, "items"); // NOI18N XMLUtil.appendChildElement(viewEl, itemsEl, viewElementsOrder); } List<Element> sourceViews = XMLUtil.findSubElements(itemsEl); for (Element sourceViewEl : sourceViews) { if (!sourceViewEl.getLocalName().equals("source-folder")) { // NOI18N continue; } String sourceStyle = sourceViewEl.getAttribute("style"); // NOI18N if (style == null || style.equals(sourceStyle)) { itemsEl.removeChild(sourceViewEl); } } for (SourceFolder sf : sources) { if (sf.style == null || sf.style.length() == 0) { // perhaps this is principal source folder? continue; } Element sourceFolderEl = doc.createElementNS(Util.NAMESPACE, "source-folder"); // NOI18N sourceFolderEl.setAttribute("style", sf.style); // NOI18N Element el; if (sf.label != null) { el = doc.createElementNS(Util.NAMESPACE, "label"); // NOI18N el.appendChild(doc.createTextNode(sf.label)); // NOI18N sourceFolderEl.appendChild(el); } if (sf.location != null) { el = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N el.appendChild(doc.createTextNode(sf.location)); // NOI18N sourceFolderEl.appendChild(el); } if (sf.includes != null) { el = doc.createElementNS(Util.NAMESPACE, "includes"); // NOI18N el.appendChild(doc.createTextNode(sf.includes)); // NOI18N sourceFolderEl.appendChild(el); } if (sf.excludes != null) { el = doc.createElementNS(Util.NAMESPACE, "excludes"); // NOI18N el.appendChild(doc.createTextNode(sf.excludes)); // NOI18N sourceFolderEl.appendChild(el); } XMLUtil.appendChildElement(itemsEl, sourceFolderEl, viewItemElementsOrder); } Util.putPrimaryConfigurationData(helper, data); }
Example 7
Source File: JavaActions.java From netbeans with Apache License 2.0 | 4 votes |
/** * Add an action binding to project.xml. * If there is no required context, the action is also added to the context menu of the project node. * @param command the command name * @param scriptPath the path to the generated script * @param target the name of the target (in scriptPath) * @param propertyName a property name to hold the selection (or null for no context, in which case remainder should be null) * @param dir the raw text to use for the directory name * @param pattern the regular expression to match, or null * @param format the format to use * @param separator the separator to use for multiple files, or null for single file only */ void addBinding(String command, String scriptPath, String target, String propertyName, String dir, String pattern, String format, String separator) throws IOException { // XXX cannot use FreeformProjectGenerator since that is currently not a public support SPI from ant/freeform // XXX should this try to find an existing binding? probably not, since it is assumed that if there was one, we would never get here to begin with Element data = Util.getPrimaryConfigurationData(helper); Element ideActions = XMLUtil.findElement(data, "ide-actions", Util.NAMESPACE); // NOI18N if (ideActions == null) { //fix for #58442: ideActions = data.getOwnerDocument().createElementNS(Util.NAMESPACE, "ide-actions"); // NOI18N XMLUtil.appendChildElement(data, ideActions, rootElementsOrder); } Document doc = data.getOwnerDocument(); Element action = doc.createElementNS(Util.NAMESPACE, "action"); // NOI18N action.setAttribute("name", command); // NOI18N Element script = doc.createElementNS(Util.NAMESPACE, "script"); // NOI18N script.appendChild(doc.createTextNode(scriptPath)); action.appendChild(script); Element targetEl = doc.createElementNS(Util.NAMESPACE, "target"); // NOI18N targetEl.appendChild(doc.createTextNode(target)); action.appendChild(targetEl); if (propertyName != null) { Element context = doc.createElementNS(Util.NAMESPACE, "context"); // NOI18N Element property = doc.createElementNS(Util.NAMESPACE, "property"); // NOI18N property.appendChild(doc.createTextNode(propertyName)); context.appendChild(property); Element folder = doc.createElementNS(Util.NAMESPACE, "folder"); // NOI18N folder.appendChild(doc.createTextNode(dir)); context.appendChild(folder); if (pattern != null) { Element patternEl = doc.createElementNS(Util.NAMESPACE, "pattern"); // NOI18N patternEl.appendChild(doc.createTextNode(pattern)); context.appendChild(patternEl); } Element formatEl = doc.createElementNS(Util.NAMESPACE, "format"); // NOI18N formatEl.appendChild(doc.createTextNode(format)); context.appendChild(formatEl); Element arity = doc.createElementNS(Util.NAMESPACE, "arity"); // NOI18N if (separator != null) { Element separatorEl = doc.createElementNS(Util.NAMESPACE, "separated-files"); // NOI18N separatorEl.appendChild(doc.createTextNode(separator)); arity.appendChild(separatorEl); } else { arity.appendChild(doc.createElementNS(Util.NAMESPACE, "one-file-only")); // NOI18N } context.appendChild(arity); action.appendChild(context); } else { // Add a context menu item, since it applies to the project as a whole. // Assume there is already a <context-menu> defined, which is quite likely. Element view = XMLUtil.findElement(data, "view", Util.NAMESPACE); // NOI18N if (view != null) { Element contextMenu = XMLUtil.findElement(view, "context-menu", Util.NAMESPACE); // NOI18N if (contextMenu != null) { Element ideAction = doc.createElementNS(Util.NAMESPACE, "ide-action"); // NOI18N ideAction.setAttribute("name", command); // NOI18N contextMenu.appendChild(ideAction); } } } ideActions.appendChild(action); Util.putPrimaryConfigurationData(helper, data); ProjectManager.getDefault().saveProject(project); }
Example 8
Source File: ProjectXMLManager.java From netbeans with Apache License 2.0 | 4 votes |
/** Position public-packages or friend-packages according to XSD. */ private void insertPublicOrFriend(Element packagesEl) { XMLUtil.appendChildElement(getConfData(), packagesEl, ORDER); }