use of org.apache.wicket.markup.MarkupResourceStream in project wicket by apache.
the class MarkupUtil method isMarkupHtml5Compliant.
/**
* @param container
* @return True if the Page and all it's Panels, Borders etc. have HTML5 compliant markup. HTML5
* markup is identified by <DOCTYPE html>
*/
public static boolean isMarkupHtml5Compliant(final MarkupContainer container) {
Args.notNull(container, "container");
Page page = container.getPage();
final boolean[] rtn = new boolean[] { true };
page.visitChildren(MarkupContainer.class, new IVisitor<MarkupContainer, Void>() {
@Override
public void component(final MarkupContainer comp, final IVisit<Void> visit) {
IMarkupFragment associatedMarkup = comp.getAssociatedMarkup();
if (associatedMarkup != null) {
MarkupResourceStream rs = associatedMarkup.getMarkupResourceStream();
if (rs.isHtml5() == false) {
rtn[0] = false;
visit.stop();
}
}
}
});
return rtn[0];
}
use of org.apache.wicket.markup.MarkupResourceStream in project wicket by apache.
the class BorderBehavior method findMarkupStream.
/**
* @param owner
* @return markup stream
*/
private MarkupStream findMarkupStream(final Component owner) {
final MarkupType markupType = getMarkupType(owner);
if (markupType == null) {
return null;
}
// TODO we need to expose this functionality for any class not just for
// markupcontainers in markupcache so we don't have to replicate this
// logic here
// Get locator to search for the resource
final IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();
final String style = owner.getStyle();
final String variation = owner.getVariation();
final Locale locale = owner.getLocale();
MarkupResourceStream markupResourceStream = null;
Class<?> containerClass = getClass();
while (!(containerClass.equals(BorderBehavior.class))) {
String path = containerClass.getName().replace('.', '/');
IResourceStream resourceStream = locator.locate(containerClass, path, style, variation, locale, markupType.getExtension(), false);
// Did we find it already?
if (resourceStream != null) {
ContainerInfo ci = new ContainerInfo(containerClass, locale, style, variation, markupType);
markupResourceStream = new MarkupResourceStream(resourceStream, ci, containerClass);
break;
}
// Walk up the class hierarchy one level, if markup has not
// yet been found
containerClass = containerClass.getSuperclass();
}
if (markupResourceStream == null) {
throw new WicketRuntimeException("Could not find markup for component border `" + getClass().getName() + "`");
}
try {
IMarkupFragment markup = MarkupFactory.get().newMarkupParser(markupResourceStream).parse();
return new MarkupStream(markup);
} catch (Exception e) {
throw new WicketRuntimeException("Could not parse markup from markup resource stream: " + markupResourceStream.toString(), e);
} finally {
try {
markupResourceStream.close();
} catch (IOException e) {
throw new WicketRuntimeException("Cannot close markup resource stream: " + markupResourceStream, e);
}
}
}
use of org.apache.wicket.markup.MarkupResourceStream in project wicket by apache.
the class BaseWicketTester method startComponentInPage.
/**
* Process a component. A web page will be automatically created with the {@code pageMarkup}
* provided. In case {@code pageMarkup} is null, the markup will be automatically created with
* {@link #createPageMarkup(String)}.
* <p>
* <strong>Note</strong>: the component id is set by the user. To reach any of its children use
* this id + their relative path to the component itself. For example if the started component
* has id <em>compId</em> and a Link child component component with id "link" then after
* starting the component you can click it with: <code>tester.clickLink("compId:link")</code>
* </p>
*
* @param <C>
* the type of the component
* @param component
* the component to be tested
* @param pageMarkup
* the markup for the Page that will be automatically created. May be {@code null}.
* @return The component processed
*/
public final <C extends Component> C startComponentInPage(final C component, IMarkupFragment pageMarkup) {
Args.notNull(component, "component");
// Create a page object and assign the markup
Page page = createPage();
if (page == null) {
fail("The automatically created page should not be null.");
}
// Automatically create the page markup if not provided
if (pageMarkup == null) {
String markup = createPageMarkup(component.getId());
if (markup == null) {
fail("The markup for the automatically created page should not be null.");
}
try {
// set a ContainerInfo to be able to use HtmlHeaderContainer so header contribution
// still work. WICKET-3700
ContainerInfo containerInfo = new ContainerInfo(page);
MarkupResourceStream markupResourceStream = new MarkupResourceStream(new StringResourceStream(markup), containerInfo, page.getClass());
MarkupParser markupParser = getApplication().getMarkupSettings().getMarkupFactory().newMarkupParser(markupResourceStream);
pageMarkup = markupParser.parse();
} catch (Exception e) {
String errorMessage = "Error while parsing the markup for the autogenerated page: " + e.getMessage();
log.error(errorMessage, e);
fail(errorMessage);
}
}
if (page instanceof StartComponentInPage) {
((StartComponentInPage) page).setPageMarkup(pageMarkup);
} else {
page.setMarkup(pageMarkup);
}
// Add the child component
page.add(component);
// Preserve 'componentInPage' because #startPage() needs to null-fy it
ComponentInPage oldComponentInPage = componentInPage;
// Process the page
startPage(page);
// Remember the "root" component processes and return it
if (oldComponentInPage != null) {
componentInPage = oldComponentInPage;
} else {
componentInPage = new ComponentInPage();
componentInPage.component = component;
}
return component;
}
use of org.apache.wicket.markup.MarkupResourceStream in project wicket by apache.
the class MergedMarkupTest method test1.
/**
* test1()
*/
@Test
public void test1() {
Page page = new SubPageWithoutMarkup();
Markup markup = page.getAssociatedMarkup();
MarkupResourceStream stream = markup.getMarkupResourceStream();
assertEquals("utf-8", stream.getEncoding());
assertEquals(MarkupParser.WICKET, stream.getWicketNamespace());
}
Aggregations