cat.inspiracio.html.HTMLTableElementImp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of html-parser Show documentation
Show all versions of html-parser Show documentation
HTML-parser provides a parser for HTML 5 that produces
HTML 5 document object model.
It aims to be a Java-implementation of
http://www.w3.org/TR/html5/.
It is for use in the server. It does not implement features
that are relevant in the client, like event handling.
It is for use from javascript, via Java's scripting library.
The newest version!
/*
Copyright 2015 Alexander Bunkenburg
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cat.inspiracio.html;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import cat.inspiracio.dom.HTMLCollection;
import cat.inspiracio.dom.HTMLCollectionImp;
import cat.inspiracio.dom.HierarchyRequestError;
import cat.inspiracio.dom.IndexSizeError;
class HTMLTableElementImp extends HTMLElementImp implements HTMLTableElement {
private static final long serialVersionUID = -3013705892481191802L;
HTMLTableElementImp(HTMLDocumentImp owner){super(owner, "table");}
@Override public HTMLTableElementImp cloneNode(boolean deep){
return (HTMLTableElementImp)super.cloneNode(deep);
}
// methods ----------------------------------------------
@Override public HTMLTableCaptionElement getCaption(){
return (HTMLTableCaptionElement)getElementByTagName("caption");
}
@Override public synchronized void setCaption(HTMLTableCaptionElement caption){
if(caption==null)throw new HierarchyRequestError();
deleteCaption();
prepend(caption);//caption should be first child
}
@Override public synchronized HTMLTableCaptionElement createCaption(){
HTMLTableCaptionElement caption=getCaption();
if(caption!=null)return caption;
caption=createElement(HTMLTableCaptionElement.class);
prepend(caption);//caption should be first child
return caption;
}
@Override public synchronized void deleteCaption(){
HTMLTableCaptionElement caption=getCaption();
if(caption!=null)removeChild(caption);
}
@Override public HTMLTableSectionElement getTHead(){
return (HTMLTableSectionElement)getElementByTagName("thead");
}
@Override public synchronized void setTHead(HTMLTableSectionElement head){
if(head==null)throw new HierarchyRequestError();
deleteTHead();
insertHead(head);
}
@Override public synchronized HTMLTableSectionElement createTHead(){
HTMLTableSectionElement head=getTHead();
if(head!=null)return head;
head=createElement(HTMLTableHeadElement.class);
insertHead(head);
return head;
}
@Override public synchronized void deleteTHead(){
HTMLTableSectionElement head=getTHead();
if(head!=null)removeChild(head);
}
/** Inserts a head into the right place,
* assuming the table has no head. */
private void insertHead(HTMLTableSectionElement thead){
appendChild(thead);//This is not always the right place.
}
@Override public HTMLTableSectionElement getTFoot() {
return (HTMLTableSectionElement)getElementByTagName("tfoot");
}
@Override public synchronized void setTFoot(HTMLTableSectionElement foot){
if(foot==null)throw new HierarchyRequestError();
deleteTFoot();
insertFoot(foot);
}
@Override public synchronized HTMLTableSectionElement createTFoot(){
HTMLTableSectionElement foot=getTFoot();
if(foot!=null)return foot;
foot=createElement(HTMLTableFootElement.class);
insertFoot(foot);
return foot;
}
@Override public synchronized void deleteTFoot(){
HTMLTableSectionElement foot=getTFoot();
if(foot!=null)removeChild(foot);
}
/** Insert a foot into the table.
* assuming that it has none. */
private void insertFoot(HTMLTableSectionElement foot){
appendChild(foot);//Not really the right place.
}
@Override public HTMLCollection getTBodies(){
HTMLCollectionImpbodies=new HTMLCollectionImp<>();
NodeList nodes=getElementsByTagName("tbody");
for(int i=0; i getRows(){
HTMLCollectionImprows=new HTMLCollectionImp<>();
NodeList nodes=getElementsByTagName("tr");
for(int i=0; i bodies=getTBodies();
if(bodies.getLength()==0)
body=createTBody();
else
body=bodies.item(0);
HTMLCollection rows=body.getRows();
if(index<-1 || rows.getLength() rows=getRows();
int length=rows.getLength();
if(index==-1) index=length-1;//last one
if(index<=0 || length-1
© 2015 - 2025 Weber Informatics LLC | Privacy Policy