private ContentElement parseContentElement(SpanManager sm,
			ContentElementParsingParameters cepp, LinkedList<Span> lineSpans,
			ContentElement result)
	{

		List<Link> localLinks = new ArrayList<Link>();
		List<Template> localTemplates = new ArrayList<Template>();

		List<Span> boldSpans = new ArrayList<Span>();
		List<Span> italicSpans = new ArrayList<Span>();
		sm.manageList(boldSpans);
		sm.manageList(italicSpans);

		List<Span> managedSpans = new ArrayList<Span>();
		sm.manageList(managedSpans);

		Span contentElementRange = new Span(lineSpans.getFirst().getStart(),
				lineSpans.getLast().getEnd()).trim(sm);
		managedSpans.add(contentElementRange);

		// set the SrcSpan
		if (calculateSrcSpans)
		{
			result.setSrcSpan(new SrcSpan(sm.getSrcPos(contentElementRange
					.getStart()), sm.getSrcPos(contentElementRange.getEnd())));
		}

		sm.manageList(lineSpans);
		while (!lineSpans.isEmpty())
		{
			Span line = lineSpans.getFirst();

			parseBoldAndItalicSpans(sm, line, boldSpans, italicSpans);

			// External links
			parseExternalLinks(sm, line, "http://", managedSpans, localLinks,
					result);
			parseExternalLinks(sm, line, "https://", managedSpans, localLinks,
					result);
			parseExternalLinks(sm, line, "ftp://", managedSpans, localLinks,
					result);
			parseExternalLinks(sm, line, "mailto:", managedSpans, localLinks,
					result);

			// end of linewhise opperations
			lineSpans.removeFirst();
		}
		sm.removeManagedList(lineSpans);

		// Links
		int i;
		i = 0;
		while (i < cepp.linkSpans.size())
		{
			if (contentElementRange.hits(cepp.linkSpans.get(i)))
			{
				Span linkSpan = cepp.linkSpans.remove(i);
				managedSpans.add(linkSpan);
				Link l = cepp.links.remove(i).setHomeElement(result);
				localLinks.add(l);
				if (!showImageText && l.getType() == Link.type.IMAGE)
				{
					// deletes the Image Text from the ContentElement Text.
					sm.delete(linkSpan);
				}
			}
			else
			{
				i++;
			}
		}

		// Templates
		i = 0;
		while (i < cepp.templateSpans.size())
		{
			Span ts = cepp.templateSpans.get(i);
			if (contentElementRange.hits(ts))
			{
				ResolvedTemplate rt = cepp.templates.remove(i);

				if (rt.getPostParseReplacement() != null)
				{
					sm.replace(ts, rt.getPostParseReplacement());
				}
				cepp.templateSpans.remove(i);

				Object parsedObject = rt.getParsedObject();
				if (parsedObject != null)
				{
					managedSpans.add(ts);

					Class parsedObjectClass = parsedObject.getClass();
					if (parsedObjectClass == Template.class)
					{
						localTemplates.add((Template) parsedObject);
					}
					else if (parsedObjectClass == Link.class)
					{
						localLinks.add(((Link) parsedObject)
								.setHomeElement(result));
					}
					else
					{
						localTemplates.add(rt.getTemplate());
					}
				}
			}
			else
			{
				i++;
			}
		}

		// HTML/XML Tags
		i = 0;
		List<Span> tags = new ArrayList<Span>();
		while (i < cepp.tagSpans.size())
		{
			Span s = cepp.tagSpans.get(i);
			if (contentElementRange.hits(s))
			{
				cepp.tagSpans.remove(i);
				if (deleteTags)
				{
					sm.delete(s);
				}
				else
				{
					tags.add(s);
					managedSpans.add(s);
				}
			}
			else
			{
				i++;
			}
		}

		// noWiki
		i = 0;
		List<Span> localNoWikiSpans = new ArrayList<Span>();
		while (i < cepp.noWikiSpans.size())
		{
			Span s = cepp.noWikiSpans.get(i);
			if (contentElementRange.hits(s))
			{
				cepp.noWikiSpans.remove(i);
				sm.replace(s, cepp.noWikiStrings.remove(i));
				localNoWikiSpans.add(s);
				managedSpans.add(s);
			}
			else
			{
				i++;
			}
		}

		// MATH Tags
		i = 0;
		List<Span> mathSpans = new ArrayList<Span>();
		while (i < cepp.mathSpans.size())
		{
			Span s = cepp.mathSpans.get(i);
			if (contentElementRange.hits(s))
			{
				cepp.mathSpans.remove(i);

				if (showMathTagContent)
				{
					mathSpans.add(s);
					managedSpans.add(s);
					sm.replace(s, cepp.mathStrings.remove(i));
				}
				else
				{
					sm.delete(s);
				}
			}
			else
			{
				i++;
			}
		}

		result.setText(sm.substring(contentElementRange));

		// managed spans must be removed here and not earlier, because every
		// change in the SpanManager affects the Spans!
		sm.removeManagedList(boldSpans);
		sm.removeManagedList(italicSpans);
		sm.removeManagedList(managedSpans);

		// contentElementRange ist auch noch in managedSpans !!! deswegen:
		final int adjust = -contentElementRange.getStart();
		for (Span s : boldSpans)
		{
			s.adjust(adjust);
		}
		for (Span s : italicSpans)
		{
			s.adjust(adjust);
		}
		for (Span s : managedSpans)
		{
			s.adjust(adjust);
		}

		result.setFormatSpans(FormatType.BOLD, boldSpans);
		result.setFormatSpans(FormatType.ITALIC, italicSpans);
		result.setFormatSpans(FormatType.TAG, tags);
		result.setFormatSpans(FormatType.MATH, mathSpans);
		result.setFormatSpans(FormatType.NOWIKI, localNoWikiSpans);

		result.setLinks(sortLinks(localLinks));
		result.setTemplates(sortTemplates(localTemplates));

		return result;
	}
