Skip to content

Instantly share code, notes, and snippets.

@webfirmframework
Last active January 31, 2018 15:46
Show Gist options
  • Save webfirmframework/e33d68868cbd43b9d9fd3542e6bde103 to your computer and use it in GitHub Desktop.
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.
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>
-------------------------------------------------
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("-------------------------------------------------");
}
}
@webfirmframework
Copy link
Author

webfirmframework commented Jan 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment