protected boolean shouldTransform()

in src/main/java/com/atlassian/uwc/converters/sharepoint/HeaderConverter.java [231:283]


	protected boolean shouldTransform(Element el) {
		//don't try to transform empty tags
		if (el.content().isEmpty()) return false;
		
		//no newlines unless they happen to come just after color tags
		String xml = toString(el.content());
		Matcher allowedNewlinesFinder = allowedNewlinesPattern.matcher(xml);
		
		//check for prior newline
		Element parent = el.getParent();
		boolean startsLine = true;
		boolean trumpsStartLine = false;
		if (parent != null) {
			int index = parent.content().indexOf(el);
			if (--index >=0) {
				Node sibling = (Node) parent.content().get(index);
				String siblingXml = sibling.asXML();
				String inline = "[*_+]|\\{color[^}]*\\}";
				String nlWillBeAdded = "<\\/[ou]l>";
				if (siblingXml.matches(inline)||
						siblingXml.endsWith(nlWillBeAdded)) { 
					if (--index < 0) {
						trumpsStartLine = true;
						startsLine = true;
					}
					else {
						Node previousSibling = (Node) parent.content().get(index);
						String previousXml = previousSibling.asXML();
						siblingXml = previousXml;
					}
				}
				if (!trumpsStartLine) {
					String regex = ".*[\n ]*\n[\n ]*" + //some pattern of newlines
							"[*_+]?" +					//opt bold, emph, or underline
							"(\\{color:[^}]*\\})?$";	//optional {color:xxx} tag
					startsLine = Pattern.matches(regex, siblingXml) ||
								 Pattern.matches(".*" + nlWillBeAdded + "$", siblingXml);
				}			}
		}
		
		//make sure it doesn't contain any more font tags with size attributes
		Pattern noFontTagsPattern = Pattern.compile("<font[^>]+size");
		Matcher noFontTagsFinder = noFontTagsPattern.matcher(xml);
		boolean noFontTags = !noFontTagsFinder.find();
		
		//disallow more panel tags
		boolean noPanelTags = !xml.contains("{panel");

		return allowedNewlinesFinder.find() &&
				startsLine &&
				noPanelTags &&
				noFontTags;
	}