Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2012, Emanuel Rabina (
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
import static;
import static*;
Allows for greater control of the resulting <title> element by specifying a pattern with some special tokens. This can be used to extend the decorator's title with the content's one, instead of simply overriding it.

Emanuel Rabina
	private static final Logger logger = LoggerFactory.getLogger(TitlePatternProcessor.class);
	private static final String PARAM_TITLE_DECORATOR = "$DECORATOR_TITLE";
	private static final String PARAM_TITLE_CONTENT   = "$CONTENT_TITLE";
	public static final String PROCESSOR_NAME_TITLEPATTERN      = "title-pattern";
	public static final String DECORATOR_TITLE = "title-pattern::decorator-title";
	public static final String CONTENT_TITLE   = "title-pattern::content-title";

Constructor, sets this processor to work on the 'title-pattern' attribute.

	public int getPrecedence() {
		return 1;

	protected ProcessorResult processAttribute(Arguments argumentsElement elementString attributeName) {
		// Ensure this attribute is only on the <title> element
			.error("layout:title-pattern attribute should only appear in a <title> element");
			throw new IllegalArgumentException("layout:title-pattern attribute should only appear in a <title> element");
		// Replace the <title> text with the expanded title pattern
		String titlepattern   = element.getAttributeValue(attributeName);
		String decoratortitle = (String)arguments.getLocalVariable();
		String contenttitle   = (String)arguments.getLocalVariable();
		element.addChild(new Text(titlepattern
				.replace(decoratortitle != null ? decoratortitle : "")
				.replace(,   contenttitle   != null ? contenttitle   : "")));
New to GrepCode? Check out our FAQ X