List of usage examples for org.w3c.dom DOMException getMessage
public String getMessage()
From source file:org.sakaiproject.tool.rutgers.LinkToolEntityProducer.java
/** * {@inheritDoc}// ww w. j a v a 2s . co m */ public String merge(String siteId, Element root, String archivePath, String fromSiteId, Map attachmentNames, Map userIdTrans, Set userListAllowImport) { logger.debug("trying to merge linktool"); // buffer for the results log StringBuilder results = new StringBuilder(); int count = 0; if (siteId != null && siteId.trim().length() > 0) { try { NodeList allChildrenNodes = root.getChildNodes(); int length = allChildrenNodes.getLength(); for (int i = 0; i < length; i++) { Node siteNode = allChildrenNodes.item(i); if (siteNode.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) siteNode; if (element.getTagName().equals(LINKTOOL)) { Site site = SiteService.getSite(siteId); // in the model, this code was there. It would require // one tool to already be present. I'm not sure whether that's right or not. // if (site.getToolForCommonId(LINKTOOL_ID) != null) { if (true) { // add the link tools NodeList nodes = element.getChildNodes(); int lengthNodes = nodes.getLength(); for (int cn = 0; cn < lengthNodes; cn++) { Node node = nodes.item(cn); if (node.getNodeType() == Node.ELEMENT_NODE) { Element linkElement = (Element) node; if (linkElement.getTagName().equals(LINKTOOL)) { String toolId = linkElement.getAttribute("toolid"); String trimBody = null; if (toolId != null && toolId.length() > 0) { trimBody = trimToNull(toolId); if (trimBody != null && trimBody.length() > 0) { toolId = trimBody; } } String toolTitle = linkElement.getAttribute("name"); trimBody = null; if (toolTitle != null && toolTitle.length() > 0) { trimBody = trimToNull(toolTitle); if (trimBody != null && trimBody.length() > 0) { toolTitle = trimBody; } } String contentUrl = linkElement.getAttribute("url"); trimBody = null; if (contentUrl != null && contentUrl.length() > 0) { trimBody = trimToNull(contentUrl); if (trimBody != null && trimBody.length() > 0) { contentUrl = trimBody; } } String height = linkElement.getAttribute("height"); if (toolTitle != null && toolTitle.length() > 0) { Tool tr = ToolManager.getTool(toolId); SitePage page = site.addPage(); page.setTitle(toolTitle); ToolConfiguration tool = page.addTool(); tool.setTool(toolId, tr); tool.setTitle(toolTitle); tool.getPlacementConfig().setProperty("url", contentUrl); count++; if (height != null) { tool.getPlacementConfig().setProperty("height", height); } } } } } SiteService.save(site); } } } } results.append("merging link tool " + siteId + " (" + count + ") items.\n"); } catch (DOMException e) { logger.error(e.getMessage(), e); results.append("merging " + getLabel() + " failed during xml parsing.\n"); } catch (Exception e) { logger.error(e.getMessage(), e); results.append("merging " + getLabel() + " failed.\n"); } } return results.toString(); }
From source file:org.structr.web.basic.HtmlServletObjectResolvingTest.java
@Test public void testObjectResolvingInHtmlServlet() { final List<String> testObjectIDs = new LinkedList<>(); try (final Tx tx = app.tx()) { // setup three different test objects to be found by HtmlServlet testObjectIDs.add(app.create(TestOne.class, new NodeAttribute<>(TestOne.anInt, 123)).getUuid()); testObjectIDs.add(app.create(TestOne.class, new NodeAttribute<>(TestOne.aDouble, 0.345)).getUuid()); testObjectIDs.add(app.create(TestOne.class, new NodeAttribute<>(TestOne.aString, "abcdefg")).getUuid()); // create a page final Page newPage = Page.createNewPage(securityContext, "testPage"); if (newPage != null) { Element html = newPage.createElement("html"); Element head = newPage.createElement("head"); Element body = newPage.createElement("body"); Text textNode = newPage.createTextNode("${current.id}"); try { // add HTML element to page newPage.appendChild(html); html.appendChild(head);//from w ww.j ava2s . c o m html.appendChild(body); body.appendChild(textNode); } catch (DOMException dex) { logger.warn("", dex); throw new FrameworkException(422, dex.getMessage()); } } tx.success(); } catch (FrameworkException fex) { logger.warn("", fex); } RestAssured.basePath = "/structr/html"; RestAssured.given().header("X-User", "superadmin").header("X-Password", "sehrgeheim") .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().response() .contentType("text/html").statusCode(200).body(Matchers.containsString(testObjectIDs.get(0))).when() .get("/testPage/123"); RestAssured.given().header("X-User", "superadmin").header("X-Password", "sehrgeheim") .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().response().statusCode(200) .body(Matchers.containsString(testObjectIDs.get(1))).when().get("/testPage/0.345"); RestAssured.given().header("X-User", "superadmin").header("X-Password", "sehrgeheim") .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(401)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(403)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)) .filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().response().statusCode(200) .body(Matchers.containsString(testObjectIDs.get(2))).when().get("/testPage/abcdefg"); }
From source file:org.structr.web.entity.dom.Page.java
/** * Creates a default simple page for the Structr backend "add page" button. * * @param securityContext// w w w . ja v a 2 s . c o m * @param name * @return * @throws FrameworkException */ public static Page createSimplePage(final SecurityContext securityContext, final String name) throws FrameworkException { final Page page = Page.createNewPage(securityContext, name); if (page != null) { Element html = page.createElement("html"); Element head = page.createElement("head"); Element body = page.createElement("body"); Element title = page.createElement("title"); Element h1 = page.createElement("h1"); Element div = page.createElement("div"); try { // add HTML element to page page.appendChild(html); // add HEAD and BODY elements to HTML html.appendChild(head); html.appendChild(body); // add TITLE element to HEAD head.appendChild(title); // add H1 element to BODY body.appendChild(h1); // add DIV element to BODY body.appendChild(div); // add text nodes title.appendChild(page.createTextNode("${capitalize(page.name)}")); h1.appendChild(page.createTextNode("${capitalize(page.name)}")); div.appendChild(page.createTextNode("Initial body text")); } catch (DOMException dex) { dex.printStackTrace(); throw new FrameworkException(422, dex.getMessage()); } } return page; }
From source file:org.structr.web.entity.dom.PageTest.java
public void testAdoptNodes() { try {//from w w w . j a v a2 s . c o m try (final Tx tx = app.tx()) { Page srcPage = Page.createNewPage(securityContext, "srcPage"); assertTrue(srcPage != null); assertTrue(srcPage instanceof Page); Node html = srcPage.createElement("html"); Node head = srcPage.createElement("head"); Node body = srcPage.createElement("body"); Node title = srcPage.createElement("title"); Node h1 = srcPage.createElement("h1"); Node div = srcPage.createElement("div"); Node p = srcPage.createElement("p"); // add HTML element to page srcPage.appendChild(html); // add HEAD and BODY elements to HTML html.appendChild(head); html.appendChild(body); // add TITLE element to HEAD head.appendChild(title); // add H1 element to BODY body.appendChild(h1); // add DIV element to BODY body.appendChild(div); div.appendChild(p); // add text element to P p.appendChild(srcPage.createTextNode("First Paragraph")); Page dstPage = Page.createNewPage(securityContext, "dstPage"); assertNotNull(dstPage); // test adopt method dstPage.adoptNode(html); // has parent been removed for the source element? assertNull(html.getParentNode()); // has owner changed for all elements? assertEquals(dstPage, html.getOwnerDocument()); assertEquals(dstPage, head.getOwnerDocument()); assertEquals(dstPage, body.getOwnerDocument()); assertEquals(dstPage, title.getOwnerDocument()); assertEquals(dstPage, h1.getOwnerDocument()); assertEquals(dstPage, div.getOwnerDocument()); assertEquals(dstPage, p.getOwnerDocument()); // have parents been kept for all other elements? assertEquals(html, head.getParentNode()); assertEquals(html, body.getParentNode()); assertEquals(head, title.getParentNode()); assertEquals(body, h1.getParentNode()); assertEquals(body, div.getParentNode()); assertEquals(div, p.getParentNode()); // srcPage should not have a document element any more assertNull(srcPage.getDocumentElement()); // srcPage should have exactly one child element assertEquals(1, srcPage.getChildNodes().getLength()); tx.success(); } catch (DOMException dex) { throw new FrameworkException(422, dex.getMessage()); } } catch (FrameworkException ex) { fail("Unexpected exception"); } }
From source file:org.structr.web.entity.dom.PageTest.java
public void testCloneNode() { try {//from www . j a v a 2 s.c o m try (final Tx tx = app.tx()) { Page page = Page.createNewPage(securityContext, "srcPage"); assertTrue(page != null); assertTrue(page instanceof Page); Node html = page.createElement("html"); Node head = page.createElement("head"); Node body = page.createElement("body"); Node title = page.createElement("title"); Node h1 = page.createElement("h1"); Node div = page.createElement("div"); Node p = page.createElement("p"); try { // add HTML element to page page.appendChild(html); // add HEAD and BODY elements to HTML html.appendChild(head); html.appendChild(body); // add TITLE element to HEAD head.appendChild(title); // add H1 element to BODY body.appendChild(h1); // add DIV element to BODY body.appendChild(div); div.appendChild(p); // add text element to P p.appendChild(page.createTextNode("First Paragraph")); Node clone = body.cloneNode(false); assertTrue(isClone(clone, body)); tx.success(); } catch (DOMException dex) { throw new FrameworkException(422, dex.getMessage()); } } } catch (FrameworkException ex) { fail("Unexpected exception"); } }
From source file:org.structr.websocket.command.dom.CreateAndAppendDOMNodeCommand.java
@Override public void processMessage(WebSocketMessage webSocketData) { final Map<String, Object> nodeData = webSocketData.getNodeData(); final String parentId = (String) nodeData.get("parentId"); final String childContent = (String) nodeData.get("childContent"); final String pageId = webSocketData.getPageId(); nodeData.remove("parentId"); if (pageId != null) { // check for parent ID before creating any nodes if (parentId == null) { getWebSocket().send(/*w w w .j av a 2 s. c o m*/ MessageBuilder.status().code(422).message("Cannot add node without parentId").build(), true); return; } // check if parent node with given ID exists final DOMNode parentNode = getDOMNode(parentId); if (parentNode == null) { getWebSocket().send(MessageBuilder.status().code(404).message("Parent node not found").build(), true); return; } final Document document = getPage(pageId); if (document != null) { final String tagName = (String) nodeData.get("tagName"); nodeData.remove("tagName"); try { DOMNode newNode; if (tagName != null && "comment".equals(tagName)) { newNode = (DOMNode) document.createComment("#comment"); } else if (tagName != null && "template".equals(tagName)) { newNode = (DOMNode) document.createTextNode("#template"); try { newNode.setProperty(NodeInterface.type, Template.class.getSimpleName()); } catch (FrameworkException fex) { logger.log(Level.WARNING, "Unable to set type of node {1} to Template: {3}", new Object[] { newNode.getUuid(), fex.getMessage() }); } } else if (tagName != null && !tagName.isEmpty()) { newNode = (DOMNode) document.createElement(tagName); } else { newNode = (DOMNode) document.createTextNode("#text"); } // Instantiate node again to get correct class newNode = getDOMNode(newNode.getUuid()); // append new node to parent if (newNode != null) { parentNode.appendChild(newNode); for (Entry entry : nodeData.entrySet()) { final String key = (String) entry.getKey(); final Object val = entry.getValue(); PropertyKey propertyKey = StructrApp.getConfiguration() .getPropertyKeyForDatabaseName(newNode.getClass(), key); if (propertyKey != null) { try { Object convertedValue = val; PropertyConverter inputConverter = propertyKey .inputConverter(SecurityContext.getSuperUserInstance()); if (inputConverter != null) { convertedValue = inputConverter.convert(val); } //newNode.unlockReadOnlyPropertiesOnce(); newNode.setProperty(propertyKey, convertedValue); } catch (FrameworkException fex) { logger.log(Level.WARNING, "Unable to set node property {0} of node {1} to {2}: {3}", new Object[] { propertyKey, newNode.getUuid(), val, fex.getMessage() }); } } } // create a child text node if content is given if (StringUtils.isNotBlank(childContent)) { final DOMNode childNode = (DOMNode) document.createTextNode(childContent); newNode.appendChild(childNode); } } } catch (DOMException dex) { // send DOM exception getWebSocket().send(MessageBuilder.status().code(422).message(dex.getMessage()).build(), true); } } else { getWebSocket().send(MessageBuilder.status().code(404).message("Page not found").build(), true); } } else { getWebSocket().send( MessageBuilder.status().code(422).message("Cannot create node without pageId").build(), true); } }