List of usage examples for org.w3c.dom Document createElement
public Element createElement(String tagName) throws DOMException;
From source file:com.meltmedia.cadmium.core.util.WarUtils.java
/** * Adds a context parameter to a web.xml file to override where the shiro environment class. * @param doc The xml DOM document to create the new xml elements with. * @param root The xml Element node to add the context param to. *//* www . j av a 2 s . c o m*/ public static void addEnvContextParam(Document doc, Element root) { Element ctxParam = doc.createElement("context-param"); Element paramName = doc.createElement("param-name"); paramName.appendChild(doc.createTextNode("shiroEnvironmentClass")); ctxParam.appendChild(paramName); Element paramValue = doc.createElement("param-value"); paramValue.appendChild(doc.createTextNode("com.meltmedia.cadmium.servlets.shiro.WebEnvironment")); ctxParam.appendChild(paramValue); addRelativeTo(root, ctxParam, "listener", false); }
From source file:com.meltmedia.cadmium.core.util.WarUtils.java
/** * Adds a context parameter to a web.xml file to override where the shiro config location is to be loaded from. * The location loaded from will be represented by the "com.meltmedia.cadmium.contentRoot" system property. * @param doc The xml DOM document to create the new xml elements with. * @param root The xml Element node to add the context param to. *//*w ww . ja v a 2 s.c om*/ public static void addContextParam(Document doc, Element root) { Element ctxParam = doc.createElement("context-param"); Element paramName = doc.createElement("param-name"); paramName.appendChild(doc.createTextNode("shiroConfigLocations")); ctxParam.appendChild(paramName); Element paramValue = doc.createElement("param-value"); paramValue.appendChild(doc.createTextNode( "file:" + new File(System.getProperty("com.meltmedia.cadmium.contentRoot"), "shiro.ini") .getAbsoluteFile().getAbsolutePath())); ctxParam.appendChild(paramValue); addRelativeTo(root, ctxParam, "listener", false); }
From source file:Main.java
public static void copyInto(Node src, Node dest) throws DOMException { Document factory = dest.getOwnerDocument(); //Node start = src; Node parent = null;/*from w ww .j av a 2 s . com*/ Node place = src; // traverse source tree while (place != null) { // copy this node Node node = null; int type = place.getNodeType(); switch (type) { case Node.CDATA_SECTION_NODE: { node = factory.createCDATASection(place.getNodeValue()); break; } case Node.COMMENT_NODE: { node = factory.createComment(place.getNodeValue()); break; } case Node.ELEMENT_NODE: { Element element = factory.createElement(place.getNodeName()); node = element; NamedNodeMap attrs = place.getAttributes(); int attrCount = attrs.getLength(); for (int i = 0; i < attrCount; i++) { Attr attr = (Attr) attrs.item(i); String attrName = attr.getNodeName(); String attrValue = attr.getNodeValue(); element.setAttribute(attrName, attrValue); } break; } case Node.ENTITY_REFERENCE_NODE: { node = factory.createEntityReference(place.getNodeName()); break; } case Node.PROCESSING_INSTRUCTION_NODE: { node = factory.createProcessingInstruction(place.getNodeName(), place.getNodeValue()); break; } case Node.TEXT_NODE: { node = factory.createTextNode(place.getNodeValue()); break; } default: { throw new IllegalArgumentException( "can't copy node type, " + type + " (" + place.getNodeName() + ')'); } } dest.appendChild(node); // iterate over children if (place.hasChildNodes()) { parent = place; place = place.getFirstChild(); dest = node; } else if (parent == null) { place = null; } else { // advance place = place.getNextSibling(); while (place == null && parent != null) { place = parent.getNextSibling(); parent = parent.getParentNode(); dest = dest.getParentNode(); } } } }
From source file:com.granule.json.utils.XML.java
private static void convertJSONObject(Document doc, Element parent, JSONObject jObject, String tagName) { Set attributes = jObject.keySet(); Iterator attrsItr = attributes.iterator(); Element element = doc.createElement(removeProblemCharacters(tagName)); if (parent != null) { parent.appendChild(element);//from w w w . j a v a 2 s . co m } else { doc.appendChild(element); } while (attrsItr.hasNext()) { String attr = (String) attrsItr.next(); Object obj = jObject.opt(attr); if (obj instanceof Number) { element.setAttribute(attr, obj.toString()); } else if (obj instanceof Boolean) { element.setAttribute(attr, obj.toString()); } else if (obj instanceof String) { element.setAttribute(attr, escapeEntityCharacters(obj.toString())); } else if (obj == null) { element.setAttribute(attr, ""); } else if (obj instanceof JSONObject) { convertJSONObject(doc, element, (JSONObject) obj, attr); } else if (obj instanceof JSONArray) { convertJSONArray(doc, element, (JSONArray) obj, attr); } } }
From source file:com.meltmedia.cadmium.core.util.WarUtils.java
/** * Adds the filter mapping for the shiro filter to a web.xml file. * @param doc The xml DOM document to create the new xml elements with. * @param root The xml Element node to add the filter mapping to. *//* w w w . jav a2 s. c om*/ public static void addFilterMapping(Document doc, Element root) { Element filterMapping = doc.createElement("filter-mapping"); Element filterName = doc.createElement("filter-name"); filterName.appendChild(doc.createTextNode("ShiroFilter")); filterMapping.appendChild(filterName); Element urlPattern = doc.createElement("url-pattern"); urlPattern.appendChild(doc.createTextNode("/*")); filterMapping.appendChild(urlPattern); addDispatchers(doc, filterMapping, "REQUEST", "FORWARD", "INCLUDE", "ERROR"); addRelativeTo(root, filterMapping, "filter-mapping", true); }
From source file:com.moviejukebox.writer.MovieJukeboxHTMLWriter.java
/** * Use an XSL file to generate the jukebox index file * * @param jukebox/*from w w w .jav a 2 s . co m*/ * @param library */ private static void generateTransformedIndexHTML(Jukebox jukebox, Library library) { LOG.debug("Generating Index file from jukebox-index.xsl"); String homePage = PropertiesUtil.getProperty("mjb.homePage", ""); if (StringUtils.isBlank(homePage)) { String defCat = library.getDefaultCategory(); if (defCat != null) { homePage = FileTools.createPrefix("Other", HTMLTools.encodeUrl(FileTools.makeSafeFilename(defCat))) + "1"; } else { // figure out something better to do here LOG.info("No categories were found, so you should specify mjb.homePage in the config file."); } } try { // Create the index.xml file with some properties in it. File indexXmlFile = new File(jukebox.getJukeboxTempLocation(), "index.xml"); FileTools.makeDirsForFile(indexXmlFile); Document docIndex = DOMHelper.createDocument(); Element eRoot = docIndex.createElement("index"); docIndex.appendChild(eRoot); DOMHelper.appendChild(docIndex, eRoot, "detailsDirName", jukebox.getDetailsDirName()); DOMHelper.appendChild(docIndex, eRoot, "homePage", homePage); DOMHelper.writeDocumentToFile(docIndex, indexXmlFile); // Now generate the HTML from the XLST File htmlFile = new File(jukebox.getJukeboxTempLocation(), PropertiesUtil.getProperty("mjb.indexFile", "index.htm")); FileTools.addJukeboxFile(indexXmlFile.getName()); FileTools.addJukeboxFile(htmlFile.getName()); Transformer transformer = getTransformer(new File(SKIN_HOME, "jukebox-index.xsl"), jukebox.getJukeboxTempLocation()); Source xmlSource = new StreamSource(indexXmlFile); Result xmlResult = new StreamResult(htmlFile); doTransform(transformer, xmlSource, xmlResult, "Jukebox index"); } catch (ParserConfigurationException | RuntimeException ex) { LOG.error("Failed generating jukebox index: {}", ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } }
From source file:com.granule.json.utils.XML.java
private static void convertJSONArray(Document doc, Element parent, JSONArray jArray, String tagName) { tagName = removeProblemCharacters(tagName); for (int i = 0; i < jArray.size(); i++) { Element element = doc.createElement(tagName); if (parent != null) { parent.appendChild(element); } else {/*from ww w. j a v a2 s . c om*/ doc.appendChild(element); } Object obj = jArray.get(i); if (obj instanceof Number) { Node tNode = doc.createTextNode(obj.toString()); element.appendChild(tNode); } else if (obj instanceof Boolean) { Node tNode = doc.createTextNode(obj.toString()); element.appendChild(tNode); } else if (obj instanceof String) { Node tNode = doc.createTextNode(escapeEntityCharacters(obj.toString())); element.appendChild(tNode); } else if (obj instanceof JSONObject) { convertJSONObject(doc, element, (JSONObject) obj, "jsonObject"); } else if (obj instanceof JSONArray) { convertJSONArray(doc, element, (JSONArray) obj, "jsonArray"); } } }
From source file:sep.gaia.resources.poi.POILoaderWorker.java
/** * Returns an element to limit a query to a specific geographical area. * @param doc The document to create the element in. * @param bbox The boundaries of the queries area. * @return The bounding-box-element ready to be added to a query. *//*from ww w .j a va 2 s. co m*/ private static Element createBBoxElement(Document doc, FloatBoundingBox bbox) { // The Overpass-API does use sides instead of corners, so convert them: float east = bbox.getUpperRight().getY(); float west = bbox.getLowerRight().getY(); float north = bbox.getUpperLeft().getX(); float south = bbox.getLowerRight().getX(); // Create the element and add the attributes describing the sides of the bbox: Element element = doc.createElement("bbox-query"); element.setAttribute("e", Float.toString(Math.max(east, west))); element.setAttribute("w", Float.toString(Math.min(east, west))); element.setAttribute("n", Float.toString(Math.max(north, south))); element.setAttribute("s", Float.toString(Math.min(north, south))); return element; }
From source file:com.connexta.arbitro.utils.PolicyUtils.java
/** * This creates XML representation of function Element using FunctionElementDTO object * * @param functionElementDTO FunctionElementDTO * @param doc Document// www . j ava2 s . c o m * @return DOM element */ public static Element createFunctionElement(FunctionElementDTO functionElementDTO, Document doc) { Element functionElement = doc.createElement(PolicyConstants.FUNCTION); if (functionElementDTO.getFunctionId() != null && functionElementDTO.getFunctionId().trim().length() > 0) { functionElement.setAttribute(PolicyConstants.FUNCTION_ID, functionElementDTO.getFunctionId()); } return functionElement; }
From source file:com.photon.phresco.framework.commons.QualityUtil.java
private static void appendHeaderManagerCollectionProp(Document document, Node elementProp, Map<String, String> headersMap) { Node collectionProp = document.createElement("collectionProp"); NamedNodeMap attributes = collectionProp.getAttributes(); attributes.setNamedItem(createAttribute(document, "name", "HeaderManager.headers")); createHeaderElementProp(document, headersMap, collectionProp); elementProp.setTextContent(null);//from w w w . j a v a2s. co m elementProp.appendChild(collectionProp); }