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.dita.dost.module.BranchFilterModule.java
/** * Duplicate branches so that each {@code ditavalref} will in a separate branch. *//* w w w . j ava 2 s .c om*/ void splitBranches(final Element elem, final Branch filter) { final List<Element> ditavalRefs = getChildElements(elem, DITAVAREF_D_DITAVALREF); if (ditavalRefs.size() > 0) { // remove ditavalrefs for (final Element branch : ditavalRefs) { elem.removeChild(branch); } // create additional branches after current element final List<Element> branches = new ArrayList<>(ditavalRefs.size()); branches.add(elem); final Node next = elem.getNextSibling(); for (int i = 1; i < ditavalRefs.size(); i++) { final Element clone = (Element) elem.cloneNode(true); if (next != null) { elem.getParentNode().insertBefore(clone, next); } else { elem.getParentNode().appendChild(clone); } branches.add(clone); } // insert ditavalrefs for (int i = 0; i < branches.size(); i++) { final Element branch = branches.get(i); final Element ditavalref = ditavalRefs.get(i); branch.appendChild(ditavalref); final Branch currentFilter = filter.merge(ditavalref); processAttributes(branch, currentFilter); final Branch childFilter = new Branch(currentFilter.resourcePrefix, currentFilter.resourceSuffix, Optional.empty(), Optional.empty()); // process children of all branches for (final Element child : getChildElements(branch, MAP_TOPICREF)) { if (DITAVAREF_D_DITAVALREF.matches(child)) { continue; } splitBranches(child, childFilter); } } } else { processAttributes(elem, filter); for (final Element child : getChildElements(elem, MAP_TOPICREF)) { splitBranches(child, filter); } } }
From source file:org.eclipse.ecr.runtime.model.persistence.fs.FileSystemStorage.java
@Override public Contribution updateContribution(Contribution contribution) throws Exception { File file = new File(root, contribution.getName() + ".xml"); String content = safeRead(file); DocumentBuilder docBuilder = factory.newDocumentBuilder(); Document doc = docBuilder.parse(new ByteArrayInputStream(content.getBytes())); Element root = doc.getDocumentElement(); if (contribution.isDisabled()) { root.setAttribute("disabled", "true"); } else {/*from w ww . j a v a 2s .c om*/ root.removeAttribute("disabled"); } Node node = root.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.ELEMENT_NODE && "documentation".equals(node.getNodeName())) { break; } node = node.getNextSibling(); } String description = contribution.getDescription(); if (description == null) { description = ""; } if (node != null) { root.removeChild(node); } Element el = doc.createElement("documentation"); el.appendChild(doc.createTextNode(description)); root.appendChild(el); safeWrite(file, DOMSerializer.toString(doc)); return getContribution(contribution.getName()); }
From source file:org.fhaes.neofhchart.svg.FireChartSVG.java
/** * Helper function that deletes all child tags of the specified element. * /* w ww .j a va 2s . c o m*/ * @param e */ private void deleteAllChildren(Element e) { if (e != null) { NodeList n = e.getChildNodes(); for (int i = 0; i < n.getLength(); i++) { e.removeChild(n.item(i)); } } }
From source file:org.fhaes.neofhchart.svg.FireChartSVG.java
/** * Positions the various parts of the fire chart. This method also re-creates the time axis since it is dependent on the total height of * the svg, due to the dashed tick lines that run vertically to denote years. *///from ww w. j av a2 s .c o m public void positionChartGroupersAndDrawTimeAxis() { // Calculate plot dimensions int cur_bottom = 0; // used for tracking where the bottom of the chart is as it is being built int index_plot_height = App.prefs.getIntPref(PrefKey.CHART_INDEX_PLOT_HEIGHT, 100); int series_spacing_and_height = App.prefs.getIntPref(PrefKey.CHART_CHRONOLOGY_PLOT_SPACING, 5) + SERIES_HEIGHT; if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CHART_TITLE, true)) { cur_bottom += App.prefs.getIntPref(PrefKey.CHART_TITLE_FONT_SIZE, 20) + 10; } if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_INDEX_PLOT, true)) { cur_bottom += index_plot_height + series_spacing_and_height; } int chronology_plot_y = cur_bottom; int num_visible = 0; for (int i = 0; i < seriesSVGList.size(); i++) { if (seriesSVGList.get(i).isVisible()) { num_visible++; } } int chronology_plot_height = num_visible * series_spacing_and_height + SERIES_HEIGHT; if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_CHRONOLOGY_PLOT, true)) { cur_bottom += chronology_plot_height + series_spacing_and_height + categoryGroupPadding; } int composite_plot_y = cur_bottom; int composite_plot_height = App.prefs.getIntPref(PrefKey.CHART_COMPOSITE_HEIGHT, 70); if (App.prefs.getBooleanPref(PrefKey.CHART_SHOW_COMPOSITE_PLOT, true)) { cur_bottom += composite_plot_height + series_spacing_and_height; } int total_height = cur_bottom + series_spacing_and_height; // reset svg dimensions Element svgRoot = doc.getDocumentElement(); // build time axis Element time_axis_g = doc.getElementById("time_axis_g"); // delete everything in the current time axis NodeList n = time_axis_g.getChildNodes(); // because getChildNodes doesn't return a seq for (int i = 0; i < n.getLength(); i++) { // no, instead we get a non-iterable custom data-structure :( time_axis_g.removeChild(n.item(i)); } // add in the new time axis time_axis_g.appendChild(getTimeAxis(total_height)); // set the translations for the chronology plot grouper Element chrono_plot_g = doc.getElementById("chrono_plot_g"); chrono_plot_g.setAttributeNS(null, "transform", "translate(0," + chronology_plot_y + ")"); // set the translations for the composite plot grouper Element comp_plot_g = doc.getElementById("comp_plot_g"); comp_plot_g.setAttributeNS(null, "transform", "translate(0," + composite_plot_y + ")"); // move the legend Element legend_g = doc.getElementById("legend_g"); legend_g.setAttributeNS(null, "transform", "translate(" + (chartWidth + 10 + this.widestChronologyLabelSize + 50) + ", " + 0 + ")"); // set the annote canvas dimensions (so it can catch key bindings) Element annote_canvas = doc.getElementById("annote_canvas"); annote_canvas.setAttributeNS(null, "width", Integer.toString(chartWidth)); annote_canvas.setAttributeNS(null, "height", Integer.toString(total_height)); // set document dimensions for png and pdf export // svgRoot.setAttributeNS(null, "width", (chart_width + this.widestChronologyLabelSize + 150 + 350) + "px"); svgRoot.setAttributeNS(null, "width", getTotalWidth() + "px"); int root_height = (total_height + 50 > 400) ? total_height + 50 : 400; totalHeight = root_height; svgRoot.setAttributeNS(null, "height", root_height + "px"); }
From source file:org.fhaes.neofhchart.svg.FireChartSVG.java
/** * Removes a line from the annotation grouper. * /* w w w . j a v a 2s .c o m*/ * @param id * @return */ public boolean deleteAnnoteLine(String id) { if (annotemode == AnnoteMode.ERASE) { Element annote_g = doc.getElementById("annote_g"); Element annote_line = doc.getElementById(id); if (annote_line == null) { return false; } annote_g.removeChild(annote_line); return true; } return false; }
From source file:org.geotools.data.wfs.internal.v1_x.MapServerWFSStrategy.java
@Override public InputStream getPostContents(WFSRequest request) throws IOException { InputStream in = super.getPostContents(request); if (request.getOperation().compareTo(WFSOperationType.GET_FEATURE) == 0 && getVersion().compareTo("1.0.0") == 0 && mapServerVersion != null) { try {/*ww w. j a va 2 s .com*/ // Pre-5.6.7 versions of MapServer do not support the following gml:Box coordinate format: // <gml:coord><gml:X>-59.0</gml:X><gml:Y>-35.0</gml:Y></gml:coord><gml:coord>< gml:X>-58.0</gml:X><gml:Y>-34.0</gml:Y></gml:coord> // Rewrite the coordinates in the following format: // <gml:coordinates cs="," decimal="." ts=" ">-59,-35 -58,-34</gml:coordinates> String[] tokens = mapServerVersion.split("\\."); if (tokens.length == 3 && versionCompare(mapServerVersion, "5.6.7") < 0) { StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String pc = writer.toString(); boolean reformatted = false; if (pc.contains("gml:Box") && pc.contains("gml:coord") && pc.contains("gml:X") && pc.contains("gml:Y")) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(pc.getBytes())); NodeList boxes = doc.getElementsByTagName("gml:Box"); for (int b = 0; b < boxes.getLength(); b++) { Element box = (Element) boxes.item(b); NodeList coords = box.getElementsByTagName("gml:coord"); if (coords != null && coords.getLength() == 2) { Element coord1 = (Element) coords.item(0); Element coord2 = (Element) coords.item(1); if (coord1 != null && coord2 != null) { Element coordX1 = (Element) (coord1.getElementsByTagName("gml:X").item(0)); Element coordY1 = (Element) (coord1.getElementsByTagName("gml:Y").item(0)); Element coordX2 = (Element) (coord2.getElementsByTagName("gml:X").item(0)); Element coordY2 = (Element) (coord2.getElementsByTagName("gml:Y").item(0)); if (coordX1 != null && coordY1 != null && coordX2 != null && coordY2 != null) { reformatted = true; String x1 = coordX1.getTextContent(); String y1 = coordY1.getTextContent(); String x2 = coordX2.getTextContent(); String y2 = coordY2.getTextContent(); box.removeChild(coord1); box.removeChild(coord2); Element coordinates = doc.createElement("gml:coordinates"); coordinates.setAttribute("cs", ","); coordinates.setAttribute("decimal", "."); coordinates.setAttribute("ts", " "); coordinates.appendChild( doc.createTextNode(x1 + "," + y1 + " " + x2 + "," + y2)); box.appendChild(coordinates); } } } } if (reformatted) { DOMSource domSource = new DOMSource(doc); StringWriter domsw = new StringWriter(); StreamResult result = new StreamResult(domsw); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(domSource, result); domsw.flush(); pc = domsw.toString(); } } in = new ByteArrayInputStream(pc.getBytes()); } } catch (SAXException | ParserConfigurationException | TransformerException | IOException ex) { LOGGER.log(Level.FINE, "Unexpected exception while rewriting 1.0.0 GETFEATURE request with BBOX filter", ex.getMessage()); } } return in; }
From source file:org.gvnix.addon.web.mvc.addon.batch.WebJpaBatchOperationsImpl.java
/** * Update the webmvc-config.xml file in order to register * Jackson2RequestMappingHandlerAdapter/*from w w w.ja v a 2 s. c o m*/ * * @param targetPackage */ private void updateWebMvcConfig() { LogicalPath webappPath = WebProjectUtils.getWebappPath(getProjectOperations()); String webMvcXmlPath = getProjectOperations().getPathResolver().getIdentifier(webappPath, "WEB-INF/spring/webmvc-config.xml"); Validate.isTrue(fileManager.exists(webMvcXmlPath), "webmvc-config.xml not found"); MutableFile webMvcXmlMutableFile = null; Document webMvcXml; try { webMvcXmlMutableFile = fileManager.updateFile(webMvcXmlPath); webMvcXml = XmlUtils.getDocumentBuilder().parse(webMvcXmlMutableFile.getInputStream()); } catch (Exception e) { throw new IllegalStateException(e); } Element root = webMvcXml.getDocumentElement(); Element dataBinder = XmlUtils.findFirstElement("bean[@id='" + WEBMCV_DATABINDER_BEAN_ID + "']", root); if (dataBinder != null) { root.removeChild(dataBinder); } // add bean tag to argument-resolvers Element bean = webMvcXml.createElement("bean"); bean.setAttribute("id", WEBMCV_DATABINDER_BEAN_ID); bean.setAttribute("p:order", "1"); bean.setAttribute("class", JACKSON2_RM_HANDLER_ADAPTER); Element property = webMvcXml.createElement("property"); property.setAttribute("name", "objectMapper"); Element objectMapperBean = webMvcXml.createElement("bean"); objectMapperBean.setAttribute("class", OBJECT_MAPPER); property.appendChild(objectMapperBean); bean.appendChild(property); root.appendChild(bean); XmlUtils.writeXml(webMvcXmlMutableFile.getOutputStream(), webMvcXml); }
From source file:org.gvnix.web.screen.roo.addon.AbstractPatternJspMetadataListener.java
/** * Modifies create.jspx or update.jspx generate by Roo based on * {@link RooJspx} param.//from ww w .j a v a 2 s . com * <p> * It wraps field element into ul/li elements and add a hidden param * <code>gvnixpattern</code> and a button * * @param rooJspx */ private void modifyRooJsp(RooJspx rooJspx) { String controllerPath = webScaffoldAnnotationValues.getPath(); Validate.notNull(controllerPath, PATH_IS_NOT_SPECIFIED + webScaffoldAnnotationValues.getGovernorTypeDetails().getName() + "'"); if (!controllerPath.startsWith("/")) { controllerPath = "/".concat(controllerPath); } PathResolver pathResolver = getProjectOperations().getPathResolver(); String docJspx = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""), "WEB-INF/views" + controllerPath + "/" + rooJspx.name() + ".jspx"); if (!getFileManager().exists(docJspx)) { // create.jspx doesn't exist, so nothing to do return; } InputStream docJspxIs = getFileManager().getInputStream(docJspx); Document docJspXml; try { docJspXml = XmlUtils.getDocumentBuilder().parse(docJspxIs); } catch (Exception ex) { throw new IllegalStateException("Could not open " + rooJspx.name() + ".jspx file", ex); } Element docRoot = docJspXml.getDocumentElement(); // Add new tag namesapces Element divMain = XmlUtils.findFirstElement("/div", docRoot); if (rooJspx.equals(RooJspx.create) || rooJspx.equals(RooJspx.update)) { divMain.setAttribute("xmlns:pattern", "urn:jsptagdir:/WEB-INF/tags/pattern"); } String divContPaneId = XmlUtils .convertId(DIV_ID_PREFIX + formbackingType.getFullyQualifiedTypeName() + "_contentPane"); Element divContentPane = XmlUtils .findFirstElement("/div/" + rooJspx.name() + "/div[@id='" + divContPaneId + "']", docRoot); if (null == divContentPane) { divContentPane = new XmlElementBuilder(DIV_ELEMENT, docJspXml).addAttribute(ID_ATTRIBUTE, divContPaneId) .addAttribute(CLASS_ATTRIBUTE, "patternContentPane").build(); } String divFormId = XmlUtils .convertId(DIV_ID_PREFIX + formbackingType.getFullyQualifiedTypeName() + "_formNoedit"); Element divForm = XmlUtils.findFirstElement("/div/" + rooJspx.name() + "/div/div[@id='" + divFormId + "']", docRoot); if (null == divForm) { divForm = new XmlElementBuilder(DIV_ELEMENT, docJspXml).addAttribute(ID_ATTRIBUTE, divFormId) .addAttribute(CLASS_ATTRIBUTE, "formularios boxNoedit").build(); divContentPane.appendChild(divForm); } String idPrefix = rooJspx.equals(RooJspx.create) ? "fc:" : rooJspx.equals(RooJspx.update) ? "fu:" : "ps:"; Element form = XmlUtils.findFirstElement( "/div/" + rooJspx.name() + "[@id='" + XmlUtils.convertId(idPrefix + formbackingType.getFullyQualifiedTypeName()) + "']", docRoot); if (form != null) { // Wrap fields into <ul><li/></ul> NodeList fields = form.getChildNodes(); if (fields.getLength() > 0) { Node thisField; for (int i = 0; i < fields.getLength(); i++) { thisField = fields.item(i); if (thisField.getNodeName().startsWith("field:") && !thisField.getParentNode().getNodeName().equalsIgnoreCase("li")) { if (null != thisField.getAttributes() /* * && null != thisField.getAttributes().getNamedItem( * "type") && * !thisField.getAttributes().getNamedItem("type") * .getNodeValue().equalsIgnoreCase("hidden") */) { Node thisNodeCpy = thisField.cloneNode(true); String fieldAttValue = thisNodeCpy.getAttributes().getNamedItem(FIELD_ATTRIBUTE) .getNodeValue(); Element li = new XmlElementBuilder("li", docJspXml) .addAttribute(CLASS_ATTRIBUTE, "size120") .addAttribute(ID_ATTRIBUTE, XmlUtils.convertId( "li:".concat(formbackingType.getFullyQualifiedTypeName()) .concat(".").concat(fieldAttValue))) .addChild(thisNodeCpy).build(); Element ul = new XmlElementBuilder("ul", docJspXml) .addAttribute(CLASS_ATTRIBUTE, "formInline") .addAttribute(ID_ATTRIBUTE, XmlUtils.convertId( "ul:".concat(formbackingType.getFullyQualifiedTypeName()) .concat(".").concat(fieldAttValue))) .addChild(li).build(); divForm.appendChild(ul); form.removeChild(thisField); // form.replaceChild(ul, thisField); } } } } if (rooJspx.equals(RooJspx.create) || rooJspx.equals(RooJspx.update)) { // Add a hidden field holding gvnixpattern parameter if exists String hiddenFieldId = XmlUtils .convertId("c:" + formbackingType.getFullyQualifiedTypeName() + "_gvnixpattern"); Element hiddenField = XmlUtils.findFirstElement( "/div/" + rooJspx.name() + "/div/div/hiddengvnixpattern[@id='" + hiddenFieldId + "']", docRoot); if (null == hiddenField) { hiddenField = new XmlElementBuilder("pattern:hiddengvnixpattern", docJspXml) .addAttribute(ID_ATTRIBUTE, hiddenFieldId) .addAttribute("value", "${param.gvnixpattern}") .addAttribute(RENDER_ATTRIBUTE, "${not empty param.gvnixpattern}").build(); divForm.appendChild(hiddenField); } // Add a cancel button String cancelId = XmlUtils .convertId(idPrefix + formbackingType.getFullyQualifiedTypeName() + "_cancel"); Element cancelButton = XmlUtils.findFirstElement( "/div/" + rooJspx.name() + "/div/div/cancelbutton[@id='" + cancelId + "']", docRoot); if (null == cancelButton) { cancelButton = new XmlElementBuilder("pattern:cancelbutton", docJspXml) .addAttribute(ID_ATTRIBUTE, cancelId) .addAttribute(RENDER_ATTRIBUTE, "${not empty param.gvnixpattern}").build(); divForm.appendChild(cancelButton); } } form.appendChild(divContentPane); } DomUtils.removeTextNodes(docJspXml); getFileManager().createOrUpdateTextFileIfRequired(docJspx, XmlUtils.nodeToString(docJspXml), true); // writeToDiskIfNecessary(docJspx, docJspXml); }
From source file:org.infoglue.cms.applications.managementtool.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type attribute up one step. *//*from w ww .j a va 2s. c om*/ public String doMoveAttributeUp() throws Exception { this.initialize(getContentTypeDefinitionId()); try { Document document = createDocumentFromDefinition(); String attributesXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element"; NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath); Element previousElement = null; for (int i = 0; i < anl.getLength(); i++) { Element element = (Element) anl.item(i); if (element.getAttribute("name").equalsIgnoreCase(this.attributeName) && previousElement != null) { Element parent = (Element) element.getParentNode(); parent.removeChild(element); parent.insertBefore(element, previousElement); } previousElement = element; } saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return USE_EDITOR; }
From source file:org.infoglue.cms.applications.managementtool.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type attribute down one step. *//*from w ww.j av a2s . c o m*/ public String doMoveAttributeDown() throws Exception { this.initialize(getContentTypeDefinitionId()); try { Document document = createDocumentFromDefinition(); String attributesXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element"; NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath); Element parent = null; Element elementToMove = null; boolean isInserted = false; int position = 0; for (int i = 0; i < anl.getLength(); i++) { Element element = (Element) anl.item(i); parent = (Element) element.getParentNode(); if (elementToMove != null) { if (position == 2) { parent.insertBefore(elementToMove, element); isInserted = true; break; } else position++; } if (element.getAttribute("name").equalsIgnoreCase(this.attributeName)) { elementToMove = element; parent.removeChild(elementToMove); position++; } } if (!isInserted && elementToMove != null) parent.appendChild(elementToMove); saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return USE_EDITOR; }