private ContentElement parseContentElement ( SpanManager sm , ContentElementParsingParameters cepp , LinkedList < Span > lineSpans , ContentElement result ) { List < Link > localLinks = new ArrayList < Link > ( ) ; List < Template > localTemplates = new ArrayList < Template > ( ) ; List < Span > boldSpans = new ArrayList < Span > ( ) ; List < Span > italicSpans = new ArrayList < Span > ( ) ; sm . manageList ( boldSpans ) ; sm . manageList ( italicSpans ) ; List < Span > managedSpans = new ArrayList < Span > ( ) ; sm . manageList ( managedSpans ) ; Span contentElementRange = new Span ( lineSpans . getFirst ( ) . getStart ( ) , lineSpans . getLast ( ) . getEnd ( ) ) . trim ( sm ) ; managedSpans . add ( contentElementRange ) ; if ( calculateSrcSpans ) { result . setSrcSpan ( new SrcSpan ( sm . getSrcPos ( contentElementRange . getStart ( ) ) , sm . getSrcPos ( contentElementRange . getEnd ( ) ) ) ) ; } sm . manageList ( lineSpans ) ; while ( ! lineSpans . isEmpty ( ) ) { Span line = lineSpans . getFirst ( ) ; parseBoldAndItalicSpans ( sm , line , boldSpans , italicSpans ) ; parseExternalLinks ( sm , line , "http://" , managedSpans , localLinks , result ) ; parseExternalLinks ( sm , line , "https://" , managedSpans , localLinks , result ) ; parseExternalLinks ( sm , line , "ftp://" , managedSpans , localLinks , result ) ; parseExternalLinks ( sm , line , "mailto:" , managedSpans , localLinks , result ) ; lineSpans . removeFirst ( ) ; } sm . removeManagedList ( lineSpans ) ; int i ; i = 0 ; while ( i < cepp . linkSpans . size ( ) ) { if ( contentElementRange . hits ( cepp . linkSpans . get ( i ) ) ) { Span linkSpan = cepp . linkSpans . remove ( i ) ; managedSpans . add ( linkSpan ) ; Link l = cepp . links . remove ( i ) . setHomeElement ( result ) ; localLinks . add ( l ) ; if ( ! showImageText && l . getType ( ) == Link . type . IMAGE ) { sm . delete ( linkSpan ) ; } } else { i ++ ; } } i = 0 ; while ( i < cepp . templateSpans . size ( ) ) { Span ts = cepp . templateSpans . get ( i ) ; if ( contentElementRange . hits ( ts ) ) { ResolvedTemplate rt = cepp . templates . remove ( i ) ; if ( rt . getPostParseReplacement ( ) != null ) { sm . replace ( ts , rt . getPostParseReplacement ( ) ) ; } cepp . templateSpans . remove ( i ) ; Object parsedObject = rt . getParsedObject ( ) ; if ( parsedObject != null ) { managedSpans . add ( ts ) ; Class parsedObjectClass = parsedObject . getClass ( ) ; if ( parsedObjectClass == Template . class ) { localTemplates . add ( ( Template ) parsedObject ) ; } else if ( parsedObjectClass == Link . class ) { localLinks . add ( ( ( Link ) parsedObject ) . setHomeElement ( result ) ) ; } else { localTemplates . add ( rt . getTemplate ( ) ) ; } } } else { i ++ ; } } i = 0 ; List < Span > tags = new ArrayList < Span > ( ) ; while ( i < cepp . tagSpans . size ( ) ) { Span s = cepp . tagSpans . get ( i ) ; if ( contentElementRange . hits ( s ) ) { cepp . tagSpans . remove ( i ) ; if ( deleteTags ) { sm . delete ( s ) ; } else { tags . add ( s ) ; managedSpans . add ( s ) ; } } else { i ++ ; } } i = 0 ; List < Span > localNoWikiSpans = new ArrayList < Span > ( ) ; while ( i < cepp . noWikiSpans . size ( ) ) { Span s = cepp . noWikiSpans . get ( i ) ; if ( contentElementRange . hits ( s ) ) { cepp . noWikiSpans . remove ( i ) ; sm . replace ( s , cepp . noWikiStrings . remove ( i ) ) ; localNoWikiSpans . add ( s ) ; managedSpans . add ( s ) ; } else { i ++ ; } } i = 0 ; List < Span > mathSpans = new ArrayList < Span > ( ) ; while ( i < cepp . mathSpans . size ( ) ) { Span s = cepp . mathSpans . get ( i ) ; if ( contentElementRange . hits ( s ) ) { cepp . mathSpans . remove ( i ) ; if ( showMathTagContent ) { mathSpans . add ( s ) ; managedSpans . add ( s ) ; sm . replace ( s , cepp . mathStrings . remove ( i ) ) ; } else { sm . delete ( s ) ; } } else { i ++ ; } } result . setText ( sm . substring ( contentElementRange ) ) ; sm . removeManagedList ( boldSpans ) ; sm . removeManagedList ( italicSpans ) ; sm . removeManagedList ( managedSpans ) ; final int adjust = - contentElementRange . getStart ( ) ; for ( Span s : boldSpans ) { s . adjust ( adjust ) ; } for ( Span s : italicSpans ) { s . adjust ( adjust ) ; } for ( Span s : managedSpans ) { s . adjust ( adjust ) ; } result . setFormatSpans ( FormatType . BOLD , boldSpans ) ; result . setFormatSpans ( FormatType . ITALIC , italicSpans ) ; result . setFormatSpans ( FormatType . TAG , tags ) ; result . setFormatSpans ( FormatType . MATH , mathSpans ) ; result . setFormatSpans ( FormatType . NOWIKI , localNoWikiSpans ) ; result . setLinks ( sortLinks ( localLinks ) ) ; result . setTemplates ( sortTemplates ( localTemplates ) ) ; return result ; }
Building a ContentElement, this funciton is calles by all the other
parseContentElement(..) functions