private Object getXmlValueText(List nodes) { if (nodes == null || nodes.isEmpty()) { return null; } Object node = nodes.get(0); if (node instanceof DefaultText) { return StringUtils.trim(((DefaultText) node).getText()); } if (node instanceof DefaultAttribute) { return StringUtils.trim(((DefaultAttribute) node).getText()); } if (node instanceof DefaultElement) { return StringUtils.trim(((DefaultElement) node).getText()); } throw new IllegalArgumentException("unsupported node type ["+node+"]."); }
/** * 将mq查询结果包装成list--dto的形式,dto内容为item中的内容 * * @param recv * @return */ public static Map MqResToDto(String recv) { // System.out.println("####recv"+recv); List res = new ArrayList(); Map map = new HashMap(); try { Document doc = DocumentHelper.parseText(recv); List list = doc.selectNodes("//item"); Iterator<DefaultElement> it = list.iterator(); while (it.hasNext()) { Map elementdto = XmlUtil.Dom2Map(it.next()); res.add(elementdto); } map.put("resultList", res);// 放入结果集 /* 如果存在REC_MNT,说明是分页查询类,需要将总记录数返回 */ Node de = doc.selectSingleNode("//REC_MNT"); if (DataUtil.isNotEmpty(de)) { map.put("countInteger", de.getText()); } } catch (Exception e) { logger.error("", e); } return map; }
/** * 将mq查询结果包装成list--dto的形式,dto内容为item中的内容 * * @param recv * @return */ public static Map MqResToDto(String recv) { // System.out.println("####recv"+recv); List res = new ArrayList(); Map map = new HashMap(); try { Document doc = DocumentHelper.parseText(recv); List list = doc.selectNodes("//item"); Iterator<DefaultElement> it = list.iterator(); while (it.hasNext()) { Map elementdto = XmlUtil.Dom2Map(it.next()); res.add(elementdto); } map.put("resultList", res);// 放入结果集 /* * 如果存在REC_MNT,说明是分页查询类,需要将总记录数返回 */ Node de = doc.selectSingleNode("//REC_MNT"); if (DataUtil.isNotEmpty(de)) { map.put("countInteger", de.getText()); } } catch (Exception e) { log.error(XmlUtil.class, e); } return map; }
@Override public boolean addAppMapping(AppMappingConfig appMapping) { try { Element rootElm = document.getRootElement(); Element mappingEle = new DefaultElement("mapping"); mappingEle.add(buildElement("deviceId", appMapping.getDeviceId())); mappingEle.add(buildElement("esdkApp", appMapping.getEsdkApp())); mappingEle.add(buildElement("deviceApp", appMapping.getDeviceApp())); mappingEle.add(buildElement("deviceAppPwd", appMapping.getDeviceAppPwd())); rootElm.add(mappingEle); writeXmlFile(document, this.file); } catch (IOException e) { LOGGER.error("", e); return false; } return true; }
private ReportSeedParsedVoCollection parseSeedsFromXML(String reportXML) throws DocumentException { Document document = DocumentHelper.parseText(reportXML); ReportSeedParsedVoCollection seeds = new ReportSeedParsedVoCollection(); List list = document.selectNodes("//Project/Seeds/Seed"); for (Iterator iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = (DefaultElement) iter.next(); ReportSeedParsedVo seed = new ReportSeedParsedVo(); seed.setName(attribute.valueOf("Name")); seed.setType(attribute.valueOf("Type")); seed.setBOName(attribute.valueOf("BOName")); seed.setBOField(attribute.valueOf("BOField")); seed.setCanBeNull(new Boolean(attribute.valueOf("CanBeNull").equalsIgnoreCase("true"))); seeds.add(seed); } return seeds; }
private void parseSeedsFromXML(String reportXML) throws DocumentException { Document document = DocumentHelper.parseText(reportXML); ReportSeedParsedVoCollection seeds = new ReportSeedParsedVoCollection(); List list = document.selectNodes("//Project/Seeds/Seed"); for (Iterator iter = list.iterator(); iter.hasNext();) { DefaultElement attribute = (DefaultElement) iter.next(); ReportSeedParsedVo seed = new ReportSeedParsedVo(); seed.setName(attribute.valueOf("Name")); seed.setType(attribute.valueOf("Type")); seed.setBOName(attribute.valueOf("BOName")); seed.setBOField(attribute.valueOf("BOField")); seed.setCanBeNull(new Boolean(attribute.valueOf("CanBeNull").equalsIgnoreCase("true"))); seeds.add(seed); } form.getGlobalContext().Admin.setReportSeedParsed(seeds); }
private void handleMacrosNode(Element xmlChannel) throws IOException { for (Object attrObj : xmlChannel.elements()) { DefaultElement e = (DefaultElement) attrObj; StringWriter sw = new StringWriter(); XMLWriter writer = new XMLWriter(sw); writer.write(e.elements()); if (this.tasker.getMacros().containsKey(e.attributeValue("name"))) { throw new RuntimeException("Macro " + e.attributeValue("name") + " already exists in map."); } this.tasker.getMacros().put(e.attributeValue("name"), sw.toString()); this.tasker.getMacroAttrs().put(e.attributeValue("name"), e.attributes()); } }
private void handleDefaultPropertiesNode(Element xmlChannel) { for (Object attrObj : xmlChannel.elements()) { DefaultElement e = (DefaultElement) attrObj; String propertyValue = e.attributeValue("value"); for (String defaultAttr : this.tasker.getDefaultProperties().keySet()) { propertyValue = propertyValue.replace("{" + defaultAttr + "}", this.tasker.getDefaultProperties().get(defaultAttr)); } this.tasker.getDefaultProperties().put(e.attributeValue("name"), propertyValue); } }
public void testNamespaceNodesAreInherited() throws JaxenException { Namespace ns0 = Namespace.get("p0", "www.acme0.org"); Namespace ns1 = Namespace.get("p1", "www.acme1.org"); Namespace ns2 = Namespace.get("p2", "www.acme2.org"); Element element = new DefaultElement("test", ns1); Attribute attribute = new DefaultAttribute("pre:foo", "bar", ns2); element.add(attribute); Element root = new DefaultElement("root", ns0); root.add(element); Document doc = new DefaultDocument(root); XPath xpath = new Dom4jXPath( "/*/*/namespace::node()" ); List results = xpath.selectNodes( doc ); assertEquals( 4, results.size() ); }
/** * Builds an html-info string about the current page and its linked resources * * @return HTML-String */ private String getCurrentPageInfoStringHTML() { // test if currentPage links to resource, which is used (linked) somewhere // else in the manifest final CPManager cpMgm = (CPManager) CoreSpringFactory.getBean(CPManager.class); final DefaultElement ele = cpMgm.getElementByIdentifier(cp, currentPage.getIdRef()); boolean single = false; if (ele instanceof CPResource) { final CPResource res = (CPResource) ele; single = cpMgm.isSingleUsedResource(res, cp); } final StringBuilder b = new StringBuilder(); b.append("<br /><ul>"); b.append("<li><b>" + translate("cptreecontroller.pagetitle") + "</b> " + currentPage.getTitle() + "</li>"); if (single) { b.append("<li><b>" + translate("cptreecontroller.file") + "</b> " + currentPage.getFileName() + "</li>"); } b.append("</ul>"); return b.toString(); }
/** */ @Override public DefaultElement getElementByIdentifier(final String id) { if (identifier.equals(id)) { return this; } DefaultElement e; for (final Iterator<CPItem> it = items.iterator(); it.hasNext();) { final CPItem item = it.next(); e = item.getElementByIdentifier(id); if (e != null) { return e; } } return null; }
/** */ @Override public void buildChildren() { final Iterator<DefaultElement> children = this.elementIterator(); // iterate through children while (children.hasNext()) { final DefaultElement child = children.next(); if (child.getName().equals(CPCore.METADATA)) { // TODO: implement METADATA metadata = new CPMetadata(child); } else { throw new OLATRuntimeException(CPOrganizations.class, "Invalid IMS-Manifest ( only <metadata> element under <file> is allowed )", new Exception()); } } this.clearContent(); validateElement(); }
/** */ @Override public void buildChildren() { final Iterator<DefaultElement> children = this.elementIterator(); // iterate through children while (children.hasNext()) { final DefaultElement child = children.next(); if (child.getName().equals(CPCore.ORGANIZATION)) { final CPOrganization org = new CPOrganization(child); org.setParentElement(this); org.buildChildren(); orgas.add(org); } else { errors.add("Invalid imsmanifest (only \"Organization\"-elements allowed under <organizations> )"); } } this.clearContent(); validateElement(); }
/** * @param doc */ public void buildDocument(final DefaultDocument doc) { // Manifest is the root-node of the document, therefore we need to pass the // "doc" final DefaultElement manifestElement = new DefaultElement(CPCore.MANIFEST); manifestElement.add(new DefaultAttribute(CPCore.IDENTIFIER, this.identifier)); manifestElement.add(new DefaultAttribute(CPCore.SCHEMALOCATION, this.schemaLocation)); // manifestElement.setNamespace(this.getNamespace()); //FIXME: namespace doc.add(manifestElement); if (metadata != null) { metadata.buildDocument(manifestElement); } organizations.buildDocument(manifestElement); resources.buildDocument(manifestElement); }
/** * ALF-19833: MacOS: Could not save to SharePoint */ @Test public void canGetListUsingCorrectListAndSiteName() throws Exception { VtiSoapRequest soapRequest = Mockito.mock(VtiSoapRequest.class); VtiSoapResponse soapResponse = new VtiSoapResponse(new MockHttpServletResponse());//Mockito.mock(VtiSoapResponse.class); Element requestElement = Mockito.mock(Element.class); SimpleNamespaceContext nc = Mockito.mock(SimpleNamespaceContext.class); Element rootElement = new DefaultElement(QName.get("root", "lists", "some://uri")); when(soapRequest.getDocument()).thenReturn(new DefaultDocument(rootElement)); // Invoke the method under test. listItemsEndpoint.executeListActionDetails(soapRequest, soapResponse, "my-site", "documentLibrary", requestElement, nc); // Check the condition this test is for. verify(listHandler).getList("documentLibrary", "my-site"); }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String param = req.getParameter("search"); Element root = new DefaultElement("result"); if (param != null && param.length() > 0) { GroupManager manager = GroupManager.getInstance(); Collection<Group> groups = manager.getGroups(); for (Group gr : groups) { if (gr.getName().startsWith(param)) { root.addElement("item").addText(gr.getName()); } } } resp.getOutputStream().write(root.asXML().getBytes()); resp.getOutputStream().close(); }
/** * adds an element to the CP. Only accepts <resource> and <organization> elements * * @param newElement * @return */ public void addElement(final DefaultElement newElement) { if (newElement instanceof CPResource) { rootNode.getResources().addResource((CPResource) newElement); } else if (newElement instanceof CPOrganization) { rootNode.getOrganizations().addOrganization((CPOrganization) newElement); } else if (newElement instanceof CPItem) { if (rootNode.getOrganizations().getOrganizations().size() > 0) { rootNode.getOrganizations().getOrganizations().elementAt(0).addItem((CPItem) newElement); } } else { throw new OLATRuntimeException(CPOrganizations.class, "invalid newElement for adding to manifest", new Exception()); } }
public void writeExternal(ObjectOutput out) throws IOException { ExternalizableUtil.getInstance().writeBoolean(out, address != null); if (address != null) { ExternalizableUtil.getInstance().writeSerializable(out, address); } ExternalizableUtil.getInstance().writeBoolean(out, streamID != null); if (streamID != null) { ExternalizableUtil.getInstance().writeSafeUTF(out, streamID); } ExternalizableUtil.getInstance().writeInt(out, sessionType.ordinal()); if (packet instanceof IQ) { ExternalizableUtil.getInstance().writeInt(out, 1); } else if (packet instanceof Message) { ExternalizableUtil.getInstance().writeInt(out, 2); } else if (packet instanceof Presence) { ExternalizableUtil.getInstance().writeInt(out, 3); } ExternalizableUtil.getInstance().writeSerializable(out, (DefaultElement) packet.getElement()); }
/** */ @Override public DefaultElement getElementByIdentifier(final String id) { if (id.equals(identifier)) { return this; } if (id.equals(CPCore.ORGANIZATIONS)) { return organizations; } DefaultElement e = organizations.getElementByIdentifier(id); if (e != null) { return e; } e = resources.getElementByIdentifier(id); if (e == null) { log.info("Element with id \"" + id + "\" not found in manifest!"); } return e; }
/** * Gets the linked page for the <item> element with given id if no resource (page) is referenced, null is returned * * @param id * @return */ public String getPageByItemID(final String id) { final DefaultElement ele = getElementByIdentifier(id); if (ele instanceof CPItem) { final CPItem item = (CPItem) ele; if (item.getIdentifierRef() == null || item.getIdentifierRef().equals("")) { return null; } final DefaultElement resElement = getElementByIdentifier(item.getIdentifierRef()); if (resElement instanceof CPResource) { final CPResource res = (CPResource) resElement; return res.getFullHref(); } else { log.info("method: getPageByItemID(" + id + ") : invalid manifest.. identifierred of <item> must point to a <resource>-element"); return null; } } else { return null; } }
public void writeExternal(ObjectOutput out) throws IOException { ExternalizableUtil.getInstance().writeBoolean(out, address != null); if (address != null) { ExternalizableUtil.getInstance().writeSerializable(out, address); } ExternalizableUtil.getInstance().writeBoolean(out, streamID != null); if (streamID != null) { ExternalizableUtil.getInstance().writeSafeUTF( out, streamID.getID() ); } ExternalizableUtil.getInstance().writeInt(out, sessionType.ordinal()); if (packet instanceof IQ) { ExternalizableUtil.getInstance().writeInt(out, 1); } else if (packet instanceof Message) { ExternalizableUtil.getInstance().writeInt(out, 2); } else if (packet instanceof Presence) { ExternalizableUtil.getInstance().writeInt(out, 3); } ExternalizableUtil.getInstance().writeSerializable(out, (DefaultElement) packet.getElement()); }
/** * Builds an html-info string about the current page and its linked resources. <br> * The untrusted text is already html escaped. * * @return HTML-String */ private String getCurrentPageInfoStringHTML() { // test if currentPage links to resource, which is used (linked) somewhere // else in the manifest final CPManager cpMgm = (CPManager) CoreSpringFactory.getBean(CPManager.class); final DefaultElement ele = cpMgm.getElementByIdentifier(cp, currentPage.getIdRef()); boolean single = false; if (ele instanceof CPResource) { final CPResource res = (CPResource) ele; single = cpMgm.isSingleUsedResource(res, cp); } final StringBuilder b = new StringBuilder(); b.append("<br /><ul>"); b.append("<li><b>" + translate("cptreecontroller.pagetitle") + "</b> " + StringHelper.escapeHtml(currentPage.getTitle()) + "</li>"); if (single) { b.append("<li><b>" + translate("cptreecontroller.file") + "</b> " + StringHelper.escapeHtml(currentPage.getFileName()) + "</li>"); } b.append("</ul>"); return b.toString(); }
/** */ @Override public void buildDocument(final DefaultElement parent) { final DefaultElement orgaElement = new DefaultElement(CPCore.ORGANIZATION); orgaElement.addAttribute(CPCore.IDENTIFIER, identifier); orgaElement.addAttribute(CPCore.STRUCTURE, structure); final DefaultElement titleElement = new DefaultElement(CPCore.TITLE); titleElement.setText(title); orgaElement.add(titleElement); if (metadata != null) { metadata.buildDocument(orgaElement); } for (final Iterator<CPItem> itItem = items.iterator(); itItem.hasNext();) { final CPItem item = itItem.next(); item.buildDocument(orgaElement); } parent.add(orgaElement); }
/** */ @Override public void buildChildren() { final Iterator<DefaultElement> children = this.elementIterator(); // iterate through children while (children.hasNext()) { final DefaultElement child = children.next(); if (child.getName().equals(CPCore.RESOURCE)) { final CPResource res = new CPResource(child); res.setParentElement(this); res.buildChildren(); resources.add(res); } else { errors.add("Invalid IMS-Manifest (only \"resource\"-elements allowed under <resources> )"); } } this.clearContent(); validateElement(); }
@Override public boolean addDevice(DeviceConfig device) { Element rootElm = document.getRootElement(); Element deviceEle = new DefaultElement("device"); deviceEle.add(buildElement("deviceId", device.getDeviceId())); deviceEle.add(buildElement("deviceName", device.getDeviceName())); deviceEle.add(buildElement("serviceAccessPoint", device.getServiceAccessPoint())); deviceEle.add(buildElement("loginUser", device.getLoginUser())); deviceEle.add(buildElement("loginPwd", device.getLoginPwd())); deviceEle.add(buildElement("deviceType", device.getDeviceType())); deviceEle.add(buildElement("deviceVersion", device.getDeviceVersion())); deviceEle.add(buildElement("connMode", device.getConnMode())); deviceEle.add(buildElement("reserver1", device.getReserver1() == null ? "" : device.getReserver1())); deviceEle.add(buildElement("reserver2", device.getReserver2() == null ? "" : device.getReserver2())); rootElm.add(deviceEle); try { writeXmlFile(document, this.file); } catch (IOException e) { rootElm.remove(deviceEle); LOGGER.error("", e); return false; } return true; }