Example usage for org.apache.wicket.markup.parser AbstractMarkupFilter AbstractMarkupFilter

List of usage examples for org.apache.wicket.markup.parser AbstractMarkupFilter AbstractMarkupFilter

Introduction

In this page you can find the example usage for org.apache.wicket.markup.parser AbstractMarkupFilter AbstractMarkupFilter.

Prototype

public AbstractMarkupFilter() 

Source Link

Document

Construct.

Usage

From source file:com.userweave.application.UserWeaveApplication.java

License:Open Source License

@Override
public void init() {
    super.init();

    getComponentInstantiationListeners().add(new SpringComponentInjector(this));

    setupAuthorization();//from  w  w w.  j a va  2  s  . c o m

    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);
}