private Element stackTrace(Throwable t, String expression) { Element stackTrace = new Element("div").addStyleClass("stackTrace"); stackTrace.setId("stackTrace" + buttonId); Element p = new Element("p") .appendText("While evaluating expression: "); p.appendChild(new Element("code").appendText(expression)); stackTrace.appendChild(p); recursivelyAppendStackTrace(t, stackTrace); return stackTrace; }
private void ensureDocumentHasTogglingScript(Element element) { Element rootElement = element.getRootElement(); if (!rootElementsWithScript.contains(rootElement)) { rootElementsWithScript.add(rootElement); Element head = rootElement.getFirstDescendantNamed("head"); if (head == null) { System.out.println(rootElement.toXML()); } Check.notNull(head, "Document <head> section is missing"); if (head != null) { Element script = new Element("script").addAttribute("type", "text/javascript"); head.prependChild(script); script.appendText(resourceSource.readResourceAsString(TOGGLING_SCRIPT_RESOURCE_PATH)); } } }
public Element addStyleClass(String styleClass) { String currentClass = getAttributeValue("class"); if (currentClass != null) { styleClass = currentClass + " " + styleClass; } addAttribute("class", styleClass); return this; }
protected void addResultsGeneratedBy(Element footer) { footer.appendText("Results generated by "); Element link = new Element("a"); link.addAttribute("href", CONCORDION_WEBSITE_URL); link.addAttribute("style", "font-weight: bold; text-decoration: none; color: #89C;"); footer.appendChild(link); link.appendText("Concordion"); } }
private Element getDocumentBody(Element rootElement) { Element body = rootElement.getFirstDescendantNamed("body"); if (body == null) { body = new Element("body"); rootElement.appendChild(body); } return body; }
private Element exceptionMessage(String exceptionMessage) { return new Element("span") .addStyleClass("exceptionMessage") .appendText(exceptionMessage); }
static Element replaceWithEmptyElement(Element origElement, String name, String namespace, Element caption) { Element anchor; if (caption != null) { origElement.appendSister(caption); anchor = caption; } else { anchor = origElement; } Element resultElement = new Element(origElement.getLocalName()); anchor.appendSister(resultElement); origElement.moveAttributesTo(resultElement); resultElement .removeAttribute(name, namespace); origElement.getParentElement().removeChild(origElement); return resultElement; }
public void throwableCaught(ThrowableCaughtEvent event) { Element element = event.getElement(); if (!(event.getThrowable() instanceof FailFastException)) { buttonId++; element.appendChild(expectedSpan(element)); // Special handling for <a> tags to avoid the stack-trace being inside the link text if (element.getLocalName().equals("a")) { Element div = new Element("div"); element.appendSister(div); element = div; } element.appendChild(exceptionMessage(event.getThrowable().getMessage())); element.appendChild(stackTraceTogglingButton()); element.appendChild(stackTrace(event.getThrowable(), event.getExpression())); ensureDocumentHasTogglingScript(element); } else { element.addStyleClass("failure"); } }
private Element expectedSpan(Element element) { Element spanExpected = new Element("del").addStyleClass("expected"); element.moveChildrenTo(spanExpected); spanExpected.appendNonBreakingSpaceIfBlank(); Element spanFailure = new Element("span").addStyleClass("failure"); spanFailure.appendChild(spanExpected); return spanFailure; }
public static void setupCommandForExample(CommandCall node, ResultRecorder resultRecorder, String exampleName) { node.getElement().addAttribute("id", exampleName); // let's be really nice and add the implementation status text into the element itself. ImplementationStatusChecker checker = ImplementationStatusChecker.implementationStatusCheckerFor(resultRecorder.getImplementationStatus()); Element fixtureNode = new Element("p"); fixtureNode.appendText(checker.printNoteToString()); node.getElement().prependChild(fixtureNode); }
private void addFooterToDocument(Element rootElement, Resource resource, long millisTaken) { Element body = rootElement.getFirstChildElement("body"); if (body != null) { Element footer = new Element("div"); footer.addStyleClass("footer"); addResultsGeneratedBy(footer); addDateGeneratedAt(millisTaken, footer); body.appendChild(footer); } }
public boolean hasJavaScriptDeclaration(String cssFilename) { Element head = getHeadElement(); for (Element script : head.getChildElements("script")) { String type = script.getAttributeValue("type"); String src = script.getAttributeValue("src"); if ("text/javascript".equals(type) && cssFilename.equals(src)) { return true; } } return false; }
private Element stackTraceTogglingButton() { return new Element("input") .addStyleClass("stackTraceButton") .setId("stackTraceButton" + buttonId) .addAttribute("type", "button") .addAttribute("onclick", "javascript:toggleStackTrace('" + buttonId + "')") .addAttribute("value", "View Stack"); }
@Test public void canMoveChildrenToAnotherElement() throws Exception { Element fred = new Element("fred"); fred.appendChild(new Element("child1")); Element child2 = new Element("child2"); fred.appendChild(child2); child2.appendChild(new Element("grandchild")); assertEquals("<fred><child1 /><child2><grandchild /></child2></fred>", fred.toXML()); Element barney = new Element("barney"); fred.moveChildrenTo(barney); assertEquals("<fred />", fred.toXML()); assertEquals("<barney><child1 /><child2><grandchild /></child2></barney>", barney.toXML()); }
protected Result getBreadcrumbsFor(String resourceName) throws Exception { Element[] spanElements = testRig .process(new Resource(resourceName)) .getRootElement() .getDescendantElements("span"); Result result = new Result(); for (Element span : spanElements) { if ("breadcrumbs".equals(span.getAttributeValue("class"))) { result.html = span.toXML(); result.text = span.getText(); } } return result; }
private Element createBreadcrumbElement(Resource documentResource, Resource indexPageResource, SpecificationConverter specificationConverter) throws IOException { String breadcrumbWording = getBreadcrumbWordingForResource(indexPageResource, specificationConverter); Element a = new Element("a"); Resource indexPageAsHtmlResource = new Resource(indexPageResource.getPath().replaceFirst("\\..*$", "\\.html")); a.addAttribute("href", documentResource.getRelativePath(indexPageAsHtmlResource)); a.appendText(breadcrumbWording); return a; }
public Row addDetailRow() { Element rowElement = new Element("tr"); Element tbody = tableElement.getFirstChildElement("tbody"); if (tbody != null) { tbody.appendChild(rowElement); } else { tableElement.appendChild(rowElement); } for (int i = 0; i < getColumnCount(); i++) { rowElement.appendChild(new Element("td")); } return new Row(rowElement); }
@Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'echo' is not supported"); Object result = evaluator.evaluate(commandCall.getExpression()); Element element = commandCall.getElement(); if (result != null) { element.appendText(result.toString()); } else { Element child = new Element("em"); child.appendText("null"); element.appendChild(child); } } }
public void beforeParsing(Document document) { Element rootElement = new Element(document.getRootElement()); String newValue = text; String existingValue = rootElement.getAttributeValue(FAKE_EXTENSION_ATTR_NAME); if (existingValue != null) { newValue = existingValue + ", " + newValue; } rootElement.addAttribute(FAKE_EXTENSION_ATTR_NAME, newValue); } }
public boolean isCssIncluded(String expectedResource) { Element[] styles = result.getRootElement().getFirstChildElement("head").getChildElements("style"); for (Element style : styles) { if (style.getText().contains("Here is a CSS file")) { return true; } } return false; }