List of usage examples for org.apache.wicket.markup MarkupParser MarkupParser
public MarkupParser(final String markup)
From source file:com.lyndir.lhunath.snaplog.webapp.SnaplogApplication.java
License:Apache License
/** * {@inheritDoc}// w w w.j a va2s . co m */ @Override protected void init() { // LinkID setup. WebappConfig.setConfig(new SnaplogWebappConfig()); // Guice injector. Injector injector = GuiceContext.get(getServletContext()); addComponentInstantiationListener(new InjectionFlagCachingGuiceComponentInjector(this, injector)); addPreComponentOnBeforeRenderListener(injector.getInstance(AuthenticationListener.class)); addPreComponentOnBeforeRenderListener( new ComponentStateListener(new NewUserTabPanel.NewUserTabActivator())); // Application setup. getApplicationSettings().setPageExpiredErrorPage(PageExpiredErrorPage.class); getApplicationSettings().setAccessDeniedPage(AccessDeniedErrorPage.class); getApplicationSettings().setInternalErrorPage(InternalErrorPage.class); getExceptionSettings().setUnexpectedExceptionDisplay(IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE); // https://issues.apache.org/jira/browse/WICKET-2650 -- Consistently create body for short tags. getMarkupSettings().setMarkupParserFactory(new IMarkupParserFactory() { @Override public MarkupParser newMarkupParser(final MarkupResourceStream resource) { MarkupParser markupParser = new MarkupParser(resource); markupParser.appendMarkupFilter(new OpenCloseTagExpander()); return markupParser; } }); getMarkupSettings().setDefaultMarkupEncoding("UTF-8"); // Page mounting. mount(new HybridUrlCodingStrategy("main", LayoutPage.class)); }
From source file:com.userweave.application.UserWeaveApplication.java
License:Open Source License
@Override public void init() { super.init(); getComponentInstantiationListeners().add(new SpringComponentInjector(this)); setupAuthorization();// ww w. ja va 2s .c om mountPages(); mountResources(); getMarkupSettings().setStripWicketTags(true); setupErrorHandling(); setupProductionSettings(); setDefaultResourceLocale(LocalizationUtils.getDefaultLocale()); getMarkupSettings().setMarkupFactory(new MarkupFactory() { @Override public MarkupParser newMarkupParser(MarkupResourceStream resource) { MarkupParser markupParser = new MarkupParser(resource); markupParser.add(new AbstractMarkupFilter() { // @Override // public MarkupElement nextTag() throws ParseException { // // // Get the next tag. If null, no more tags are available // final ComponentTag tag = (ComponentTag)getParent().nextTag(); // if ( null == tag || null != tag.getId() ) // return tag; // // // Process open <html> tags // if( null != tag.getName() && tag.getName().equals( "html" ) && tag.isOpen()) // { // String language = UserWeaveSession.get().getLocale().getLanguage(); // tag.getAttributes().put("lang", language); // tag.getAttributes().put("xml:lang", language); // tag.setModified( true ); // } // // return tag; // } @Override protected MarkupElement onComponentTag(ComponentTag tag) throws ParseException { if (null == tag || null != tag.getId()) { return tag; } // Process open <html> tags if (null != tag.getName() && tag.getName().equals("html") && tag.isOpen()) { String language = UserWeaveSession.get().getLocale().getLanguage(); tag.getAttributes().put("lang", language); tag.getAttributes().put("xml:lang", language); tag.setModified(true); } return tag; } }); return markupParser; } }); /* * @see: migration guide to wicket 1.5 Request cycle * * Instead of overrride newRequestCycle, we have to create a factory, * that builds our custom RequestCycle. */ setRequestCycleProvider(new IRequestCycleProvider() { @Override public RequestCycle get(RequestCycleContext context) { return new UserWeaveWebRequestCycle(context); } }); /* * @see: https://cwiki.apache.org/WICKET/request-mapping.html * * newRequestCycleProcessor is obsolete, so we replace the * CryptedUrlWebRequestCodingStrategy with a CryptoMapper, */ // if(ENCRYPTION) // { // setRootRequestMapper(new CryptoMapper(getRootRequestMapper(), this)); // } // add custom listener for runtime exceptions. getRequestCycleListeners().add(new AbstractRequestCycleListener() { @Override public IRequestHandler onException(RequestCycle cycle, Exception ex) { if (ex instanceof RuntimeException) { ((UserWeaveWebRequestCycle) cycle).handleRuntimeException((RuntimeException) ex); } return null; } }); // disable caching strategy getResourceSettings().setCachingStrategy(NoOpResourceCachingStrategy.INSTANCE); }
From source file:org.opensingular.lib.wicket.util.bootstrap.layout.TemplatePanel.java
License:Apache License
@Override protected IMarkupSourcingStrategy newMarkupSourcingStrategy() { return new PanelMarkupSourcingStrategy(false) { @Override// w w w. j a v a 2 s .c o m public IMarkupFragment getMarkup(MarkupContainer parent, Component child) { // corrige o problema de encoding StringResourceStream stringResourceStream = new StringResourceStream( "<wicket:panel>" + getTemplateFunction().apply(TemplatePanel.this) + "</wicket:panel>", "text/html"); stringResourceStream.setCharset(Charset.forName( Optional.ofNullable(Application.get().getMarkupSettings().getDefaultMarkupEncoding()) .orElse(StandardCharsets.UTF_8.name()))); MarkupParser markupParser = new MarkupParser(new MarkupResourceStream(stringResourceStream)); markupParser.setWicketNamespace(MarkupParser.WICKET); Markup markup; try { markup = markupParser.parse(); } catch (Exception e) { throw SingularUtil.propagate(e); } // If child == null, than return the markup fragment starting // with <wicket:panel> if (child == null) { return markup; } // Copiado da superclasse. buscando markup do child IMarkupFragment associatedMarkup = markup.find(child.getId()); if (associatedMarkup != null) { return associatedMarkup; } associatedMarkup = searchMarkupInTransparentResolvers(parent, parent.getMarkup(), child); if (associatedMarkup != null) { return associatedMarkup; } return findMarkupInAssociatedFileHeader(parent, child); } @Override public void onComponentTagBody(Component component, MarkupStream markupStream, ComponentTag openTag) { TemplatePanel.this.onBeforeComponentTagBody(markupStream, openTag); super.onComponentTagBody(component, markupStream, openTag); TemplatePanel.this.onAfterComponentTagBody(markupStream, openTag); } }; }
From source file:sf.wicklet.wicketext.test.TestMarkupParser01.java
License:Apache License
@Test public void test01() throws Exception { final String input = ResourceUtil.readString( new PackageResourceStream(getClass(), "sf/wicklet/wicketext/test/TestMarkupParser01Test01.html")); final MarkupParser parser = new MarkupParser(input); final IRootMarkup ret = parser.parse(); final MarkupStat stat = WicketExtrasUtil.dump(System.out, DEBUG, ret); assertEquals(17, stat.ctags);/*from ww w.j a v a2 s . c om*/ assertEquals(18, stat.rtags); assertEquals(0, stat.others); }
From source file:sf.wicklet.wicketext.wicket.core.test.MarkupParser01.java
License:Apache License
@Test public void test01() throws IOException, ResourceStreamNotFoundException { final String DATA = "/sf/wicklet/wicketext/wicket/core/test/MarkupParser01Test01.html"; final String content = FileUtil.getResourceAsString(DATA); new WicketTester(); final MarkupParser parser = new MarkupParser(content); final IMarkupFragment ret = parser.parse(); int components = 0; if (DEBUG) {// w w w . j a v a 2s . c om System.out.println("### Markup: " + ret.size()); } for (final IMarkupElement e : ret) { if (DEBUG) { System.out.println(e.getClass().getName() + ": " + e.toUserDebugString()); } if (e instanceof ComponentTag) { ++components; } } assertEquals(7, components); }