List of usage examples for org.w3c.dom Element removeChild
public Node removeChild(Node oldChild) throws DOMException;
oldChild
from the list of children, and returns it. From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_7.java
/** * Downgrade <energiepass> elements to OpenImmo 1.2.6. * <p>/*from w w w. j a va2s . c o m*/ * The child elements <stromwert>, <waermewert>, * <wertklasse>, <baujahr>, <ausstelldatum>, * <jahrgang>, <gebaeudeart> are copied into separate * <user_defined_simplefield> elements as it was * <a href="http://www.openimmo.de/go.php/p/44/cm_enev2014.htm">suggested by OpenImmo e.V.</a>. * <p> * The child elements <primaerenergietraeger>, <epasstext> * are not available in OpenImmo 1.2.6. * * @param doc OpenImmo document in version 1.2.7 * @throws JaxenException */ protected void downgradeEnergiepassElements(Document doc) throws JaxenException { List nodes = XmlUtils .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass", doc) .selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element parentNode = (Element) node.getParentNode(); boolean stromwertPassed = false; boolean waermewertPassed = false; boolean wertklassePassed = false; boolean baujahrPassed = false; boolean ausstelldatumPassed = false; boolean jahrgangPassed = false; boolean gebaeudeartPassed = false; List childNodes; // <primaerenergietraeger> elements are not supported in version 1.2.6 childNodes = XmlUtils.newXPath("io:primaerenergietraeger", doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; node.removeChild(childNode); } // <epasstext> elements are not supported in version 1.2.6 childNodes = XmlUtils.newXPath("io:epasstext", doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; node.removeChild(childNode); } // create a <user_defined_simplefield> for <stromwert> elements childNodes = XmlUtils.newXPath("io:stromwert", doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!stromwertPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild( OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_stromwert", value)); stromwertPassed = true; } } node.removeChild(childNode); } // create a <user_defined_simplefield> for <waermewert> elements childNodes = XmlUtils.newXPath("io:waermewert", doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!waermewertPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild( OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_waermewert", value)); waermewertPassed = true; } } node.removeChild(childNode); } // create a <user_defined_simplefield> for <wertklasse> elements childNodes = XmlUtils.newXPath("io:wertklasse", doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!wertklassePassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild( OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_wertklasse", value)); wertklassePassed = true; } } node.removeChild(childNode); } // create a <user_defined_simplefield> for <baujahr> elements childNodes = XmlUtils.newXPath("io:baujahr", doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!baujahrPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild( OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_baujahr", value)); baujahrPassed = true; } } node.removeChild(childNode); } // create a <user_defined_simplefield> for <ausstelldatum> elements childNodes = XmlUtils.newXPath("io:ausstelldatum", doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!ausstelldatumPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild( OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_ausstelldatum", value)); ausstelldatumPassed = true; } } node.removeChild(childNode); } // create a <user_defined_simplefield> for <jahrgang> elements childNodes = XmlUtils.newXPath("io:jahrgang", doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!jahrgangPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if ("2008".equalsIgnoreCase(value) || "2014".equalsIgnoreCase(value) || "ohne".equalsIgnoreCase(value)) { parentNode.appendChild( OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_jahrgang", value)); jahrgangPassed = true; } } node.removeChild(childNode); } // create a <user_defined_simplefield> for <gebaeudeart> elements childNodes = XmlUtils.newXPath("io:gebaeudeart", doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!gebaeudeartPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if ("wohn".equalsIgnoreCase(value) || "nichtwohn".equalsIgnoreCase(value) || "ohne".equalsIgnoreCase(value)) { parentNode.appendChild( OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_gebaeudeart", value)); gebaeudeartPassed = true; } } node.removeChild(childNode); } } }
From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_7.java
/** * Only use one <energiepass> element for each <immobilie>. * <p>/*from w ww. jav a 2 s . c om*/ * OpenImmo 1.2.6 does not allow more then one <energiepass> element * for each <immobilie> (maxOccurs=1). Odd <energiepass> elements * are removed by this function. * * @param doc OpenImmo document in version 1.2.7 * @throws JaxenException */ protected void removeMultipleEnergiepassElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben", doc) .selectNodes(doc); for (Object item : nodes) { Element parentNode = (Element) item; List childNodes = XmlUtils.newXPath("io:energiepass", doc).selectNodes(parentNode); if (childNodes.size() < 2) continue; for (int j = 1; j < childNodes.size(); j++) { parentNode.removeChild((Node) childNodes.get(j)); } } }
From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_7.java
/** * Remove <objekt_text> elements. * <p>/*from ww w.j ava 2 s .c o m*/ * OpenImmo 1.2.6 does not support <objekt_text> elements. * * @param doc OpenImmo document in version 1.2.7 * @throws JaxenException */ protected void removeObjektTextElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:freitexte/io:objekt_text", doc) .selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element parentNode = (Element) node.getParentNode(); parentNode.removeChild(node); } }
From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_7.java
/** * Upgrade <energiepass> elements to OpenImmo 1.2.7. * <p>/* w ww. j a v a 2s. c o m*/ * The <user_defined_simplefield> elements for EnEv2014, that were * <a href="http://www.openimmo.de/go.php/p/44/cm_enev2014.htm">suggested by OpenImmo e.V.</a>, * are explicitly supported in OpenImmo 1.2.7 as child elements of * <energiepass>. Any matching <user_defined_simplefield> elements * are moved into the <energiepass> element. * * @param doc OpenImmo document in version 1.2.6 * @throws JaxenException */ protected void upgradeEnergiepassElements(Document doc) throws JaxenException { Map<String, String> fields = new HashMap<String, String>(); fields.put("stromwert", "user_defined_simplefield[@feldname='epass_stromwert']"); fields.put("waermewert", "user_defined_simplefield[@feldname='epass_waermewert']"); fields.put("wertklasse", "user_defined_simplefield[@feldname='epass_wertklasse']"); fields.put("baujahr", "user_defined_simplefield[@feldname='epass_baujahr']"); fields.put("ausstelldatum", "user_defined_simplefield[@feldname='epass_ausstelldatum']"); fields.put("jahrgang", "user_defined_simplefield[@feldname='epass_jahrgang']"); fields.put("gebaeudeart", "user_defined_simplefield[@feldname='epass_gebaeudeart']"); List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben", doc) .selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element energiepassNode = (Element) XmlUtils.newXPath("io:energiepass", doc).selectSingleNode(node); if (energiepassNode == null) { energiepassNode = doc.createElementNS(StringUtils.EMPTY, "energiepass"); } for (Map.Entry<String, String> entry : fields.entrySet()) { boolean fieldProcessed = false; List childNodes = XmlUtils.newXPath(entry.getValue(), doc).selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!fieldProcessed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { Element newElement = doc.createElementNS(StringUtils.EMPTY, entry.getKey()); newElement.setTextContent(value); energiepassNode.appendChild(newElement); fieldProcessed = true; } } node.removeChild(childNode); } } if (energiepassNode.getParentNode() == null && energiepassNode.hasChildNodes()) { node.appendChild(energiepassNode); } } }
From source file:org.openestate.io.openimmo.OpenImmoFeedbackDocument.java
@Override public void setDocumentVersion(OpenImmoVersion version) { try {//from www. java 2s . c om Document doc = this.getDocument(); String currentVersion = StringUtils.trimToEmpty( XmlUtils.newXPath("/io:openimmo/io:uebertragung/@version", doc).stringValueOf(doc)); String[] ver = StringUtils.split(currentVersion, "/", 2); Element node = (Element) XmlUtils.newXPath("/io:openimmo_feedback/io:version", doc) .selectSingleNode(doc); // versions older then 1.2.4 do not support the <version> element if (OpenImmoVersion.V1_2_4.isNewerThen(version)) { if (node != null) { Element root = XmlUtils.getRootElement(doc); root.removeChild(node); } return; } if (node == null) { Element parentNode = (Element) XmlUtils.newXPath("/io:openimmo_feedback", doc) .selectSingleNode(doc); if (parentNode == null) { LOGGER.warn("Can't find an <openimmo_feedback> element in the document!"); return; } node = doc.createElement("version"); parentNode.insertBefore(node, parentNode.getFirstChild()); } String newVersion = version.toReadableVersion(); if (ver.length > 1) newVersion += "/" + ver[1]; node.setTextContent(newVersion); } catch (JaxenException ex) { LOGGER.error("Can't evaluate XPath expression!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); } }
From source file:org.openlegacy.ide.eclipse.editors.TrailEditor.java
private void createTable(final Composite composite, final TerminalPersistedTrail terminalSessionTrail) { tableViewer = new TableViewer(composite); tableViewer.setContentProvider(new ArrayContentProvider()); tableViewer.setInput(terminalSessionTrail.getSnapshots().toArray()); Menu menu = new Menu(tableViewer.getTable()); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(Messages.getString("menu_generate_model")); menuItem.addSelectionListener(new SelectionListener() { @Override/*w ww. j a v a2s . c o m*/ public void widgetSelected(SelectionEvent event) { int[] selectionIndexes = tableViewer.getTable().getSelectionIndices(); TerminalSnapshot[] snapshots = new TerminalSnapshot[selectionIndexes.length]; for (int i = 0; i < selectionIndexes.length; i++) { TerminalSnapshot snapshot = terminalSessionTrail.getSnapshots().get(selectionIndexes[i]); snapshots[i] = snapshot; } GenerateScreenModelDialog dialog = new GenerateScreenModelDialog(getEditorSite().getShell(), ((FileEditorInput) getEditorInput()).getFile(), false, snapshots); dialog.open(); } @Override public void widgetDefaultSelected(SelectionEvent arg0) { widgetSelected(arg0); } }); menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(Messages.getString("menu_new_screen")); menuItem.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent event) { int[] selectionIndexes = tableViewer.getTable().getSelectionIndices(); TerminalSnapshot snapshot = terminalSessionTrail.getSnapshots().get(selectionIndexes[0]); GenerateScreenModelDialog dialog = new GenerateScreenModelDialog(getEditorSite().getShell(), ((FileEditorInput) getEditorInput()).getFile(), true, snapshot); dialog.open(); } @Override public void widgetDefaultSelected(SelectionEvent arg0) { widgetSelected(arg0); } }); menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText(Messages.getString("menu_update_screen_image")); menuItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String title = null; ScreenPreview screenPreview = (ScreenPreview) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().findView(ScreenPreview.ID); if (screenPreview != null) { IEditorPart lastActiveEditor = screenPreview.getLastActiveEditor(); if (lastActiveEditor != null) { title = lastActiveEditor.getTitle(); } } if (StringUtils.isEmpty(title) && !StringUtils.isEmpty(editorId)) { IEditorReference editorReference = getEditorReferenceById(editorId); if (editorReference != null) { title = editorReference.getTitle(); } } if (StringUtils.isEmpty(title)) { return; } String entityName = title.replace(".java", ""); String message = MessageFormat.format("Are you sure you want to replace the image of {0} screen?", entityName); boolean confirmed = MessageDialog.openQuestion(getEditorSite().getShell(), "Update Screen image", message); if (confirmed) { int[] selectionIndexes = tableViewer.getTable().getSelectionIndices(); TerminalSnapshot snapshot = terminalSessionTrail.getSnapshots().get(selectionIndexes[0]); IFile file = ((FileEditorInput) getEditorInput()).getFile(); EclipseDesignTimeExecuter.instance().generateScreenEntityResources(file, snapshot, entityName); } } }); tableViewer.getTable().setMenu(menu); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 1; data.widthHint = 200; tableViewer.getTable().setLayoutData(data); tableViewer.getTable().addKeyListener(new KeyListener() { @Override public void keyReleased(KeyEvent event) { } @Override public void keyPressed(KeyEvent event) { // delete if (event.keyCode == SWT.DEL) { Table table = (Table) event.getSource(); int selectionIndex = table.getSelectionIndex(); terminalSessionTrail.getSnapshots().remove(selectionIndex); table.remove(selectionIndex); try { Element root = extractDocumentRoot(); List<Element> snapshots = DomUtils.getChildElementsByTagName(root, "snapshot"); //$NON-NLS-1$ root.removeChild(snapshots.get(selectionIndex)); } catch (Exception e) { throw (new DesigntimeException(e)); } } } }); TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); column.getColumn().setWidth(100); column.getColumn().setText(Messages.getString("label_sequence")); column.setLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { TerminalSnapshot snapshot = (TerminalSnapshot) element; String direction = snapshot.getSnapshotType() == SnapshotType.INCOMING ? Messages.getString("label_screen_in") : Messages.getString("label_screen_out"); return String .valueOf(Messages.getString("label_screen_prefix") + snapshot.getSequence() + direction); } }); tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); Object firstElement = ((StructuredSelection) selection).getFirstElement(); TerminalSnapshot snapshot = (TerminalSnapshot) firstElement; snapshotComposite.setSnapshot(snapshot); tableViewer.getTable().getMenu().getItem(0) .setEnabled(snapshot.getSnapshotType() == SnapshotType.INCOMING); int[] selectionIndexes = tableViewer.getTable().getSelectionIndices(); tableViewer.getTable().getMenu().getItem(1).setEnabled(selectionIndexes.length == 1); editorId = null; // editorId will be set in isOpenlegacyEditorOpened() if it will be found tableViewer.getTable().getMenu().getItem(2) .setEnabled(isOpenlegacyEditorOpened() && (selectionIndexes.length == 1)); } }); refreshSnapshots(); }
From source file:org.openmrs.module.drawing.obs.handler.DrawingHandler.java
public void saveAnnotation(Obs obs, ImageAnnotation annotation, boolean delete) { try {/* w w w.j a v a2s .co m*/ log.info("drawing: Saving annotation for obs " + obs.getObsId()); File metadataFile = getComplexMetadataFile(obs); log.info("drawing: Using file " + metadataFile.getCanonicalPath()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document xmldoc; Element annotationsParent; int newId = 0; if (metadataFile.exists()) { xmldoc = builder.parse(metadataFile); annotationsParent = (Element) xmldoc.getElementsByTagName("Annotations").item(0); NodeList annotationNodeList = xmldoc.getElementsByTagName("Annotation"); for (int i = 0; i < annotationNodeList.getLength(); i++) { NamedNodeMap attributes = annotationNodeList.item(i).getAttributes(); String idString = attributes.getNamedItem("id").getNodeValue(); int existingId = Integer.parseInt(idString); if (existingId == annotation.getId() && !(annotation.getStatus() == Status.UNCHANGED)) { annotationsParent.removeChild(annotationNodeList.item(i)); break; } if (existingId >= newId) newId = existingId + 1; } } else { metadataFile.createNewFile(); DOMImplementation domImpl = builder.getDOMImplementation(); xmldoc = domImpl.createDocument(null, "ImageMetadata", null); Element root = xmldoc.getDocumentElement(); annotationsParent = xmldoc.createElementNS(null, "Annotations"); root.appendChild(annotationsParent); } if (!delete && annotation.getStatus() != Status.UNCHANGED) { if (annotation.getId() >= 0) newId = annotation.getId(); Element e = xmldoc.createElementNS(null, "Annotation"); Node n = xmldoc.createTextNode(annotation.getText()); e.setAttributeNS(null, "id", newId + ""); e.setAttributeNS(null, "xcoordinate", annotation.getLocation().getX() + ""); e.setAttributeNS(null, "ycoordinate", annotation.getLocation().getY() + ""); e.setAttributeNS(null, "userid", annotation.getUser().getUserId() + ""); e.setAttributeNS(null, "date", annotation.getDate().getTime() + ""); e.appendChild(n); annotationsParent.appendChild(e); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(xmldoc), new StreamResult(metadataFile)); log.info("drawing: Saving annotation complete"); } catch (Exception e) { log.error("drawing: Error saving image metadata: " + e.getClass() + " " + e.getMessage()); } }
From source file:org.openmrs.module.web.WebModuleUtil.java
/** * Reverses all visible activities done by startModule(org.openmrs.module.Module) * * @param mod//from ww w .j a va 2 s. c o m * @param servletContext * @param skipRefresh */ private static void stopModule(Module mod, ServletContext servletContext, boolean skipRefresh) { String moduleId = mod.getModuleId(); String modulePackage = mod.getPackageName(); // stop all dependent modules for (Module dependentModule : ModuleFactory.getStartedModules()) { if (!dependentModule.equals(mod) && dependentModule.getRequiredModules().contains(modulePackage)) { stopModule(dependentModule, servletContext, skipRefresh); } } String realPath = getRealPath(servletContext); // delete the web files from the webapp String absPath = realPath + "/WEB-INF/view/module/" + moduleId; File moduleWebFolder = new File(absPath.replace("/", File.separator)); if (moduleWebFolder.exists()) { try { OpenmrsUtil.deleteDirectory(moduleWebFolder); } catch (IOException io) { log.warn("Couldn't delete: " + moduleWebFolder.getAbsolutePath(), io); } } // (not) deleting module message properties // remove the module's servlets unloadServlets(mod); // remove the module's filters and filter mappings unloadFilters(mod); // stop all tasks associated with mod stopTasks(mod); // remove this module's entries in the dwr xml file InputStream inputStream = null; try { Document config = mod.getConfig(); Element root = config.getDocumentElement(); // if they defined any xml element if (root.getElementsByTagName("dwr").getLength() > 0) { // get the dwr-module.xml file that we're appending our code to File f = new File(realPath + "/WEB-INF/dwr-modules.xml".replace("/", File.separator)); // testing if file exists if (!f.exists()) { // if it does not -> needs to be created createDwrModulesXml(realPath); } inputStream = new FileInputStream(f); Document dwrmodulexml = getDWRModuleXML(inputStream, realPath); Element outputRoot = dwrmodulexml.getDocumentElement(); // loop over all of the children of the "dwr" tag // and remove all "allow" and "signature" tags that have the // same moduleId attr as the module being stopped NodeList nodeList = outputRoot.getChildNodes(); int i = 0; while (i < nodeList.getLength()) { Node current = nodeList.item(i); if ("allow".equals(current.getNodeName()) || "signatures".equals(current.getNodeName())) { NamedNodeMap attrs = current.getAttributes(); Node attr = attrs.getNamedItem("moduleId"); if (attr != null && moduleId.equals(attr.getNodeValue())) { outputRoot.removeChild(current); } else { i++; } } else { i++; } } // save the dwr-modules.xml file. OpenmrsUtil.saveDocument(dwrmodulexml, f); } } catch (FileNotFoundException e) { throw new ModuleException(realPath + "/WEB-INF/dwr-modules.xml file doesn't exist.", e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException io) { log.error("Error while closing input stream", io); } } } if (skipRefresh == false) { //try { // if (dispatcherServlet != null) // dispatcherServlet.reInitFrameworkServlet(); // if (dwrServlet != null) // dwrServlet.reInitServlet(); //} //catch (ServletException se) { // log.warn("Unable to reinitialize webapplicationcontext for dispatcherservlet for module: " + mod.getName(), se); //} refreshWAC(servletContext, false, null); } }
From source file:org.reficio.p2.FeatureBuilder.java
public void generateSourceFeature(File destinationFolder) { Element featureElement = XmlUtils.fetchOrCreateElement(xmlDoc, xmlDoc, "feature"); featureElement.setAttribute("id", featureElement.getAttribute("id") + ".source"); featureElement.setAttribute("label", featureElement.getAttribute("label") + " Developer Resources"); NodeList nl = featureElement.getElementsByTagName("plugin"); List<Element> elements = new ArrayList<Element>(); //can't remove as we iterate over nl, because its size changes when we remove for (int n = 0; n < nl.getLength(); ++n) { elements.add((Element) nl.item(n)); }/*w ww .ja va2 s .co m*/ for (Element e : elements) { featureElement.removeChild(e); } for (P2Artifact artifact : this.p2FeatureDefintion.artifacts) { Element pluginElement = XmlUtils.createElement(xmlDoc, featureElement, "plugin"); String id = this.bundlerInstructions.get(artifact).getSourceSymbolicName(); String version = this.bundlerInstructions.get(artifact).getProposedVersion(); pluginElement.setAttribute("id", id); pluginElement.setAttribute("download-size", "0"); //TODO pluginElement.setAttribute("install-size", "0"); //TODO pluginElement.setAttribute("version", version); pluginElement.setAttribute("unpack", "false"); } try { File sourceFeatureContent = new File(destinationFolder, this.getFeatureFullName() + ".source"); sourceFeatureContent.mkdir(); XmlUtils.writeXml(this.xmlDoc, new File(sourceFeatureContent, "feature.xml")); //TODO: add other files that are required by the feature FileOutputStream fos = new FileOutputStream( new File(destinationFolder, this.getFeatureFullName() + ".jar")); Manifest mf = new Manifest(); JarOutputStream jar = new JarOutputStream(fos, mf); addToJar(jar, sourceFeatureContent); } catch (Exception e) { throw new RuntimeException("Cannot generate feature", e); } }
From source file:org.springframework.ide.eclipse.boot.core.internal.MavenSpringBootProject.java
@Override public void setStarters(Collection<SpringBootStarter> _starters) throws CoreException { try {/*from ww w. j a v a 2 s . c om*/ final Set<MavenId> starters = new HashSet<>(); for (SpringBootStarter s : _starters) { starters.add(s.getMavenId()); } IFile file = getPomFile(); performOnDOMDocument(new OperationTuple(file, new Operation() { public void process(Document pom) { Element depsEl = getChild(pom.getDocumentElement(), DEPENDENCIES); List<Element> children = findChilds(depsEl, DEPENDENCY); for (Element c : children) { //We only care about 'starter' dependencies. Leave everything else alone. // Also... don't touch nodes that are already there, unless they are to // be removed. This way we don't mess up versions, comments or other stuff // that a user may have inserted via manual edits. String aid = getTextValue(findChild(c, ARTIFACT_ID)); String gid = getTextValue(findChild(c, GROUP_ID)); if (aid != null && gid != null) { //ignore invalid entries that don't have gid or aid if (isKnownStarter(new MavenId(gid, aid))) { MavenId id = new MavenId(gid, aid); boolean keep = starters.remove(id); if (!keep) { depsEl.removeChild(c); } } } } //if 'starters' is not empty at this point, it contains remaining ids we have not seen // in the pom, so we need to add them. for (MavenId mid : starters) { SpringBootStarter starter = getStarter(mid); createDependency(depsEl, starter.getDependency(), starter.getScope()); createBomIfNeeded(pom, starter.getBom()); createRepoIfNeeded(pom, starter.getRepo()); } } })); } catch (Throwable e) { throw ExceptionUtil.coreException(e); } }