private Element transformColors()

in src/main/java/com/atlassian/uwc/converters/sharepoint/ColorConverter.java [56:98]


	private Element transformColors(Element root) {
		//look through all elements for color or background color attribtues or css
		List<Attribute> atts = root.attributes();
		Color color = null;
		Background bg = null;
		for (int i = 0; i < atts.size(); i++) {
			Attribute att = atts.get(i);
			if (att.getName().equals("color")) { //look for color attributes
				color = getColor(att);
				root.remove(att);
				i--;
			}
			else if (att.getName().equals("style")) { 	//look for style attributes
				if (hasStyleColor(att))					//style attribute has color
					color = getStyleColor(att);
				if (hasStyleBackground(att)) 			//style attribtue has background-color
					bg = getStyleBackground(att);
				root.remove(att);
				i--;
			}
			if (color != null && bg != null) break;
		}
		if (color != null || bg != null ) { //we've identified color attributes. 
			//if the element has data that needs to be maintained, then don't remove the element
			if (shouldSaveElement(root.getName())) {
				transformContentAddChildTextNodes(color, bg, root);
			} 
			else { //otherwise remove the element
				//remove the element and add attribute to this as text child
				transformContentReplaceWithText(color, bg, root); 
			}
		}
		//look at children nodes
		List rootContent = root.content();
		for (int i = 0; i < rootContent.size(); i++) {
			Object node = rootContent.get(i); //could be Text or Element objects
			if (node instanceof Element) {
				Element nodeEl = (Element) node;
				transformColors(nodeEl);
			}
		}
		return root;
	}