private String mapItemParamsToAdviceCaseParams( String adviceName, List<YParameter> inAspectParams, String data) { org.jdom2.Element result = new org.jdom2.Element(adviceName); SAXBuilder builder = new SAXBuilder(); org.jdom2.Element root = null; try { org.jdom2.Document document = builder.build(new StringReader(data)); root = document.getRootElement(); } catch (Exception e) { System.out.println(e); } for (YParameter param : inAspectParams) { String paramName = param.getName(); org.jdom2.Element advElem = root.getChild(paramName); try { if (advElem != null) { org.jdom2.Element copy = (org.jdom2.Element) advElem.clone(); result.addContent(copy); } else { result.addContent(new org.jdom2.Element(paramName)); } } catch (IllegalAddException iae) { System.out.println("+++++++++++++++++ error:" + iae.getMessage()); } } return JDOMUtil.elementToString(result); }
private org.jdom2.Element getDataforCase(String specName, String caseID, String data) { String caseData = ""; try { caseData = _ibClient.getCaseData(caseID, _handle); } catch (IOException e) { e.printStackTrace(); } org.jdom2.Element result = new org.jdom2.Element(specName); SAXBuilder builder = new SAXBuilder(); org.jdom2.Element root = null; List<org.jdom2.Element> ls = null; try { org.jdom2.Document document = builder.build(new StringReader(data)); root = document.getRootElement(); ls = document.getRootElement().getChildren(); } catch (Exception e) { System.out.println(e); } for (org.jdom2.Element l : ls) { String paramName = l.getName(); org.jdom2.Element advElem = root.getChild(paramName); try { if (advElem != null) { org.jdom2.Element copy = (org.jdom2.Element) advElem.clone(); result.addContent(copy); } else { result.addContent(new org.jdom2.Element(paramName)); } } catch (IllegalAddException iae) { } } return result; }
@Test public void testOutputElementPreserveSpaceComplex() { // the purpose of this test is to ensure that the different // formatting values are used when going down one level, // back up, then in to 'preserve', back up, and then again // down in to normal (not preserve). // this is essentially a test of the FormatStack code.... Element tst = new Element("child"); Comment cmt = new Comment("comment"); tst.addContent(cmt); String spaced = " <child>\n <!--comment-->\n </child>\n"; String compact = "<child><!--comment--></child>"; String preserved = "<child xml:space=\"preserve\"><!--comment--></child>"; Element root = new Element("root"); root.addContent(tst.clone()); root.addContent(tst.clone().setAttribute("space", "preserve", Namespace.XML_NAMESPACE)); root.addContent(tst.clone()); String rawcompact = "<root>" + compact + preserved + compact + "</root>"; String pretty = "<root>\n" + spaced + " " + preserved + "\n" + spaced + "</root>"; checkOutput(root, rawcompact, rawcompact, pretty, pretty, pretty); }
protected void buildJNLP(HttpServletRequest request, HttpServletResponse response) throws IOException { try { if (logger.isDebugEnabled()) { ServletUtil.logInfo(request, logger); } if (handleRequestAndRedirect(request, response)) { return; } // Store jnlp templates jdom structure in hashMap, avoid to always read the same jnlp file Element rootJnlp = null; JnlpTemplate launcher = createLauncherTemplate(request); final Map<URL, Element> jnlpTemplates = (Map<URL, Element>) this.getServletContext().getAttribute("jnlpTemplates"); if (jnlpTemplates != null) { Element element = jnlpTemplates.get(launcher.realPathURL); if (element != null) { rootJnlp = element.clone(); } } if (rootJnlp == null) { parseLauncherTemplate(launcher); rootJnlp = launcher.rootElt; if (jnlpTemplates != null && rootJnlp != null) { jnlpTemplates.put(launcher.realPathURL, rootJnlp.clone()); } } else { launcher.rootElt = rootJnlp; } Object uploadedArg = request.getAttribute(ATTRIBUTE_UPLOADED_ARGUMENT); if (uploadedArg instanceof String) { Object argValues = ServletUtil.addParameter( launcher.parameterMap.get(PARAM_ARGUMENT), (String) uploadedArg); launcher.parameterMap.put(PARAM_ARGUMENT, argValues); } String launcherStr = buildJnlpResponse(launcher); logger.debug("doGet() - launcherStr = [\n{}\n]", launcherStr); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1 response.setHeader("Pragma", "no-cache"); // HTTP 1.0 response.setDateHeader("Expires", -1); // Proxies response.setContentType(JNLP_MIME_TYPE); response.setHeader( "Content-Disposition", String.format("inline; filename=\"%s\"", launcher.templateFileName)); ServletUtil.write(launcherStr, response.getOutputStream()); } catch (ServletErrorException e) { logger.error("doGet()", e); response.sendError(e.responseErrorCode); } catch (Exception e) { logger.error("doGet()", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }