Last active
January 31, 2018 15:46
-
-
Save webfirmframework/e33d68868cbd43b9d9fd3542e6bde103 to your computer and use it in GitHub Desktop.
Usage of static methods in TagRepository class. It doesn't contain all of the methods usage. It will be updated later.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Initial html.toHtmlString | |
<html> | |
<head> | |
<title>some title</title> | |
</head> | |
<body id="one"> | |
<span></span> | |
<br/> | |
<br/> | |
<span></span> | |
<div></div> | |
<div> | |
<div> | |
<div></div> | |
</div> | |
</div> | |
<div></div> | |
</body> | |
</html> | |
------------------------------------------------- html.toHtmlString after title modified | |
<html> | |
<head> | |
<title>Title changed</title> | |
</head> | |
<body id="one"> | |
<span></span> | |
<br/> | |
<br/> | |
<span></span> | |
<div></div> | |
<div> | |
<div> | |
<div></div> | |
</div> | |
</div> | |
<div></div> | |
</body> | |
</html> | |
------------------------------------------------- html.toHtmlString after all spans modified | |
<html> | |
<head> | |
<title>Title changed</title> | |
</head> | |
<body id="one"> | |
<span>span 1</span> | |
<br/> | |
<br/> | |
<span>span 2</span> | |
<div></div> | |
<div> | |
<div> | |
<div></div> | |
</div> | |
</div> | |
<div></div> | |
</body> | |
</html> | |
------------------------------------------------- body.toHtmlString | |
<body id="one"> | |
<span>span 1</span> | |
<br/> | |
<br/> | |
<span>span 2</span> | |
<div></div> | |
<div> | |
<div> | |
<div></div> | |
</div> | |
</div> | |
<div></div> | |
</body> | |
------------------------------------------------- bodyAttr.toHtmlString id="one" ------------------------------------------------- body.getRootTag().toHtmlString which equal to html.toHtmlString because the rootTag is html object here. | |
<html> | |
<head> | |
<title>Title changed</title> | |
</head> | |
<body id="one"> | |
<span>span 1</span> | |
<br/> | |
<br/> | |
<span>span 2</span> | |
<div></div> | |
<div> | |
<div> | |
<div></div> | |
</div> | |
</div> | |
<div></div> | |
</body> | |
</html> | |
------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collection; | |
import com.webfirmframework.wffweb.tag.html.Body; | |
import com.webfirmframework.wffweb.tag.html.Br; | |
import com.webfirmframework.wffweb.tag.html.Html; | |
import com.webfirmframework.wffweb.tag.html.TagNameConstants; | |
import com.webfirmframework.wffweb.tag.html.TitleTag; | |
import com.webfirmframework.wffweb.tag.html.attribute.core.AbstractAttribute; | |
import com.webfirmframework.wffweb.tag.html.attribute.global.Id; | |
import com.webfirmframework.wffweb.tag.html.metainfo.Head; | |
import com.webfirmframework.wffweb.tag.html.stylesandsemantics.Div; | |
import com.webfirmframework.wffweb.tag.html.stylesandsemantics.Span; | |
import com.webfirmframework.wffweb.tag.htmlwff.NoTag; | |
@SuppressWarnings("serial") | |
public class TagRepositoryStaticMethodsUsage { | |
public static void main(String[] args) { | |
Html html = new Html(null) {{ | |
new Head(this) {{ | |
new TitleTag(this) {{ | |
new NoTag(this, "some title"); | |
}}; | |
}}; | |
new Body(this, new Id("one")) {{ | |
new Span(this); | |
new Br(this); | |
new Br(this); | |
new Span(this); | |
new Div(this); | |
new Div(this) {{ | |
new Div(this) {{ | |
new Div(this); | |
}}; | |
}}; | |
new Div(this); | |
}}; | |
}}; | |
System.out.println("Initial html.toHtmlString"); | |
System.out.println(html.toHtmlString()); | |
System.out.println("-------------------------------------------------"); | |
TitleTag titleTag = TagRepository.findOneTagAssignableToTag(TitleTag.class, html); | |
titleTag.addInnerHtml(new NoTag(null, "Title changed")); | |
System.out.println("html.toHtmlString after title modified"); | |
System.out.println(html.toHtmlString()); | |
System.out.println("-------------------------------------------------"); | |
Collection<Span> spans = TagRepository.findTagsAssignableToTag(Span.class, html); | |
int count = 0; | |
for (Span span : spans) { | |
count++; | |
span.addInnerHtml(new NoTag(null, "span " + count)); | |
} | |
System.out.println("html.toHtmlString after all spans modified"); | |
System.out.println(html.toHtmlString()); | |
System.out.println("-------------------------------------------------"); | |
Body body = (Body) TagRepository.findTagById("one", html); | |
System.out.println("body.toHtmlString"); | |
System.out.println(body.toHtmlString()); | |
System.out.println("-------------------------------------------------"); | |
Collection<AbstractAttribute> attributesOfBody = TagRepository.findAttributesByTagName(TagNameConstants.BODY, html); | |
for (AbstractAttribute bodyAttr : attributesOfBody) { | |
System.out.println("bodyAttr.toHtmlString"); | |
System.out.println(bodyAttr.toHtmlString()); | |
} | |
System.out.println("-------------------------------------------------"); | |
//body.getRootTag() == html | |
System.out.println("body.getRootTag().toHtmlString which equal to html.toHtmlString because the rootTag is html object here."); | |
System.out.println(body.getRootTag().toHtmlString()); | |
System.out.println("-------------------------------------------------"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Developers guide to get started
Convert HTML5 to webfirmframework Java Code