libcobra-java-0.98.4.orig/ 0000755 0001750 0001750 00000000000 11134672336 015213 5 ustar twerner twerner libcobra-java-0.98.4.orig/lib/ 0000755 0001750 0001750 00000000000 11134672336 015761 5 ustar twerner twerner libcobra-java-0.98.4.orig/COBRA-README.txt 0000644 0001750 0001750 00000000331 10630211126 017514 0 ustar twerner twerner Please see http://html.xamjwg.org/cobra.jsp for
additional information on this toolkit.
See the LICENSE.txt file for Cobra licensing
and the COBRA-ACK.txt file for licensing
information on Cobra dependencies.
libcobra-java-0.98.4.orig/COBRA-ACK.txt 0000644 0001750 0001750 00000001662 10743401044 017172 0 ustar twerner twerner The following externals are used by this project:
* [http://www.mozilla.org/rhino/] Rhino - Javascript for Java (MPL/GPL)
We are using Rhino to process Javascript
embedded in HTML documents. Rhino binaries
(js.jar under the lib directory) are
redistributed unmodified. We use Rhino
1.6R5 which is released under a dual MPL/GPL
license. Note that the GPL license is
applicable in this case, as that is the
license that is compatible with the LGPL.
Users should observe the GPL license of
Rhino.
* [http://cssparser.sourceforge.net/] Cssparser (LGPL)
We use it to parse CSS code. We distribute its
source code (modified) with Cobra. It is also
available in CVS in module XAMJ_Project/cssparser.
* [http://w3c.org] W3C DOM Java Bindings (W3C Software Copyright Notice and License)
We implement these DOM interfaces. Source
redistributed unmodified. See package
org.w3c.dom.html2.
libcobra-java-0.98.4.orig/LICENSE.txt 0000644 0001750 0001750 00000063437 10603777472 017062 0 ustar twerner twerner GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Cobra is an HTML Toolkit for Java
Copyright (C) 2007 The XAMJ Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Website: http://xamjwg.org libcobra-java-0.98.4.orig/src/ 0000755 0001750 0001750 00000000000 11134672336 016002 5 ustar twerner twerner libcobra-java-0.98.4.orig/src/org/ 0000755 0001750 0001750 00000000000 10641432632 016564 5 ustar twerner twerner libcobra-java-0.98.4.orig/src/org/lobobrowser/ 0000755 0001750 0001750 00000000000 10641432704 021123 5 ustar twerner twerner libcobra-java-0.98.4.orig/src/org/lobobrowser/html/ 0000755 0001750 0001750 00000000000 11125630302 022057 5 ustar twerner twerner libcobra-java-0.98.4.orig/src/org/lobobrowser/html/AbstractHtmlRendererContext.java 0000644 0001750 0001750 00000010700 11126720504 030351 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The XAMJ Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html;
import java.awt.event.MouseEvent;
import java.net.URL;
import org.w3c.dom.html2.HTMLCollection;
import org.w3c.dom.html2.HTMLElement;
import org.w3c.dom.html2.HTMLLinkElement;
/**
* Abstract implementation of the {@link HtmlRendererContext} interface with
* blank methods, provided for developer convenience.
*/
public abstract class AbstractHtmlRendererContext implements HtmlRendererContext {
public void alert(String message) {
}
public void back() {
}
public void blur() {
}
public void close() {
}
public boolean confirm(String message) {
return false;
}
public BrowserFrame createBrowserFrame() {
return null;
}
public void focus() {
}
public String getDefaultStatus() {
return null;
}
public HTMLCollection getFrames() {
return null;
}
public HtmlObject getHtmlObject(HTMLElement element) {
return null;
}
public String getName() {
return null;
}
public HtmlRendererContext getOpener() {
return null;
}
public HtmlRendererContext getParent() {
return null;
}
public String getStatus() {
return null;
}
public HtmlRendererContext getTop() {
return null;
}
public UserAgentContext getUserAgentContext() {
return null;
}
/**
* Returns false unless overridden.
*/
public boolean isClosed() {
return false;
}
/**
* Returns true unless overridden.
*/
public boolean isImageLoadingEnabled() {
return true;
}
/**
* Returns false unless overridden.
*/
public boolean isVisitedLink(HTMLLinkElement link) {
return false;
}
public void linkClicked(HTMLElement linkNode, URL url, String target) {
}
public void navigate(URL url, String target) {
}
/**
* Returns true unless overridden.
*/
public boolean onContextMenu(HTMLElement element, MouseEvent event) {
return true;
}
public void onMouseOut(HTMLElement element, MouseEvent event) {
}
public void onMouseOver(HTMLElement element, MouseEvent event) {
}
public HtmlRendererContext open(String absoluteUrl, String windowName,
String windowFeatures, boolean replace) {
return null;
}
public HtmlRendererContext open(URL url, String windowName,
String windowFeatures, boolean replace) {
return null;
}
public String prompt(String message, String inputDefault) {
return null;
}
public void reload() {
}
public void scroll(int x, int y) {
}
public void setDefaultStatus(String value) {
}
public void setOpener(HtmlRendererContext opener) {
}
public void setStatus(String message) {
}
public void submitForm(String method, URL action, String target,
String enctype, FormInput[] formInputs) {
}
/**
* Returns true unless overridden.
*/
public boolean onDoubleClick(HTMLElement element, MouseEvent event) {
return true;
}
/**
* Returns true unless overridden.
*/
public boolean onMouseClick(HTMLElement element, MouseEvent event) {
return true;
}
public void scrollBy(int x, int y) {
}
public void resizeBy(int byWidth, int byHeight) {
}
public void resizeTo(int width, int height) {
}
public void forward() {
}
public String getCurrentURL() {
return null;
}
public int getHistoryLength() {
return 0;
}
public String getNextURL() {
return null;
}
public String getPreviousURL() {
return null;
}
public void goToHistoryURL(String url) {
}
public void moveInHistory(int offset) {
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/BrowserFrame.java 0000644 0001750 0001750 00000004447 11134671040 025335 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 29, 2006
*/
package org.lobobrowser.html;
import java.awt.Component;
import java.net.URL;
import org.w3c.dom.*;
/**
* The BrowserFrame
interface represents a browser frame.
* A simple implementation of this interface is
* provided in {@link org.lobobrowser.html.test.SimpleBrowserFrame}.
*/
public interface BrowserFrame {
/**
* Gets the component that renders the frame.
* This can be a {@link org.lobobrowser.html.gui.HtmlPanel}.
*/
public Component getComponent();
/**
* Loads a URL in the frame.
*/
public void loadURL(URL url);
/**
* Gets the content document.
*/
public Document getContentDocument();
/**
* Gets the {@link HtmlRendererContext} of the frame.
*/
public HtmlRendererContext getHtmlRendererContext();
/**
* Sets the default margin insets of the browser frame.
* @param insets The margin insets.
*/
public void setDefaultMarginInsets(java.awt.Insets insets);
/**
* Sets the default horizontal overflow of the browser frame.
* @param overflowX See constants in {@link org.lobobrowser.html.style.RenderState}.
*/
public void setDefaultOverflowX(int overflowX);
/**
* Sets the default vertical overflow of the browser frame.
* @param overflowY See constants in {@link org.lobobrowser.html.style.RenderState}.
*/
public void setDefaultOverflowY(int overflowY);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/FormInput.java 0000644 0001750 0001750 00000007222 10750307714 024663 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 15, 2006
*/
package org.lobobrowser.html;
/**
* The FormInput
class contains the state
* of an HTML form input item.
*/
public class FormInput {
//private final InputStream inputStream;
//private final String charset;
public static final FormInput[] EMPTY_ARRAY = new FormInput[0];
private final String name;
private final String textValue;
private final java.io.File fileValue;
/**
* Constructs a FormInput
* with a text value.
* @param name The name of the input.
* @param value The value of the input.
*/
public FormInput(String name, String value) {
super();
this.name = name;
this.textValue = value;
this.fileValue = null;
}
/**
* Constructs a FormInput
* with a file value.
* @param name The name of the input.
* @param value The value of the input.
*/
public FormInput(String name, java.io.File value) {
this.name = name;
this.textValue = null;
this.fileValue = value;
}
/**
* Gets the name of the input.
*/
public String getName() {
return this.name;
}
/**
* Returns true if the form input holds a text value.
*/
public boolean isText() {
return this.textValue != null;
}
/**
* Returns true if the form input holds a file value.
*/
public boolean isFile() {
return this.fileValue != null;
}
/**
* Gets the text value of the form input.
* If the form input does not hold a text value,
* this method should not be called.
* @see #isText()
*/
public String getTextValue() {
return this.textValue;
}
/**
* Gets the file value of the form input.
* If the form input does not hold a file
* value, this method should not be called.
* @see #isFile()
*/
public java.io.File getFileValue() {
return this.fileValue;
}
/**
* Always returns UTF-8.
* @deprecated The method is implemented only to provide some backward compatibility.
*/
public String getCharset() {
return "UTF-8";
}
/**
* Gets data as an input stream. The caller
* is responsible for closing the stream.
* @deprecated Call either {@link #getTextValue()} or {@link #getFileValue()} instead.
*/
public java.io.InputStream getInputStream() throws java.io.IOException {
if(this.isText()) {
return new java.io.ByteArrayInputStream(this.getTextValue().getBytes("UTF-8"));
}
else if(this.isFile()) {
return new java.io.FileInputStream(this.getFileValue());
}
else {
return null;
}
}
/**
* Shows a string representation of the FormInput
* that may be useful in debugging.
* @see #getTextValue()
*/
public String toString() {
return "FormInput[name=" + this.name + ",textValue=" + this.textValue + "]";
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/HtmlObject.java 0000644 0001750 0001750 00000001216 10641432374 024770 0 ustar twerner twerner package org.lobobrowser.html;
import java.awt.*;
/**
* This interface should be implemented to provide
* OBJECT, EMBED or APPLET functionality.
*/
public interface HtmlObject {
public Component getComponent();
public void suspend();
public void resume();
public void destroy();
/**
* Called as the object is layed out, either
* the first time it's layed out or whenever
* the DOM changes. This is where the object
* should reset its state based on element
* children or attributes and possibly change
* its preferred size if appropriate.
*/
public void reset(int availableWidth, int availableHeight);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/HtmlRendererContext.java 0000644 0001750 0001750 00000025076 11126720412 026677 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Aug 28, 2005
*/
package org.lobobrowser.html;
import java.net.URL;
import org.w3c.dom.html2.*;
/**
* The HtmlRendererContext
interface must be implemented
* in order to use the Cobra HTML renderer. An instance of this interface
* will be called back whenever the renderer needs to perform an action that
* it is not designed to know how to perform on its own, e.g. opening a browser window
* or a context menu. In many ways this
* interface parallers the Javascript Window
class (which
* in reality represents a browser frame, not a window).
*
* A simple implementation of this interface is provided in
* {@link org.lobobrowser.html.test.SimpleHtmlRendererContext SimpleHtmlRendererContext}.
* @see org.lobobrowser.html.gui.HtmlPanel#setDocument(org.w3c.dom.Document, HtmlRendererContext)
*/
public interface HtmlRendererContext {
/**
* Navigates to the location given. Implementations should
* retrieve the URL content, parse it and render it.
* @param url The destination URL.
* @param target Same as the target attribute in the HTML anchor tag, i.e. _top, _blank, etc.
*/
public void navigate(URL url, String target);
/**
* Performs a link click. Implementations should
* invoke {@link #navigate(URL, String)}.
* @param linkNode The HTML node that was clicked.
* @param url The destination URL.
* @param target Same as the target attribute in the HTML anchor tag, i.e. _top, _blank, etc.
*/
public void linkClicked(org.w3c.dom.html2.HTMLElement linkNode, URL url, String target);
/**
* Gets a collection of frames from the document
* currently in the context.
*/
public HTMLCollection getFrames();
/**
* Submits a HTML form. Note that when the the method is "GET", parameters
* are still expected to be part of formInputs
.
* @param method The request method, GET or POST.
* @param action The destination URL.
* @param target Same as the target attribute in the FORM tag, i.e. _blank, _top, etc.
* @param enctype The encoding type.
* @param formInputs An array of {@link org.lobobrowser.html.FormInput} instances.
*/
public void submitForm(String method, URL action, String target, String enctype, FormInput[] formInputs);
/**
* Creates a {@link org.lobobrowser.html.BrowserFrame} instance.
*/
public BrowserFrame createBrowserFrame();
/**
* Gets the user agent context.
*/
public UserAgentContext getUserAgentContext();
/**
* Gets a HtmlObject
instance that implements
* a OBJECT tag from HTML.
* @param element The DOM element for the object, which may
* either represent an OBJECT, EMBED or an APPLET tag.
* @return Implementations of this method must return null
* if they have any problems producing a HtmlObject
instance.
* This is particularly true of OBJECT tags, where inner HTML of
* the tag must be rendered if the OBJECT content cannot be handled.
*/
public HtmlObject getHtmlObject(org.w3c.dom.html2.HTMLElement element);
/**
* This method is called when a visual element is right-clicked.
* @param element The narrowest element enclosing the mouse location.
* @param event The mouse event.
* @return The method should return true to continue propagating the event,
* or false to stop propagating it.
*/
public boolean onContextMenu(org.w3c.dom.html2.HTMLElement element, java.awt.event.MouseEvent event);
/**
* This method is called when there's a mouse click on an element.
* @param element The narrowest element enclosing the mouse location.
* @param event The mouse event.
* @return The method should return true to continue propagating the event,
* or false to stop propagating it.
*/
public boolean onMouseClick(org.w3c.dom.html2.HTMLElement element, java.awt.event.MouseEvent event);
/**
* This method is called when there's a mouse double-click on an element.
* @param element The narrowest element enclosing the mouse location.
* @param event The mouse event.
* @return The method should return true to continue propagating the event,
* or false to stop propagating it.
*/
public boolean onDoubleClick(org.w3c.dom.html2.HTMLElement element, java.awt.event.MouseEvent event);
/**
* This method is called when the mouse first hovers over an element.
* @param element The element that the mouse has just entered.
* @param event The mouse event.
*/
public void onMouseOver(org.w3c.dom.html2.HTMLElement element, java.awt.event.MouseEvent event);
/**
* This method is called when the mouse no longer hovers a given element.
* @param element The element that the mouse has just exited.
* @param event The mouse event.
*/
public void onMouseOut(org.w3c.dom.html2.HTMLElement element, java.awt.event.MouseEvent event);
/**
* This method should return true if and only if image loading
* needs to be enabled.
*/
public boolean isImageLoadingEnabled();
//------ Methods useful for Window implementation:
/**
* Opens an alert dialog.
* @param message Message shown by the dialog.
*/
public void alert(String message);
/**
* Goes to the previous page in the browser's history.
*/
public void back();
/**
* Relinquishes focus.
*/
public void blur();
/**
* Closes the browser window, provided this
* is allowed for the current context.
*/
public void close();
/**
* Opens a confirmation dialog.
* @param message The message shown by the confirmation dialog.
* @return True if the user selects YES.
*/
public boolean confirm(String message);
/**
* Requests focus for the current window.
*/
public void focus();
/**
* Opens a separate browser window and renders a URL.
* @param absoluteUrl The URL to be rendered.
* @param windowName The name of the new window.
* @param windowFeatures The features of the new window (same as in Javascript open method).
* @param replace
* @return A new {@link org.lobobrowser.html.HtmlRendererContext} instance.
* @deprecated Use {@link #open(URL, String, String, boolean)} instead.
*/
public HtmlRendererContext open(String absoluteUrl, String windowName, String windowFeatures, boolean replace);
/**
* Opens a separate browser window and renders a URL.
* @param url The URL to be rendered.
* @param windowName The name of the new window.
* @param windowFeatures The features of the new window (same as in Javascript open method).
* @param replace
* @return A new {@link org.lobobrowser.html.HtmlRendererContext} instance.
*/
public HtmlRendererContext open(java.net.URL url, String windowName, String windowFeatures, boolean replace);
/**
* Shows a prompt dialog.
* @param message The message shown by the dialog.
* @param inputDefault The default input value.
* @return The user's input value.
*/
public String prompt(String message, String inputDefault);
/**
* Scrolls the client area.
* @param x Document's x coordinate.
* @param y Document's y coordinate.
*/
public void scroll(int x, int y);
/**
* Scrolls the client area.
* @param x Horizontal pixels to scroll.
* @param y Vertical pixels to scroll.
*/
public void scrollBy(int x, int y);
/**
* Resizes the window.
* @param width The new width.
* @param height The new height.
*/
public void resizeTo(int width, int height);
/**
* Resizes the window.
* @param byWidth The number of pixels to resize the width by.
* @param byHeight The number of pixels to resize the height by.
*/
public void resizeBy(int byWidth, int byHeight);
/**
* Gets a value indicating if the window is closed.
*/
public boolean isClosed();
public String getDefaultStatus();
public void setDefaultStatus(String value);
/**
* Gets the window name.
*/
public String getName();
/**
* Gets the parent of the frame/window in the current context.
*/
public HtmlRendererContext getParent();
/**
* Gets the opener of the frame/window in the current context.
*/
public HtmlRendererContext getOpener();
/**
* Sets the context that opened the current frame/window.
* @param opener A {@link org.lobobrowser.html.HtmlRendererContext}.
*/
public void setOpener(HtmlRendererContext opener);
/**
* Gets the window status text.
*/
public String getStatus();
/**
* Sets the window status text.
* @param message A string.
*/
public void setStatus(String message);
/**
* Gets the top-most browser frame/window.
*/
public HtmlRendererContext getTop();
/**
* It should return true if the link provided has been visited.
*/
public boolean isVisitedLink(HTMLLinkElement link);
/**
* Reloads the current document.
*/
public void reload();
/**
* Gets the number of pages in the history list.
*/
public int getHistoryLength();
/**
* Gets the current URL in history.
*/
public String getCurrentURL();
/**
* Gets the next URL in the history.
*/
public String getNextURL();
/**
* Gets the previous URL in the history.
*/
public String getPreviousURL();
/**
* Goes forward one page.
*/
public void forward();
/**
* Navigates the history according to the given offset.
* @param offset A positive or negative number. -1 is
* equivalent to {@link #back()}. +1 is
* equivalent to {@link #forward()}.
*/
public void moveInHistory(int offset);
/**
* Navigates to a URL in the history list.
*/
public void goToHistoryURL(String url);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/HttpRequest.java 0000644 0001750 0001750 00000013060 10771510712 025222 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Nov 13, 2005
*/
package org.lobobrowser.html;
import java.awt.Image;
import java.net.URL;
import org.w3c.dom.Document;
/**
* The HttpRequest
interface should
* be implemented to provide web request capabilities. It is
* used a similar manner to XMLHttpRequest
in
* Javascript (AJAX). Normally, a listener will be added
* by calling {@link #addReadyStateChangeListener(ReadyStateChangeListener)},
* the method {@link #open(String, URL, boolean, String, String) open}
* will be called, and finally, {@link #send(String)} will be called to
* complete the request.
* @see UserAgentContext#createHttpRequest()
*/
public interface HttpRequest {
/**
* The uninitialized request state.
*/
public static final int STATE_UNINITIALIZED = 0;
/**
* The loading request state. The open
method
* has been called, but a response has not been received yet.
*/
public static final int STATE_LOADING = 1;
/**
* The loaded request state. Headers and status are now available.
*/
public static final int STATE_LOADED = 2;
/**
* The interactive request state. Downloading response.
*/
public static final int STATE_INTERACTIVE = 3;
/**
* The complete request state. All operations are finished.
*/
public static final int STATE_COMPLETE = 4;
/**
* Gets the state of the request, a value
* between 0 and 4.
* @return A value corresponding to one of the STATE* constants in this class.
*/
public int getReadyState();
/**
* Gets the request response as text.
*/
public String getResponseText();
/**
* Gets the request response as an XML DOM.
*/
public Document getResponseXML();
/**
* Gets the request response as an AWT image.
*/
public Image getResponseImage();
/**
* Gets the request response bytes.
*/
public byte[] getResponseBytes();
/**
* Gets the status of the response. Note that this
* can be 0 for file requests in addition to 200
* for successful HTTP requests.
*/
public int getStatus();
/**
* Gets the status text of the request, e.g. "OK" for 200.
*/
public String getStatusText();
/**
* Aborts an ongoing request.
*/
public void abort();
/**
* Gets a string with all the response headers.
*/
public String getAllResponseHeaders();
/**
* Gets a response header value.
* @param headerName The name of the header.
*/
public String getResponseHeader(String headerName);
/**
* Starts an asynchronous request.
* @param method The request method.
* @param url The destination URL.
*/
public void open(String method, String url) throws java.io.IOException;
/**
* Opens an asynchronous request.
* @param method The request method.
* @param url The destination URL.
*/
public void open(String method, URL url) throws java.io.IOException;
/**
* Opens an request.
* @param method The request method.
* @param url The destination URL.
* @param asyncFlag Whether the request is asynchronous.
*/
public void open(String method, URL url, boolean asyncFlag) throws java.io.IOException;
/**
* Opens a request.
* @param method The request method.
* @param url The destination URL.
* @param asyncFlag Whether the request should be asynchronous.
*/
public void open(String method, String url, boolean asyncFlag) throws java.io.IOException;
/**
* Opens a request.
* @param method The request method.
* @param url The destination URL.
* @param asyncFlag Whether the request should be asynchronous.
* @param userName The HTTP authentication user name.
*/
public void open(String method, java.net.URL url, boolean asyncFlag, String userName) throws java.io.IOException;
/**
* Opens a request.
* @param method The request method.
* @param url The destination URL.
* @param asyncFlag Whether the request should be asynchronous.
* @param userName The HTTP authentication user name.
* @param password The HTTP authentication password.
*/
public void open(String method, java.net.URL url, boolean asyncFlag, String userName, String password) throws java.io.IOException;
/**
* Sends POST content if any.
* @param content POST content or null
for GET requests.
* @throws java.io.IOException
*/
public void send(String content) throws java.io.IOException;
/**
* Adds a listener of ReadyState changes. The listener should be invoked
* even in the case of errors.
* @param listener An instanceof of {@link org.lobobrowser.html.ReadyStateChangeListener}
*/
public void addReadyStateChangeListener(ReadyStateChangeListener listener);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/ReadyStateChangeListener.java 0000644 0001750 0001750 00000002673 10726473510 027627 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Nov 13, 2005
*/
package org.lobobrowser.html;
import java.util.EventListener;
/**
* The ReadyStateChangeListener
interface
* is implemented to receive ReadyState change events
* from {@link org.lobobrowser.html.HttpRequest}.
* @see org.lobobrowser.html.HttpRequest#addReadyStateChangeListener(ReadyStateChangeListener)
* @author J. H. S.
*/
public interface ReadyStateChangeListener extends EventListener {
/**
* This method is called when the ReadyState changes.
*/
public void readyStateChanged();
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/UserAgentContext.java 0000644 0001750 0001750 00000006307 11125726656 026214 0 ustar twerner twerner package org.lobobrowser.html;
/**
* Provides information about the user agent (browser) driving
* the parser and/or renderer.
*
* A simple implementation of this interface is provided in
* {@link org.lobobrowser.html.test.SimpleUserAgentContext}.
* @see HtmlRendererContext#getUserAgentContext()
* @see org.lobobrowser.html.parser.DocumentBuilderImpl#DocumentBuilderImpl(UserAgentContext)
*/
public interface UserAgentContext {
/**
* Creates an instance of {@link org.lobobrowser.html.HttpRequest} which
* can be used by the renderer to load images, scripts, external style sheets,
* and implement the Javascript XMLHttpRequest class (AJAX).
*/
public HttpRequest createHttpRequest();
/**
* Gets browser "code" name.
*/
public String getAppCodeName();
/**
* Gets browser application name.
*/
public String getAppName();
/**
* Gets browser application version.
*/
public String getAppVersion();
/**
* Gets browser application minor version.
*/
public String getAppMinorVersion();
/**
* Gets browser language code. See ISO 639-1 codes.
*/
public String getBrowserLanguage();
/**
* Returns a boolean value indicating whether cookies are
* enabled in the user agent. This value is used for reporting
* purposes only.
*/
public boolean isCookieEnabled();
/**
* Returns a boolean value indicating whether scripting
* is enabled in the user agent. If this value is false
,
* the parser will not process scripts and Javascript element
* attributes will have no effect.
*/
public boolean isScriptingEnabled();
/**
* Returns a boolean value indicating whether
* remote (non-inline) CSS documents should be loaded.
*/
public boolean isExternalCSSEnabled();
/**
* Gets the name of the user's operating system.
*/
public String getPlatform();
/**
* Should return the string used in
* the User-Agent header.
*/
public String getUserAgent();
/**
* Method used to implement Javascript document.cookie
property.
*/
public String getCookie(java.net.URL url);
/**
* Method used to implement document.cookie
property.
* @param cookieSpec Specification of cookies, as they
* would appear in the Set-Cookie
* header value of HTTP.
*/
public void setCookie(java.net.URL url, String cookieSpec);
/**
* Gets the security policy for scripting. Return null
* if JavaScript code is trusted.
*/
public java.security.Policy getSecurityPolicy();
/**
* Gets the scripting optimization level, which is a value
* equivalent to Rhino's optimization level.
*/
public int getScriptingOptimizationLevel();
/**
* Returns true if the current media matches the name provided.
* @param mediaName Media name, which
* may be screen
, tty
, etc. (See HTML Specification).
*/
public boolean isMedia(String mediaName);
public String getVendor();
public String getProduct();
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/ 0000755 0001750 0001750 00000000000 11125630302 023520 5 ustar twerner twerner libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/AttrImpl.java 0000644 0001750 0001750 00000005333 10726473500 026136 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Sep 10, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.*;
public class AttrImpl extends NodeImpl implements Attr {
private String name;
private String value;
private boolean specified;
private Element ownerElement;
private boolean isId;
/**
* @param name
* @param value
*/
public AttrImpl(String name, String value, boolean specified, Element owner, boolean isId) {
super();
this.name = name;
this.value = value;
this.specified = specified;
this.ownerElement = owner;
this.isId = isId;
}
/**
* @param name
*/
public AttrImpl(String name) {
super();
this.name = name;
this.value = "";
this.specified = false;
this.ownerElement = null;
this.isId = false;
}
public String getLocalName() {
return this.name;
}
public String getNodeName() {
return this.name;
}
public String getNodeValue() throws DOMException {
return this.value;
}
public void setNodeValue(String nodeValue) throws DOMException {
this.value = nodeValue;
}
public short getNodeType() {
return Node.ATTRIBUTE_NODE;
}
public String getName() {
return this.name;
}
public boolean getSpecified() {
return this.specified;
}
public String getValue() {
return this.value;
}
public void setValue(String value) throws DOMException {
this.value = value;
}
public Element getOwnerElement() {
return this.ownerElement;
}
public TypeInfo getSchemaTypeInfo() {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Namespaces not supported");
}
public boolean isId() {
return this.isId;
}
public void setId(boolean value) {
this.isId = value;
}
protected Node createSimilarNode() {
return new AttrImpl(this.name, this.value, this.specified, this.ownerElement, this.isId);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/CDataSectionImpl.java 0000644 0001750 0001750 00000002730 10726473510 027524 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Sep 4, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.*;
public class CDataSectionImpl extends TextImpl implements CDATASection {
public CDataSectionImpl() {
super();
}
public CDataSectionImpl(String text) {
super(text);
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getnodeName()
*/
public String getNodeName() {
return "#cdata-section";
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getnodeType()
*/
public short getNodeType() {
return Node.CDATA_SECTION_NODE;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/CharacterDataImpl.java 0000644 0001750 0001750 00000007054 10763031256 027713 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Sep 3, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.*;
public abstract class CharacterDataImpl extends NodeImpl implements
CharacterData {
protected volatile String text;
public CharacterDataImpl() {
super();
}
public CharacterDataImpl(String text) {
this.text = text;
}
public String getClassName() {
return "HTMLCharacterData";
}
public String getTextContent() throws DOMException {
return this.text;
}
public void setTextContent(String textContent) throws DOMException {
this.text = textContent;
if(!this.notificationsSuspended) {
this.informInvalid();
}
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#cloneNode(boolean)
*/
public Node cloneNode(boolean deep) {
CharacterDataImpl newNode = (CharacterDataImpl) super.cloneNode(deep);
newNode.setData(this.getData());
return newNode;
}
public void appendData(String arg) throws DOMException {
this.text += arg;
if(!this.notificationsSuspended) {
this.informInvalid();
}
}
public void deleteData(int offset, int count)
throws DOMException {
StringBuffer buffer = new StringBuffer(this.text);
StringBuffer result = buffer.delete(offset, offset + count);
this.text = result.toString();
if(!this.notificationsSuspended) {
this.informInvalid();
}
}
public String getData() throws DOMException {
return this.text;
}
public int getLength() {
return this.text.length();
}
public void insertData(int offset, String arg)
throws DOMException {
StringBuffer buffer = new StringBuffer(this.text);
StringBuffer result = buffer.insert(offset, arg);
this.text = result.toString();
if(!this.notificationsSuspended) {
this.informInvalid();
}
}
public void replaceData(int offset, int count, String arg)
throws DOMException {
StringBuffer buffer = new StringBuffer(this.text);
StringBuffer result = buffer.replace(offset, offset + count, arg);
this.text = result.toString();
if(!this.notificationsSuspended) {
this.informInvalid();
}
}
public void setData(String data) throws DOMException {
this.text = data;
if(!this.notificationsSuspended) {
this.informInvalid();
}
}
public String substringData(int offset, int count)
throws DOMException {
return this.text.substring(offset, offset + count);
}
public String toString() {
String someText = this.text;
int length = someText.length();
if(someText != null && someText.length() > 32) {
someText = someText.substring(0, 29) + "...";
}
return this.getNodeName() + "[length=" + length + ",text=" + someText + "]";
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/ChildHTMLCollection.java 0000644 0001750 0001750 00000003616 10726473504 030134 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Dec 3, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.js.*;
import org.w3c.dom.Node;
import org.w3c.dom.html2.HTMLCollection;
public class ChildHTMLCollection extends AbstractScriptableDelegate implements HTMLCollection {
private final NodeImpl rootNode;
/**
* @param node
*/
public ChildHTMLCollection(NodeImpl node) {
super();
rootNode = node;
}
public int getLength() {
return this.rootNode.getChildCount();
}
public Node item(int index) {
return this.rootNode.getChildAtIndex(index);
}
public Node namedItem(String name) {
org.w3c.dom.Document doc = this.rootNode.getOwnerDocument();
if(doc == null) {
return null;
}
//TODO: This might get elements that are not descendents.
Node node = (Node) doc.getElementById(name);
if(node != null && node.getParentNode() == this.rootNode) {
return node;
}
return null;
}
public int indexOf(Node node) {
return this.rootNode.getChildIndex(node);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/CommentImpl.java 0000644 0001750 0001750 00000003200 10726473476 026631 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 9, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.Comment;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
public class CommentImpl extends CharacterDataImpl implements Comment {
public CommentImpl(String text) {
super(text);
}
public String getLocalName() {
return null;
}
public String getNodeName() {
return "#comment";
}
public String getNodeValue() throws DOMException {
return this.getTextContent();
}
public void setNodeValue(String nodeValue) throws DOMException {
this.setTextContent(nodeValue);
}
public short getNodeType() {
return Node.COMMENT_NODE;
}
protected Node createSimilarNode() {
return new CommentImpl(this.text);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/DOMConfigurationImpl.java 0000644 0001750 0001750 00000003402 10726473502 030370 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 9, 2005
*/
package org.lobobrowser.html.domimpl;
import java.util.*;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMStringList;
public class DOMConfigurationImpl implements DOMConfiguration {
private final Map parameters = new HashMap();
public DOMConfigurationImpl() {
super();
}
public void setParameter(String name, Object value) throws DOMException {
synchronized(this) {
this.parameters.put(name, value);
}
}
public Object getParameter(String name) throws DOMException {
synchronized(this) {
return this.parameters.get(name);
}
}
public boolean canSetParameter(String name, Object value) {
//TODO
return true;
}
public DOMStringList getParameterNames() {
synchronized(this) {
return new DOMStringListImpl(parameters.keySet());
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/DOMImplementationImpl.java 0000644 0001750 0001750 00000003777 10726473506 030571 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 15, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.*;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
public class DOMImplementationImpl implements DOMImplementation {
private final UserAgentContext context;
public DOMImplementationImpl(UserAgentContext context) {
this.context = context;
}
public boolean hasFeature(String feature, String version) {
return "HTML".equals(feature) && "2.0".compareTo(version) <= 0;
}
public DocumentType createDocumentType(String qualifiedName,
String publicId, String systemId) throws DOMException {
return new DocumentTypeImpl(qualifiedName, publicId, systemId);
}
public Document createDocument(String namespaceURI, String qualifiedName,
DocumentType doctype) throws DOMException {
return new HTMLDocumentImpl(this.context);
}
public Object getFeature(String feature, String version) {
if("HTML".equals(feature) && "2.0".compareTo(version) <= 0) {
return this;
}
else {
return null;
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/DOMStringListImpl.java 0000644 0001750 0001750 00000003071 10726473504 027667 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 9, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.DOMStringList;
import java.util.*;
public class DOMStringListImpl implements DOMStringList {
private final List sourceList;
public DOMStringListImpl(Collection sourceList) {
List list = new ArrayList();
list.addAll(sourceList);
this.sourceList = list;
}
public String item(int index) {
try {
return (String) this.sourceList.get(index);
} catch(IndexOutOfBoundsException iob) {
return null;
}
}
public int getLength() {
return this.sourceList.size();
}
public boolean contains(String str) {
return this.sourceList.contains(str);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/DescendentHTMLCollection.java 0000644 0001750 0001750 00000014542 11123247206 031153 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Dec 3, 2005
*/
package org.lobobrowser.html.domimpl;
import java.util.*;
import java.lang.ref.*;
import org.lobobrowser.js.*;
import org.lobobrowser.util.*;
import org.w3c.dom.Node;
import org.w3c.dom.html2.HTMLCollection;
public class DescendentHTMLCollection extends AbstractScriptableDelegate implements HTMLCollection {
private final NodeImpl rootNode;
private final NodeFilter nodeFilter;
private final Object treeLock;
private final boolean nestIntoMatchingNodes;
public DescendentHTMLCollection(NodeImpl node, NodeFilter filter, Object treeLock) {
this(node, filter, treeLock, true);
}
/**
* @param node
* @param filter
*/
public DescendentHTMLCollection(NodeImpl node, NodeFilter filter, Object treeLock, boolean nestMatchingNodes) {
rootNode = node;
nodeFilter = filter;
this.treeLock = treeLock;
this.nestIntoMatchingNodes = nestMatchingNodes;
HTMLDocumentImpl document = (HTMLDocumentImpl) node.getOwnerDocument();
document.addDocumentNotificationListener(new LocalNotificationListener(document, this));
}
private Map itemsByName = null;
private List itemsByIndex = null;
private void ensurePopulatedImpl() {
if(this.itemsByName == null) {
ArrayList descendents = this.rootNode.getDescendents(this.nodeFilter, this.nestIntoMatchingNodes);
this.itemsByIndex = descendents == null ? Collections.EMPTY_LIST : descendents;
int size = descendents == null ? 0 : descendents.size();
Map itemsByName = new HashMap(size * 3 / 2);
this.itemsByName = itemsByName;
for(int i = 0; i < size; i++) {
Object descNode = descendents.get(i);
if(descNode instanceof ElementImpl) {
ElementImpl element = (ElementImpl) descNode;
String id = element.getId();
if(id != null && id.length() != 0) {
itemsByName.put(id, element);
}
String name = element.getAttribute("name");
if(name != null && name.length() != 0 && !name.equals(id)) {
itemsByName.put(name, element);
}
}
}
}
}
private void invalidate() {
synchronized(this.treeLock) {
this.itemsByName = null;
this.itemsByIndex = null;
}
}
private boolean isValid() {
synchronized(this.treeLock) {
return this.itemsByName != null && this.itemsByIndex != null;
}
}
public int getLength() {
synchronized(this.treeLock) {
this.ensurePopulatedImpl();
return this.itemsByIndex.size();
}
}
public Node item(int index) {
synchronized(this.treeLock) {
this.ensurePopulatedImpl();
try {
return (Node) this.itemsByIndex.get(index);
} catch(java.lang.IndexOutOfBoundsException iob) {
return null;
}
}
}
public Node namedItem(String name) {
synchronized(this.treeLock) {
this.ensurePopulatedImpl();
return (Node) this.itemsByName.get(name);
}
}
public int indexOf(Node node) {
synchronized(this.treeLock) {
this.ensurePopulatedImpl();
return this.itemsByIndex.indexOf(node);
}
}
// private final class NodeCounter implements NodeVisitor {
// private int count = 0;
//
// public final void visit(Node node) {
// if(nodeFilter.accept(node)) {
// this.count++;
// throw new SkipVisitorException();
// }
// }
//
// public int getCount() {
// return this.count;
// }
// }
//
// private final class NodeScanner implements NodeVisitor {
// private int count = 0;
// private Node foundNode = null;
// private final int targetIndex;
//
// public NodeScanner(int idx) {
// this.targetIndex = idx;
// }
//
// public final void visit(Node node) {
// if(nodeFilter.accept(node)) {
// if(this.count == this.targetIndex) {
// this.foundNode = node;
// throw new StopVisitorException();
// }
// this.count++;
// throw new SkipVisitorException();
// }
// }
//
// public Node getNode() {
// return this.foundNode;
// }
// }
//
// private final class NodeScanner2 implements NodeVisitor {
// private int count = 0;
// private int foundIndex = -1;
// private final Node targetNode;
//
// public NodeScanner2(Node node) {
// this.targetNode = node;
// }
//
// public final void visit(Node node) {
// if(nodeFilter.accept(node)) {
// if(node == this.targetNode) {
// this.foundIndex = this.count;
// throw new StopVisitorException();
// }
// this.count++;
// throw new SkipVisitorException();
// }
// }
//
// public int getIndex() {
// return this.foundIndex;
// }
// }
private static class LocalNotificationListener extends DocumentNotificationAdapter {
// Needs to be a static class with a weak reference to
// the collection object.
private final HTMLDocumentImpl document;
private final WeakReference collectionRef;
public LocalNotificationListener(final HTMLDocumentImpl document, final DescendentHTMLCollection collection) {
super();
this.document = document;
this.collectionRef = new WeakReference(collection);
}
public void structureInvalidated(NodeImpl node) {
DescendentHTMLCollection collection = (DescendentHTMLCollection) this.collectionRef.get();
if(collection == null) {
// Gone!
this.document.removeDocumentNotificationListener(this);
return;
}
if(collection.isValid()) {
if(Nodes.isSameOrAncestorOf(collection.rootNode, node)) {
collection.invalidate();
}
}
}
public void nodeLoaded(NodeImpl node) {
this.structureInvalidated(node);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/DocumentFragmentImpl.java 0000644 0001750 0001750 00000003171 10726473504 030470 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 9, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.DOMException;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
public class DocumentFragmentImpl extends NodeImpl implements DocumentFragment {
public DocumentFragmentImpl() {
super();
}
public String getLocalName() {
return null;
}
public String getNodeName() {
return "#document-fragment";
}
public String getNodeValue() throws DOMException {
return null;
}
public void setNodeValue(String nodeValue) throws DOMException {
}
public short getNodeType() {
return org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE;
}
protected Node createSimilarNode() {
return new DocumentFragmentImpl();
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/DocumentNotificationAdapter.java 0000644 0001750 0001750 00000003062 10764534434 032033 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The XAMJ Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
/**
* An abstract implementation of {@link DocumentNotificationListener}
* with blank methods, provided for convenience.
*/
public abstract class DocumentNotificationAdapter implements
DocumentNotificationListener {
public void allInvalidated() {
}
public void externalScriptLoading(NodeImpl node) {
}
public void invalidated(NodeImpl node) {
}
public void lookInvalidated(NodeImpl node) {
}
public void nodeLoaded(NodeImpl node) {
}
public void positionInvalidated(NodeImpl node) {
}
public void sizeInvalidated(NodeImpl node) {
}
public void structureInvalidated(NodeImpl node) {
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/DocumentNotificationListener.java 0000644 0001750 0001750 00000003073 10764534256 032244 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
/**
* A listener of document changes.
*/
public interface DocumentNotificationListener {
/**
* Called if a property related to the node's
* size has changed.
* @param node
*/
public void sizeInvalidated(NodeImpl node);
/**
* Called if something such as a color or
* decoration has changed. This would be
* something which does not affect the
* rendered size.
* @param node
*/
public void lookInvalidated(NodeImpl node);
/**
* Changed if the position of the node in a
* parent has changed.
* @param node
*/
public void positionInvalidated(NodeImpl node);
/**
* This is called when the node has changed, but
* it is unclear if it's a size change or a look
* change. Typically, a node attribute has changed,
* but the set of child nodes has not changed.
* @param node
*/
public void invalidated(NodeImpl node);
/**
* Called when the node (with all its contents) is first
* created by the parser.
* @param node
*/
public void nodeLoaded(NodeImpl node);
/**
* The children of the node might have changed.
* @param node
*/
public void structureInvalidated(NodeImpl node);
/**
* Called when a external script (a SCRIPT tag with a src attribute)
* is about to start loading.
* @param node
*/
public void externalScriptLoading(NodeImpl node);
/**
* This is called when the whole document
* is potentially invalid, e.g. when a new
* style sheet has been added.
*/
public void allInvalidated();
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/DocumentTypeImpl.java 0000644 0001750 0001750 00000004601 10726473510 027642 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 15, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.DOMException;
import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
public class DocumentTypeImpl extends NodeImpl implements DocumentType {
private final String qualifiedName;
private final String publicId;
private final String systemId;
public DocumentTypeImpl(String qname, String publicId, String systemId) {
super();
this.qualifiedName = qname;
this.publicId = publicId;
this.systemId = systemId;
}
public String getLocalName() {
return null;
}
public String getNodeName() {
return this.getName();
}
public String getNodeValue() throws DOMException {
return null;
}
public void setNodeValue(String nodeValue) throws DOMException {
// nop
}
public short getNodeType() {
return org.w3c.dom.Node.DOCUMENT_TYPE_NODE;
}
public String getName() {
return this.qualifiedName;
}
public NamedNodeMap getEntities() {
//TODO: DOCTYPE declared entities
return null;
}
public NamedNodeMap getNotations() {
//TODO: DOCTYPE notations
return null;
}
public String getPublicId() {
return this.publicId;
}
public String getSystemId() {
return this.systemId;
}
public String getInternalSubset() {
//TODO: DOCTYPE internal subset
return null;
}
protected Node createSimilarNode() {
return new DocumentTypeImpl(this.qualifiedName, this.publicId, this.systemId);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/ElementFactory.java 0000644 0001750 0001750 00000012343 11047522134 027315 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 8, 2005
*/
package org.lobobrowser.html.domimpl;
import java.util.*;
import org.w3c.dom.html2.*;
import org.w3c.dom.*;
class ElementFactory {
private final Map builders = new HashMap(80);
private ElementFactory() {
// This sets up builders for each known element tag.
Map builders = this.builders;
builders.put("HTML", new HTMLElementBuilder.Html());
builders.put("TITLE", new HTMLElementBuilder.Title());
builders.put("BASE", new HTMLElementBuilder.Base());
HTMLElementBuilder div = new HTMLElementBuilder.Div();
builders.put("DIV", div);
builders.put("DL", div);
builders.put("BODY", new HTMLElementBuilder.Body());
builders.put("CENTER", new HTMLElementBuilder.Center());
builders.put("CAPTION", new HTMLElementBuilder.Center());
builders.put("PRE", new HTMLElementBuilder.Pre());
builders.put("P", new HTMLElementBuilder.P());
HTMLElementBuilder bq = new HTMLElementBuilder.Blockquote();
builders.put("BLOCKQUOTE", bq);
builders.put("DD", bq);
builders.put("SPAN", new HTMLElementBuilder.Span());
builders.put("SCRIPT", new HTMLElementBuilder.Script());
builders.put("IMG", new HTMLElementBuilder.Img());
builders.put("STYLE", new HTMLElementBuilder.Style());
builders.put("LINK", new HTMLElementBuilder.Link());
builders.put("A", new HTMLElementBuilder.Anchor());
builders.put("ANCHOR", new HTMLElementBuilder.Anchor());
builders.put("TABLE", new HTMLElementBuilder.Table());
builders.put("TD", new HTMLElementBuilder.Td());
builders.put("TH", new HTMLElementBuilder.Th());
builders.put("TR", new HTMLElementBuilder.Tr());
builders.put("FORM", new HTMLElementBuilder.Form());
builders.put("INPUT", new HTMLElementBuilder.Input());
builders.put("BUTTON", new HTMLElementBuilder.Button());
builders.put("TEXTAREA", new HTMLElementBuilder.Textarea());
builders.put("SELECT", new HTMLElementBuilder.Select());
builders.put("OPTION", new HTMLElementBuilder.Option());
builders.put("FRAMESET", new HTMLElementBuilder.Frameset());
builders.put("FRAME", new HTMLElementBuilder.Frame());
builders.put("IFRAME", new HTMLElementBuilder.IFrame());
builders.put("UL", new HTMLElementBuilder.Ul());
builders.put("OL", new HTMLElementBuilder.Ol());
builders.put("LI", new HTMLElementBuilder.Li());
builders.put("HR", new HTMLElementBuilder.Hr());
builders.put("BR", new HTMLElementBuilder.Br());
builders.put("OBJECT", new HTMLElementBuilder.HtmlObject());
builders.put("APPLET", new HTMLElementBuilder.Applet());
builders.put("EMBED", new HTMLElementBuilder.NonStandard());
builders.put("FONT", new HTMLElementBuilder.Font());
builders.put("BASEFONT", new HTMLElementBuilder.BaseFont());
builders.put("TT", new HTMLElementBuilder.Tt());
builders.put("CODE", new HTMLElementBuilder.Code());
builders.put("SMALL", new HTMLElementBuilder.Small());
builders.put("BIG", new HTMLElementBuilder.Big());
builders.put("B", new HTMLElementBuilder.Strong());
builders.put("STRONG", new HTMLElementBuilder.Strong());
builders.put("U", new HTMLElementBuilder.Underline());
builders.put("STRIKE", new HTMLElementBuilder.Strike());
builders.put("SUP", new HTMLElementBuilder.Sup());
builders.put("SUB", new HTMLElementBuilder.Sub());
HTMLElementBuilder em = new HTMLElementBuilder.Em();
builders.put("I", em);
builders.put("EM", em);
builders.put("CITE", em);
HTMLElementBuilder heading = new HTMLElementBuilder.Heading();
builders.put("H1", heading);
builders.put("H2", heading);
builders.put("H3", heading);
builders.put("H4", heading);
builders.put("H5", heading);
builders.put("H6", heading);
}
private static ElementFactory instance = new ElementFactory();
public static ElementFactory getInstance() {
return instance;
}
public final HTMLElement createElement(HTMLDocumentImpl document, String name) throws DOMException {
String normalName = name.toUpperCase();
// No need to synchronize; read-only map at this point.
HTMLElementBuilder builder = (HTMLElementBuilder) this.builders.get(normalName);
if(builder == null) {
//TODO: IE would assume name is html text here?
HTMLElementImpl element = new HTMLElementImpl(name);
element.setOwnerDocument(document);
return element;
}
else {
return builder.create(document, name);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/ElementFilter.java 0000644 0001750 0001750 00000002454 10726473506 027150 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Dec 3, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.Node;
public final class ElementFilter implements NodeFilter {
private final String elementName;
/**
* @param name
*/
public ElementFilter(String name) {
super();
elementName = name;
}
public final boolean accept(Node node) {
return this.elementName.equalsIgnoreCase(node.getNodeName());
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/ElementImpl.java 0000644 0001750 0001750 00000033524 11055031236 026610 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 29, 2005
*/
package org.lobobrowser.html.domimpl;
import java.util.*;
import org.lobobrowser.util.*;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.TypeInfo;
import org.w3c.dom.Text;
import org.w3c.dom.Comment;
public class ElementImpl extends NodeImpl implements Element {
private final String name;
public ElementImpl(String name) {
super();
this.name = name;
}
protected Map attributes;
/*
* (non-Javadoc)
*
* @see org.xamjwg.html.domimpl.NodeImpl#getattributes()
*/
public NamedNodeMap getAttributes() {
synchronized(this) {
Map attrs = this.attributes;
if (attrs == null) {
attrs = new HashMap();
this.attributes = attrs;
}
return new NamedNodeMapImpl(this, this.attributes);
}
}
public boolean hasAttributes() {
synchronized(this) {
Map attrs = this.attributes;
return attrs == null ? false : !attrs.isEmpty();
}
}
public boolean equalAttributes(Node arg) {
if (arg instanceof ElementImpl) {
synchronized(this) {
Map attrs1 = this.attributes;
if (attrs1 == null) {
attrs1 = Collections.EMPTY_MAP;
}
Map attrs2 = ((ElementImpl) arg).attributes;
if (attrs2 == null) {
attrs2 = Collections.EMPTY_MAP;
}
return Objects.equals(attrs1, attrs2);
}
} else {
return false;
}
}
private String id;
public String getId() {
String id = this.id;
return id == null ? "" : id;
}
public void setId(String id) {
this.setAttribute("id", id);
}
//private String title;
public String getTitle() {
return this.getAttribute("title");
}
public void setTitle(String title) {
this.setAttribute("title", title);
}
public String getLang() {
return this.getAttribute("lang");
}
public void setLang(String lang) {
this.setAttribute("lang", lang);
}
public String getDir() {
return this.getAttribute("dir");
}
public void setDir(String dir) {
this.setAttribute("dir", dir);
}
public final String getAttribute(String name) {
String normalName = this.normalizeAttributeName(name);
synchronized(this) {
Map attributes = this.attributes;
return attributes == null ? null : (String) attributes
.get(normalName);
}
}
private Attr getAttr(String normalName, String value) {
// TODO: "specified" attributes
return new AttrImpl(normalName, value, true, this, "id"
.equals(normalName));
}
public Attr getAttributeNode(String name) {
String normalName = this.normalizeAttributeName(name);
synchronized(this) {
Map attributes = this.attributes;
String value = attributes == null ? null : (String) attributes
.get(normalName);
return value == null ? null : this.getAttr(normalName, value);
}
}
public Attr getAttributeNodeNS(String namespaceURI, String localName)
throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"Namespaces not supported");
}
public String getAttributeNS(String namespaceURI, String localName)
throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"Namespaces not supported");
}
protected static boolean isTagName(Node node, String name) {
return node.getNodeName().equalsIgnoreCase(name);
}
public NodeList getElementsByTagName(String name) {
boolean matchesAll = "*".equals(name);
List descendents = new LinkedList();
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while (i.hasNext()) {
Object child = i.next();
if (child instanceof Element) {
Element childElement = (Element) child;
if (matchesAll || isTagName(childElement, name)) {
descendents.add(child);
}
NodeList sublist = childElement.getElementsByTagName(name);
int length = sublist.getLength();
for (int idx = 0; idx < length; idx++) {
descendents.add(sublist.item(idx));
}
}
}
}
}
return new NodeListImpl(descendents);
}
public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"Namespaces not supported");
}
public TypeInfo getSchemaTypeInfo() {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"Namespaces not supported");
}
public String getTagName() {
return this.getNodeName();
}
public boolean hasAttribute(String name) {
String normalName = this.normalizeAttributeName(name);
synchronized(this) {
Map attributes = this.attributes;
return attributes == null ? false : attributes
.containsKey(normalName);
}
}
public boolean hasAttributeNS(String namespaceURI, String localName)
throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"Namespaces not supported");
}
public void removeAttribute(String name) throws DOMException {
String normalName = this.normalizeAttributeName(name);
synchronized(this) {
Map attributes = this.attributes;
if (attributes == null) {
return;
}
attributes.remove(normalName);
}
}
public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
String normalName = this.normalizeAttributeName(oldAttr.getName());
synchronized(this) {
Map attributes = this.attributes;
if (attributes == null) {
return null;
}
String oldValue = (String) attributes.remove(normalName);
// TODO: "specified" attributes
return oldValue == null ? null : this.getAttr(normalName, oldValue);
}
}
public void removeAttributeNS(String namespaceURI, String localName)
throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"Namespaces not supported");
}
protected void assignAttributeField(String normalName, String value) {
// Note: overriders assume that processing here is only done after
// checking attribute names, i.e. they may not call the super
// implementation if an attribute is already taken care of.
boolean isName = false;
if ("id".equals(normalName) || (isName = "name".equals(normalName))) {
// Note that the value of name is used
// as an ID, but the value of ID is not
// used as a name.
if(!isName) {
this.id = value;
}
HTMLDocumentImpl document = (HTMLDocumentImpl) this.document;
if (document != null) {
//// Do not remove old ID. Consider scenario where both
//// name and ID are provided in an element.
// if (oldId != null) {
// document.removeElementById(oldId);
// }
document.setElementById(value, this);
if(isName) {
String oldName = this.getAttribute("name");
if(oldName != null) {
document.removeNamedItem(oldName);
}
document.setNamedItem(value, this);
}
}
}
}
protected final String normalizeAttributeName(String name) {
return name.toLowerCase();
}
public void setAttribute(String name, String value) throws DOMException {
String normalName = this.normalizeAttributeName(name);
synchronized(this) {
Map attribs = this.attributes;
if (attribs == null) {
attribs = new HashMap(2);
this.attributes = attribs;
}
attribs.put(normalName, value);
}
this.assignAttributeField(normalName, value);
}
/**
* Fast method to set attributes. It is not thread safe.
* Calling thread should hold a treeLock.
*/
public void setAttributeImpl(String name, String value) throws DOMException {
String normalName = this.normalizeAttributeName(name);
Map attribs = this.attributes;
if (attribs == null) {
attribs = new HashMap(2);
this.attributes = attribs;
}
this.assignAttributeField(normalName, value);
attribs.put(normalName, value);
}
public Attr setAttributeNode(Attr newAttr) throws DOMException {
String normalName = this.normalizeAttributeName(newAttr.getName());
String value = newAttr.getValue();
synchronized(this) {
if (this.attributes == null) {
this.attributes = new HashMap();
}
this.attributes.put(normalName, value);
// this.setIdAttribute(normalName, newAttr.isId());
}
this.assignAttributeField(normalName, value);
return newAttr;
}
public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"Namespaces not supported");
}
public void setAttributeNS(String namespaceURI, String qualifiedName,
String value) throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"Namespaces not supported");
}
public void setIdAttribute(String name, boolean isId) throws DOMException {
String normalName = this.normalizeAttributeName(name);
if (!"id".equals(normalName)) {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"IdAttribute can't be anything other than ID");
}
}
public void setIdAttributeNode(Attr idAttr, boolean isId)
throws DOMException {
String normalName = this.normalizeAttributeName(idAttr.getName());
if (!"id".equals(normalName)) {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"IdAttribute can't be anything other than ID");
}
}
public void setIdAttributeNS(String namespaceURI, String localName,
boolean isId) throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
"Namespaces not supported");
}
/*
* (non-Javadoc)
*
* @see org.xamjwg.html.domimpl.NodeImpl#getLocalName()
*/
public String getLocalName() {
return this.getNodeName();
}
/*
* (non-Javadoc)
*
* @see org.xamjwg.html.domimpl.NodeImpl#getNodeName()
*/
public String getNodeName() {
return this.name;
}
/*
* (non-Javadoc)
*
* @see org.xamjwg.html.domimpl.NodeImpl#getNodeType()
*/
public short getNodeType() {
return Node.ELEMENT_NODE;
}
/*
* (non-Javadoc)
*
* @see org.xamjwg.html.domimpl.NodeImpl#getNodeValue()
*/
public String getNodeValue() throws DOMException {
return null;
}
/*
* (non-Javadoc)
*
* @see org.xamjwg.html.domimpl.NodeImpl#setNodeValue(java.lang.String)
*/
public void setNodeValue(String nodeValue) throws DOMException {
// nop
}
/**
* Gets inner text of the element, possibly including text in comments.
* This can be used to get Javascript code out of a SCRIPT element.
*
* @param includeComment
*/
protected String getRawInnerText(boolean includeComment) {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
StringBuffer sb = null;
while (i.hasNext()) {
Object node = i.next();
if (node instanceof Text) {
Text tn = (Text) node;
String txt = tn.getNodeValue();
if (!"".equals(txt)) {
if (sb == null) {
sb = new StringBuffer();
}
sb.append(txt);
}
} else if (node instanceof ElementImpl) {
ElementImpl en = (ElementImpl) node;
String txt = en.getRawInnerText(includeComment);
if (!"".equals(txt)) {
if (sb == null) {
sb = new StringBuffer();
}
sb.append(txt);
}
} else if (includeComment && node instanceof Comment) {
Comment cn = (Comment) node;
String txt = cn.getNodeValue();
if (!"".equals(txt)) {
if (sb == null) {
sb = new StringBuffer();
}
sb.append(txt);
}
}
}
return sb == null ? "" : sb.toString();
}
else {
return "";
}
}
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(this.getNodeName());
sb.append(" [");
NamedNodeMap attribs = this.getAttributes();
int length = attribs.getLength();
for (int i = 0; i < length; i++) {
Attr attr = (Attr) attribs.item(i);
sb.append(attr.getNodeName());
sb.append('=');
sb.append(attr.getNodeValue());
if (i + 1 < length) {
sb.append(',');
}
}
sb.append("]");
return sb.toString();
}
public void setInnerText(String newText) {
org.w3c.dom.Document document = this.document;
if(document == null) {
this.warn("setInnerText(): Element " + this + " does not belong to a document.");
return;
}
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if (nl != null) {
nl.clear();
}
}
// Create node and call appendChild outside of synchronized block.
Node textNode = document.createTextNode(newText);
this.appendChild(textNode);
}
protected Node createSimilarNode() {
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
return doc == null ? null : doc.createElement(this.getTagName());
}
protected String htmlEncodeChildText(String text) {
if(org.lobobrowser.html.parser.HtmlParser.isDecodeEntities(this.name)) {
return Strings.strictHtmlEncode(text, false);
}
else {
return text;
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/FilteredNodeListImpl.java 0000644 0001750 0001750 00000004102 10726473504 030421 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 9, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.js.*;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.*;
class FilteredNodeListImpl extends AbstractScriptableDelegate implements NodeList {
private final Collection sourceNodeList;
private final NodeFilter filter;
private final Object lock;
/**
* @param filter
* @param list
*/
public FilteredNodeListImpl(NodeFilter filter, Collection list, Object lock) {
super();
this.filter = filter;
sourceNodeList = list;
this.lock = lock;
}
public Node item(int index) {
synchronized(this.lock) {
int count = 0;
Iterator i = this.sourceNodeList.iterator();
while(i.hasNext()) {
Node node = (Node) i.next();
if(this.filter.accept(node)) {
if(count == index) {
return node;
}
count++;
}
}
return null;
}
}
public int getLength() {
synchronized(this.lock) {
int count = 0;
Iterator i = this.sourceNodeList.iterator();
while(i.hasNext()) {
Node node = (Node) i.next();
if(this.filter.accept(node)) {
count++;
}
}
return count;
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/FrameNode.java 0000644 0001750 0001750 00000000365 10641432430 026233 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.*;
/**
* Tag interface for frame nodes.
*/
public interface FrameNode {
public BrowserFrame getBrowserFrame();
public void setBrowserFrame(BrowserFrame frame);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLAbstractUIElement.java 0000644 0001750 0001750 00000013460 11130421054 030365 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.*;
import org.lobobrowser.html.js.Executor;
import org.lobobrowser.js.*;
import org.mozilla.javascript.*;
import org.w3c.dom.*;
import java.util.*;
import java.util.logging.Level;
/**
* Implements common functionality of most elements.
*/
public class HTMLAbstractUIElement extends HTMLElementImpl {
private Function onfocus, onblur, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup, oncontextmenu;
public HTMLAbstractUIElement(String name) {
super(name);
}
public Function getOnblur() {
return this.getEventFunction(onblur, "onblur");
}
public void setOnblur(Function onblur) {
this.onblur = onblur;
}
public Function getOnclick() {
return this.getEventFunction(onclick, "onclick");
}
public void setOnclick(Function onclick) {
this.onclick = onclick;
}
public Function getOndblclick() {
return this.getEventFunction(ondblclick, "ondblclick");
}
public void setOndblclick(Function ondblclick) {
this.ondblclick = ondblclick;
}
public Function getOnfocus() {
return this.getEventFunction(onfocus, "onfocus");
}
public void setOnfocus(Function onfocus) {
this.onfocus = onfocus;
}
public Function getOnkeydown() {
return this.getEventFunction(onkeydown, "onkeydown");
}
public void setOnkeydown(Function onkeydown) {
this.onkeydown = onkeydown;
}
public Function getOnkeypress() {
return this.getEventFunction(onkeypress, "onkeypress");
}
public void setOnkeypress(Function onkeypress) {
this.onkeypress = onkeypress;
}
public Function getOnkeyup() {
return this.getEventFunction(onkeyup, "onkeyup");
}
public void setOnkeyup(Function onkeyup) {
this.onkeyup = onkeyup;
}
public Function getOnmousedown() {
return this.getEventFunction(onmousedown, "onmousedown");
}
public void setOnmousedown(Function onmousedown) {
this.onmousedown = onmousedown;
}
public Function getOnmousemove() {
return this.getEventFunction(onmousemove, "onmousemove");
}
public void setOnmousemove(Function onmousemove) {
this.onmousemove = onmousemove;
}
public Function getOnmouseout() {
return this.getEventFunction(onmouseout, "onmouseout");
}
public void setOnmouseout(Function onmouseout) {
this.onmouseout = onmouseout;
}
public Function getOnmouseover() {
return this.getEventFunction(onmouseover, "onmouseover");
}
public void setOnmouseover(Function onmouseover) {
this.onmouseover = onmouseover;
}
public Function getOnmouseup() {
return this.getEventFunction(onmouseup, "onmouseup");
}
public void setOnmouseup(Function onmouseup) {
this.onmouseup = onmouseup;
}
public Function getOncontextmenu() {
return this.getEventFunction(oncontextmenu, "oncontextmenu");
}
public void setOncontextmenu(Function oncontextmenu) {
this.oncontextmenu = oncontextmenu;
}
public void focus() {
UINode node = this.getUINode();
if(node != null) {
node.focus();
}
}
public void blur() {
UINode node = this.getUINode();
if(node != null) {
node.blur();
}
}
private Map functionByAttribute = null;
protected Function getEventFunction(Function varValue, String attributeName) {
if(varValue != null) {
return varValue;
}
String normalAttributeName = this.normalizeAttributeName(attributeName);
synchronized(this) {
Map fba = this.functionByAttribute;
Function f = fba == null ? null : (Function) fba.get(normalAttributeName);
if(f != null) {
return f;
}
UserAgentContext uac = this.getUserAgentContext();
if(uac == null) {
throw new IllegalStateException("No user agent context.");
}
if(uac.isScriptingEnabled()) {
String attributeValue = this.getAttribute(attributeName);
if(attributeValue == null || attributeValue.length() == 0) {
f = null;
}
else {
String functionCode = "function " + normalAttributeName + "_" + System.identityHashCode(this) + "() { " + attributeValue + " }";
Document doc = this.document;
if(doc == null) {
throw new IllegalStateException("Element does not belong to a document.");
}
Context ctx = Executor.createContext(this.getDocumentURL(), uac);
try {
Scriptable scope = (Scriptable) doc.getUserData(Executor.SCOPE_KEY);
if(scope == null) {
throw new IllegalStateException("Scriptable (scope) instance was expected to be keyed as UserData to document using " + Executor.SCOPE_KEY);
}
Scriptable thisScope = (Scriptable) JavaScript.getInstance().getJavascriptObject(this, scope);
try {
//TODO: Get right line number for script. //TODO: Optimize this in case it's called multiple times? Is that done?
f = ctx.compileFunction(thisScope, functionCode, this.getTagName() + "[" + this.getId() + "]." + attributeName, 1, null);
} catch(EcmaError ecmaError) {
logger.log(Level.WARNING, "Javascript error at " + ecmaError.getSourceName() + ":" + ecmaError.getLineNumber() + ": " + ecmaError.getMessage(), ecmaError);
f = null;
} catch(Throwable err) {
logger.log(Level.WARNING, "Unable to evaluate Javascript code", err);
f = null;
}
} finally {
Context.exit();
}
}
if(fba == null) {
fba = new HashMap(1);
this.functionByAttribute = fba;
}
fba.put(normalAttributeName, f);
}
return f;
}
}
protected void assignAttributeField(String normalName, String value) {
super.assignAttributeField(normalName, value);
if(normalName.startsWith("on")) {
synchronized(this) {
Map fba = this.functionByAttribute;
if(fba != null) {
fba.remove(normalName);
}
}
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLAppletElementImpl.java 0000644 0001750 0001750 00000003722 10641432432 030443 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.w3c.dom.html.HTMLAppletElement;
public class HTMLAppletElementImpl extends HTMLAbstractUIElement implements
HTMLAppletElement {
public HTMLAppletElementImpl(String name) {
super(name);
}
public String getAlign() {
return this.getAttribute("align");
}
public String getAlt() {
return this.getAttribute("alt");
}
public String getArchive() {
return this.getAttribute("archive");
}
public String getCode() {
return this.getAttribute("code");
}
public String getCodeBase() {
return this.getAttribute("codebase");
}
public String getHeight() {
return this.getAttribute("height");
}
public String getHspace() {
return this.getAttribute("hspace");
}
public String getName() {
return this.getAttribute("name");
}
public String getObject() {
return this.getAttribute("object");
}
public String getVspace() {
return this.getAttribute("vspace");
}
public String getWidth() {
return this.getAttribute("width");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
public void setAlt(String alt) {
this.setAttribute("alt", alt);
}
public void setArchive(String archive) {
this.setAttribute("archive", archive);
}
public void setCode(String code) {
this.setAttribute("code", code);
}
public void setCodeBase(String codeBase) {
this.setAttribute("codebase", codeBase);
}
public void setHeight(String height) {
this.setAttribute("height", height);
}
public void setHspace(String hspace) {
this.setAttribute("hspace", hspace);
}
public void setName(String name) {
this.setAttribute("name", name);
}
public void setObject(String object) {
this.setAttribute("object", object);
}
public void setVspace(String vspace) {
this.setAttribute("vspace", vspace);
}
public void setWidth(String width) {
this.setAttribute("width", width);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLBRElementImpl.java 0000644 0001750 0001750 00000001007 10641432432 027513 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.w3c.dom.html2.HTMLBRElement;
public class HTMLBRElementImpl extends HTMLElementImpl implements HTMLBRElement {
public HTMLBRElementImpl(String name) {
super(name);
}
public String getClear() {
return this.getAttribute("clear");
}
public void setClear(String clear) {
this.setAttribute("clear", clear);
}
protected void appendInnerTextImpl(StringBuffer buffer) {
buffer.append("\r\n");
super.appendInnerTextImpl(buffer);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLBaseElementImpl.java 0000644 0001750 0001750 00000003116 10726473504 030076 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The XAMJ Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.UserDataHandler;
public class HTMLBaseElementImpl extends HTMLElementImpl {
public HTMLBaseElementImpl(String name) {
super(name, true);
}
public Object setUserData(String key, Object data, UserDataHandler handler) {
if(org.lobobrowser.html.parser.HtmlParser.MODIFYING_KEY.equals(key) && data != Boolean.TRUE) {
this.processBaseTag();
}
return super.setUserData(key, data, handler);
}
private final void processBaseTag() {
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.setBaseURI(this.getAttribute("href"));
doc.setDefaultTarget(this.getAttribute("target"));
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLBaseFontElementImpl.java 0000644 0001750 0001750 00000006355 11134546340 030726 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.lobobrowser.util.gui.ColorFactory;
import org.w3c.dom.html2.HTMLBaseFontElement;
public class HTMLBaseFontElementImpl extends HTMLAbstractUIElement implements
HTMLBaseFontElement {
public HTMLBaseFontElementImpl(String name) {
super(name);
}
public String getColor() {
return this.getAttribute("color");
}
public String getFace() {
return this.getAttribute("face");
}
public void setColor(String color) {
this.setAttribute("color", color);
}
public void setFace(String face) {
this.setAttribute("face", face);
}
public int getSize() {
try {
return Integer.parseInt(this.getAttribute("size"));
} catch(Exception thrown) {
this.warn("getSize(): Unable to parse size attribute in " + this + ".", thrown);
return 0;
}
}
public void setSize(int size) {
this.setAttribute("size", String.valueOf(size));
}
protected RenderState createRenderState(RenderState prevRenderState) {
String size = this.getAttribute("size");
if(size != null) {
int fontNumber = HtmlValues.getFontNumberOldStyle(size, prevRenderState);
float fontSize = HtmlValues.getFontSize(fontNumber);
prevRenderState = new BaseFontRenderState(prevRenderState, fontNumber);
}
return super.createRenderState(prevRenderState);
}
protected AbstractCSS2Properties createDefaultStyleSheet() {
String fontFamily = this.getAttribute("face");
String color = this.getAttribute("color");
String size = this.getAttribute("size");
ModelNode parentModelNode = this.getParentModelNode();
RenderState parentRS = parentModelNode == null ? null : parentModelNode.getRenderState();
String fontSize = null;
if(parentRS != null) {
int fontNumber = HtmlValues.getFontNumberOldStyle(size, parentRS);
fontSize = HtmlValues.getFontSizeSpec(fontNumber);
}
ComputedCSS2Properties css = new ComputedCSS2Properties(this);
if(fontSize != null) {
css.internalSetLC("font-size", fontSize);
}
if(fontFamily != null) {
css.internalSetLC("font-family", fontFamily);
}
if(color != null) {
css.internalSetLC("color", color);
}
return css;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLBaseInputElement.java 0000644 0001750 0001750 00000020260 10772245354 030274 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 15, 2006
*/
package org.lobobrowser.html.domimpl;
import java.util.ArrayList;
import org.lobobrowser.html.FormInput;
import org.lobobrowser.html.js.Executor;
import org.mozilla.javascript.Function;
import org.w3c.dom.Node;
import org.w3c.dom.html2.HTMLFormElement;
public abstract class HTMLBaseInputElement extends HTMLAbstractUIElement {
public HTMLBaseInputElement(String name) {
super(name);
}
protected InputContext inputContext;
protected String deferredValue;
public void setInputContext(InputContext ic) {
String dv = null;
synchronized(this) {
this.inputContext = ic;
if(ic != null) {
dv = this.deferredValue;
}
}
if(dv != null) {
ic.setValue(dv);
}
}
public String getDefaultValue() {
return this.getAttribute("defaultValue");
}
public void setDefaultValue(String defaultValue) {
this.setAttribute("defaultValue", defaultValue);
}
public HTMLFormElement getForm() {
Node parent = this.getParentNode();
while(parent != null && !(parent instanceof HTMLFormElement)) {
parent = parent.getParentNode();
}
return (HTMLFormElement) parent;
}
public void submitForm(FormInput[] extraFormInputs) {
HTMLFormElementImpl form = (HTMLFormElementImpl) this.getForm();
if(form != null) {
form.submit(extraFormInputs);
}
}
public void resetForm() {
HTMLFormElement form = this.getForm();
if (form != null) {
form.reset();
}
}
public String getAccept() {
return this.getAttribute("accept");
}
public void setAccept(String accept) {
this.setAttribute("accept", accept);
}
public String getAccessKey() {
return this.getAttribute("accessKey");
}
public void setAccessKey(String accessKey) {
this.setAttribute("accessKey", accessKey);
}
public String getAlign() {
return this.getAttribute("align");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
public String getAlt() {
return this.getAttribute("alit");
}
public void setAlt(String alt) {
this.setAttribute("alt", alt);
}
public boolean getDisabled() {
InputContext ic = this.inputContext;
return ic == null ? false : ic.getDisabled();
}
public void setDisabled(boolean disabled) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setDisabled(disabled);
}
}
public String getName() {
//TODO: Should this return valid of "id"?
return this.getAttribute("name");
}
public void setName(String name) {
this.setAttribute("name", name);
}
public boolean getReadOnly() {
InputContext ic = this.inputContext;
return ic == null ? false : ic.getReadOnly();
}
public void setReadOnly(boolean readOnly) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setReadOnly(readOnly);
}
}
public int getTabIndex() {
InputContext ic = this.inputContext;
return ic == null ? 0 : ic.getTabIndex();
}
public void setTabIndex(int tabIndex) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setTabIndex(tabIndex);
}
}
public String getValue() {
InputContext ic = this.inputContext;
if(ic != null) {
//Note: Per HTML Spec, setValue does not set attribute.
return ic.getValue();
}
else {
String dv = this.deferredValue;
if(dv != null) {
return dv;
}
else {
String val = this.getAttribute("value");
return val == null ? "" : val;
}
}
}
protected java.io.File getFileValue() {
InputContext ic = this.inputContext;
if(ic != null) {
return ic.getFileValue();
}
else {
return null;
}
}
public void setValue(String value) {
InputContext ic = null;
synchronized(this) {
ic = this.inputContext;
if(ic == null) {
this.deferredValue = value;
}
}
if(ic != null) {
ic.setValue(value);
}
}
public void blur() {
InputContext ic = this.inputContext;
if(ic != null) {
ic.blur();
}
}
public void focus() {
InputContext ic = this.inputContext;
if(ic != null) {
ic.focus();
}
}
public void select() {
InputContext ic = this.inputContext;
if(ic != null) {
ic.select();
}
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.HTMLElementImpl#assignAttributeField(java.lang.String, java.lang.String)
*/
protected void assignAttributeField(String normalName, String value) {
if("value".equals(normalName)) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setValue(value);
}
}
else if("src".equals(normalName)) {
this.loadImage(value);
}
else {
super.assignAttributeField(normalName, value);
}
}
private Function onload;
public Function getOnload() {
return this.getEventFunction(this.onload, "onload");
}
public void setOnload(Function onload) {
this.onload = onload;
}
private java.awt.Image image = null;
private String imageSrc;
private void loadImage(String src) {
HTMLDocumentImpl document = (HTMLDocumentImpl) this.document;
if(document != null) {
synchronized(this.imageListeners) {
this.imageSrc = src;
this.image = null;
}
if(src != null) {
document.loadImage(src, new LocalImageListener(src));
}
}
}
public final java.awt.Image getImage() {
synchronized(this.imageListeners) {
return this.image;
}
}
private final ArrayList imageListeners = new ArrayList(1);
/**
* Adds a listener of image loading events.
* The listener gets called right away if there's already
* an image.
* @param listener
*/
public void addImageListener(ImageListener listener) {
ArrayList l = this.imageListeners;
java.awt.Image currentImage;
synchronized(l) {
currentImage = this.image;
l.add(listener);
}
if(currentImage != null) {
// Call listener right away if there's already an
// image; holding no locks.
listener.imageLoaded(new ImageEvent(this, currentImage));
// Should not call onload handler here. That's taken
// care of otherwise.
}
}
public void removeImageListener(ImageListener listener) {
ArrayList l = this.imageListeners;
synchronized(l) {
l.remove(l);
}
}
void resetInput() {
InputContext ic = this.inputContext;
if(ic != null) {
ic.resetInput();
}
}
private void dispatchEvent(String expectedImgSrc, ImageEvent event) {
ArrayList l = this.imageListeners;
ImageListener[] listenerArray;
synchronized(l) {
if(!expectedImgSrc.equals(this.imageSrc)) {
return;
}
this.image = event.image;
// Get array of listeners while holding lock.
listenerArray = (ImageListener[]) l.toArray(ImageListener.EMPTY_ARRAY);
}
int llength = listenerArray.length;
for(int i = 0; i < llength; i++) {
// Inform listener, holding no lock.
listenerArray[i].imageLoaded(event);
}
Function onload = this.getOnload();
if(onload != null) {
//TODO: onload event object?
Executor.executeFunction(HTMLBaseInputElement.this, onload, null);
}
}
private class LocalImageListener implements ImageListener {
private final String expectedImgSrc;
public LocalImageListener(String imgSrc) {
this.expectedImgSrc = imgSrc;
}
public void imageLoaded(ImageEvent event) {
dispatchEvent(this.expectedImgSrc, event);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLBlockQuoteElementImpl.java 0000644 0001750 0001750 00000002361 11134376672 031277 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The XAMJ Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
public class HTMLBlockQuoteElementImpl extends HTMLAbstractUIElement {
public HTMLBlockQuoteElementImpl(String name) {
super(name);
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new BlockQuoteRenderState(prevRenderState, this);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLBodyElementImpl.java 0000644 0001750 0001750 00000006710 10726473504 030124 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 8, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.mozilla.javascript.Function;
import org.w3c.dom.Document;
import org.w3c.dom.html2.*;
public class HTMLBodyElementImpl extends HTMLAbstractUIElement implements
HTMLBodyElement {
public HTMLBodyElementImpl(String name) {
super(name);
}
void setOwnerDocument(Document value, boolean deep) {
super.setOwnerDocument(value, deep);
if(value instanceof HTMLDocument) {
((HTMLDocument) value).setBody(this);
}
}
void setOwnerDocument(Document value) {
super.setOwnerDocument(value);
if(value instanceof HTMLDocument) {
((HTMLDocument) value).setBody(this);
}
}
public String getALink() {
return this.getAttribute("alink");
}
public void setALink(String aLink) {
this.setAttribute("alink", aLink);
}
public String getBackground() {
return this.getAttribute("background");
}
public void setBackground(String background) {
this.setAttribute("background", background);
}
public String getBgColor() {
return this.getAttribute("bgcolor");
}
public void setBgColor(String bgColor) {
this.setAttribute("bgcolor", bgColor);
}
public String getLink() {
return this.getAttribute("link");
}
public void setLink(String link) {
this.setAttribute("link", link);
}
public String getText() {
return this.getAttribute("text");
}
public void setText(String text) {
this.setAttribute("text", text);
}
public String getVLink() {
return this.getAttribute("vlink");
}
public void setVLink(String vLink) {
this.setAttribute("vlink", vLink);
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new BodyRenderState(prevRenderState, this);
}
public Function getOnload() {
Object document = this.document;
if(document instanceof HTMLDocumentImpl) {
return ((HTMLDocumentImpl) document).getOnloadHandler();
}
else {
return null;
}
}
public void setOnload(Function onload) {
Object document = this.document;
if(document instanceof HTMLDocumentImpl) {
//Note that body.onload overrides
//Window.onload.
((HTMLDocumentImpl) document).setOnloadHandler(onload);
}
}
protected void assignAttributeField(String normalName, String value) {
if("onload".equals(normalName)) {
Function onload = this.getEventFunction(null, normalName);
if(onload != null) {
this.setOnload(onload);
}
}
else {
super.assignAttributeField(normalName, value);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLButtonElementImpl.java 0000644 0001750 0001750 00000002065 10726473506 030503 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
public class HTMLButtonElementImpl extends HTMLBaseInputElement {
public HTMLButtonElementImpl(String name) {
super(name);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLCenterElementImpl.java 0000644 0001750 0001750 00000002445 10726473504 030450 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
public class HTMLCenterElementImpl extends HTMLAbstractUIElement {
public HTMLCenterElementImpl(String name) {
super(name);
}
protected RenderState createRenderState(RenderState prevRenderState) {
prevRenderState = new AlignXRenderState(prevRenderState, 50);
return new BlockRenderState(prevRenderState, this);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLDivElementImpl.java 0000644 0001750 0001750 00000003743 11111755164 027746 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.w3c.dom.html2.HTMLDivElement;
public class HTMLDivElementImpl extends HTMLAbstractUIElement implements
HTMLDivElement {
public HTMLDivElementImpl(String name) {
super(name);
}
public String getAlign() {
return this.getAttribute("align");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new BlockRenderState(prevRenderState, this);
}
protected void appendInnerTextImpl(StringBuffer buffer) {
int length = buffer.length();
int lineBreaks;
if(length == 0) {
lineBreaks = 2;
}
else {
int start = length - 2;
if (start < 0) {
start = 0;
}
lineBreaks = 0;
for(int i = start; i < length; i++) {
char ch = buffer.charAt(i);
if(ch == '\n') {
lineBreaks++;
}
}
}
for(int i = 0; i < 1 - lineBreaks; i++) {
buffer.append("\r\n");
}
super.appendInnerTextImpl(buffer);
buffer.append("\r\n");
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLDocumentImpl.java 0000644 0001750 0001750 00000111014 11067635334 027465 0 ustar twerner twerner /* GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Sep 3, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.*;
import org.lobobrowser.html.io.*;
import org.lobobrowser.html.js.*;
import org.lobobrowser.html.parser.HtmlParser;
import org.lobobrowser.html.style.*;
import org.lobobrowser.util.*;
import org.lobobrowser.util.io.EmptyReader;
import org.w3c.dom.*;
import org.w3c.dom.css.CSSStyleSheet;
import org.w3c.dom.views.*;
import org.w3c.dom.html2.*;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.mozilla.javascript.Function;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.logging.*;
import java.security.*;
/**
* Implementation of the W3C HTMLDocument
interface.
*/
public class HTMLDocumentImpl extends NodeImpl implements HTMLDocument, DocumentView {
private static final Logger logger = Logger.getLogger(HTMLDocumentImpl.class.getName());
private final ElementFactory factory;
private final HtmlRendererContext rcontext;
private final UserAgentContext ucontext;
private final Window window;
private final Map elementsById = new WeakValueHashMap();
private String documentURI;
private java.net.URL documentURL;
private WritableLineReader reader;
public HTMLDocumentImpl(HtmlRendererContext rcontext) {
this(rcontext.getUserAgentContext(), rcontext, null, null);
}
public HTMLDocumentImpl(UserAgentContext ucontext) {
this(ucontext, null, null, null);
}
public HTMLDocumentImpl(final UserAgentContext ucontext, final HtmlRendererContext rcontext, WritableLineReader reader, String documentURI) {
this.factory = ElementFactory.getInstance();
this.rcontext = rcontext;
this.ucontext = ucontext;
this.reader = reader;
this.documentURI = documentURI;
try {
java.net.URL docURL = new java.net.URL(documentURI);
SecurityManager sm = System.getSecurityManager();
if(sm != null) {
// Do not allow creation of HTMLDocumentImpl if there's
// no permission to connect to the host of the URL.
// This is so that cookies cannot be written arbitrarily
// with setCookie() method.
sm.checkPermission(new java.net.SocketPermission(docURL.getHost(), "connect"));
}
this.documentURL = docURL;
this.domain = docURL.getHost();
} catch(java.net.MalformedURLException mfu) {
logger.warning("HTMLDocumentImpl(): Document URI [" + documentURI + "] is malformed.");
}
this.document = this;
// Get Window object
Window window;
if(rcontext != null) {
window = Window.getWindow(rcontext);
}
else {
// Plain parsers may use Javascript too.
window = new Window(null, ucontext);
}
// Window must be retained or it will be garbage collected.
this.window = window;
window.setDocument(this);
// Set up Javascript scope
this.setUserData(Executor.SCOPE_KEY, window.getWindowScope(), null);
}
private Set locales;
/**
* Gets an immutable set of locales previously set for this document.
*/
public Set getLocales() {
return locales;
}
/**
* Sets the locales of the document. This helps
* determine whether specific fonts can display text
* in the languages of all the locales.
* @param locales An immutable set of java.util.Locale
instances.
*/
public void setLocales(Set locales) {
this.locales = locales;
}
String getDocumentHost() {
URL docUrl = this.documentURL;
return docUrl == null ? null : docUrl.getHost();
}
public URL getDocumentURL() {
//TODO: Security considerations?
return this.documentURL;
}
/**
* Caller should synchronize on document.
*/
void setElementById(String id, Element element) {
synchronized(this) {
this.elementsById.put(id, element);
}
}
void removeElementById(String id) {
synchronized(this) {
this.elementsById.remove(id);
}
}
private volatile String baseURI;
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getbaseURI()
*/
public String getBaseURI() {
String buri = this.baseURI;
return buri == null ? this.documentURI : buri;
}
public void setBaseURI(String value) {
this.baseURI = value;
}
private String defaultTarget;
public String getDefaultTarget() {
return this.defaultTarget;
}
public void setDefaultTarget(String value) {
this.defaultTarget = value;
}
public AbstractView getDefaultView() {
return this.window;
}
public String getTextContent() throws DOMException {
return null;
}
public void setTextContent(String textContent) throws DOMException {
// NOP, per spec
}
private String title;
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
private String referrer;
public String getReferrer() {
return this.referrer;
}
public void setReferrer(String value) {
this.referrer = value;
}
private String domain;
public String getDomain() {
return this.domain;
}
public void setDomain(String domain) {
String oldDomain = this.domain;
if(oldDomain != null && Domains.isValidCookieDomain(domain, oldDomain)) {
this.domain = domain;
}
else {
throw new SecurityException("Cannot set domain to '" + domain + "' when current domain is '" + oldDomain + "'");
}
}
public HTMLElement getBody() {
synchronized(this) {
return this.body;
}
}
private HTMLCollection images;
private HTMLCollection applets;
private HTMLCollection links;
private HTMLCollection forms;
private HTMLCollection anchors;
private HTMLCollection frames;
public HTMLCollection getImages() {
synchronized(this) {
if(this.images == null) {
this.images = new DescendentHTMLCollection(this, new ImageFilter(), this.treeLock);
}
return this.images;
}
}
public HTMLCollection getApplets() {
synchronized(this) {
if(this.applets == null) {
//TODO: Should include OBJECTs that are applets?
this.applets = new DescendentHTMLCollection(this, new AppletFilter(), this.treeLock);
}
return this.applets;
}
}
public HTMLCollection getLinks() {
synchronized(this) {
if(this.links == null) {
this.links = new DescendentHTMLCollection(this, new LinkFilter(), this.treeLock);
}
return this.links;
}
}
public HTMLCollection getForms() {
synchronized(this) {
if(this.forms == null) {
this.forms = new DescendentHTMLCollection(this, new FormFilter(), this.treeLock);
}
return this.forms;
}
}
public HTMLCollection getFrames() {
synchronized(this) {
if(this.frames == null) {
this.frames = new DescendentHTMLCollection(this, new FrameFilter(), this.treeLock);
}
return this.frames;
}
}
public HTMLCollection getAnchors() {
synchronized(this) {
if(this.anchors == null) {
this.anchors = new DescendentHTMLCollection(this, new AnchorFilter(), this.treeLock);
}
return this.anchors;
}
}
public String getCookie() {
SecurityManager sm = System.getSecurityManager();
if(sm != null) {
return (String) AccessController.doPrivileged(new PrivilegedAction() {
// Justification: A caller (e.g. Google Analytics script)
// might want to get cookies from the parent document.
// If the caller has access to the document, it appears
// they should be able to get cookies on that document.
// Note that this Document instance cannot be created
// with an arbitrary URL.
// TODO: Security: Review rationale.
public Object run() {
return ucontext.getCookie(documentURL);
}
});
}
else {
return this.ucontext.getCookie(this.documentURL);
}
}
public void setCookie(final String cookie) throws DOMException {
SecurityManager sm = System.getSecurityManager();
if(sm != null) {
AccessController.doPrivileged(new PrivilegedAction() {
// Justification: A caller (e.g. Google Analytics script)
// might want to set cookies on the parent document.
// If the caller has access to the document, it appears
// they should be able to set cookies on that document.
// Note that this Document instance cannot be created
// with an arbitrary URL.
public Object run() {
ucontext.setCookie(documentURL, cookie);
return null;
}
});
}
else {
this.ucontext.setCookie(this.documentURL, cookie);
}
}
public void open() {
synchronized(this.treeLock) {
if(this.reader != null) {
if(this.reader instanceof LocalWritableLineReader) {
try {
this.reader.close();
} catch(IOException ioe) {
//ignore
}
this.reader = null;
}
else {
// Already open, return.
// Do not close http/file documents in progress.
return;
}
}
this.removeAllChildrenImpl();
this.reader = new LocalWritableLineReader(new EmptyReader());
}
}
/**
* Loads the document from the reader provided when the
* current instance of HTMLDocumentImpl
was constructed.
* It then closes the reader.
* @throws IOException
* @throws SAXException
* @throws UnsupportedEncodingException
*/
public void load() throws IOException,SAXException,UnsupportedEncodingException {
this.load(true);
}
public void load(boolean closeReader) throws IOException,SAXException,UnsupportedEncodingException {
WritableLineReader reader;
synchronized(this.treeLock) {
this.removeAllChildrenImpl();
this.setTitle(null);
this.setBaseURI(null);
this.setDefaultTarget(null);
this.styleSheets.clear();
this.styleSheetAggregator = null;
reader = this.reader;
}
if(reader != null) {
try {
ErrorHandler errorHandler = new LocalErrorHandler();
String systemId = this.documentURI;
String publicId = systemId;
HtmlParser parser = new HtmlParser(this.ucontext, this, errorHandler, publicId, systemId);
parser.parse(reader);
} finally {
if(closeReader) {
try {
reader.close();
} catch(Exception err) {
logger.log(Level.WARNING,"load(): Unable to close stream", err);
}
synchronized(this.treeLock) {
this.reader = null;
}
}
}
}
}
public void close() {
synchronized(this.treeLock) {
if(this.reader instanceof LocalWritableLineReader) {
try {
this.reader.close();
} catch(java.io.IOException ioe) {
// ignore
}
this.reader = null;
}
else {
// do nothing - could be parsing document off the web.
}
//TODO: cause it to render
}
}
public void write(String text) {
synchronized(this.treeLock) {
if(this.reader != null) {
try {
// This can end up in openBufferChanged
this.reader.write(text);
} catch(IOException ioe) {
//ignore
}
}
}
}
public void writeln(String text) {
synchronized(this.treeLock) {
if(this.reader != null) {
try {
// This can end up in openBufferChanged
this.reader.write(text + "\r\n");
} catch(IOException ioe) {
//ignore
}
}
}
}
private void openBufferChanged(String text) {
// Assumed to execute in a lock
// Assumed that text is not broken up HTML.
ErrorHandler errorHandler = new LocalErrorHandler();
String systemId = this.documentURI;
String publicId = systemId;
HtmlParser parser = new HtmlParser(this.ucontext, this, errorHandler, publicId, systemId);
StringReader strReader = new StringReader(text);
try {
// This sets up another Javascript scope Window. Does it matter?
parser.parse(strReader);
} catch(Exception err) {
this.warn("Unable to parse written HTML text. BaseURI=[" + this.getBaseURI() + "].", err);
}
}
/**
* Gets the collection of elements whose name
* attribute is elementName
.
*/
public NodeList getElementsByName(String elementName) {
return this.getNodeList(new ElementNameFilter(elementName));
}
private DocumentType doctype;
public DocumentType getDoctype() {
return this.doctype;
}
public void setDoctype(DocumentType doctype) {
this.doctype = doctype;
}
public Element getDocumentElement() {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
Object node = i.next();
if(node instanceof Element) {
return (Element) node;
}
}
}
return null;
}
}
public Element createElement(String tagName)
throws DOMException {
return this.factory.createElement(this, tagName);
}
/* (non-Javadoc)
* @see org.w3c.dom.Document#createDocumentFragment()
*/
public DocumentFragment createDocumentFragment() {
//TODO: According to documentation, when a document
//fragment is added to a node, its children are added,
//not itself.
DocumentFragmentImpl node = new DocumentFragmentImpl();
node.setOwnerDocument(this);
return node;
}
public Text createTextNode(String data) {
TextImpl node = new TextImpl(data);
node.setOwnerDocument(this);
return node;
}
public Comment createComment(String data) {
CommentImpl node = new CommentImpl(data);
node.setOwnerDocument(this);
return node;
}
public CDATASection createCDATASection(String data)
throws DOMException {
CDataSectionImpl node = new CDataSectionImpl(data);
node.setOwnerDocument(this);
return node;
}
public ProcessingInstruction createProcessingInstruction(
String target, String data) throws DOMException {
HTMLProcessingInstruction node = new HTMLProcessingInstruction(target, data);
node.setOwnerDocument(this);
return node;
}
public Attr createAttribute(String name) throws DOMException {
return new AttrImpl(name);
}
public EntityReference createEntityReference(String name)
throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "HTML document");
}
/**
* Gets all elements that match the given tag name.
* @param tagname The element tag name or an asterisk
* character (*) to match all elements.
*/
public NodeList getElementsByTagName(String tagname) {
if("*".equals(tagname)) {
return this.getNodeList(new ElementFilter());
}
else {
return this.getNodeList(new TagNameFilter(tagname));
}
}
public Node importNode(Node importedNode, boolean deep)
throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented");
}
public Element createElementNS(String namespaceURI,
String qualifiedName) throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "HTML document");
}
public Attr createAttributeNS(String namespaceURI,
String qualifiedName) throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "HTML document");
}
public NodeList getElementsByTagNameNS(String namespaceURI,
String localName) {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "HTML document");
}
public Element getElementById(String elementId) {
Element element;
synchronized(this) {
element = (Element) this.elementsById.get(elementId);
}
return element;
}
private final Map elementsByName = new HashMap(0);
public Element namedItem(String name) {
Element element;
synchronized(this) {
element = (Element) this.elementsByName.get(name);
}
return element;
}
void setNamedItem(String name, Element element) {
synchronized(this) {
this.elementsByName.put(name, element);
}
}
void removeNamedItem(String name) {
synchronized(this) {
this.elementsByName.remove(name);
}
}
private String inputEncoding;
public String getInputEncoding() {
return this.inputEncoding;
}
private String xmlEncoding;
public String getXmlEncoding() {
return this.xmlEncoding;
}
private boolean xmlStandalone;
public boolean getXmlStandalone() {
return this.xmlStandalone;
}
public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
this.xmlStandalone = xmlStandalone;
}
private String xmlVersion = null;
public String getXmlVersion() {
return this.xmlVersion;
}
public void setXmlVersion(String xmlVersion) throws DOMException {
this.xmlVersion = xmlVersion;
}
private boolean strictErrorChecking = true;
public boolean getStrictErrorChecking() {
return this.strictErrorChecking;
}
public void setStrictErrorChecking(boolean strictErrorChecking) {
this.strictErrorChecking = strictErrorChecking;
}
public String getDocumentURI() {
return this.documentURI;
}
public void setDocumentURI(String documentURI) {
//TODO: Security considerations? Chaging documentURL?
this.documentURI = documentURI;
}
public Node adoptNode(Node source) throws DOMException {
if(source instanceof NodeImpl) {
NodeImpl node = (NodeImpl) source;
node.setOwnerDocument(this, true);
return node;
}
else {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Invalid Node implementation");
}
}
private DOMConfiguration domConfig;
public DOMConfiguration getDomConfig() {
synchronized(this) {
if(this.domConfig == null) {
this.domConfig = new DOMConfigurationImpl();
}
return this.domConfig;
}
}
public void normalizeDocument() {
//TODO: Normalization options from domConfig
synchronized(this.treeLock) {
this.visitImpl(new NodeVisitor() {
public void visit(Node node) {
node.normalize();
}
});
}
}
public Node renameNode(Node n, String namespaceURI,
String qualifiedName) throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "No renaming");
}
private DOMImplementation domImplementation;
/* (non-Javadoc)
* @see org.w3c.dom.Document#getImplementation()
*/
public DOMImplementation getImplementation() {
synchronized(this) {
if(this.domImplementation == null) {
this.domImplementation = new DOMImplementationImpl(this.ucontext);
}
return this.domImplementation;
}
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getLocalName()
*/
public String getLocalName() {
// Always null for document
return null;
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getNodeName()
*/
public String getNodeName() {
return "#document";
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getNodeType()
*/
public short getNodeType() {
return Node.DOCUMENT_NODE;
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getNodeValue()
*/
public String getNodeValue() throws DOMException {
// Always null for document
return null;
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#setNodeValue(java.lang.String)
*/
public void setNodeValue(String nodeValue) throws DOMException {
throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "Cannot set node value of document");
}
public final HtmlRendererContext getHtmlRendererContext() {
return this.rcontext;
}
public UserAgentContext getUserAgentContext() {
return this.ucontext;
}
public final URL getFullURL(String uri) {
try {
String baseURI = this.getBaseURI();
URL documentURL = baseURI == null ? null : new URL(baseURI);
return Urls.createURL(documentURL, uri);
} catch(MalformedURLException mfu) {
// Try agan, without the baseURI.
try {
return new URL(uri);
} catch(MalformedURLException mfu2) {
logger.log(Level.WARNING,"Unable to create URL for URI=[" + uri + "], with base=[" + this.getBaseURI() + "].", mfu);
return null;
}
}
}
public final Location getLocation() {
return this.window.getLocation();
}
public void setLocation(String location) {
this.getLocation().setHref(location);
}
public String getURL() {
return this.documentURI;
}
private HTMLElement body;
public void setBody(HTMLElement body) {
synchronized(this) {
this.body = body;
}
}
private final Collection styleSheets = new CSSStyleSheetList();
public class CSSStyleSheetList extends ArrayList {
public int getLength(){
return this.size();
}
public CSSStyleSheet item(int index){
return (CSSStyleSheet) get(index);
}
}
final void addStyleSheet(CSSStyleSheet ss) {
synchronized(this.treeLock) {
this.styleSheets.add(ss);
this.styleSheetAggregator = null;
// Need to invalidate all children up to
// this point.
this.forgetRenderState();
//TODO: this might be ineffcient.
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
Object node = i.next();
if(node instanceof HTMLElementImpl) {
((HTMLElementImpl) node).forgetStyle(true);
}
}
}
}
this.allInvalidated();
}
public void allInvalidated(boolean forgetRenderStates) {
if(forgetRenderStates) {
synchronized(this.treeLock) {
this.styleSheetAggregator = null;
// Need to invalidate all children up to
// this point.
this.forgetRenderState();
//TODO: this might be ineffcient.
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
Object node = i.next();
if(node instanceof HTMLElementImpl) {
((HTMLElementImpl) node).forgetStyle(true);
}
}
}
}
}
this.allInvalidated();
}
public Collection getStyleSheets(){
return this.styleSheets;
}
private StyleSheetAggregator styleSheetAggregator = null;
final StyleSheetAggregator getStyleSheetAggregator() {
synchronized(this.treeLock) {
StyleSheetAggregator ssa = this.styleSheetAggregator;
if(ssa == null) {
ssa = new StyleSheetAggregator(this);
try {
ssa.addStyleSheets(this.styleSheets);
} catch(MalformedURLException mfu) {
logger.log(Level.WARNING,"getStyleSheetAggregator()", mfu);
}
this.styleSheetAggregator = ssa;
}
return ssa;
}
}
private final ArrayList documentNotificationListeners = new ArrayList(1);
/**
* Adds a document notification listener, which is informed about
* changes to the document.
* @param listener An instance of {@link DocumentNotificationListener}.
*/
public void addDocumentNotificationListener(DocumentNotificationListener listener) {
ArrayList listenersList = this.documentNotificationListeners;
synchronized(listenersList) {
listenersList.add(listener);
}
}
public void removeDocumentNotificationListener(DocumentNotificationListener listener) {
ArrayList listenersList = this.documentNotificationListeners;
synchronized(listenersList) {
listenersList.remove(listener);
}
}
public void sizeInvalidated(NodeImpl node) {
ArrayList listenersList = this.documentNotificationListeners;
int size;
synchronized(listenersList) {
size = listenersList.size();
}
// Traverse list outside synchronized block.
// (Shouldn't call listener methods in synchronized block.
// Deadlock is possible). But assume list could have
// been changed.
for(int i = 0; i < size; i++) {
try {
DocumentNotificationListener dnl = (DocumentNotificationListener) listenersList.get(i);
dnl.sizeInvalidated(node);
} catch(IndexOutOfBoundsException iob) {
// ignore
}
}
}
/**
* Called if something such as a color or
* decoration has changed. This would be
* something which does not affect the
* rendered size, and can be revalidated
* with a simple repaint.
* @param node
*/
public void lookInvalidated(NodeImpl node) {
ArrayList listenersList = this.documentNotificationListeners;
int size;
synchronized(listenersList) {
size = listenersList.size();
}
// Traverse list outside synchronized block.
// (Shouldn't call listener methods in synchronized block.
// Deadlock is possible). But assume list could have
// been changed.
for(int i = 0; i < size; i++) {
try {
DocumentNotificationListener dnl = (DocumentNotificationListener) listenersList.get(i);
dnl.lookInvalidated(node);
} catch(IndexOutOfBoundsException iob) {
// ignore
}
}
}
/**
* Changed if the position of the node in a
* parent has changed.
* @param node
*/
public void positionInParentInvalidated(NodeImpl node) {
ArrayList listenersList = this.documentNotificationListeners;
int size;
synchronized(listenersList) {
size = listenersList.size();
}
// Traverse list outside synchronized block.
// (Shouldn't call listener methods in synchronized block.
// Deadlock is possible). But assume list could have
// been changed.
for(int i = 0; i < size; i++) {
try {
DocumentNotificationListener dnl = (DocumentNotificationListener) listenersList.get(i);
dnl.positionInvalidated(node);
} catch(IndexOutOfBoundsException iob) {
// ignore
}
}
}
/**
* This is called when the node has changed, but
* it is unclear if it's a size change or a look
* change. An attribute change should trigger this.
* @param node
*/
public void invalidated(NodeImpl node) {
ArrayList listenersList = this.documentNotificationListeners;
int size;
synchronized(listenersList) {
size = listenersList.size();
}
// Traverse list outside synchronized block.
// (Shouldn't call listener methods in synchronized block.
// Deadlock is possible). But assume list could have
// been changed.
for(int i = 0; i < size; i++) {
try {
DocumentNotificationListener dnl = (DocumentNotificationListener) listenersList.get(i);
dnl.invalidated(node);
} catch(IndexOutOfBoundsException iob) {
// ignore
}
}
}
/**
* This is called when children of the node might
* have changed.
* @param node
*/
public void structureInvalidated(NodeImpl node) {
ArrayList listenersList = this.documentNotificationListeners;
int size;
synchronized(listenersList) {
size = listenersList.size();
}
// Traverse list outside synchronized block.
// (Shouldn't call listener methods in synchronized block.
// Deadlock is possible). But assume list could have
// been changed.
for(int i = 0; i < size; i++) {
try {
DocumentNotificationListener dnl = (DocumentNotificationListener) listenersList.get(i);
dnl.structureInvalidated(node);
} catch(IndexOutOfBoundsException iob) {
// ignore
}
}
}
public void nodeLoaded(NodeImpl node) {
ArrayList listenersList = this.documentNotificationListeners;
int size;
synchronized(listenersList) {
size = listenersList.size();
}
// Traverse list outside synchronized block.
// (Shouldn't call listener methods in synchronized block.
// Deadlock is possible). But assume list could have
// been changed.
for(int i = 0; i < size; i++) {
try {
DocumentNotificationListener dnl = (DocumentNotificationListener) listenersList.get(i);
dnl.nodeLoaded(node);
} catch(IndexOutOfBoundsException iob) {
// ignore
}
}
}
public void externalScriptLoading(NodeImpl node) {
ArrayList listenersList = this.documentNotificationListeners;
int size;
synchronized(listenersList) {
size = listenersList.size();
}
// Traverse list outside synchronized block.
// (Shouldn't call listener methods in synchronized block.
// Deadlock is possible). But assume list could have
// been changed.
for(int i = 0; i < size; i++) {
try {
DocumentNotificationListener dnl = (DocumentNotificationListener) listenersList.get(i);
dnl.externalScriptLoading(node);
} catch(IndexOutOfBoundsException iob) {
// ignore
}
}
}
/**
* Informs listeners that the whole document has been
* invalidated.
*/
public void allInvalidated() {
ArrayList listenersList = this.documentNotificationListeners;
int size;
synchronized(listenersList) {
size = listenersList.size();
}
// Traverse list outside synchronized block.
// (Shouldn't call listener methods in synchronized block.
// Deadlock is possible). But assume list could have
// been changed.
for(int i = 0; i < size; i++) {
try {
DocumentNotificationListener dnl = (DocumentNotificationListener) listenersList.get(i);
dnl.allInvalidated();
} catch(IndexOutOfBoundsException iob) {
// ignore
}
}
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new StyleSheetRenderState(this);
}
private final Map imageInfos = new HashMap(4);
private final ImageEvent BLANK_IMAGE_EVENT = new ImageEvent(this, null);
/**
* Loads images asynchronously such that they are shared if loaded
* simultaneously from the same URI.
* Informs the listener immediately if an image is already known.
* @param relativeUri
* @param imageListener
*/
protected void loadImage(String relativeUri, ImageListener imageListener) {
HtmlRendererContext rcontext = this.getHtmlRendererContext();
if(rcontext == null || !rcontext.isImageLoadingEnabled()) {
// Ignore image loading when there's no renderer context.
// Consider Cobra users who are only using the parser.
imageListener.imageLoaded(BLANK_IMAGE_EVENT);
return;
}
final URL url = this.getFullURL(relativeUri);
if(url == null) {
imageListener.imageLoaded(BLANK_IMAGE_EVENT);
return;
}
final String urlText = url.toExternalForm();
final Map map = this.imageInfos;
ImageEvent event = null;
synchronized(map) {
ImageInfo info = (ImageInfo) map.get(urlText);
if(info != null) {
if(info.loaded) {
// TODO: This can't really happen because ImageInfo
// is removed right after image is loaded.
event = info.imageEvent;
}
else {
info.addListener(imageListener);
}
}
else {
UserAgentContext uac = rcontext.getUserAgentContext();
final HttpRequest httpRequest = uac.createHttpRequest();
final ImageInfo newInfo = new ImageInfo();
map.put(urlText, newInfo);
newInfo.addListener(imageListener);
httpRequest.addReadyStateChangeListener(new ReadyStateChangeListener() {
public void readyStateChanged() {
if(httpRequest.getReadyState() == HttpRequest.STATE_COMPLETE) {
java.awt.Image newImage = httpRequest.getResponseImage();
ImageEvent newEvent = newImage == null ? null : new ImageEvent(HTMLDocumentImpl.this, newImage);
ImageListener[] listeners;
synchronized(map) {
newInfo.imageEvent = newEvent;
newInfo.loaded = true;
listeners = newEvent == null ? null : newInfo.getListeners();
// Must remove from map in the locked block
// that got the listeners. Otherwise a new
// listener might miss the event??
map.remove(urlText);
}
if(listeners != null) {
int llength = listeners.length;
for(int i = 0; i < llength; i++) {
// Call holding no locks
listeners[i].imageLoaded(newEvent);
}
}
}
}
});
SecurityManager sm = System.getSecurityManager();
if(sm == null) {
try {
httpRequest.open("GET", url, true);
httpRequest.send(null);
} catch(java.io.IOException thrown) {
logger.log(Level.WARNING, "loadImage()", thrown);
}
}
else {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
// Code might have restrictions on accessing
// items from elsewhere.
try {
httpRequest.open("GET", url, true);
httpRequest.send(null);
} catch(java.io.IOException thrown) {
logger.log(Level.WARNING, "loadImage()", thrown);
}
return null;
}
});
}
}
}
if(event != null) {
// Call holding no locks.
imageListener.imageLoaded(event);
}
}
private Function onloadHandler;
public Function getOnloadHandler() {
return onloadHandler;
}
public void setOnloadHandler(Function onloadHandler) {
this.onloadHandler = onloadHandler;
}
public Object setUserData(String key, Object data, UserDataHandler handler) {
Function onloadHandler = this.onloadHandler;
if(onloadHandler != null) {
if(org.lobobrowser.html.parser.HtmlParser.MODIFYING_KEY.equals(key) && data == Boolean.FALSE) {
//TODO: onload event object?
Executor.executeFunction(this, onloadHandler, null);
}
}
return super.setUserData(key, data, handler);
}
protected Node createSimilarNode() {
return new HTMLDocumentImpl(this.ucontext, this.rcontext, this.reader, this.documentURI);
}
private static class ImageInfo {
// Access to this class is synchronized on imageInfos.
public ImageEvent imageEvent;
public boolean loaded;
private ArrayList listeners = new ArrayList(1);
void addListener(ImageListener listener) {
this.listeners.add(listener);
}
ImageListener[] getListeners() {
return (ImageListener[]) this.listeners.toArray(ImageListener.EMPTY_ARRAY);
}
}
private class ImageFilter implements NodeFilter {
public boolean accept(Node node) {
return "IMG".equalsIgnoreCase(node.getNodeName());
}
}
private class AppletFilter implements NodeFilter {
public boolean accept(Node node) {
//TODO: "OBJECT" elements that are applets too.
return "APPLET".equalsIgnoreCase(node.getNodeName());
}
}
private class LinkFilter implements NodeFilter {
public boolean accept(Node node) {
return node instanceof HTMLLinkElement;
}
}
private class AnchorFilter implements NodeFilter {
public boolean accept(Node node) {
String nodeName = node.getNodeName();
return "A".equalsIgnoreCase(nodeName) || "ANCHOR".equalsIgnoreCase(nodeName);
}
}
private class FormFilter implements NodeFilter {
public boolean accept(Node node) {
String nodeName = node.getNodeName();
return "FORM".equalsIgnoreCase(nodeName);
}
}
private class FrameFilter implements NodeFilter {
public boolean accept(Node node) {
return node instanceof org.w3c.dom.html2.HTMLFrameElement ||
node instanceof org.w3c.dom.html2.HTMLIFrameElement;
}
}
// private class BodyFilter implements NodeFilter {
// public boolean accept(Node node) {
// return node instanceof org.w3c.dom.html2.HTMLBodyElement;
// }
// }
private class ElementNameFilter implements NodeFilter {
private final String name;
public ElementNameFilter(String name) {
this.name = name;
}
public boolean accept(Node node) {
//TODO: Case sensitive?
return (node instanceof Element) &&
this.name.equals(((Element) node).getAttribute("name"));
}
}
private class ElementFilter implements NodeFilter {
public ElementFilter() {
}
public boolean accept(Node node) {
return node instanceof Element;
}
}
private class TagNameFilter implements NodeFilter {
private final String name;
public TagNameFilter(String name) {
this.name = name;
}
public boolean accept(Node node) {
if(!(node instanceof Element)) {
return false;
}
String n = this.name;
return n.equalsIgnoreCase(((Element) node).getTagName());
}
}
/**
* Tag class that also notifies document
* when text is written to an open buffer.
* @author J. H. S.
*/
private class LocalWritableLineReader extends WritableLineReader {
/**
* @param reader
*/
public LocalWritableLineReader(LineNumberReader reader) {
super(reader);
}
/**
* @param reader
*/
public LocalWritableLineReader(Reader reader) {
super(reader);
}
public void write(String text) throws IOException {
super.write(text);
if("".equals(text)) {
openBufferChanged(text);
}
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLElementBuilder.java 0000644 0001750 0001750 00000022064 11047522134 027762 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 8, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.html2.*;
public abstract class HTMLElementBuilder {
public final HTMLElement create(HTMLDocument document, String name) {
HTMLElementImpl element = this.build(name);
element.setOwnerDocument(document);
return element;
}
protected abstract HTMLElementImpl build(String name);
public static class Html extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLHtmlElementImpl(name);
}
}
public static class Title extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLTitleElementImpl(name);
}
}
public static class Base extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLBaseElementImpl(name);
}
}
public static class Body extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLBodyElementImpl(name);
}
}
public static class Span extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLSpanElementImpl(name);
}
}
public static class Script extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLScriptElementImpl(name);
}
}
public static class Img extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLImageElementImpl(name);
}
}
public static class Style extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLStyleElementImpl(name);
}
}
public static class Table extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLTableElementImpl(name);
}
}
public static class Td extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLTableCellElementImpl(name);
}
}
public static class Th extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLTableHeadElementImpl(name);
}
}
public static class Tr extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLTableRowElementImpl(name);
}
}
public static class Link extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLLinkElementImpl(name);
}
}
public static class Anchor extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLLinkElementImpl(name);
}
}
public static class Form extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLFormElementImpl(name);
}
}
public static class Input extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLInputElementImpl(name);
}
}
public static class Button extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLButtonElementImpl(name);
}
}
public static class Textarea extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLTextAreaElementImpl(name);
}
}
public static class Select extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLSelectElementImpl(name);
}
}
public static class Option extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLOptionElementImpl(name);
}
}
public static class Frameset extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLFrameSetElementImpl(name);
}
}
public static class Frame extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLFrameElementImpl(name);
}
}
public static class Ul extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLUListElementImpl(name);
}
}
public static class Ol extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLOListElementImpl(name);
}
}
public static class Li extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLLIElementImpl(name);
}
}
public static class Pre extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLPreElementImpl(name);
}
}
public static class Div extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLDivElementImpl(name);
}
}
public static class Blockquote extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLBlockQuoteElementImpl(name);
}
}
public static class Hr extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLHRElementImpl(name);
}
}
public static class Br extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLBRElementImpl(name);
}
}
public static class P extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLPElementImpl(name);
}
}
public static class GenericMarkup extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLGenericMarkupElement(name);
}
}
public static class HtmlObject extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLObjectElementImpl(name);
}
}
public static class Applet extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLAppletElementImpl(name);
}
}
public static class IFrame extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLIFrameElementImpl(name);
}
}
public static class BaseFont extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLBaseFontElementImpl(name);
}
}
public static class Font extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLFontElementImpl(name);
}
}
public static class Tt extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLMonospacedElementImpl(name);
}
}
public static class Code extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLMonospacedElementImpl(name);
}
}
public static class Heading extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLHeadingElementImpl(name);
}
}
public static class Small extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLFontSizeChangeElementImpl(name, -1);
}
}
public static class Big extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLFontSizeChangeElementImpl(name, +1);
}
}
public static class Em extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLEmElementImpl(name);
}
}
public static class Strong extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLStrongElementImpl(name);
}
}
public static class Underline extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLUnderlineElementImpl(name);
}
}
public static class Strike extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLStrikeElementImpl(name);
}
}
public static class Center extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLCenterElementImpl(name);
}
}
public static class NonStandard extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLNonStandardElement(name);
}
}
public static class Sup extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLSuperscriptElementImpl(name,1);
}
}
public static class Sub extends HTMLElementBuilder {
public HTMLElementImpl build(String name) {
return new HTMLSuperscriptElementImpl(name,-1);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLElementImpl.java 0000644 0001750 0001750 00000057200 11134547602 027301 0 ustar twerner twerner /* GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Sep 3, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.FormInput;
import org.lobobrowser.html.parser.HtmlParser;
import org.lobobrowser.html.style.*;
import org.lobobrowser.util.*;
import org.w3c.css.sac.InputSource;
import org.w3c.dom.*;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.html2.*;
import com.steadystate.css.parser.CSSOMParser;
import java.io.*;
import java.util.*;
import java.util.logging.*;
public class HTMLElementImpl extends ElementImpl implements HTMLElement, CSS2PropertiesContext {
private final boolean noStyleSheet;
public HTMLElementImpl(String name, boolean noStyleSheet) {
super(name);
this.noStyleSheet = noStyleSheet;
}
public HTMLElementImpl(String name) {
super(name);
this.noStyleSheet = false;
}
private volatile AbstractCSS2Properties currentStyleDeclarationState;
private volatile AbstractCSS2Properties localStyleDeclarationState;
protected final void forgetLocalStyle() {
synchronized(this) {
this.currentStyleDeclarationState = null;
this.localStyleDeclarationState = null;
this.computedStyles = null;
}
}
protected final void forgetStyle(boolean deep) {
//TODO: OPTIMIZATION: If we had a ComputedStyle map in
//window (Mozilla model) the map could be cleared in one shot.
synchronized(this) {
this.currentStyleDeclarationState = null;
this.computedStyles = null;
this.isHoverStyle = null;
this.hasHoverStyleByElement = null;
if(deep) {
java.util.ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
Object node = i.next();
if(node instanceof HTMLElementImpl) {
((HTMLElementImpl) node).forgetStyle(deep);
}
}
}
}
}
}
/**
* Gets the style object associated with the element.
* It may return null only if the type of element does not handle stylesheets.
*/
public AbstractCSS2Properties getCurrentStyle() {
AbstractCSS2Properties sds;
synchronized(this) {
sds = this.currentStyleDeclarationState;
if(sds != null) {
return sds;
}
}
// Can't do the following in synchronized block (reverse locking order with document).
// First, add declarations from stylesheet
sds = this.createDefaultStyleSheet();
sds = this.addStyleSheetDeclarations(sds, this.getPseudoNames());
// Now add local style if any.
AbstractCSS2Properties localStyle = this.getStyle();
if(sds == null) {
sds = new ComputedCSS2Properties(this);
sds.setLocalStyleProperties(localStyle);
}
else {
sds.setLocalStyleProperties(localStyle);
}
synchronized(this) {
// Check if style properties were set while outside
// the synchronized block (can happen).
AbstractCSS2Properties setProps = this.currentStyleDeclarationState;
if(setProps != null) {
return setProps;
}
this.currentStyleDeclarationState = sds;
return sds;
}
}
/**
* Gets the local style object associated with the element. The properties
* object returned only includes properties from the local style attribute.
* It may return null only if the type of element does not handle stylesheets.
*/
public AbstractCSS2Properties getStyle() {
AbstractCSS2Properties sds;
synchronized(this) {
sds = this.localStyleDeclarationState;
if(sds != null) {
return sds;
}
sds = new LocalCSS2Properties(this);
// Add any declarations in style attribute (last takes precedence).
String style = this.getAttribute("style");
if(style != null && style.length() != 0) {
CSSOMParser parser = new CSSOMParser();
InputSource inputSource = this.getCssInputSourceForDecl(style);
try {
CSSStyleDeclaration sd = parser.parseStyleDeclaration(inputSource);
sds.addStyleDeclaration(sd);
} catch(Exception err) {
String id = this.getId();
String withId = id == null ? "" : " with ID '" + id + "'";
this.warn("Unable to parse style attribute value for element " + this.getTagName() + withId + " in " + this.getDocumentURL() + ".", err);
}
}
this.localStyleDeclarationState = sds;
}
// Synchronization note: Make sure getStyle() does not return multiple values.
return sds;
}
protected AbstractCSS2Properties createDefaultStyleSheet() {
// Override to provide element defaults.
return null;
}
private Map computedStyles;
public AbstractCSS2Properties getComputedStyle(String pseudoElement) {
if(pseudoElement == null) {
pseudoElement = "";
}
synchronized(this) {
Map cs = this.computedStyles;
if(cs != null) {
AbstractCSS2Properties sds = (AbstractCSS2Properties) cs.get(pseudoElement);
if(sds != null) {
return sds;
}
}
}
// Can't do the following in synchronized block (reverse locking order with document).
// First, add declarations from stylesheet
Set pes = pseudoElement.length() == 0 ? null : Collections.singleton(pseudoElement);
AbstractCSS2Properties sds = this.createDefaultStyleSheet();
sds = this.addStyleSheetDeclarations(sds, pes);
// Now add local style if any.
AbstractCSS2Properties localStyle = this.getStyle();
if(sds == null) {
sds = new ComputedCSS2Properties(this);
sds.setLocalStyleProperties(localStyle);
}
else {
sds.setLocalStyleProperties(localStyle);
}
synchronized(this) {
// Check if style properties were set while outside
// the synchronized block (can happen). We need to
// return instance already set for consistency.
Map cs = this.computedStyles;
if(cs == null) {
cs = new HashMap(2);
this.computedStyles = cs;
}
else {
AbstractCSS2Properties sds2 = (AbstractCSS2Properties) cs.get(pseudoElement);
if(sds2 != null) {
return sds2;
}
}
cs.put(pseudoElement, sds);
}
return sds;
}
public void setStyle(Object value) {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot set style property");
}
public void setCurrentStyle(Object value) {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot set currentStyle property");
}
public String getClassName() {
String className = this.getAttribute("class");
// Blank required instead of null.
return className == null ? "" : className;
}
public void setClassName(String className) {
this.setAttribute("class", className);
}
public String getCharset() {
return this.getAttribute("charset");
}
public void setCharset(String charset) {
this.setAttribute("charset", charset);
}
public void warn(String message, Throwable err) {
logger.log(Level.WARNING, message, err);
}
public void warn(String message) {
logger.log(Level.WARNING, message);
}
protected int getAttributeAsInt(String name, int defaultValue) {
String value = this.getAttribute(name);
try {
return Integer.parseInt(value);
} catch(Exception err) {
this.warn("Bad integer", err);
return defaultValue;
}
}
public boolean getAttributeAsBoolean(String name) {
return this.getAttribute(name) != null;
}
protected void assignAttributeField(String normalName, String value) {
if(!this.notificationsSuspended) {
this.informInvalidAttibute(normalName);
}
else {
if("style".equals(normalName)) {
this.forgetLocalStyle();
}
}
super.assignAttributeField(normalName, value);
}
protected final InputSource getCssInputSourceForDecl(String text) {
java.io.Reader reader = new StringReader("{" + text + "}");
InputSource is = new InputSource(reader);
return is;
}
/**
* Adds style sheet declarations applicable
* to this element.
* A properties object is created if necessary
* when the one passed is null
.
* @param style
*/
protected final AbstractCSS2Properties addStyleSheetDeclarations(AbstractCSS2Properties style, Set pseudoNames) {
Node pn = this.parentNode;
if(pn == null) {
// do later
return style;
}
String classNames = this.getClassName();
if(classNames != null && classNames.length() != 0) {
String id = this.getId();
String elementName = this.getTagName();
String[] classNameArray = Strings.split(classNames);
for(int i = classNameArray.length; --i >= 0;) {
String className = classNameArray[i];
Collection sds = this.findStyleDeclarations(elementName, id, className, pseudoNames);
if(sds != null) {
Iterator sdsi = sds.iterator();
while(sdsi.hasNext()) {
CSSStyleDeclaration sd = (CSSStyleDeclaration) sdsi.next();
if(style == null) {
style = new ComputedCSS2Properties(this);
}
style.addStyleDeclaration(sd);
}
}
}
}
else {
String id = this.getId();
String elementName = this.getTagName();
Collection sds = this.findStyleDeclarations(elementName, id, null, pseudoNames);
if(sds != null) {
Iterator sdsi = sds.iterator();
while(sdsi.hasNext()) {
CSSStyleDeclaration sd = (CSSStyleDeclaration) sdsi.next();
if(style == null) {
style = new ComputedCSS2Properties(this);
}
style.addStyleDeclaration(sd);
}
}
}
return style;
}
private boolean isMouseOver = false;
public void setMouseOver(boolean mouseOver) {
if(this.isMouseOver != mouseOver) {
// Change isMouseOver field before checking to invalidate.
this.isMouseOver = mouseOver;
// Check if descendents are affected (e.g. div:hover a { ... } )
this.invalidateDescendentsForHover();
if(this.hasHoverStyle()) {
//TODO: OPTIMIZATION: In some cases it should be much
//better to simply invalidate the "look" of the node.
this.informInvalid();
}
}
}
private void invalidateDescendentsForHover() {
synchronized(this.treeLock) {
this.invalidateDescendentsForHoverImpl(this);
}
}
private void invalidateDescendentsForHoverImpl(HTMLElementImpl ancestor) {
ArrayList nodeList = this.nodeList;
if(nodeList != null) {
int size = nodeList.size();
for(int i = 0; i < size; i++) {
Object node = nodeList.get(i);
if(node instanceof HTMLElementImpl) {
HTMLElementImpl descendent = (HTMLElementImpl) node;
if(descendent.hasHoverStyle(ancestor)) {
descendent.informInvalid();
}
descendent.invalidateDescendentsForHoverImpl(ancestor);
}
}
}
}
private Boolean isHoverStyle = null;
private Map hasHoverStyleByElement = null;
private boolean hasHoverStyle() {
Boolean ihs;
synchronized(this) {
ihs = this.isHoverStyle;
if(ihs != null) {
return ihs.booleanValue();
}
}
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc == null) {
ihs = Boolean.FALSE;
}
else {
StyleSheetAggregator ssa = doc.getStyleSheetAggregator();
String id = this.getId();
String elementName = this.getTagName();
String classNames = this.getClassName();
String[] classNameArray = null;
if(classNames != null && classNames.length() != 0) {
classNameArray = Strings.split(classNames);
}
ihs = Boolean.valueOf(ssa.affectedByPseudoNameInAncestor(this, this, elementName, id, classNameArray, "hover"));
}
synchronized(this) {
this.isHoverStyle = ihs;
}
return ihs.booleanValue();
}
private boolean hasHoverStyle(HTMLElementImpl ancestor) {
Map ihs;
synchronized(this) {
ihs = this.hasHoverStyleByElement;
if(ihs != null) {
Boolean f = (Boolean) ihs.get(ancestor);
if(f != null) {
return f.booleanValue();
}
}
}
Boolean hhs;
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc == null) {
hhs = Boolean.FALSE;
}
else {
StyleSheetAggregator ssa = doc.getStyleSheetAggregator();
String id = this.getId();
String elementName = this.getTagName();
String classNames = this.getClassName();
String[] classNameArray = null;
if(classNames != null && classNames.length() != 0) {
classNameArray = Strings.split(classNames);
}
hhs = Boolean.valueOf(ssa.affectedByPseudoNameInAncestor(this, ancestor, elementName, id, classNameArray, "hover"));
}
synchronized(this) {
ihs = this.hasHoverStyleByElement;
if(ihs == null) {
ihs = new HashMap(2);
this.hasHoverStyleByElement = ihs;
}
ihs.put(ancestor, hhs);
}
return hhs.booleanValue();
}
/**
* Gets the pseudo-element lowercase names currently
* applicable to this element. Method must return
* null
if there are no such
* pseudo-elements.
*/
public Set getPseudoNames() {
Set pnset = null;
if(this.isMouseOver) {
if(pnset == null) {
pnset = new HashSet(1);
}
pnset.add("hover");
}
return pnset;
}
protected final Collection findStyleDeclarations(String elementName, String id, String className, Set pseudoNames) {
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc == null) {
return null;
}
StyleSheetAggregator ssa = doc.getStyleSheetAggregator();
return ssa.getActiveStyleDeclarations(this, elementName, id, className, pseudoNames);
}
public void informInvalid() {
// This is called when an attribute or child changes.
this.forgetStyle(false);
super.informInvalid();
}
public void informInvalidAttibute(String normalName) {
// This is called when an attribute changes while
// the element is allowing notifications.
if("style".equals(normalName)) {
this.forgetLocalStyle();
}
else if("id".equals(normalName) || "class".equals(normalName)) {
this.forgetStyle(false);
}
// Call super implementation of informValid().
super.informInvalid();
}
/**
* Gets form input due to the current element. It should
* return null
except when the element is a form input element.
*/
protected FormInput[] getFormInputs() {
// Override in input elements
return null;
}
private boolean classMatch(String classTL) {
String classNames = this.getClassName();
if(classNames == null || classNames.length() == 0) {
return classTL == null;
}
StringTokenizer tok = new StringTokenizer(classNames, " \t\r\n");
while(tok.hasMoreTokens()) {
String token = tok.nextToken();
if(token.toLowerCase().equals(classTL)) {
return true;
}
}
return false;
}
/**
* Get an ancestor that matches the element tag name given and the
* style class given.
* @param elementTL An tag name in lowercase or an asterisk (*).
* @param classTL A class name in lowercase.
*/
public HTMLElementImpl getAncestorWithClass(String elementTL, String classTL) {
Object nodeObj = this.getParentNode();
if(nodeObj instanceof HTMLElementImpl) {
HTMLElementImpl parentElement = (HTMLElementImpl) nodeObj;
String pelementTL = parentElement.getTagName().toLowerCase();
if(("*".equals(elementTL) || elementTL.equals(pelementTL)) && parentElement.classMatch(classTL)) {
return parentElement;
}
return parentElement.getAncestorWithClass(elementTL, classTL);
}
else {
return null;
}
}
public HTMLElementImpl getParentWithClass(String elementTL, String classTL) {
Object nodeObj = this.getParentNode();
if(nodeObj instanceof HTMLElementImpl) {
HTMLElementImpl parentElement = (HTMLElementImpl) nodeObj;
String pelementTL = parentElement.getTagName().toLowerCase();
if(("*".equals(elementTL) || elementTL.equals(pelementTL)) && parentElement.classMatch(classTL)) {
return parentElement;
}
}
return null;
}
public HTMLElementImpl getPreceedingSiblingElement() {
Node parentNode = this.getParentNode();
if(parentNode == null) {
return null;
}
NodeList childNodes = parentNode.getChildNodes();
if(childNodes == null) {
return null;
}
int length = childNodes.getLength();
HTMLElementImpl priorElement = null;
for(int i = 0; i < length; i++) {
Node child = childNodes.item(i);
if(child == this) {
return priorElement;
}
if(child instanceof HTMLElementImpl) {
priorElement = (HTMLElementImpl) child;
}
}
return null;
}
public HTMLElementImpl getPreceedingSiblingWithClass(String elementTL, String classTL) {
HTMLElementImpl psibling = this.getPreceedingSiblingElement();
if(psibling != null) {
String pelementTL = psibling.getTagName().toLowerCase();
if(("*".equals(elementTL) || elementTL.equals(pelementTL)) && psibling.classMatch(classTL)) {
return psibling;
}
}
return null;
}
public HTMLElementImpl getAncestorWithId(String elementTL, String idTL) {
Object nodeObj = this.getParentNode();
if(nodeObj instanceof HTMLElementImpl) {
HTMLElementImpl parentElement = (HTMLElementImpl) nodeObj;
String pelementTL = parentElement.getTagName().toLowerCase();
String pid = parentElement.getId();
String pidTL = pid == null ? null : pid.toLowerCase();
if(("*".equals(elementTL) || elementTL.equals(pelementTL)) && idTL.equals(pidTL)) {
return parentElement;
}
return parentElement.getAncestorWithId(elementTL, idTL);
}
else {
return null;
}
}
public HTMLElementImpl getParentWithId(String elementTL, String idTL) {
Object nodeObj = this.getParentNode();
if(nodeObj instanceof HTMLElementImpl) {
HTMLElementImpl parentElement = (HTMLElementImpl) nodeObj;
String pelementTL = parentElement.getTagName().toLowerCase();
String pid = parentElement.getId();
String pidTL = pid == null ? null : pid.toLowerCase();
if(("*".equals(elementTL) || elementTL.equals(pelementTL)) && idTL.equals(pidTL)) {
return parentElement;
}
}
return null;
}
public HTMLElementImpl getPreceedingSiblingWithId(String elementTL, String idTL) {
HTMLElementImpl psibling = this.getPreceedingSiblingElement();
if(psibling != null) {
String pelementTL = psibling.getTagName().toLowerCase();
String pid = psibling.getId();
String pidTL = pid == null ? null : pid.toLowerCase();
if(("*".equals(elementTL) || elementTL.equals(pelementTL)) && idTL.equals(pidTL)) {
return psibling;
}
}
return null;
}
public HTMLElementImpl getAncestor(String elementTL) {
Object nodeObj = this.getParentNode();
if(nodeObj instanceof HTMLElementImpl) {
HTMLElementImpl parentElement = (HTMLElementImpl) nodeObj;
if("*".equals(elementTL)) {
return parentElement;
}
String pelementTL = parentElement.getTagName().toLowerCase();
if(elementTL.equals(pelementTL)) {
return parentElement;
}
return parentElement.getAncestor(elementTL);
}
else {
return null;
}
}
public HTMLElementImpl getParent(String elementTL) {
Object nodeObj = this.getParentNode();
if(nodeObj instanceof HTMLElementImpl) {
HTMLElementImpl parentElement = (HTMLElementImpl) nodeObj;
if("*".equals(elementTL)) {
return parentElement;
}
String pelementTL = parentElement.getTagName().toLowerCase();
if(elementTL.equals(pelementTL)) {
return parentElement;
}
}
return null;
}
public HTMLElementImpl getPreceedingSibling(String elementTL) {
HTMLElementImpl psibling = this.getPreceedingSiblingElement();
if(psibling != null) {
if("*".equals(elementTL)) {
return psibling;
}
String pelementTL = psibling.getTagName().toLowerCase();
if(elementTL.equals(pelementTL)) {
return psibling;
}
}
return null;
}
protected Object getAncestorForJavaClass(Class javaClass) {
Object nodeObj = this.getParentNode();
if(nodeObj == null || javaClass.isInstance(nodeObj)) {
return nodeObj;
}
else if(nodeObj instanceof HTMLElementImpl) {
return ((HTMLElementImpl) nodeObj).getAncestorForJavaClass(javaClass);
}
else {
return null;
}
}
public void setInnerHTML(String newHtml) {
HTMLDocumentImpl document = (HTMLDocumentImpl) this.document;
if(document == null) {
this.warn("setInnerHTML(): Element " + this + " does not belong to a document.");
return;
}
HtmlParser parser = new HtmlParser(document.getUserAgentContext(), document, null, null, null);
synchronized(this) {
ArrayList nl = this.nodeList;
if (nl != null) {
nl.clear();
}
}
// Should not synchronize around parser probably.
try {
Reader reader = new StringReader(newHtml);
try {
parser.parse(reader, this);
} finally {
reader.close();
}
} catch(Exception thrown) {
this.warn("setInnerHTML(): Error setting inner HTML.", thrown);
}
}
public String getOuterHTML() {
StringBuffer buffer = new StringBuffer();
synchronized(this) {
this.appendOuterHTMLImpl(buffer);
}
return buffer.toString();
}
protected void appendOuterHTMLImpl(StringBuffer buffer) {
String tagName = this.getTagName();
buffer.append('<');
buffer.append(tagName);
Map attributes = this.attributes;
if(attributes != null) {
Iterator i = attributes.entrySet().iterator();
while(i.hasNext()) {
Map.Entry entry = (Map.Entry) i.next();
String value = (String) entry.getValue();
if(value != null) {
buffer.append(' ');
buffer.append(entry.getKey());
buffer.append("=\"");
buffer.append(Strings.strictHtmlEncode(value, true));
buffer.append("\"");
}
}
}
ArrayList nl = this.nodeList;
if(nl == null || nl.size() == 0) {
buffer.append("/>");
return;
}
buffer.append('>');
this.appendInnerHTMLImpl(buffer);
buffer.append("");
buffer.append(tagName);
buffer.append('>');
}
protected RenderState createRenderState(RenderState prevRenderState) {
// Overrides NodeImpl method
// Called in synchronized block already
return new StyleSheetRenderState(prevRenderState, this);
}
public int getOffsetTop() {
//TODO: Sometimes this can be called while parsing, and
//browsers generally give the right answer.
UINode uiNode = this.getUINode();
return uiNode == null ? 0 : uiNode.getBoundsRelativeToBlock().y;
}
public int getOffsetLeft() {
UINode uiNode = this.getUINode();
return uiNode == null ? 0 : uiNode.getBoundsRelativeToBlock().x;
}
public int getOffsetWidth() {
UINode uiNode = this.getUINode();
return uiNode == null ? 0 : uiNode.getBoundsRelativeToBlock().width;
}
public int getOffsetHeight() {
UINode uiNode = this.getUINode();
return uiNode == null ? 0 : uiNode.getBoundsRelativeToBlock().height;
}
public AbstractCSS2Properties getParentStyle() {
Object parent = this.parentNode;
if(parent instanceof HTMLElementImpl) {
return ((HTMLElementImpl) parent).getCurrentStyle();
}
return null;
}
public String getDocumentBaseURI() {
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
return doc.getBaseURI();
}
else {
return null;
}
}
public String toString() {
return super.toString() + "[currentStyle=" + this.getCurrentStyle() + "]";
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLEmElementImpl.java 0000644 0001750 0001750 00000002536 10726473512 027571 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
/**
* Element used for I, EM and CITE.
*/
public class HTMLEmElementImpl extends HTMLAbstractUIElement {
public HTMLEmElementImpl(String name) {
super(name);
}
protected RenderState createRenderState(RenderState prevRenderState) {
prevRenderState = new FontStyleRenderState(prevRenderState, java.awt.Font.ITALIC);
return super.createRenderState(prevRenderState);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLFontElementImpl.java 0000644 0001750 0001750 00000006245 11134556006 030131 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.AbstractCSS2Properties;
import org.lobobrowser.html.style.BaseFontRenderState;
import org.lobobrowser.html.style.ColorRenderState;
import org.lobobrowser.html.style.ComputedCSS2Properties;
import org.lobobrowser.html.style.FontNameRenderState;
import org.lobobrowser.html.style.HtmlValues;
import org.lobobrowser.html.style.RenderState;
import org.lobobrowser.util.gui.ColorFactory;
import org.w3c.dom.html2.HTMLFontElement;
public class HTMLFontElementImpl extends HTMLAbstractUIElement implements
HTMLFontElement {
public HTMLFontElementImpl(String name) {
super(name);
}
public String getColor() {
return this.getAttribute("color");
}
public String getFace() {
return this.getAttribute("face");
}
public String getSize() {
return this.getAttribute("size");
}
public void setColor(String color) {
this.setAttribute("color", color);
}
public void setFace(String face) {
this.setAttribute("face", face);
}
public void setSize(String size) {
this.setAttribute("size", size);
}
protected RenderState createRenderState(RenderState prevRenderState) {
return super.createRenderState(prevRenderState);
}
protected AbstractCSS2Properties createDefaultStyleSheet() {
String fontFamily = this.getAttribute("face");
String color = this.getAttribute("color");
String size = this.getAttribute("size");
String fontSize = null;
if(size != null) {
ModelNode parentModelNode = this.getParentModelNode();
RenderState parentRS = parentModelNode == null ? null : parentModelNode.getRenderState();
if(parentRS != null) {
int fontNumber = HtmlValues.getFontNumberOldStyle(size, parentRS);
fontSize = HtmlValues.getFontSizeSpec(fontNumber);
}
}
ComputedCSS2Properties css = new ComputedCSS2Properties(this);
if(fontSize != null) {
css.internalSetLC("font-size", fontSize);
}
if(fontFamily != null) {
css.internalSetLC("font-family", fontFamily);
}
if(color != null) {
css.internalSetLC("color", color);
}
return css;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLFontSizeChangeElementImpl.java 0000644 0001750 0001750 00000003766 11134547262 032103 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
/**
* This element is used for SMALL and BIG.
*/
public class HTMLFontSizeChangeElementImpl extends HTMLAbstractUIElement {
private final int fontChange;
public HTMLFontSizeChangeElementImpl(String name, int fontChange) {
super(name);
this.fontChange = fontChange;
}
protected RenderState createRenderState(RenderState prevRenderState) {
return super.createRenderState(prevRenderState);
}
protected AbstractCSS2Properties createDefaultStyleSheet() {
ModelNode parentModelNode = this.getParentModelNode();
RenderState parentRS = parentModelNode == null ? null : parentModelNode.getRenderState();
String fontSize = null;
int prevFontSize = parentRS != null ? parentRS.getFont().getSize() : HtmlValues.DEFAULT_FONT_SIZE_INT;
int newFontSize = prevFontSize + (this.fontChange * 2);
fontSize = newFontSize + "px";
ComputedCSS2Properties css = new ComputedCSS2Properties(this);
css.internalSetLC("font-size", fontSize);
return css;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLFormElementImpl.java 0000644 0001750 0001750 00000014530 10763034036 030123 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 14, 2006
*/
package org.lobobrowser.html.domimpl;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.html2.HTMLCollection;
import org.w3c.dom.html2.HTMLFormElement;
import org.lobobrowser.html.FormInput;
import org.lobobrowser.html.HtmlRendererContext;
import org.lobobrowser.html.js.*;
import org.mozilla.javascript.*;
public class HTMLFormElementImpl extends HTMLAbstractUIElement implements
HTMLFormElement {
public HTMLFormElementImpl(String name) {
super(name);
}
public HTMLFormElementImpl() {
super("FORM");
}
public Object namedItem(final String name) {
try {
//TODO: This could use document.namedItem.
this.visit(new NodeVisitor() {
public void visit(Node node) {
if(HTMLFormElementImpl.isInput(node)) {
if(name.equals(((Element) node).getAttribute("name"))) {
throw new StopVisitorException(node);
}
}
}
});
} catch(StopVisitorException sve) {
return sve.getTag();
}
return null;
}
public Object item(final int index) {
try {
this.visit(new NodeVisitor() {
private int current = 0;
public void visit(Node node) {
if(HTMLFormElementImpl.isInput(node)) {
if(this.current == index) {
throw new StopVisitorException(node);
}
this.current++;
}
}
});
} catch(StopVisitorException sve) {
return sve.getTag();
}
return null;
}
private HTMLCollection elements;
public HTMLCollection getElements() {
HTMLCollection elements = this.elements;
if(elements == null) {
elements = new DescendentHTMLCollection(this, new InputFilter(), this.treeLock, false);
this.elements = elements;
}
return elements;
}
public int getLength() {
return this.getElements().getLength();
}
public String getName() {
return this.getAttribute("name");
}
public void setName(String name) {
this.setAttribute("name", name);
}
public String getAcceptCharset() {
return this.getAttribute("acceptCharset");
}
public void setAcceptCharset(String acceptCharset) {
this.setAttribute("acceptCharset", acceptCharset);
}
public String getAction() {
return this.getAttribute("action");
}
public void setAction(String action) {
this.setAttribute("action", action);
}
public String getEnctype() {
return this.getAttribute("enctype");
}
public void setEnctype(String enctype) {
this.setAttribute("enctype", enctype);
}
public String getMethod() {
String method = this.getAttribute("method");
if(method == null) {
method = "GET";
}
return method;
}
public void setMethod(String method) {
this.setAttribute("method", method);
}
public String getTarget() {
return this.getAttribute("target");
}
public void setTarget(String target) {
this.setAttribute("target", target);
}
public void submit() {
this.submit(null);
}
private Function onsubmit;
public void setOnsubmit(Function value) {
this.onsubmit = value;
}
public Function getOnsubmit() {
return this.getEventFunction(this.onsubmit, "onsubmit");
}
/**
* This method should be called when form submission is
* done by a submit button.
* @param extraFormInputs Any additional form inputs that
* need to be submitted, e.g. the submit button parameter.
*/
public final void submit(final FormInput[] extraFormInputs) {
Function onsubmit = this.getOnsubmit();
if(onsubmit != null) {
//TODO: onsubmit event object?
if(!Executor.executeFunction(this, onsubmit, null)) {
return;
}
}
HtmlRendererContext context = this.getHtmlRendererContext();
if(context != null) {
final ArrayList formInputs = new ArrayList();
if(extraFormInputs != null) {
for(int i = 0; i < extraFormInputs.length; i++) {
formInputs.add(extraFormInputs[i]);
}
}
this.visit(new NodeVisitor() {
public void visit(Node node) {
if(node instanceof HTMLElementImpl) {
FormInput[] fis = ((HTMLElementImpl) node).getFormInputs();
if(fis != null) {
for(int i = 0; i < fis.length; i++) {
FormInput fi = fis[i];
if(fi.getName() == null) {
throw new IllegalStateException("Form input does not have a name: " + node);
}
formInputs.add(fi);
}
}
}
}
});
FormInput[] fia = (FormInput[]) formInputs.toArray(FormInput.EMPTY_ARRAY);
String href = this.getAction();
if(href == null) {
href = this.getBaseURI();
}
try {
URL url = this.getFullURL(href);
context.submitForm(this.getMethod(), url, this.getTarget(), this.getEnctype(), fia);
} catch(MalformedURLException mfu) {
this.warn("submit()", mfu);
}
}
}
public void reset() {
this.visit(new NodeVisitor() {
public void visit(Node node) {
if(node instanceof HTMLBaseInputElement) {
((HTMLBaseInputElement) node).resetInput();
}
}
});
}
static boolean isInput(Node node) {
String name = node.getNodeName().toLowerCase();
return name.equals("input") || name.equals("textarea") || name.equals("select");
}
private class InputFilter implements NodeFilter {
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeFilter#accept(org.w3c.dom.Node)
*/
public boolean accept(Node node) {
return HTMLFormElementImpl.isInput(node);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLFrameElementImpl.java 0000644 0001750 0001750 00000006556 10726473510 030266 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 28, 2006
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.BrowserFrame;
import org.lobobrowser.html.js.*;
import org.w3c.dom.Document;
import org.w3c.dom.html2.HTMLFrameElement;
public class HTMLFrameElementImpl extends HTMLElementImpl implements
HTMLFrameElement, FrameNode {
private volatile BrowserFrame browserFrame;
public HTMLFrameElementImpl(String name, boolean noStyleSheet) {
super(name, noStyleSheet);
}
public HTMLFrameElementImpl(String name) {
super(name);
}
public void setBrowserFrame(BrowserFrame frame) {
this.browserFrame = frame;
}
public BrowserFrame getBrowserFrame() {
return this.browserFrame;
}
public String getFrameBorder() {
return this.getAttribute("frameBorder");
}
public void setFrameBorder(String frameBorder) {
this.setAttribute("frameBorder", frameBorder);
}
public String getLongDesc() {
return this.getAttribute("longdesc");
}
public void setLongDesc(String longDesc) {
this.setAttribute("longdesc", longDesc);
}
public String getMarginHeight() {
return this.getAttribute("marginHeight");
}
public void setMarginHeight(String marginHeight) {
this.setAttribute("marginHeight", marginHeight);
}
public String getMarginWidth() {
return this.getAttribute("marginWidth");
}
public void setMarginWidth(String marginWidth) {
this.setAttribute("marginWidth", marginWidth);
}
public String getName() {
return this.getAttribute("name");
}
public void setName(String name) {
this.setAttribute("name", name);
}
private boolean noResize;
public boolean getNoResize() {
return this.noResize;
}
public void setNoResize(boolean noResize) {
this.noResize = noResize;
}
public String getScrolling() {
return this.getAttribute("scrolling");
}
public void setScrolling(String scrolling) {
this.setAttribute("scrolling", scrolling);
}
public String getSrc() {
return this.getAttribute("src");
}
public void setSrc(String src) {
this.setAttribute("src", src);
}
public Document getContentDocument() {
BrowserFrame frame = this.browserFrame;
if(frame == null) {
// Not loaded yet
return null;
}
return frame.getContentDocument();
}
public Window getContentWindow() {
BrowserFrame frame = this.browserFrame;
if(frame == null) {
// Not loaded yet
return null;
}
return Window.getWindow(frame.getHtmlRendererContext());
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLFrameSetElementImpl.java 0000644 0001750 0001750 00000003104 10726473506 030731 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 28, 2006
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.html2.HTMLFrameSetElement;
public class HTMLFrameSetElementImpl extends HTMLElementImpl implements
HTMLFrameSetElement {
public HTMLFrameSetElementImpl(String name, boolean noStyleSheet) {
super(name, noStyleSheet);
}
public HTMLFrameSetElementImpl(String name) {
super(name);
}
public String getCols() {
return this.getAttribute("cols");
}
public void setCols(String cols) {
this.setAttribute("cols", cols);
}
public String getRows() {
return this.getAttribute("rows");
}
public void setRows(String rows) {
this.setAttribute("rows", rows);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLGenericMarkupElement.java 0000644 0001750 0001750 00000000270 10641432430 031121 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
public class HTMLGenericMarkupElement extends HTMLAbstractUIElement {
public HTMLGenericMarkupElement(String name) {
super(name);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLHRElementImpl.java 0000644 0001750 0001750 00000001625 10641432432 027527 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.w3c.dom.html2.HTMLHRElement;
public class HTMLHRElementImpl extends HTMLAbstractUIElement implements HTMLHRElement {
public HTMLHRElementImpl(String name) {
super(name);
}
public String getAlign() {
return this.getAttribute("align");
}
public boolean getNoShade() {
return "noshade".equalsIgnoreCase(this.getAttribute("noshade"));
}
public String getSize() {
return this.getAttribute("size");
}
public String getWidth() {
return this.getAttribute("width");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
public void setNoShade(boolean noShade) {
this.setAttribute("noshade", noShade ? "noshade" : null);
}
public void setSize(String size) {
this.setAttribute("size", size);
}
public void setWidth(String width) {
this.setAttribute("width", width);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLHeadingElementImpl.java 0000644 0001750 0001750 00000007170 11134441044 030553 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.w3c.dom.html2.HTMLHeadingElement;
public class HTMLHeadingElementImpl extends HTMLAbstractUIElement implements
HTMLHeadingElement {
public HTMLHeadingElementImpl(String name) {
super(name);
}
public String getAlign() {
return this.getAttribute("align");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
private final float getHeadingFontSize() {
String tagName = this.getTagName();
try {
int lastCharValue = tagName.charAt(1) - '0';
switch(lastCharValue) {
case 1:
return 24.0f;
case 2:
return 18.0f;
case 3:
return 15.0f;
case 4:
return 12.0f;
case 5:
return 10.0f;
case 6:
return 8.0f;
}
} catch(Exception thrown) {
this.warn("getHeadingFontSize(): Bad heading tag: " + this.getTagName(), thrown);
}
return 14.0f;
}
private final String getHeadingFontSizeText() {
String tagName = this.getTagName();
try {
int lastCharValue = tagName.charAt(1) - '0';
switch(lastCharValue) {
case 1:
return "24pt";
case 2:
return "18pt";
case 3:
return "13.55pt";
case 4:
return "12pt";
case 5:
return "10pt";
case 6:
return "7.55pt";
}
} catch(Exception thrown) {
this.warn("getHeadingFontSizeText(): Bad heading tag: " + this.getTagName(), thrown);
}
return "14px";
}
protected RenderState createRenderState(RenderState prevRenderState) {
float fontSize = this.getHeadingFontSize();
//(can't put a RenderState in the middle - messes up "em" sizes).
//prevRenderState = new FontSizeRenderState(prevRenderState, fontSize, java.awt.Font.BOLD);
return new HeadingRenderState(prevRenderState, this);
}
protected void appendInnerTextImpl(StringBuffer buffer) {
int length = buffer.length();
int lineBreaks;
if(length == 0) {
lineBreaks = 2;
}
else {
int start = length - 4;
if (start < 0) {
start = 0;
}
lineBreaks = 0;
for(int i = start; i < length; i++) {
char ch = buffer.charAt(i);
if(ch == '\n') {
lineBreaks++;
}
}
}
for(int i = 0; i < 2 - lineBreaks; i++) {
buffer.append("\r\n");
}
super.appendInnerTextImpl(buffer);
buffer.append("\r\n\r\n");
}
protected AbstractCSS2Properties createDefaultStyleSheet() {
ComputedCSS2Properties css = new ComputedCSS2Properties(this);
css.internalSetLC("font-size", this.getHeadingFontSizeText());
css.internalSetLC("font-weight", "bolder");
return css;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLHtmlElementImpl.java 0000644 0001750 0001750 00000002612 10726473504 030130 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 8, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.html2.HTMLHtmlElement;
public class HTMLHtmlElementImpl extends HTMLElementImpl implements
HTMLHtmlElement {
public HTMLHtmlElementImpl() {
super("HTML", true);
}
public HTMLHtmlElementImpl(String name) {
super(name, true);
}
public String getVersion() {
return this.getAttribute("version");
}
public void setVersion(String version) {
this.setAttribute("version", version);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLIFrameElementImpl.java 0000644 0001750 0001750 00000007151 11130344650 030357 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.*;
import org.lobobrowser.html.js.Window;
import org.lobobrowser.html.style.*;
import org.lobobrowser.util.gui.ColorFactory;
import org.w3c.dom.Document;
import org.w3c.dom.html2.HTMLIFrameElement;
public class HTMLIFrameElementImpl extends HTMLAbstractUIElement implements
HTMLIFrameElement, FrameNode {
private volatile BrowserFrame browserFrame;
public HTMLIFrameElementImpl(String name) {
super(name);
}
public void setBrowserFrame(BrowserFrame frame) {
this.browserFrame = frame;
if(frame != null) {
String src = this.getAttribute("src");
if(src != null) {
try {
frame.loadURL(this.getFullURL(src));
} catch(java.net.MalformedURLException mfu) {
this.warn("setBrowserFrame(): Unable to navigate to src.", mfu);
}
}
}
}
public BrowserFrame getBrowserFrame() {
return this.browserFrame;
}
public String getAlign() {
return this.getAttribute("align");
}
public Document getContentDocument() {
//TODO: Domain-based security
BrowserFrame frame = this.browserFrame;
if(frame == null) {
// Not loaded yet
return null;
}
return frame.getContentDocument();
}
public Window getContentWindow() {
BrowserFrame frame = this.browserFrame;
if(frame == null) {
// Not loaded yet
return null;
}
return Window.getWindow(frame.getHtmlRendererContext());
}
public String getFrameBorder() {
return this.getAttribute("frameborder");
}
public String getHeight() {
return this.getAttribute("height");
}
public String getLongDesc() {
return this.getAttribute("longdesc");
}
public String getMarginHeight() {
return this.getAttribute("marginheight");
}
public String getMarginWidth() {
return this.getAttribute("marginwidth");
}
public String getName() {
return this.getAttribute("name");
}
public String getScrolling() {
return this.getAttribute("scrolling");
}
public String getSrc() {
return this.getAttribute("src");
}
public String getWidth() {
return this.getAttribute("width");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
public void setFrameBorder(String frameBorder) {
this.setAttribute("frameborder", frameBorder);
}
public void setHeight(String height) {
this.setAttribute("height", height);
}
public void setLongDesc(String longDesc) {
this.setAttribute("longdesc", longDesc);
}
public void setMarginHeight(String marginHeight) {
this.setAttribute("marginHeight", marginHeight);
}
public void setMarginWidth(String marginWidth) {
this.setAttribute("marginWidth", marginWidth);
}
public void setName(String name) {
this.setAttribute("name", name);
}
public void setScrolling(String scrolling) {
this.setAttribute("scrolling", scrolling);
}
public void setSrc(String src) {
this.setAttribute("src", src);
}
public void setWidth(String width) {
this.setAttribute("width", width);
}
protected void assignAttributeField(String normalName, String value) {
if("src".equals(normalName)) {
BrowserFrame frame = this.browserFrame;
if(frame != null) {
try {
frame.loadURL(this.getFullURL(value));
} catch(java.net.MalformedURLException mfu) {
this.warn("assignAttributeField(): Unable to navigate to src.", mfu);
}
}
}
else {
super.assignAttributeField(normalName, value);
}
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new IFrameRenderState(prevRenderState, this);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLImageElementImpl.java 0000644 0001750 0001750 00000014545 10726473510 030253 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Nov 19, 2005
*/
package org.lobobrowser.html.domimpl;
import java.util.*;
import org.lobobrowser.html.js.*;
import org.lobobrowser.html.style.*;
import org.mozilla.javascript.Function;
import org.w3c.dom.html2.HTMLImageElement;
public class HTMLImageElementImpl extends HTMLAbstractUIElement implements
HTMLImageElement {
public HTMLImageElementImpl() {
super("IMG");
}
public HTMLImageElementImpl(String name) {
super(name);
}
public String getName() {
return this.getAttribute("name");
}
public void setName(String name) {
this.setAttribute("name", name);
}
public String getAlign() {
return this.getAttribute("align");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
public String getAlt() {
return this.getAttribute("alt");
}
public void setAlt(String alt) {
this.setAttribute("alt", alt);
}
public String getBorder() {
return this.getAttribute("border");
}
public void setBorder(String border) {
this.setAttribute("border", border);
}
public int getHeight() {
UINode r = this.uiNode;
return r == null ? 0 : r.getBounds().height;
}
public void setHeight(int height) {
this.setAttribute("height", String.valueOf(height));
}
public int getHspace() {
return this.getAttributeAsInt("hspace", 0);
}
public void setHspace(int hspace) {
this.setAttribute("hspace", String.valueOf("hspace"));
}
public boolean getIsMap() {
return this.getAttributeAsBoolean("isMap");
}
public void setIsMap(boolean isMap) {
this.setAttribute("isMap", isMap ? "isMap" : null);
}
public String getLongDesc() {
return this.getAttribute("longDesc");
}
public void setLongDesc(String longDesc) {
this.setAttribute("longDesc", longDesc);
}
public String getSrc() {
return this.getAttribute("src");
}
/**
* Sets the image URI and starts to load the image.
* Note that an HtmlRendererContext should be available
* to the HTML document for images to be loaded.
*/
public void setSrc(String src) {
this.setAttribute("src", src);
}
public String getUseMap() {
return this.getAttribute("useMap");
}
public void setUseMap(String useMap) {
this.setAttribute("useMap", useMap);
}
public int getVspace() {
return this.getAttributeAsInt("vspace", 0);
}
public void setVspace(int vspace) {
this.setAttribute("vspace", String.valueOf(vspace));
}
public int getWidth() {
UINode r = this.uiNode;
return r == null ? 0 : r.getBounds().width;
}
public void setWidth(int width) {
this.setAttribute("width", String.valueOf(width));
}
protected void assignAttributeField(String normalName, String value) {
super.assignAttributeField(normalName, value);
if("src".equals(normalName)) {
this.loadImage(value);
}
}
private Function onload;
public Function getOnload() {
return this.getEventFunction(this.onload, "onload");
}
public void setOnload(Function onload) {
this.onload = onload;
}
private java.awt.Image image = null;
private String imageSrc;
private void loadImage(String src) {
HTMLDocumentImpl document = (HTMLDocumentImpl) this.document;
if(document != null) {
synchronized(this.listeners) {
this.imageSrc = src;
this.image = null;
}
if(src != null) {
document.loadImage(src, new LocalImageListener(src));
}
}
}
public final java.awt.Image getImage() {
synchronized(this.listeners) {
return this.image;
}
}
private final ArrayList listeners = new ArrayList(1);
/**
* Adds a listener of image loading events.
* The listener gets called right away if there's already
* an image.
* @param listener
*/
public void addImageListener(ImageListener listener) {
ArrayList l = this.listeners;
java.awt.Image currentImage;
synchronized(l) {
currentImage = this.image;
l.add(listener);
}
if(currentImage != null) {
// Call listener right away if there's already an
// image; holding no locks.
listener.imageLoaded(new ImageEvent(this, currentImage));
// Should not call onload handler here. That's taken
// care of otherwise.
}
}
public void removeImageListener(ImageListener listener) {
ArrayList l = this.listeners;
synchronized(l) {
l.remove(l);
}
}
private void dispatchEvent(String expectedImgSrc, ImageEvent event) {
ArrayList l = this.listeners;
ImageListener[] listenerArray;
synchronized(l) {
if(!expectedImgSrc.equals(this.imageSrc)) {
return;
}
this.image = event.image;
// Get array of listeners while holding lock.
listenerArray = (ImageListener[]) l.toArray(ImageListener.EMPTY_ARRAY);
}
int llength = listenerArray.length;
for(int i = 0; i < llength; i++) {
// Inform listener, holding no lock.
listenerArray[i].imageLoaded(event);
}
Function onload = this.getOnload();
if(onload != null) {
//TODO: onload event object?
Executor.executeFunction(HTMLImageElementImpl.this, onload, null);
}
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new ImageRenderState(prevRenderState, this);
}
private class LocalImageListener implements ImageListener {
private final String expectedImgSrc;
public LocalImageListener(String imgSrc) {
this.expectedImgSrc = imgSrc;
}
public void imageLoaded(ImageEvent event) {
dispatchEvent(this.expectedImgSrc, event);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLInputElementImpl.java 0000644 0001750 0001750 00000012071 10726473510 030320 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 15, 2006
*/
package org.lobobrowser.html.domimpl;
import java.util.logging.*;
import org.lobobrowser.html.FormInput;
import org.w3c.dom.html2.*;
public class HTMLInputElementImpl extends HTMLBaseInputElement implements
HTMLInputElement {
public HTMLInputElementImpl(String name) {
super(name);
}
private boolean defaultChecked;
public boolean getDefaultChecked() {
return this.defaultChecked;
}
public void setDefaultChecked(boolean defaultChecked) {
this.defaultChecked = defaultChecked;
}
public boolean getChecked() {
InputContext ic = this.inputContext;
if(ic == null) {
return this.getAttributeAsBoolean("checked");
}
else {
return ic.getChecked();
}
}
public void setChecked(boolean checked) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setChecked(checked);
}
}
public int getMaxLength() {
InputContext ic = this.inputContext;
return ic == null ? 0 : ic.getMaxLength();
}
public void setMaxLength(int maxLength) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setMaxLength(maxLength);
}
}
public int getSize() {
InputContext ic = this.inputContext;
return ic == null ? 0 : ic.getControlSize();
}
public void setSize(int size) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setControlSize(size);
}
}
public String getSrc() {
return this.getAttribute("src");
}
public void setSrc(String src) {
this.setAttribute("src", src);
}
/**
* Gets input type in lowercase.
*/
public String getType() {
String type = this.getAttribute("type");
return type == null ? null : type.toLowerCase();
}
public void setType(String type) {
this.setAttribute("type", type);
}
public String getUseMap() {
return this.getAttribute("usemap");
}
public void setUseMap(String useMap) {
this.setAttribute("usemap", useMap);
}
public void click() {
InputContext ic = this.inputContext;
if(ic != null) {
ic.click();
}
}
public boolean isSubmittableWithEnterKey() {
String type = this.getType();
return (type == null || "".equals(type) || "text".equals(type) || "password".equals(type));
}
public boolean isSubmittableWithPress() {
String type = this.getType();
return "submit".equals(type) || "image".equals(type);
}
public boolean isSubmitInput() {
String type = this.getType();
return "submit".equals(type);
}
public boolean isImageInput() {
String type = this.getType();
return "image".equals(type);
}
public boolean isResetInput() {
String type = this.getType();
return "reset".equals(type);
}
void resetInput() {
InputContext ic = this.inputContext;
if(ic != null) {
ic.resetInput();
}
}
protected FormInput[] getFormInputs() {
String type = this.getType();
String name = this.getName();
if(name == null) {
return null;
}
if(type == null) {
return new FormInput[] { new FormInput(name, this.getValue()) };
}
else {
if("text".equals(type) || "password".equals(type) || "hidden".equals(type) || "".equals(type)) {
return new FormInput[] { new FormInput(name, this.getValue()) };
}
else if("submit".equals(type)) {
// It's done as an "extra" form input
return null;
}
else if("radio".equals(type) || "checkbox".equals(type)) {
if(this.getChecked()) {
String value = this.getValue();
if(value == null || value.length() == 0) {
value = "on";
}
return new FormInput[] { new FormInput(name, value) };
}
else {
return null;
}
}
else if("image".equals(type)) {
// It's done as an "extra" form input
return null;
}
else if("file".equals(type)) {
java.io.File file = this.getFileValue();
if(file == null) {
if(logger.isLoggable(Level.INFO)) {
logger.info("getFormInputs(): File input named " + name + " has null file.");
}
return null;
}
else {
return new FormInput[] { new FormInput(name, file) };
}
}
else {
return null;
}
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLLIElementImpl.java 0000644 0001750 0001750 00000003506 10726473506 027535 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Feb 12, 2006
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.w3c.dom.html2.HTMLLIElement;
public class HTMLLIElementImpl extends HTMLAbstractUIElement implements HTMLLIElement {
public HTMLLIElementImpl(String name) {
super(name);
}
public String getType() {
return this.getAttribute("type");
}
public void setType(String type) {
this.setAttribute("type", type);
}
public int getValue() {
String valueText = this.getAttribute("value");
if(valueText == null) {
return 0;
}
try {
return Integer.parseInt(valueText);
} catch(NumberFormatException nfe) {
return 0;
}
}
public void setValue(int value) {
this.setAttribute("value", String.valueOf(value));
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new DisplayRenderState(prevRenderState, this, RenderState.DISPLAY_LIST_ITEM);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLLinkElementImpl.java 0000644 0001750 0001750 00000020147 11126723430 030113 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import java.net.MalformedURLException;
import java.net.URL;
import org.w3c.dom.UserDataHandler;
import org.w3c.dom.css.CSSStyleSheet;
import org.w3c.dom.html2.*;
import org.lobobrowser.html.*;
import org.lobobrowser.html.style.*;
import org.lobobrowser.util.gui.*;
import com.steadystate.css.dom.*;
import java.util.logging.*;
public class HTMLLinkElementImpl extends HTMLAbstractUIElement implements
HTMLLinkElement {
private static final Logger logger = Logger.getLogger(HTMLLinkElementImpl.class.getName());
private static final boolean loggableInfo = logger.isLoggable(Level.INFO);
private CSSStyleSheet styleSheet;
public HTMLLinkElementImpl(String name) {
super(name);
}
private boolean disabled;
public boolean getDisabled() {
return this.disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
CSSStyleSheet sheet = this.styleSheet;
if(sheet != null) {
sheet.setDisabled(disabled);
}
}
public String getHref() {
String href = this.getAttribute("href");
return href == null ? "" : href;
}
public void setHref(String href) {
this.setAttribute("href", href);
}
public String getHreflang() {
return this.getAttribute("hreflang");
}
public void setHreflang(String hreflang) {
this.setAttribute("hreflang", hreflang);
}
public String getMedia() {
return this.getAttribute("media");
}
public void setMedia(String media) {
this.setAttribute("media", media);
}
public String getRel() {
return this.getAttribute("rel");
}
public void setRel(String rel) {
this.setAttribute("rel", rel);
}
public String getRev() {
return this.getAttribute("rev");
}
public void setRev(String rev) {
this.setAttribute("rev", rev);
}
public String getTarget() {
String target = this.getAttribute("target");
if(target != null) {
return target;
}
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
return doc == null ? null : doc.getDefaultTarget();
}
public void setTarget(String target) {
this.setAttribute("target", target);
}
public String getType() {
return this.getAttribute("type");
}
public void setType(String type) {
this.setAttribute("type", type);
}
public Object setUserData(String key, Object data, UserDataHandler handler) {
if(org.lobobrowser.html.parser.HtmlParser.MODIFYING_KEY.equals(key) && data != Boolean.TRUE) {
this.processLink();
}
else if(com.steadystate.css.dom.CSSStyleSheetImpl.KEY_DISABLED_CHANGED.equals(key)) {
this.informDocumentInvalid();
}
return super.setUserData(key, data, handler);
}
/**
* If the LINK refers to a stylesheet document, this method
* loads and parses it.
*/
protected void processLink() {
this.styleSheet = null;
String rel = this.getAttribute("rel");
if(rel != null) {
String cleanRel = rel.trim().toLowerCase();
boolean isStyleSheet = cleanRel.equals("stylesheet");
boolean isAltStyleSheet = cleanRel.equals("alternate stylesheet");
if(isStyleSheet || isAltStyleSheet) {
UserAgentContext uacontext = this.getUserAgentContext();
if(uacontext.isExternalCSSEnabled()) {
String media = this.getMedia();
if(CSSUtilities.matchesMedia(media, uacontext)) {
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.getOwnerDocument();
try {
boolean liflag = loggableInfo;
long time1 = liflag ? System.currentTimeMillis() : 0;
try {
CSSStyleSheet sheet = CSSUtilities.parse(this, this.getHref(), doc, doc.getBaseURI(), false);
if(sheet != null) {
this.styleSheet = sheet;
if(sheet instanceof CSSStyleSheetImpl) {
CSSStyleSheetImpl sheetImpl = (CSSStyleSheetImpl) sheet;
if(isAltStyleSheet) {
sheetImpl.setDisabledOnly(true);
}
else {
sheetImpl.setDisabledOnly(this.disabled);
}
}
else {
if(isAltStyleSheet) {
sheet.setDisabled(true);
}
else {
sheet.setDisabled(this.disabled);
}
}
doc.addStyleSheet(sheet);
}
} finally {
if(liflag) {
long time2 = System.currentTimeMillis();
logger.info("processLink(): Loaded and parsed CSS (or attempted to) at URI=[" + this.getHref() + "] in " + (time2 - time1) + " ms.");
}
}
} catch(MalformedURLException mfe) {
this.warn("Will not parse CSS. URI=[" + this.getHref() + "] with BaseURI=[" + doc.getBaseURI() + "] does not appear to be a valid URI.");
} catch(Throwable err) {
this.warn("Unable to parse CSS. URI=[" + this.getHref() + "].", err);
}
}
}
}
}
}
public String getAbsoluteHref() {
HtmlRendererContext rcontext = this.getHtmlRendererContext();
if(rcontext != null) {
String href = this.getHref();
if(href != null && href.length() > 0) {
String target = this.getTarget();
try {
URL url = this.getFullURL(href);
return url == null ? null : url.toExternalForm();
} catch(MalformedURLException mfu) {
this.warn("Malformed URI: [" + href + "].", mfu);
}
}
}
return null;
}
public void navigate() {
if(this.disabled) {
return;
}
HtmlRendererContext rcontext = this.getHtmlRendererContext();
if(rcontext != null) {
String href = this.getHref();
if(href != null && href.length() > 0) {
String target = this.getTarget();
try {
URL url = this.getFullURL(href);
if(url == null) {
this.warn("Unable to resolve URI: [" + href + "].");
}
else {
rcontext.linkClicked(this, url, target);
}
} catch(MalformedURLException mfu) {
this.warn("Malformed URI: [" + href + "].", mfu);
}
}
}
}
private java.awt.Color getLinkColor() {
HTMLDocument doc = (HTMLDocument) this.document;
if(doc != null) {
HTMLBodyElement body = (HTMLBodyElement) doc.getBody();
if(body != null) {
String vlink = body.getVLink();
String link = body.getLink();
if(vlink != null || link != null) {
HtmlRendererContext rcontext = this.getHtmlRendererContext();
if(rcontext != null) {
boolean visited = rcontext.isVisitedLink(this);
String colorText = visited ? vlink : link;
if(colorText != null) {
return ColorFactory.getInstance().getColor(colorText);
}
}
}
}
}
return java.awt.Color.BLUE;
}
protected RenderState createRenderState(RenderState prevRenderState) {
if(this.hasAttribute("href")) {
prevRenderState = new TextDecorationRenderState(prevRenderState, RenderState.MASK_TEXTDECORATION_UNDERLINE);
prevRenderState = new ColorRenderState(prevRenderState, this.getLinkColor());
}
return super.createRenderState(prevRenderState);
}
public String toString() {
// Javascript code often depends on this being exactly href. See js9.html.
// To change, perhaps add method to AbstractScriptableDelegate.
return this.getHref();
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLMonospacedElementImpl.java 0000644 0001750 0001750 00000002543 10726473500 031313 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
/**
* Element used for TT and CODE.
*/
public class HTMLMonospacedElementImpl extends HTMLAbstractUIElement {
public HTMLMonospacedElementImpl(String name) {
super(name);
}
protected RenderState createRenderState(RenderState prevRenderState) {
prevRenderState = new FontNameRenderState(prevRenderState, "Monospaced");
return super.createRenderState(prevRenderState);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLNonStandardElement.java 0000644 0001750 0001750 00000000427 10641432430 030604 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
public class HTMLNonStandardElement extends HTMLElementImpl {
public HTMLNonStandardElement(String name, boolean noStyleSheet) {
super(name, noStyleSheet);
}
public HTMLNonStandardElement(String name) {
super(name);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLOListElementImpl.java 0000644 0001750 0001750 00000004061 11134376520 030250 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Feb 12, 2006
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.w3c.dom.html2.HTMLOListElement;
public class HTMLOListElementImpl extends HTMLAbstractUIElement implements
HTMLOListElement {
public HTMLOListElementImpl(String name) {
super(name);
}
public boolean getCompact() {
String compactText = this.getAttribute("compact");
return "compact".equalsIgnoreCase(compactText);
}
public void setCompact(boolean compact) {
this.setAttribute("compact", compact ? "compact" : null);
}
public int getStart() {
String startText = this.getAttribute("start");
if(startText == null) {
return 1;
}
try {
return Integer.parseInt(startText);
} catch(NumberFormatException nfe) {
return 1;
}
}
public void setStart(int start) {
this.setAttribute("start", String.valueOf(start));
}
public String getType() {
return this.getAttribute("type");
}
public void setType(String type) {
this.setAttribute("type", type);
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new ListRenderState(prevRenderState, this);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLObjectElementImpl.java 0000644 0001750 0001750 00000007471 10641432430 030427 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.w3c.dom.Document;
import org.w3c.dom.html2.HTMLFormElement;
import org.w3c.dom.html2.HTMLObjectElement;
public class HTMLObjectElementImpl extends HTMLAbstractUIElement implements
HTMLObjectElement {
public HTMLObjectElementImpl(String name) {
super(name);
}
public String getAlign() {
return this.getAttribute("align");
}
public String getAlt() {
return this.getAttribute("alt");
}
public String getArchive() {
return this.getAttribute("archive");
}
public String getCode() {
return this.getAttribute("code");
}
public String getCodeBase() {
return this.getAttribute("codebase");
}
public String getHeight() {
return this.getAttribute("height");
}
public String getName() {
return this.getAttribute("name");
}
public String getObject() {
return this.getAttribute("object");
}
public String getWidth() {
return this.getAttribute("width");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
public void setAlt(String alt) {
this.setAttribute("alt", alt);
}
public void setArchive(String archive) {
this.setAttribute("archive", archive);
}
public void setCode(String code) {
this.setAttribute("code", code);
}
public void setCodeBase(String codeBase) {
this.setAttribute("codebase", codeBase);
}
public void setHeight(String height) {
this.setAttribute("height", height);
}
public void setName(String name) {
this.setAttribute("name", name);
}
public void setObject(String object) {
this.setAttribute("object", object);
}
public void setWidth(String width) {
this.setAttribute("width", width);
}
public String getBorder() {
return this.getAttribute("border");
}
public String getCodeType() {
return this.getAttribute("codetype");
}
public Document getContentDocument() {
return this.getOwnerDocument();
}
public String getData() {
return this.getAttribute("data");
}
public boolean getDeclare() {
return "declare".equalsIgnoreCase(this.getAttribute("declare"));
}
public HTMLFormElement getForm() {
return (HTMLFormElement) this.getAncestorForJavaClass(HTMLFormElement.class);
}
public int getHspace() {
try {
return Integer.parseInt(this.getAttribute("hspace"));
} catch(Exception err) {
return 0;
}
}
public String getStandby() {
return this.getAttribute("standby");
}
public int getTabIndex() {
try {
return Integer.parseInt(this.getAttribute("tabindex"));
} catch(Exception err) {
return 0;
}
}
public String getType() {
return this.getAttribute("type");
}
public String getUseMap() {
return this.getAttribute("usemap");
}
public int getVspace() {
try {
return Integer.parseInt(this.getAttribute("vspace"));
} catch(Exception err) {
return 0;
}
}
public void setBorder(String border) {
this.setAttribute("border", border);
}
public void setCodeType(String codeType) {
this.setAttribute("codetype", codeType);
}
public void setData(String data) {
this.setAttribute("data", data);
}
public void setDeclare(boolean declare) {
this.setAttribute("declare", declare ? "declare" : null);
}
public void setHspace(int hspace) {
this.setAttribute("hspace", String.valueOf(hspace));
}
public void setStandby(String standby) {
this.setAttribute("standby", standby);
}
public void setTabIndex(int tabIndex) {
this.setAttribute("tabindex", String.valueOf(tabIndex));
}
public void setType(String type) {
this.setAttribute("type", type);
}
public void setUseMap(String useMap) {
this.setAttribute("usemap", useMap);
}
public void setVspace(int vspace) {
this.setAttribute("vspace", String.valueOf(vspace));
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLOptionElementImpl.java 0000644 0001750 0001750 00000004620 11125506242 030463 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.w3c.dom.html2.*;
public class HTMLOptionElementImpl extends HTMLElementImpl implements HTMLOptionElement {
public HTMLOptionElementImpl(String name) {
super(name, true);
}
public boolean getDefaultSelected() {
return this.getAttributeAsBoolean("selected");
}
public boolean getDisabled() {
return false;
}
public HTMLFormElement getForm() {
return this.getForm();
}
public int getIndex() {
Object parent = this.getParentNode();
if(parent instanceof HTMLSelectElement) {
HTMLOptionsCollectionImpl options = (HTMLOptionsCollectionImpl) ((HTMLSelectElement) parent).getOptions();
return options.indexOf(this);
}
else {
return -1;
}
}
public String getLabel() {
return this.getAttribute("label");
}
public boolean getSelected() {
return this.selected;
}
public String getText() {
return this.getRawInnerText(false);
}
public void setText(String value) {
this.setTextContent(value);
}
public String getValue() {
return this.getAttribute("value");
}
public void setDefaultSelected(boolean defaultSelected) {
this.setAttribute("selected", defaultSelected ? "selected" : null);
}
public void setDisabled(boolean disabled) {
//TODO Unsupported
}
public void setLabel(String label) {
this.setAttribute("label", label);
}
private boolean selected;
void setSelectedImpl(boolean selected) {
this.selected = selected;
}
public void setSelected(boolean selected) {
boolean changed = selected != this.selected;
this.selected = selected;
// Changing the option state changes the selected index.
Object parent = this.getParentNode();
if(parent instanceof HTMLSelectElementImpl) {
HTMLSelectElementImpl parentSelect = ((HTMLSelectElementImpl) parent);
if(changed || parentSelect.getSelectedIndex() == -1) {
if(selected) {
parentSelect.setSelectedIndexImpl(this.getIndex());
}
else {
int currentIndex = parentSelect.getSelectedIndex();
if(currentIndex != -1 && currentIndex == this.getIndex()) {
parentSelect.setSelectedIndexImpl(-1);
}
}
}
}
}
public void setValue(String value) {
this.setAttribute("value", value);
}
public String toString() {
return "HTMLOptionElementImpl[text=" + this.getText() + ",selected=" + this.getSelected() + "]";
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLOptionsCollectionImpl.java 0000644 0001750 0001750 00000001324 10763033610 031347 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.html2.*;
public class HTMLOptionsCollectionImpl extends DescendentHTMLCollection implements HTMLOptionsCollection {
public static final NodeFilter OPTION_FILTER = new OptionFilter();
public HTMLOptionsCollectionImpl(HTMLElementImpl selectElement) {
super(selectElement, OPTION_FILTER, selectElement.treeLock, false);
}
public void setLength(int length) throws DOMException {
throw new UnsupportedOperationException();
}
private static class OptionFilter implements NodeFilter {
public boolean accept(Node node) {
return node instanceof HTMLOptionElement;
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLPElementImpl.java 0000644 0001750 0001750 00000002153 11134376350 027416 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.w3c.dom.html2.HTMLParagraphElement;
public class HTMLPElementImpl extends HTMLAbstractUIElement implements
HTMLParagraphElement {
public HTMLPElementImpl(String name) {
super(name);
}
public String getAlign() {
return this.getAttribute("align");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
protected void appendInnerTextImpl(StringBuffer buffer) {
int length = buffer.length();
int lineBreaks;
if(length == 0) {
lineBreaks = 2;
}
else {
int start = length - 4;
if (start < 0) {
start = 0;
}
lineBreaks = 0;
for(int i = start; i < length; i++) {
char ch = buffer.charAt(i);
if(ch == '\n') {
lineBreaks++;
}
}
}
for(int i = 0; i < 2 - lineBreaks; i++) {
buffer.append("\r\n");
}
super.appendInnerTextImpl(buffer);
buffer.append("\r\n\r\n");
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new ParagraphRenderState(prevRenderState, this);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLPreElementImpl.java 0000644 0001750 0001750 00000003224 10726473504 027752 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Feb 12, 2006
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.w3c.dom.html2.HTMLPreElement;
public class HTMLPreElementImpl extends HTMLAbstractUIElement implements
HTMLPreElement {
public HTMLPreElementImpl(String name) {
super(name);
}
public int getWidth() {
String widthText = this.getAttribute("width");
if(widthText == null) {
return 0;
}
try {
return Integer.parseInt(widthText);
} catch(NumberFormatException nfe) {
return 0;
}
}
public void setWidth(int width) {
this.setAttribute("width", String.valueOf(width));
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new PreRenderState(prevRenderState, this);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLProcessingInstruction.java 0000644 0001750 0001750 00000003057 10764510266 031451 0 ustar twerner twerner /*
* HtmlProcessingInstruction.java
* Selima Prague FBI Project
* 5th-March-2008
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.domimpl.NodeImpl;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
/**
* HTML DOM object representing processing instruction as per HTML 4.0 specification.
*
* @author vitek
*/
public class HTMLProcessingInstruction extends NodeImpl
implements ProcessingInstruction, Cloneable
{
String target;
String data;
public HTMLProcessingInstruction(String target,String data)
{
this.target = target;
this.data = data;
}
protected Node createSimilarNode()
{
return (Node) clone();
}
public String getLocalName()
{
return target;
}
public String getNodeName()
{
return target;
}
public short getNodeType()
{
return Node.PROCESSING_INSTRUCTION_NODE;
}
public String getNodeValue() throws DOMException
{
return data;
}
public void setNodeValue(String nodeValue) throws DOMException
{
this.data = nodeValue;
}
public String getData()
{
return data;
}
public String getTarget()
{
return target;
}
public void setData(String data) throws DOMException
{
this.data = data;
}
public Object clone()
{
try
{
return (HTMLProcessingInstruction) super.clone();
}
catch (CloneNotSupportedException e)
{
throw new IllegalStateException(e);
}
}
public String toString()
{
return ""+target+" "+data+">";
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLScriptElementImpl.java 0000644 0001750 0001750 00000014575 11130421122 030456 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 8, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.Document;
import org.w3c.dom.UserDataHandler;
import org.w3c.dom.html2.HTMLScriptElement;
import org.lobobrowser.html.*;
import org.lobobrowser.html.js.Executor;
import org.mozilla.javascript.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.*;
public class HTMLScriptElementImpl extends HTMLElementImpl implements
HTMLScriptElement {
private static final Logger logger = Logger.getLogger(HTMLScriptElementImpl.class.getName());
private static final boolean loggableInfo = logger.isLoggable(Level.INFO);
public HTMLScriptElementImpl() {
super("SCRIPT", true);
}
public HTMLScriptElementImpl(String name) {
super(name, true);
}
private String text;
public String getText() {
String t = this.text;
if(t == null) {
return this.getRawInnerText(true);
}
else {
return t;
}
}
public void setText(String text) {
this.text = text;
}
public String getHtmlFor() {
return this.getAttribute("htmlFor");
}
public void setHtmlFor(String htmlFor) {
this.setAttribute("htmlFor", htmlFor);
}
public String getEvent() {
return this.getAttribute("event");
}
public void setEvent(String event) {
this.setAttribute("event", event);
}
private boolean defer;
public boolean getDefer() {
return this.defer;
}
public void setDefer(boolean defer) {
this.defer = defer;
}
public String getSrc() {
return this.getAttribute("src");
}
public void setSrc(String src) {
this.setAttribute("src", src);
}
public String getType() {
return this.getAttribute("type");
}
public void setType(String type) {
this.setAttribute("type", type);
}
public Object setUserData(String key, Object data, UserDataHandler handler) {
if(org.lobobrowser.html.parser.HtmlParser.MODIFYING_KEY.equals(key) && data != Boolean.TRUE) {
this.processScript();
}
return super.setUserData(key, data, handler);
}
protected final void processScript() {
UserAgentContext bcontext = this.getUserAgentContext();
if(bcontext == null) {
throw new IllegalStateException("No user agent context.");
}
if(bcontext.isScriptingEnabled()) {
String text;
final String scriptURI;
int baseLineNumber;
String src = this.getSrc();
Document doc = this.document;
if(!(doc instanceof HTMLDocumentImpl)) {
throw new IllegalStateException("no valid document");
}
boolean liflag = loggableInfo;
if(src == null) {
text = this.getText();
scriptURI = doc.getBaseURI();
baseLineNumber = 1; //TODO: Line number of inner text??
}
else {
this.informExternalScriptLoading();
java.net.URL scriptURL = ((HTMLDocumentImpl) doc).getFullURL(src);
scriptURI = scriptURL == null ? src : scriptURL.toExternalForm();
long time1 = liflag ? System.currentTimeMillis() : 0;
try {
final HttpRequest request = bcontext.createHttpRequest();
// Perform a synchronous request
SecurityManager sm = System.getSecurityManager();
if(sm == null) {
try {
request.open("GET", scriptURI, false);
request.send(null);
} catch(java.io.IOException thrown) {
logger.log(Level.WARNING, "processScript()", thrown);
}
}
else {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
// Code might have restrictions on accessing
// items from elsewhere.
try {
request.open("GET", scriptURI, false);
request.send(null);
} catch(java.io.IOException thrown) {
logger.log(Level.WARNING, "processScript()", thrown);
}
return null;
}
});
}
int status = request.getStatus();
if(status != 200 && status != 0) {
this.warn("Script at [" + scriptURI + "] failed to load; HTTP status: " + status + ".");
return;
}
text = request.getResponseText();
} finally {
if(liflag) {
long time2 = System.currentTimeMillis();
logger.info("processScript(): Loaded external Javascript from URI=[" + scriptURI + "] in " + (time2 - time1) + " ms.");
}
}
baseLineNumber = 1;
}
Context ctx = Executor.createContext(this.getDocumentURL(), bcontext);
try {
Scriptable scope = (Scriptable) doc.getUserData(Executor.SCOPE_KEY);
if(scope == null) {
throw new IllegalStateException("Scriptable (scope) instance was expected to be keyed as UserData to document using " + Executor.SCOPE_KEY);
}
try {
long time1 = liflag ? System.currentTimeMillis() : 0;
if(text == null) {
throw new java.lang.IllegalStateException("Script source is null: " + this + ".");
}
ctx.evaluateString(scope, text, scriptURI, baseLineNumber, null);
if(liflag) {
long time2 = System.currentTimeMillis();
logger.info("addNotify(): Evaluated (or attempted to evaluate) Javascript in " + (time2 - time1) + " ms.");
}
} catch(EcmaError ecmaError) {
logger.log(Level.WARNING, "Javascript error at " + ecmaError.getSourceName() + ":" + ecmaError.getLineNumber() + ": " + ecmaError.getMessage(), ecmaError);
} catch(Throwable err) {
logger.log(Level.WARNING, "Unable to evaluate Javascript code", err);
}
} finally {
Context.exit();
}
}
}
protected void appendInnerTextImpl(StringBuffer buffer) {
// nop
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLSelectElementImpl.java 0000644 0001750 0001750 00000007715 10773452512 030452 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import java.util.*;
import org.lobobrowser.html.FormInput;
import org.mozilla.javascript.*;
import org.w3c.dom.DOMException;
import org.w3c.dom.html2.HTMLElement;
import org.w3c.dom.html2.HTMLOptionsCollection;
import org.w3c.dom.html2.HTMLSelectElement;
public class HTMLSelectElementImpl extends HTMLBaseInputElement implements
HTMLSelectElement {
public HTMLSelectElementImpl(String name) {
super(name);
}
public void add(HTMLElement element, HTMLElement before)
throws DOMException {
this.insertBefore(element, before);
}
public int getLength() {
return this.getOptions().getLength();
}
private Boolean multipleState = null;
public boolean getMultiple() {
Boolean m = this.multipleState;
if(m != null) {
return m.booleanValue();
}
return this.getAttributeAsBoolean("multiple");
}
private HTMLOptionsCollection options;
public HTMLOptionsCollection getOptions() {
synchronized(this) {
if(this.options == null) {
this.options = new HTMLOptionsCollectionImpl(this);
}
return this.options;
}
}
public int getSelectedIndex() {
InputContext ic = this.inputContext;
if(ic != null) {
return ic.getSelectedIndex();
}
else {
return this.deferredSelectedIndex;
}
}
public int getSize() {
InputContext ic = this.inputContext;
if(ic != null) {
return ic.getVisibleSize();
}
else {
return 0;
}
}
public String getType() {
return this.getMultiple() ? "select-multiple" : "select-one";
}
public void remove(int index) {
try {
this.removeChild(this.getOptions().item(index));
} catch(DOMException de) {
this.warn("remove(): Unable to remove option at index " + index + ".", de);
}
}
public void setLength(int length) throws DOMException {
this.getOptions().setLength(length);
}
public void setMultiple(boolean multiple) {
boolean prevMultiple = this.getMultiple();
this.multipleState = Boolean.valueOf(multiple);
if(prevMultiple != multiple) {
this.informLayoutInvalid();
}
}
private int deferredSelectedIndex = -1;
public void setSelectedIndex(int selectedIndex) {
this.setSelectedIndexImpl(selectedIndex);
HTMLOptionsCollection options = this.getOptions();
int length = options.getLength();
for(int i = 0; i < length; i++) {
HTMLOptionElementImpl option = (HTMLOptionElementImpl) options.item(i);
option.setSelectedImpl(i == selectedIndex);
}
}
void setSelectedIndexImpl(int selectedIndex) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setSelectedIndex(selectedIndex);
}
else {
this.deferredSelectedIndex = selectedIndex;
}
}
public void setSize(int size) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setVisibleSize(size);
}
}
protected FormInput[] getFormInputs() {
// Needs to be overriden for forms to submit.
InputContext ic = this.inputContext;
String[] values = ic == null ? null : ic.getValues();
if(values == null) {
String value = this.getValue();
values = value == null ? null : new String[] { value };
if(values == null) {
return null;
}
}
String name = this.getName();
if(name == null) {
return null;
}
ArrayList formInputs = new ArrayList();
for(int i = 0; i < values.length; i++) {
formInputs.add(new FormInput(name, values[i]));
}
return (FormInput[]) formInputs.toArray(FormInput.EMPTY_ARRAY);
}
public void resetInput() {
InputContext ic = this.inputContext;
if(ic != null) {
ic.resetInput();
}
}
public void setInputContext(InputContext ic) {
super.setInputContext(ic);
if(ic != null) {
ic.setSelectedIndex(this.deferredSelectedIndex);
}
}
private Function onchange;
public Function getOnchange() {
return this.getEventFunction(this.onchange, "onchange");
}
public void setOnchange(Function value) {
this.onchange = value;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLSpanElementImpl.java 0000644 0001750 0001750 00000002226 10726473510 030123 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 8, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.html2.HTMLElement;
public class HTMLSpanElementImpl extends HTMLAbstractUIElement implements HTMLElement {
public HTMLSpanElementImpl(String name) {
super(name);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLStrikeElementImpl.java 0000644 0001750 0001750 00000002573 10726473500 030467 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
/**
* Element used for STRIKE.
*/
public class HTMLStrikeElementImpl extends HTMLAbstractUIElement {
public HTMLStrikeElementImpl(String name) {
super(name);
}
protected RenderState createRenderState(RenderState prevRenderState) {
prevRenderState = new TextDecorationRenderState(prevRenderState, RenderState.MASK_TEXTDECORATION_LINE_THROUGH);
return super.createRenderState(prevRenderState);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLStrongElementImpl.java 0000644 0001750 0001750 00000002542 10726473502 030500 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
/**
* Element used for B and STRONG.
*/
public class HTMLStrongElementImpl extends HTMLAbstractUIElement {
public HTMLStrongElementImpl(String name) {
super(name);
}
protected RenderState createRenderState(RenderState prevRenderState) {
prevRenderState = new FontStyleRenderState(prevRenderState, java.awt.Font.BOLD);
return super.createRenderState(prevRenderState);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLStyleElementImpl.java 0000644 0001750 0001750 00000007173 11107761130 030320 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Nov 27, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.CSSUtilities;
import org.w3c.css.sac.InputSource;
import org.w3c.dom.UserDataHandler;
import org.w3c.dom.css.CSSStyleSheet;
import org.w3c.dom.html2.HTMLStyleElement;
import com.steadystate.css.dom.CSSStyleSheetImpl;
import com.steadystate.css.parser.CSSOMParser;
public class HTMLStyleElementImpl extends HTMLElementImpl implements
HTMLStyleElement {
private CSSStyleSheet styleSheet;
public HTMLStyleElementImpl() {
super("STYLE", true);
}
public HTMLStyleElementImpl(String name) {
super(name, true);
}
private boolean disabled;
public boolean getDisabled() {
return this.disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
CSSStyleSheet sheet = this.styleSheet;
if(sheet != null) {
sheet.setDisabled(disabled);
}
}
public String getMedia() {
return this.getAttribute("media");
}
public void setMedia(String media) {
this.setAttribute("media", media);
}
public String getType() {
return this.getAttribute("type");
}
public void setType(String type) {
this.setAttribute("type", type);
}
public Object setUserData(String key, Object data, UserDataHandler handler) {
if(org.lobobrowser.html.parser.HtmlParser.MODIFYING_KEY.equals(key) && data != Boolean.TRUE) {
this.processStyle();
}
else if(com.steadystate.css.dom.CSSStyleSheetImpl.KEY_DISABLED_CHANGED.equals(key)) {
this.informDocumentInvalid();
}
return super.setUserData(key, data, handler);
}
protected void processStyle() {
this.styleSheet = null;
if(CSSUtilities.matchesMedia(this.getMedia(), this.getUserAgentContext())) {
String text = this.getRawInnerText(true);
if(text != null && !"".equals(text)) {
String processedText = CSSUtilities.preProcessCss(text);
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.getOwnerDocument();
CSSOMParser parser = new CSSOMParser();
String baseURI = doc.getBaseURI();
InputSource is = CSSUtilities.getCssInputSourceForStyleSheet(processedText, baseURI);
try {
CSSStyleSheetImpl sheet = (CSSStyleSheetImpl) parser.parseStyleSheet(is);
sheet.setOwnerNode(this);
sheet.setHref(baseURI);
doc.addStyleSheet(sheet);
this.styleSheet = sheet;
if(sheet instanceof CSSStyleSheetImpl) {
CSSStyleSheetImpl sheetImpl = (CSSStyleSheetImpl) sheet;
sheetImpl.setDisabledOnly(this.disabled);
}
else {
sheet.setDisabled(this.disabled);
}
} catch(Throwable err) {
this.warn("Unable to parse style sheet", err);
}
}
}
}
protected void appendInnerTextImpl(StringBuffer buffer) {
// nop
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLSuperscriptElementImpl.java 0000644 0001750 0001750 00000001310 11047522352 031532 0 ustar twerner twerner package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.FontStyleRenderState;
import org.lobobrowser.html.style.RenderState;
/**
* Element used for SUB
*/
public class HTMLSuperscriptElementImpl extends HTMLAbstractUIElement {
private int superscript;
public HTMLSuperscriptElementImpl(String name, int superscript) {
super(name);
this.superscript = superscript;
}
protected RenderState createRenderState(RenderState prevRenderState) {
prevRenderState = FontStyleRenderState.createSuperscriptFontStyleRenderState(prevRenderState, new Integer(this.superscript));
return super.createRenderState(prevRenderState);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLTableCellElementImpl.java 0000644 0001750 0001750 00000010043 10726473500 031044 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Dec 4, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.w3c.dom.html2.HTMLTableCellElement;
public class HTMLTableCellElementImpl extends HTMLAbstractUIElement implements
HTMLTableCellElement {
public HTMLTableCellElementImpl(String name) {
super(name);
}
public int getCellIndex() {
// TODO Cell index in row
return 0;
}
public String getAbbr() {
return this.getAttribute("abbr");
}
public void setAbbr(String abbr) {
this.setAttribute("abbr", abbr);
}
public String getAlign() {
return this.getAttribute("align");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
public String getAxis() {
return this.getAttribute("axis");
}
public void setAxis(String axis) {
this.setAttribute("axis", axis);
}
public String getBgColor() {
return this.getAttribute("bgcolor");
}
public void setBgColor(String bgColor) {
this.setAttribute("bgcolor", bgColor);
}
public String getCh() {
return this.getAttribute("ch");
}
public void setCh(String ch) {
this.setAttribute("ch", ch);
}
public String getChOff() {
return this.getAttribute("choff");
}
public void setChOff(String chOff) {
this.setAttribute("choff", chOff);
}
public int getColSpan() {
String colSpanText = this.getAttribute("colspan");
if(colSpanText == null) {
return 1;
}
else {
try {
return Integer.parseInt(colSpanText);
} catch(NumberFormatException nfe) {
return 1;
}
}
}
public void setColSpan(int colSpan) {
this.setAttribute("colspan", String.valueOf(colSpan));
}
public String getHeaders() {
return this.getAttribute("headers");
}
public void setHeaders(String headers) {
this.setAttribute("headers", headers);
}
public String getHeight() {
return this.getAttribute("height");
}
public void setHeight(String height) {
this.setAttribute("height", height);
}
public boolean getNoWrap() {
return "nowrap".equalsIgnoreCase(this.getAttribute("nowrap"));
}
public void setNoWrap(boolean noWrap) {
this.setAttribute("nowrap", noWrap ? "nowrap" : null);
}
public int getRowSpan() {
String rowSpanText = this.getAttribute("rowspan");
if(rowSpanText == null) {
return 1;
}
else {
try {
return Integer.parseInt(rowSpanText);
} catch(NumberFormatException nfe) {
return 1;
}
}
}
public void setRowSpan(int rowSpan) {
this.setAttribute("rowspan", String.valueOf(rowSpan));
}
public String getScope() {
return this.getAttribute("scope");
}
public void setScope(String scope) {
this.setAttribute("scope", scope);
}
public String getVAlign() {
return this.getAttribute("valign");
}
public void setVAlign(String vAlign) {
this.setAttribute("valign", vAlign);
}
public String getWidth() {
return this.getAttribute("width");
}
public void setWidth(String width) {
this.setAttribute("width", width);
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new TableCellRenderState(prevRenderState, this);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLTableElementImpl.java 0000644 0001750 0001750 00000016702 10763034072 030252 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Dec 3, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.html2.HTMLCollection;
import org.w3c.dom.html2.HTMLElement;
import org.w3c.dom.html2.HTMLTableCaptionElement;
import org.w3c.dom.html2.HTMLTableElement;
import org.w3c.dom.html2.HTMLTableSectionElement;
import java.util.*;
public class HTMLTableElementImpl extends HTMLAbstractUIElement implements
HTMLTableElement {
public HTMLTableElementImpl() {
super("TABLE");
}
public HTMLTableElementImpl(String name) {
super(name);
}
private HTMLTableCaptionElement caption;
public HTMLTableCaptionElement getCaption() {
return this.caption;
}
public void setCaption(HTMLTableCaptionElement caption) throws DOMException {
this.caption = caption;
}
private HTMLTableSectionElement thead;
public HTMLTableSectionElement getTHead() {
return this.thead;
}
public void setTHead(HTMLTableSectionElement tHead) throws DOMException {
this.thead = tHead;
}
private HTMLTableSectionElement tfoot;
public HTMLTableSectionElement getTFoot() {
return this.tfoot;
}
public void setTFoot(HTMLTableSectionElement tFoot) throws DOMException {
this.tfoot = tFoot;
}
public HTMLCollection getRows() {
return new DescendentHTMLCollection(this, new ElementFilter("TR"), this.treeLock, false);
}
public HTMLCollection getTBodies() {
return new DescendentHTMLCollection(this, new ElementFilter("TBODY"), this.treeLock, false);
}
public String getAlign() {
return this.getAttribute("align");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
public String getBgColor() {
return this.getAttribute("bgcolor");
}
public void setBgColor(String bgColor) {
this.setAttribute("bgcolor", bgColor);
}
public String getBorder() {
return this.getAttribute("border");
}
public void setBorder(String border) {
this.setAttribute("border", border);
}
public String getCellPadding() {
return this.getAttribute("cellpadding");
}
public void setCellPadding(String cellPadding) {
this.setAttribute("cellpadding", cellPadding);
}
public String getCellSpacing() {
return this.getAttribute("cellspacing");
}
public void setCellSpacing(String cellSpacing) {
this.setAttribute("cellspacing", cellSpacing);
}
public String getFrame() {
return this.getAttribute("frame");
}
public void setFrame(String frame) {
this.setAttribute("frame", frame);
}
public String getRules() {
return this.getAttribute("rules");
}
public void setRules(String rules) {
this.setAttribute("rules", rules);
}
public String getSummary() {
return this.getAttribute("summary");
}
public void setSummary(String summary) {
this.setAttribute("summary", summary);
}
public String getWidth() {
return this.getAttribute("width");
}
public void setWidth(String width) {
this.setAttribute("width", width);
}
/* (non-Javadoc)
* @see org.xamjwg.html.renderer.RenderableContext#getHeightLength()
*/
public HtmlLength getHeightLength(int availHeight) {
try {
AbstractCSS2Properties props = this.getCurrentStyle();
String heightText = props == null ? null : props.getHeight();
if(heightText == null) {
return new HtmlLength(this.getAttribute("height"));
}
else {
return new HtmlLength(HtmlValues.getPixelSize(heightText, this.getRenderState(), 0, availHeight));
}
} catch(Exception err) {
return null;
}
}
/* (non-Javadoc)
* @see org.xamjwg.html.renderer.RenderableContext#getWidthLength()
*/
public HtmlLength getWidthLength(int availWidth) {
try {
AbstractCSS2Properties props = this.getCurrentStyle();
String widthText = props == null ? null : props.getWidth();
if(widthText == null) {
return new HtmlLength(this.getAttribute("width"));
}
else {
return new HtmlLength(HtmlValues.getPixelSize(widthText, this.getRenderState(), 0, availWidth));
}
} catch(Exception err) {
return null;
}
}
public HTMLElement createTHead() {
org.w3c.dom.Document doc = this.document;
return doc == null ? null : (HTMLElement) doc.createElement("thead");
}
public void deleteTHead() {
this.removeChildren(new ElementFilter("THEAD"));
}
public HTMLElement createTFoot() {
org.w3c.dom.Document doc = this.document;
return doc == null ? null : (HTMLElement) doc.createElement("tfoot");
}
public void deleteTFoot() {
this.removeChildren(new ElementFilter("TFOOT"));
}
public HTMLElement createCaption() {
org.w3c.dom.Document doc = this.document;
return doc == null ? null : (HTMLElement) doc.createElement("caption");
}
public void deleteCaption() {
this.removeChildren(new ElementFilter("CAPTION"));
}
/**
* Inserts a row at the index given. If index
is -1
,
* the row is appended as the last row.
*/
public HTMLElement insertRow(int index) throws DOMException {
org.w3c.dom.Document doc = this.document;
if(doc == null) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Orphan element");
}
HTMLElement rowElement = (HTMLElement) doc.createElement("TR");
synchronized(this.treeLock) {
if(index == -1) {
this.appendChild(rowElement);
return rowElement;
}
ArrayList nl = this.nodeList;
if(nl != null) {
int size = nl.size();
int trcount = 0;
for(int i = 0; i < size; i++) {
Node node = (Node) nl.get(i);
if("TR".equalsIgnoreCase(node.getNodeName())) {
if(trcount == index) {
this.insertAt(rowElement, i);
return rowElement;
}
trcount++;
}
}
}
else {
this.appendChild(rowElement);
return rowElement;
}
}
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of range");
}
public void deleteRow(int index) throws DOMException {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl != null) {
int size = nl.size();
int trcount = 0;
for(int i = 0; i < size; i++) {
Node node = (Node) nl.get(i);
if("TR".equalsIgnoreCase(node.getNodeName())) {
if(trcount == index) {
this.removeChildAt(i);
return;
}
trcount++;
}
}
}
}
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of range");
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new TableRenderState(prevRenderState, this);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLTableHeadElementImpl.java 0000644 0001750 0001750 00000002644 10726473504 031042 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.FontStyleRenderState;
import org.lobobrowser.html.style.RenderState;
/**
* Element used for TH.
*/
public class HTMLTableHeadElementImpl extends HTMLTableCellElementImpl {
public HTMLTableHeadElementImpl(String name) {
super(name);
}
protected RenderState createRenderState(RenderState prevRenderState) {
prevRenderState = new FontStyleRenderState(prevRenderState, java.awt.Font.BOLD);
return super.createRenderState(prevRenderState);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLTableRowElementImpl.java 0000644 0001750 0001750 00000012050 11123426710 030725 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Dec 4, 2005
*/
package org.lobobrowser.html.domimpl;
import java.util.ArrayList;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
import org.w3c.dom.html2.HTMLCollection;
import org.w3c.dom.html2.HTMLElement;
import org.w3c.dom.html2.HTMLTableRowElement;
public class HTMLTableRowElementImpl extends HTMLElementImpl implements
HTMLTableRowElement {
public HTMLTableRowElementImpl(String name) {
super(name, true);
}
public HTMLTableRowElementImpl() {
super("TR", true);
}
public int getRowIndex() {
NodeImpl parent = (NodeImpl) this.getParentNode();
if(parent == null) {
return -1;
}
try {
parent.visit(new NodeVisitor() {
private int count = 0;
public void visit(Node node) {
if(node instanceof HTMLTableRowElementImpl) {
if(HTMLTableRowElementImpl.this == node) {
throw new StopVisitorException(new Integer(this.count));
}
this.count++;
}
}
});
} catch(StopVisitorException sve) {
return ((Integer) sve.getTag()).intValue();
}
return -1;
}
public int getSectionRowIndex() {
// TODO Auto-generated method stub
return 0;
}
public HTMLCollection getCells() {
NodeFilter filter = new NodeFilter() {
public boolean accept(Node node) {
return node instanceof HTMLTableCellElementImpl;
}
};
return new DescendentHTMLCollection(this, filter, this.treeLock, false);
}
public String getAlign() {
return this.getAttribute("align");
}
public void setAlign(String align) {
this.setAttribute("align", align);
}
public String getBgColor() {
return this.getAttribute("bgcolor");
}
public void setBgColor(String bgColor) {
this.setAttribute("bgcolor", bgColor);
}
public String getCh() {
return this.getAttribute("ch");
}
public void setCh(String ch) {
this.setAttribute("ch", ch);
}
public String getChOff() {
return this.getAttribute("choff");
}
public void setChOff(String chOff) {
this.setAttribute("choff", chOff);
}
public String getVAlign() {
return this.getAttribute("valign");
}
public void setVAlign(String vAlign) {
this.setAttribute("valign", vAlign);
}
/**
* Inserts a TH element at the specified index.
*
* Note: This method is non-standard.
* @param index The cell index to insert at.
* @return The element that was inserted.
* @throws DOMException When the index is out of range.
*/
public HTMLElement insertHeader(int index) throws DOMException {
return this.insertCell(index, "TH");
}
public HTMLElement insertCell(int index) throws DOMException {
return this.insertCell(index, "TD");
}
private HTMLElement insertCell(int index, String tagName) throws DOMException {
org.w3c.dom.Document doc = this.document;
if(doc == null) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Orphan element");
}
HTMLElement cellElement = (HTMLElement) doc.createElement(tagName);
synchronized(this.treeLock) {
if(index == -1) {
this.appendChild(cellElement);
return cellElement;
}
ArrayList nl = this.nodeList;
if(nl != null) {
int size = nl.size();
int trcount = 0;
for(int i = 0; i < size; i++) {
Node node = (Node) nl.get(i);
if(node instanceof org.w3c.dom.html2.HTMLTableCellElement) {
if(trcount == index) {
this.insertAt(cellElement, i);
return cellElement;
}
trcount++;
}
}
}
else {
this.appendChild(cellElement);
return cellElement;
}
}
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of range");
}
public void deleteCell(int index) throws DOMException {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl != null) {
int size = nl.size();
int trcount = 0;
for(int i = 0; i < size; i++) {
Node node = (Node) nl.get(i);
if(node instanceof org.w3c.dom.html2.HTMLTableCellElement) {
if(trcount == index) {
this.removeChildAt(index);
}
trcount++;
}
}
}
}
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Index out of range");
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLTextAreaElementImpl.java 0000644 0001750 0001750 00000004763 10726473510 030747 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 15, 2006
*/
package org.lobobrowser.html.domimpl;
import java.io.UnsupportedEncodingException;
import org.lobobrowser.html.FormInput;
import org.w3c.dom.html2.HTMLFormElement;
import org.w3c.dom.html2.HTMLTextAreaElement;
public class HTMLTextAreaElementImpl extends HTMLBaseInputElement implements
HTMLTextAreaElement {
public HTMLTextAreaElementImpl(String name) {
super(name);
}
public HTMLTextAreaElementImpl() {
super("TEXTAREA");
}
protected FormInput[] getFormInputs() {
String name = this.getName();
if(name == null) {
return null;
}
return new FormInput[] { new FormInput(name, this.getValue()) };
}
/* (non-Javadoc)
* @see org.w3c.dom.html2.HTMLTextAreaElement#getCols()
*/
public int getCols() {
InputContext ic = this.inputContext;
return ic == null ? 0 : ic.getCols();
}
/* (non-Javadoc)
* @see org.w3c.dom.html2.HTMLTextAreaElement#getRows()
*/
public int getRows() {
InputContext ic = this.inputContext;
return ic == null ? 0 : ic.getRows();
}
/* (non-Javadoc)
* @see org.w3c.dom.html2.HTMLTextAreaElement#getType()
*/
public String getType() {
return "textarea";
}
/* (non-Javadoc)
* @see org.w3c.dom.html2.HTMLTextAreaElement#setCols(int)
*/
public void setCols(int cols) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setCols(cols);
}
}
/* (non-Javadoc)
* @see org.w3c.dom.html2.HTMLTextAreaElement#setRows(int)
*/
public void setRows(int rows) {
InputContext ic = this.inputContext;
if(ic != null) {
ic.setRows(rows);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLTitleElementImpl.java 0000644 0001750 0001750 00000003110 10726473506 030301 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.*;
public class HTMLTitleElementImpl extends HTMLElementImpl {
public HTMLTitleElementImpl(String name) {
super(name, true);
}
public Object setUserData(String key, Object data, UserDataHandler handler) {
if(org.lobobrowser.html.parser.HtmlParser.MODIFYING_KEY.equals(key) && data == Boolean.FALSE) {
Document document = this.document;
if(document instanceof HTMLDocumentImpl) {
String textContent = this.getTextContent();
String title = textContent == null ? null : textContent.trim();
((HTMLDocumentImpl) document).setTitle(title);
}
}
return super.setUserData(key, data, handler);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLUListElementImpl.java 0000644 0001750 0001750 00000003346 11134376542 030267 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Feb 12, 2006
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
import org.w3c.dom.html2.HTMLUListElement;
public class HTMLUListElementImpl extends HTMLAbstractUIElement implements
HTMLUListElement {
public HTMLUListElementImpl(String name) {
super(name);
}
public boolean getCompact() {
String compactText = this.getAttribute("compact");
return "compact".equalsIgnoreCase(compactText);
}
public void setCompact(boolean compact) {
this.setAttribute("compact", compact ? "compact" : null);
}
public String getType() {
return this.getAttribute("type");
}
public void setType(String type) {
this.setAttribute("type", type);
}
protected RenderState createRenderState(RenderState prevRenderState) {
return new ListRenderState(prevRenderState, this);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/HTMLUnderlineElementImpl.java 0000644 0001750 0001750 00000002571 10726473502 031153 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.html.style.*;
/**
* Element used for U.
*/
public class HTMLUnderlineElementImpl extends HTMLAbstractUIElement {
public HTMLUnderlineElementImpl(String name) {
super(name);
}
protected RenderState createRenderState(RenderState prevRenderState) {
prevRenderState = new TextDecorationRenderState(prevRenderState, RenderState.MASK_TEXTDECORATION_UNDERLINE);
return super.createRenderState(prevRenderState);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/ImageEvent.java 0000644 0001750 0001750 00000002220 10726473510 026417 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
import java.util.EventObject;
public class ImageEvent extends EventObject {
public final java.awt.Image image;
public ImageEvent(Object source, java.awt.Image image) {
super(source);
this.image = image;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/ImageListener.java 0000644 0001750 0001750 00000002151 10726473510 027126 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.domimpl;
public interface ImageListener extends java.util.EventListener {
public static final ImageListener[] EMPTY_ARRAY = new ImageListener[0];
public void imageLoaded(ImageEvent event);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/InputContext.java 0000644 0001750 0001750 00000003762 10773432746 027063 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 15, 2006
*/
package org.lobobrowser.html.domimpl;
public interface InputContext {
public boolean getChecked();
public void setChecked(boolean checked);
public boolean getDisabled();
public void setDisabled(boolean disabled);
public int getMaxLength();
public void setMaxLength(int maxLength);
public String getName();
public void setName(String name);
public boolean getReadOnly();
public void setReadOnly(boolean readOnly);
public int getControlSize();
public void setControlSize(int size);
public int getTabIndex();
public void setTabIndex(int tabIndex);
public String getValue();
public String[] getValues();
public void setValue(String value);
public void blur();
public void focus();
public void select();
public void click();
public int getRows();
public int getCols();
public void setRows(int rows);
public void setCols(int cols);
public int getSelectedIndex();
public void setSelectedIndex(int value);
public int getVisibleSize();
public void setVisibleSize(int value);
public java.io.File getFileValue();
public void resetInput();
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/LocalErrorHandler.java 0000644 0001750 0001750 00000003400 10726473510 027736 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 22, 2005
*/
package org.lobobrowser.html.domimpl;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import java.util.logging.*;
class LocalErrorHandler implements ErrorHandler {
private static final Logger logger = Logger.getLogger(LocalErrorHandler.class.getName());
/**
* @param context
*/
public LocalErrorHandler() {
}
public void warning(SAXParseException exception) throws SAXException {
logger.log(Level.WARNING,exception.getMessage(), exception.getCause());
}
public void error(SAXParseException exception) throws SAXException {
logger.log(Level.SEVERE,exception.getMessage(), exception.getCause());
}
public void fatalError(SAXParseException exception) throws SAXException {
logger.log(Level.SEVERE,exception.getMessage(), exception.getCause());
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/ModelNode.java 0000644 0001750 0001750 00000003463 10726473500 026252 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 23, 2005
*/
package org.lobobrowser.html.domimpl;
import java.net.MalformedURLException;
import org.lobobrowser.html.style.*;
/**
* A generic node interface. The idea is that implementors could
* be W3C nodes or not.
*/
public interface ModelNode {
//There shouldn't be any references to GUI components here.
//Events are processed by controller in renderer package.
public java.net.URL getFullURL(String spec) throws MalformedURLException;
public void warn(String message, Throwable err);
public boolean isEqualOrDescendentOf(ModelNode otherNode);
public ModelNode getParentModelNode();
public RenderState getRenderState();
/**
* Sets a document item. A radio button, for example,
* can use this to set button group state.
* @param name
* @param value
*/
public void setDocumentItem(String name, Object value);
public Object getDocumentItem(String name);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/NamedNodeMapImpl.java 0000644 0001750 0001750 00000006075 10726473510 027521 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Sep 3, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.js.*;
import org.w3c.dom.*;
import java.util.*;
public class NamedNodeMapImpl extends AbstractScriptableDelegate implements NamedNodeMap {
//Note: class must be public for reflection to work.
private final Map attributes = new HashMap();
private final ArrayList attributeList = new ArrayList();
public NamedNodeMapImpl(Element owner, Map attribs) {
Iterator i = attribs.entrySet().iterator();
while(i.hasNext()) {
Map.Entry entry = (Map.Entry) i.next();
String name = (String) entry.getKey();
String value = (String) entry.getValue();
//TODO: "specified" attributes
Attr attr = new AttrImpl(name, value, true, owner, "ID".equals(name));
this.attributes.put(name, attr);
this.attributeList.add(attr);
}
}
public int getLength() {
return this.attributeList.size();
}
public Node getNamedItem(String name) {
return (Node) this.attributes.get(name);
}
/**
* @param name
*/
public Node namedItem(String name) {
// Method needed for Javascript indexing.
return this.getNamedItem(name);
}
public Node getNamedItemNS(String namespaceURI,
String localName) throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "No namespace support");
}
public Node item(int index) {
try {
return (Node) this.attributeList.get(index);
} catch(IndexOutOfBoundsException iob) {
return null;
}
}
public Node removeNamedItem(String name) throws DOMException {
return (Node) this.attributes.remove(name);
}
public Node removeNamedItemNS(String namespaceURI,
String localName) throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "No namespace support");
}
public Node setNamedItem(Node arg) throws DOMException {
Object prevValue = this.attributes.put(arg.getNodeName(), arg);
if(prevValue != null) {
this.attributeList.remove(prevValue);
}
this.attributeList.add(arg);
return arg;
}
public Node setNamedItemNS(Node arg) throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "No namespace support");
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/NodeFilter.java 0000644 0001750 0001750 00000002060 10726473510 026430 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 8, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.*;
public interface NodeFilter {
public boolean accept(Node node);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/NodeImpl.java 0000644 0001750 0001750 00000076240 11067635342 026121 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Sep 3, 2005
*/
package org.lobobrowser.html.domimpl;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.logging.*;
import org.lobobrowser.html.*;
import org.lobobrowser.html.style.*;
import org.lobobrowser.js.*;
import org.lobobrowser.util.*;
import org.w3c.dom.*;
public abstract class NodeImpl extends AbstractScriptableDelegate implements Node, ModelNode {
private static final NodeImpl[] EMPTY_ARRAY = new NodeImpl[0];
private static final RenderState INVALID_RENDER_STATE = new StyleSheetRenderState(null);
protected static final Logger logger = Logger.getLogger(NodeImpl.class.getName());
protected UINode uiNode;
protected ArrayList nodeList;
protected volatile Document document;
/**
* A tree lock is less deadlock-prone than
* a node-level lock. This is assigned in
* setOwnerDocument.
*/
protected volatile Object treeLock = this;
public NodeImpl() {
super();
}
public void setUINode(UINode uiNode) {
// Called in GUI thread always.
this.uiNode = uiNode;
}
public UINode getUINode() {
// Called in GUI thread always.
return this.uiNode;
}
/**
* Tries to get a UINode associated with the current node.
* Failing that, it tries ancestors recursively. This method
* will return the closest block-level renderer node, if any.
*/
public UINode findUINode() {
// Called in GUI thread always.
UINode uiNode = this.uiNode;
if(uiNode != null) {
return uiNode;
}
NodeImpl parentNode = (NodeImpl) this.getParentNode();
return parentNode == null ? null : parentNode.findUINode();
}
public Node appendChild(Node newChild)
throws DOMException {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl == null) {
nl = new ArrayList(3);
this.nodeList = nl;
}
nl.add(newChild);
if(newChild instanceof NodeImpl) {
((NodeImpl) newChild).setParentImpl(this);
}
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
return newChild;
}
protected void removeAllChildren() {
synchronized(this.treeLock) {
this.removeAllChildrenImpl();
}
}
protected void removeAllChildrenImpl() {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl != null) {
nl.clear();
//this.nodeList = null;
}
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
}
protected NodeList getNodeList(NodeFilter filter) {
Collection collection = new ArrayList();
synchronized(this.treeLock) {
this.appendChildrenToCollectionImpl(filter, collection);
}
return new NodeListImpl(collection);
}
public NodeImpl[] getChildrenArray() {
ArrayList nl = this.nodeList;
synchronized(this.treeLock) {
return nl == null ? null : (NodeImpl[]) nl.toArray(NodeImpl.EMPTY_ARRAY);
}
}
int getChildCount() {
ArrayList nl = this.nodeList;
synchronized(this.treeLock) {
return nl == null ? 0 : nl.size();
}
}
private ChildHTMLCollection childrenCollection;
public ChildHTMLCollection getChildren() {
// Method required by JavaScript
synchronized(this) {
ChildHTMLCollection collection = this.childrenCollection;
if(collection == null) {
collection = new ChildHTMLCollection(this);
this.childrenCollection = collection;
}
return collection;
}
}
/**
* Creates an ArrayList
of descendent nodes that
* the given filter condition.
*/
public ArrayList getDescendents(NodeFilter filter, boolean nestIntoMatchingNodes) {
ArrayList al = new ArrayList();
synchronized(this.treeLock) {
this.extractDescendentsArrayImpl(filter, al, nestIntoMatchingNodes);
}
return al;
}
/**
* Extracts all descendents that match the filter, except those
* descendents of nodes that match the filter.
* @param filter
* @param al
*/
private void extractDescendentsArrayImpl(NodeFilter filter, ArrayList al, boolean nestIntoMatchingNodes) {
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
NodeImpl n = (NodeImpl) i.next();
if(filter.accept(n)) {
al.add(n);
if(nestIntoMatchingNodes) {
n.extractDescendentsArrayImpl(filter, al, nestIntoMatchingNodes);
}
}
else if(n.getNodeType() == Node.ELEMENT_NODE) {
n.extractDescendentsArrayImpl(filter, al, nestIntoMatchingNodes);
}
}
}
}
private void appendChildrenToCollectionImpl(NodeFilter filter, Collection collection) {
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
NodeImpl node = (NodeImpl) i.next();
if(filter.accept(node)) {
collection.add(node);
}
node.appendChildrenToCollectionImpl(filter, collection);
}
}
}
/**
* Should create a node with some cloned properties, like the node name,
* but not attributes or children.
*/
protected abstract Node createSimilarNode();
public Node cloneNode(boolean deep) {
try {
Node newNode = this.createSimilarNode();
NodeList children = this.getChildNodes();
int length = children.getLength();
for(int i = 0; i < length; i++) {
Node child = (Node) children.item(i);
Node newChild = deep ? child.cloneNode(deep) : child;
newNode.appendChild(newChild);
}
if(newNode instanceof Element) {
Element elem = (Element) newNode;
NamedNodeMap nnmap = this.getAttributes();
if(nnmap != null) {
int nnlength = nnmap.getLength();
for(int i = 0; i < nnlength; i++) {
Attr attr = (Attr) nnmap.item(i);
elem.setAttributeNode((Attr) attr.cloneNode(true));
}
}
}
synchronized(this){
if (userDataHandlers != null && userData != null) {
for(Iterator handlers = userDataHandlers.entrySet().iterator();handlers.hasNext();){
Map.Entry entry = (Map.Entry) handlers.next();
UserDataHandler handler = (UserDataHandler)entry.getValue();
handler.handle(UserDataHandler.NODE_CLONED,(String) entry.getKey(),userData.get(entry.getKey()), this, newNode);
}
}
}
return newNode;
} catch(Exception err) {
throw new IllegalStateException(err.getMessage());
}
}
private int getNodeIndex() {
NodeImpl parent = (NodeImpl) this.getParentNode();
return parent == null ? -1 : parent.getChildIndex(this);
}
int getChildIndex(Node child) {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
return nl == null ? -1 : nl.indexOf(child);
}
}
Node getChildAtIndex(int index) {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
try {
return nl == null ? null : (Node) nl.get(index);
} catch(IndexOutOfBoundsException iob) {
this.warn("getChildAtIndex(): Bad index=" + index + " for node=" + this + ".");
return null;
}
}
}
private boolean isAncestorOf(Node other) {
NodeImpl parent = (NodeImpl) other.getParentNode();
if(parent == this) {
return true;
}
else if(parent == null) {
return false;
}
else {
return this.isAncestorOf(parent);
}
}
public short compareDocumentPosition(Node other)
throws DOMException {
Node parent = this.getParentNode();
if(!(other instanceof NodeImpl)) {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Unknwon node implementation");
}
if(parent != null && parent == other.getParentNode()) {
int thisIndex = this.getNodeIndex();
int otherIndex = ((NodeImpl) other).getNodeIndex();
if(thisIndex == -1 || otherIndex == -1) {
return Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
}
if(thisIndex < otherIndex) {
return Node.DOCUMENT_POSITION_FOLLOWING;
}
else {
return Node.DOCUMENT_POSITION_PRECEDING;
}
}
else if(this.isAncestorOf(other)) {
return Node.DOCUMENT_POSITION_CONTAINED_BY;
}
else if(((NodeImpl) other).isAncestorOf(this)) {
return Node.DOCUMENT_POSITION_CONTAINS;
}
else {
return Node.DOCUMENT_POSITION_DISCONNECTED;
}
}
public NamedNodeMap getAttributes() {
return null;
}
public Document getOwnerDocument() {
return this.document;
}
void setOwnerDocument(Document value) {
this.document = value;
this.treeLock = value == null ? this : (Object) value;
}
void setOwnerDocument(Document value, boolean deep) {
this.document = value;
this.treeLock = value == null ? this : (Object) value;
if(deep) {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
NodeImpl child = (NodeImpl) i.next();
child.setOwnerDocument(value, deep);
}
}
}
}
}
void visitImpl(NodeVisitor visitor) {
try {
visitor.visit(this);
} catch(SkipVisitorException sve) {
return;
} catch(StopVisitorException sve) {
throw sve;
}
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
NodeImpl child = (NodeImpl) i.next();
try {
// Call with child's synchronization
child.visit(visitor);
} catch(StopVisitorException sve) {
throw sve;
}
}
}
}
void visit(NodeVisitor visitor) {
synchronized(this.treeLock) {
this.visitImpl(visitor);
}
}
public Node insertBefore(Node newChild, Node refChild)
throws DOMException {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
int idx = nl == null ? -1 : nl.indexOf(refChild);
if(idx == -1) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "refChild not found");
}
nl.add(idx, newChild);
if(newChild instanceof NodeImpl) {
((NodeImpl) newChild).setParentImpl(this);
}
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
return newChild;
}
protected Node insertAt(Node newChild, int idx)
throws DOMException {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl == null) {
nl = new ArrayList();
this.nodeList = nl;
}
nl.add(idx, newChild);
if(newChild instanceof NodeImpl) {
((NodeImpl) newChild).setParentImpl(this);
}
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
return newChild;
}
public Node replaceChild(Node newChild, Node oldChild)
throws DOMException {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
int idx = nl == null ? -1 : nl.indexOf(oldChild);
if(idx == -1) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "oldChild not found");
}
nl.set(idx, newChild);
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
return newChild;
}
public Node removeChild(Node oldChild)
throws DOMException {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl == null || !nl.remove(oldChild)) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "oldChild not found");
}
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
return oldChild;
}
public Node removeChildAt(int index)
throws DOMException {
try {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl == null) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Empty list of children");
}
Node n = (Node) nl.remove(index);
if (n == null) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "No node with that index");
}
return n;
}
} finally {
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
}
}
public boolean hasChildNodes() {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
return nl != null && !nl.isEmpty();
}
}
public String getBaseURI() {
Document document = this.document;
return document == null ? null : document.getBaseURI();
}
public NodeList getChildNodes() {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
return new NodeListImpl(nl == null ? Collections.EMPTY_LIST : nl);
}
}
public Node getFirstChild() {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
try {
return nl == null ? null : (Node) nl.get(0);
} catch(IndexOutOfBoundsException iob) {
return null;
}
}
}
public Node getLastChild() {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
try {
return nl == null ? null : (Node) nl.get(nl.size() - 1);
} catch(IndexOutOfBoundsException iob) {
return null;
}
}
}
private Node getPreviousTo(Node node) {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
int idx = nl == null ? -1 : nl.indexOf(node);
if(idx == -1) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "node not found");
}
try {
return (Node) nl.get(idx-1);
} catch(IndexOutOfBoundsException iob) {
return null;
}
}
}
private Node getNextTo(Node node) {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
int idx = nl == null ? -1 : nl.indexOf(node);
if(idx == -1) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "node not found");
}
try {
return (Node) nl.get(idx+1);
} catch(IndexOutOfBoundsException iob) {
return null;
}
}
}
public Node getPreviousSibling() {
NodeImpl parent = (NodeImpl) this.getParentNode();
return parent == null ? null : parent.getPreviousTo(this);
}
public Node getNextSibling() {
NodeImpl parent = (NodeImpl) this.getParentNode();
return parent == null ? null : parent.getNextTo(this);
}
public Object getFeature(String feature, String version) {
//TODO What should this do?
return null;
}
private Map userData;
//TODO: Inform handlers on cloning, etc.
private Map userDataHandlers;
protected volatile boolean notificationsSuspended = false;
public Object setUserData(String key, Object data,
UserDataHandler handler) {
if(org.lobobrowser.html.parser.HtmlParser.MODIFYING_KEY.equals(key)) {
boolean ns = (Boolean.TRUE == data);
this.notificationsSuspended = ns;
if(!ns) {
this.informNodeLoaded();
}
}
//here we spent some effort preventing our maps from growing too much
synchronized(this) {
if(handler != null) {
if(this.userDataHandlers == null) {
this.userDataHandlers = new HashMap();
}
else if (handler == null){
this.userDataHandlers.remove(key);
}
if (handler != null)
this.userDataHandlers.put(key,handler);
}
Map userData = this.userData;
if (data != null){
if(userData == null) {
userData = new HashMap();
this.userData = userData;
}
return userData.put(key, data);
}
else if (userData != null)
return userData.remove(key);
else
return null;
}
}
public Object getUserData(String key) {
synchronized(this) {
Map ud = this.userData;
return ud == null ? null : ud.get(key);
}
}
public abstract String getLocalName();
public boolean hasAttributes() {
return false;
}
public String getNamespaceURI() {
return null;
}
public abstract String getNodeName();
public abstract String getNodeValue() throws DOMException;
private volatile String prefix;
public String getPrefix() {
return this.prefix;
}
public void setPrefix(String prefix) throws DOMException {
this.prefix = prefix;
}
public abstract void setNodeValue(String nodeValue) throws DOMException;
public abstract short getNodeType();
/**
* Gets the text content of this node
* and its descendents.
*/
public String getTextContent() throws DOMException {
StringBuffer sb = new StringBuffer();
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
Node node = (Node) i.next();
short type = node.getNodeType();
switch(type) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
case Node.ELEMENT_NODE:
String textContent = node.getTextContent();
if(textContent != null) {
sb.append(textContent);
}
break;
default:
break;
}
}
}
}
return sb.toString();
}
public void setTextContent(String textContent) throws DOMException {
synchronized(this.treeLock) {
this.removeChildrenImpl(new TextFilter());
if(textContent != null && !"".equals(textContent)) {
TextImpl t = new TextImpl(textContent);
t.setOwnerDocument(this.document);
t.setParentImpl(this);
ArrayList nl = this.nodeList;
if(nl == null) {
nl = new ArrayList();
this.nodeList = nl;
}
nl.add(t);
}
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
}
protected void removeChildren(NodeFilter filter) {
synchronized(this.treeLock) {
this.removeChildrenImpl(filter);
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
}
protected void removeChildrenImpl(NodeFilter filter) {
ArrayList nl = this.nodeList;
if(nl != null) {
int len = nl.size();
for(int i = len; --i >= 0;) {
Node node = (Node) nl.get(i);
if(filter.accept(node)) {
nl.remove(i);
}
}
}
}
public Node insertAfter(Node newChild, Node refChild) {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
int idx = nl == null ? -1 : nl.indexOf(refChild);
if(idx == -1) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "refChild not found");
}
nl.add(idx+1, newChild);
if(newChild instanceof NodeImpl) {
((NodeImpl) newChild).setParentImpl(this);
}
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
return newChild;
}
public Text replaceAdjacentTextNodes(Text node, String textContent) {
try {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl == null) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "Node not a child");
}
int idx = nl.indexOf(node);
if(idx == -1) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "Node not a child");
}
int firstIdx = idx;
List toDelete = new LinkedList();
for(int adjIdx = idx; --adjIdx >= 0;) {
Object child = this.nodeList.get(adjIdx);
if(child instanceof Text) {
firstIdx = adjIdx;
toDelete.add(child);
}
}
int length = this.nodeList.size();
for(int adjIdx = idx; ++adjIdx < length;) {
Object child = this.nodeList.get(adjIdx);
if(child instanceof Text) {
toDelete.add(child);
}
}
this.nodeList.removeAll(toDelete);
TextImpl textNode = new TextImpl(textContent);
textNode.setOwnerDocument(this.document);
textNode.setParentImpl(this);
this.nodeList.add(firstIdx, textNode);
return textNode;
}
} finally {
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
}
}
public Text replaceAdjacentTextNodes(Text node) {
try {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl == null) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "Node not a child");
}
int idx = nl.indexOf(node);
if(idx == -1) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "Node not a child");
}
StringBuffer textBuffer = new StringBuffer();
int firstIdx = idx;
List toDelete = new LinkedList();
for(int adjIdx = idx; --adjIdx >= 0;) {
Object child = this.nodeList.get(adjIdx);
if(child instanceof Text) {
firstIdx = adjIdx;
toDelete.add(child);
textBuffer.append(((Text) child).getNodeValue());
}
}
int length = this.nodeList.size();
for(int adjIdx = idx; ++adjIdx < length;) {
Object child = this.nodeList.get(adjIdx);
if(child instanceof Text) {
toDelete.add(child);
textBuffer.append(((Text) child).getNodeValue());
}
}
this.nodeList.removeAll(toDelete);
TextImpl textNode = new TextImpl(textBuffer.toString());
textNode.setOwnerDocument(this.document);
textNode.setParentImpl(this);
this.nodeList.add(firstIdx, textNode);
return textNode;
}
} finally {
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
}
}
protected volatile Node parentNode;
public Node getParentNode() {
// Should it be synchronized? Could have side-effects.
return this.parentNode;
}
public boolean isSameNode(Node other) {
return this == other;
}
public boolean isSupported(String feature, String version) {
return ("HTML".equals(feature) && version.compareTo("4.01") <= 0);
}
public String lookupNamespaceURI(String prefix) {
return null;
}
public boolean equalAttributes(Node arg) {
return false;
}
public boolean isEqualNode(Node arg) {
return arg instanceof NodeImpl &&
this.getNodeType() == arg.getNodeType() &&
Objects.equals(this.getNodeName(), arg.getNodeName()) &&
Objects.equals(this.getNodeValue(), arg.getNodeValue()) &&
Objects.equals(this.getLocalName(), arg.getLocalName()) &&
Objects.equals(this.nodeList, ((NodeImpl) arg).nodeList) &&
this.equalAttributes(arg);
}
public boolean isDefaultNamespace(String namespaceURI) {
return namespaceURI == null;
}
public String lookupPrefix(String namespaceURI) {
return null;
}
public void normalize() {
synchronized(this.treeLock) {
ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
List textNodes = new LinkedList();
boolean prevText = false;
while(i.hasNext()) {
Node child = (Node) i.next();
if(child.getNodeType() == Node.TEXT_NODE) {
if(!prevText) {
prevText = true;
textNodes.add(child);
}
}
else {
prevText = false;
}
}
i = textNodes.iterator();
while(i.hasNext()) {
Text text = (Text) i.next();
this.replaceAdjacentTextNodes(text);
}
}
}
if(!this.notificationsSuspended) {
this.informStructureInvalid();
}
}
public String toString() {
return this.getNodeName();
}
public UserAgentContext getUserAgentContext() {
Object doc = this.document;
if(doc instanceof HTMLDocumentImpl) {
return ((HTMLDocumentImpl) doc).getUserAgentContext();
}
else {
return null;
}
}
public HtmlRendererContext getHtmlRendererContext() {
Object doc = this.document;
if(doc instanceof HTMLDocumentImpl) {
return ((HTMLDocumentImpl) doc).getHtmlRendererContext();
}
else {
return null;
}
}
final void setParentImpl(Node parent) {
// Call holding treeLock.
this.parentNode = parent;
}
//----- ModelNode implementation
/* (non-Javadoc)
* @see org.xamjwg.html.renderer.RenderableContext#getAlignmentX()
*/
public float getAlignmentX() {
//TODO: Removable method?
return 0.5f;
}
/* (non-Javadoc)
* @see org.xamjwg.html.renderer.RenderableContext#getAlignmentY()
*/
public float getAlignmentY() {
return 0.5f;
}
/* (non-Javadoc)
* @see org.xamjwg.html.renderer.RenderableContext#getFullURL(java.lang.String)
*/
public URL getFullURL(String spec) throws MalformedURLException {
Object doc = this.document;
if(doc instanceof HTMLDocumentImpl) {
return ((HTMLDocumentImpl) doc).getFullURL(spec);
}
else {
return new java.net.URL(spec);
}
}
public URL getDocumentURL() {
Object doc = this.document;
if(doc instanceof HTMLDocumentImpl) {
return ((HTMLDocumentImpl) doc).getDocumentURL();
}
else {
return null;
}
}
/* (non-Javadoc)
* @see org.xamjwg.html.renderer.RenderableContext#getDocumentItem(java.lang.String)
*/
public Object getDocumentItem(String name) {
org.w3c.dom.Document document = this.document;
return document == null ? null : document.getUserData(name);
}
/* (non-Javadoc)
* @see org.xamjwg.html.renderer.RenderableContext#setDocumentItem(java.lang.String, java.lang.Object)
*/
public void setDocumentItem(String name, Object value) {
org.w3c.dom.Document document = this.document;
if(document == null) {
return;
}
document.setUserData(name, value, null);
}
/* (non-Javadoc)
* @see org.xamjwg.html.renderer.RenderableContext#isEqualOrDescendentOf(org.xamjwg.html.renderer.RenderableContext)
*/
public final boolean isEqualOrDescendentOf(ModelNode otherContext) {
if(otherContext == this) {
return true;
}
Object parent = this.getParentNode();
if(parent instanceof HTMLElementImpl) {
return ((HTMLElementImpl) parent).isEqualOrDescendentOf(otherContext);
}
else {
return false;
}
}
public final ModelNode getParentModelNode() {
return (ModelNode) this.parentNode;
}
public void warn(String message, Throwable err) {
logger.log(Level.WARNING, message, err);
}
public void warn(String message) {
logger.log(Level.WARNING, message);
}
public void informSizeInvalid() {
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.sizeInvalidated(this);
}
}
public void informLookInvalid() {
this.forgetRenderState();
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.lookInvalidated(this);
}
}
public void informPositionInvalid() {
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.positionInParentInvalidated(this);
}
}
public void informInvalid() {
// This is called when an attribute or child changes.
this.forgetRenderState();
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.invalidated(this);
}
}
public void informStructureInvalid() {
// This is called when an attribute or child changes.
this.forgetRenderState();
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.structureInvalidated(this);
}
}
protected void informNodeLoaded() {
// This is called when an attribute or child changes.
this.forgetRenderState();
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.nodeLoaded(this);
}
}
protected void informExternalScriptLoading() {
// This is called when an attribute or child changes.
this.forgetRenderState();
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.externalScriptLoading(this);
}
}
public void informLayoutInvalid() {
// This is called by the style properties object.
this.forgetRenderState();
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.invalidated(this);
}
}
public void informDocumentInvalid() {
// This is called when an attribute or child changes.
HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
if(doc != null) {
doc.allInvalidated(true);
}
}
private RenderState renderState = INVALID_RENDER_STATE;
public RenderState getRenderState() {
// Generally called from the GUI thread, except for
// offset properties.
RenderState rs;
synchronized(this.treeLock) {
rs = this.renderState;
if(rs != INVALID_RENDER_STATE) {
return rs;
}
Object parent = this.parentNode;
if(parent != null || this instanceof Document) {
RenderState prs = this.getParentRenderState(parent);
rs = this.createRenderState(prs);
this.renderState = rs;
return rs;
}
else {
// Return null without caching.
// Scenario is possible due to Javascript.
return null;
}
}
}
protected final RenderState getParentRenderState(Object parent) {
if(parent instanceof NodeImpl) {
return ((NodeImpl) parent).getRenderState();
}
else {
return null;
}
}
protected RenderState createRenderState(RenderState prevRenderState) {
return prevRenderState;
}
protected void forgetRenderState() {
synchronized(this.treeLock) {
if(this.renderState != INVALID_RENDER_STATE) {
this.renderState = INVALID_RENDER_STATE;
// Note that getRenderState() "validates"
// ancestor states as well.
java.util.ArrayList nl = this.nodeList;
if(nl != null) {
Iterator i = nl.iterator();
while(i.hasNext()) {
((NodeImpl) i.next()).forgetRenderState();
}
}
}
}
}
public String getInnerHTML() {
StringBuffer buffer = new StringBuffer();
synchronized(this) {
this.appendInnerHTMLImpl(buffer);
}
return buffer.toString();
}
protected void appendInnerHTMLImpl(StringBuffer buffer) {
ArrayList nl = this.nodeList;
int size;
if (nl != null && (size = nl.size()) > 0) {
for (int i = 0; i < size; i++) {
Node child = (Node) nl.get(i);
if (child instanceof HTMLElementImpl) {
((HTMLElementImpl) child).appendOuterHTMLImpl(buffer);
}
else if(child instanceof Comment) {
buffer.append("");
}
else if (child instanceof Text) {
String text = ((Text) child).getTextContent();
String encText = this.htmlEncodeChildText(text);
buffer.append(encText);
}
else if (child instanceof ProcessingInstruction) {
buffer.append(child.toString());
}
}
}
}
protected String htmlEncodeChildText(String text) {
return Strings.strictHtmlEncode(text, false);
}
/**
* Attempts to convert the subtree starting at this point to a close text
* representation. BR elements are converted to line breaks, and so forth.
*/
public String getInnerText() {
StringBuffer buffer = new StringBuffer();
synchronized(this.treeLock) {
this.appendInnerTextImpl(buffer);
}
return buffer.toString();
}
protected void appendInnerTextImpl(StringBuffer buffer) {
ArrayList nl = this.nodeList;
if (nl == null) {
return;
}
int size = nl.size();
if (size == 0) {
return;
}
for (int i = 0; i < size; i++) {
Node child = (Node) nl.get(i);
if (child instanceof ElementImpl) {
((ElementImpl) child).appendInnerTextImpl(buffer);
}
if(child instanceof Comment) {
// skip
}
else if (child instanceof Text) {
buffer.append(((Text) child).getTextContent());
}
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/NodeListImpl.java 0000644 0001750 0001750 00000003043 10726473506 026747 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Sep 3, 2005
*/
package org.lobobrowser.html.domimpl;
import org.lobobrowser.js.*;
import org.w3c.dom.*;
import java.util.*;
public class NodeListImpl extends AbstractScriptableDelegate implements NodeList {
//Note: class must be public for reflection to work.
private final ArrayList nodeList = new ArrayList();
public NodeListImpl(Collection collection) {
super();
nodeList.addAll(collection);
}
public int getLength() {
return this.nodeList.size();
}
public Node item(int index) {
try {
return (Node) this.nodeList.get(index);
} catch(IndexOutOfBoundsException iob) {
return null;
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/NodeVisitor.java 0000644 0001750 0001750 00000002272 10726473510 026647 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 9, 2005
*/
package org.lobobrowser.html.domimpl;
public interface NodeVisitor {
/**
* Visits a node. The call should be
* expected to occur in a synchronized
* block. The lock will be node-dependent.
* @param node
*/
public void visit(org.w3c.dom.Node node);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/SkipVisitorException.java 0000644 0001750 0001750 00000002461 10726473510 030547 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Dec 3, 2005
*/
package org.lobobrowser.html.domimpl;
class SkipVisitorException extends RuntimeException {
public SkipVisitorException() {
super();
}
public SkipVisitorException(String message) {
super(message);
}
public SkipVisitorException(String message, Throwable cause) {
super(message, cause);
}
public SkipVisitorException(Throwable cause) {
super(cause);
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/StopVisitorException.java 0000644 0001750 0001750 00000003037 10726473510 030566 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Dec 3, 2005
*/
package org.lobobrowser.html.domimpl;
class StopVisitorException extends RuntimeException {
private final Object tag;
public StopVisitorException() {
super();
this.tag = null;
}
public StopVisitorException(String message) {
super(message);
this.tag = null;
}
public StopVisitorException(String message, Throwable cause) {
super(message, cause);
this.tag = null;
}
public StopVisitorException(Throwable cause) {
super(cause);
this.tag = null;
}
public StopVisitorException(Object tag) {
this.tag = tag;
}
public final Object getTag() {
return this.tag;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/TextFilter.java 0000644 0001750 0001750 00000002241 10726473476 026503 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Nov 13, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.Node;
public class TextFilter implements NodeFilter {
public TextFilter() {
super();
}
public boolean accept(Node node) {
return node instanceof org.w3c.dom.Text;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/TextImpl.java 0000644 0001750 0001750 00000007761 10726473502 026161 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Sep 4, 2005
*/
package org.lobobrowser.html.domimpl;
import org.w3c.dom.*;
import org.lobobrowser.util.*;
public class TextImpl extends CharacterDataImpl implements Text {
public TextImpl() {
this("");
}
public TextImpl(String text) {
this.text = text;
}
/* (non-Javadoc)
* @see org.w3c.dom.html2.Text#isElementContentWhitespace()
*/
public boolean isElementContentWhitespace() {
String t = this.text;
return t == null || t.trim().equals("");
}
/* (non-Javadoc)
* @see org.w3c.dom.html2.Text#replaceWholeText(java.lang.String)
*/
public Text replaceWholeText(String content) throws DOMException {
NodeImpl parent = (NodeImpl) this.getParentNode();
if(parent == null) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Text node has no parent");
}
return parent.replaceAdjacentTextNodes(this, content);
}
/* (non-Javadoc)
* @see org.w3c.dom.html2.Text#splitText(int)
*/
public Text splitText(int offset) throws DOMException {
NodeImpl parent = (NodeImpl) this.getParentNode();
if(parent == null) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Text node has no parent");
}
String t = this.text;
if(offset < 0 || offset > t.length()) {
throw new DOMException(DOMException.INDEX_SIZE_ERR, "Bad offset: " + offset);
}
String content1 = t.substring(0, offset);
String content2 = t.substring(offset);
this.text = content1;
TextImpl newNode = new TextImpl(content2);
newNode.setOwnerDocument(this.document);
return (Text) parent.insertAfter(newNode, this);
}
/* (non-Javadoc)
* @see org.w3c.dom.html2.Text#getwholeText()
*/
public String getWholeText() {
NodeImpl parent = (NodeImpl) this.getParentNode();
if(parent == null) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Text node has no parent");
}
return parent.getTextContent();
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getlocalName()
*/
public String getLocalName() {
return null;
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getnodeName()
*/
public String getNodeName() {
return "#text";
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getnodeType()
*/
public short getNodeType() {
return Node.TEXT_NODE;
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#getnodeValue()
*/
public String getNodeValue() throws DOMException {
return this.text;
}
/* (non-Javadoc)
* @see org.xamjwg.html.domimpl.NodeImpl#setnodeValue(java.lang.String)
*/
public void setNodeValue(String nodeValue) throws DOMException {
this.text = nodeValue;
}
public void setTextContent(String textContent) throws DOMException {
this.text = textContent;
}
protected Node createSimilarNode() {
return new TextImpl(this.text);
}
public String toString() {
String text = this.text;
int textLength = text == null ? 0 : text.length();
return "#text[length=" + textLength + ",value=\"" + Strings.truncate(text, 64) + "\",renderState=" + this.getRenderState() + "]";
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/UINode.java 0000644 0001750 0001750 00000002625 11050517260 025517 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Jan 14, 2006
*/
package org.lobobrowser.html.domimpl;
import java.awt.Rectangle;
/**
* A UI node abstraction that is used to send notifications
* back to the UI and to obtain information the DOM needs
* from the UI (such as image dimensions).
*/
public interface UINode {
/**
* Called
* @param modelNode
*/
public void repaint(ModelNode modelNode);
public Rectangle getBounds();
public Rectangle getBoundsRelativeToBlock();
public void focus();
public void blur();
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/domimpl/package.html 0000644 0001750 0001750 00000000121 10741125662 026006 0 ustar twerner twerner
HtmlBlockPanel
* is used by {@link HtmlPanel} whenever the DOM
* is determined not to be a FRAMESET.
* @see HtmlPanel
* @see FrameSetPanel
* @author J. H. S.
*/
public class HtmlBlockPanel extends JComponent implements NodeRenderer, RenderableContainer, ClipboardOwner {
private static final Logger logger = Logger.getLogger(HtmlBlockPanel.class.getName());
private static final boolean loggableInfo = logger.isLoggable(Level.INFO);
protected final FrameContext frameContext;
protected final UserAgentContext ucontext;
protected final HtmlRendererContext rcontext;
protected RenderableSpot startSelection;
protected RenderableSpot endSelection;
protected RBlock rblock;
protected int preferredWidth = -1;
protected Insets defaultMarginInsets = null;
//protected Insets defaultPaddingInsets = null;
protected int defaultOverflowX = RenderState.OVERFLOW_AUTO;
protected int defaultOverflowY = RenderState.OVERFLOW_SCROLL;
public HtmlBlockPanel(UserAgentContext pcontext, HtmlRendererContext rcontext, FrameContext frameContext) {
this(ColorFactory.TRANSPARENT, false, pcontext, rcontext, frameContext);
}
public HtmlBlockPanel(Color background, boolean opaque, UserAgentContext pcontext, HtmlRendererContext rcontext, FrameContext frameContext) {
this.setLayout(null);
this.setAutoscrolls(true);
this.frameContext = frameContext;
this.ucontext = pcontext;
this.rcontext = rcontext;
this.setOpaque(opaque);
this.setBackground(background);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if("copy".equals(command)) {
copy();
}
}
};
if(!GraphicsEnvironment.isHeadless()) {
this.registerKeyboardAction(actionListener, "copy", KeyStroke.getKeyStroke(KeyEvent.VK_COPY, 0), JComponent.WHEN_FOCUSED);
this.registerKeyboardAction(actionListener, "copy", KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), JComponent.WHEN_FOCUSED);
}
this.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
onMouseClick(e);
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
onMouseExited(e);
}
public void mousePressed(MouseEvent e) {
onMousePressed(e);
}
public void mouseReleased(MouseEvent e) {
onMouseReleased(e);
}
});
this.addMouseMotionListener(new MouseMotionListener() {
/* (non-Javadoc)
* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
*/
public void mouseDragged(MouseEvent e) {
onMouseDragged(e);
}
/* (non-Javadoc)
* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
*/
public void mouseMoved(MouseEvent arg0) {
onMouseMoved(arg0);
}
});
this.addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
onMouseWheelMoved(e);
}
});
}
/**
* Scrolls the body area to the given location.
* * This method should be called from the GUI thread. * @param bounds The bounds in the scrollable block area that should * become visible. * @param xIfNeeded If this parameter is true, scrolling will only occur if the * requested bounds are not currently visible horizontally. * @param yIfNeeded If this parameter is true, scrolling will only occur if the * requested bounds are not currently visible vertically. */ public void scrollTo(Rectangle bounds, boolean xIfNeeded, boolean yIfNeeded) { RBlock block = this.rblock; if(block != null) { block.scrollTo(bounds, xIfNeeded, yIfNeeded); } } public void scrollBy(int xOffset, int yOffset) { RBlock block = this.rblock; if(block != null) { if(xOffset != 0) { block.scrollBy(JScrollBar.HORIZONTAL, xOffset); } if(yOffset != 0) { block.scrollBy(JScrollBar.VERTICAL, yOffset); } } } /** * Scrolls the body area to the node given, if it is * part of the current document. *
* This method should be called from the GUI thread. * @param node A DOM node. */ public void scrollTo(Node node) { Rectangle bounds = this.getNodeBounds(node, true); if(bounds == null) { return; } this.scrollTo(bounds, true, false); } /** * Gets the rectangular bounds of the given node. *
* This method should be called from the GUI thread.
* @param node A node in the current document.
* @param relativeToScrollable Whether the bounds should be relative to the
* scrollable body area. Otherwise, they are
* relative to the root block (which is the
* essentially the same as being relative to this
*
* Invoke method {@link #setDocument(Document, HtmlRendererContext)}
* in order to schedule a document for rendering.
*/
public class HtmlPanel extends JComponent implements FrameContext {
private final EventDispatch2 selectionDispatch = new SelectionDispatch();
private final javax.swing.Timer notificationTimer;
private final DocumentNotificationListener notificationListener;
private final Runnable notificationImmediateAction;
private static final int NOTIF_TIMER_DELAY = 300;
private volatile boolean isFrameSet = false;
private volatile NodeRenderer nodeRenderer = null;
private volatile NodeImpl rootNode;
private volatile int preferredWidth = -1;
private volatile Insets defaultMarginInsets = new Insets(8, 8, 8, 8);
private volatile int defaultOverflowX = RenderState.OVERFLOW_AUTO;
private volatile int defaultOverflowY = RenderState.OVERFLOW_SCROLL;
protected volatile HtmlBlockPanel htmlBlockPanel;
protected volatile FrameSetPanel frameSetPanel;
/**
* Constructs an
* This method currently does not have any effect when the
* document is a FRAMESET.
*
* Note also that setting the preferred width (to a value other
* than
* This method should be called from the GUI thread.
* @param bounds The bounds in the scrollable block area that should
* become visible.
* @param xIfNeeded If this parameter is true, scrolling will only occur if the
* requested bounds are not currently visible horizontally.
* @param yIfNeeded If this parameter is true, scrolling will only occur if the
* requested bounds are not currently visible vertically.
*/
public void scrollTo(Rectangle bounds, boolean xIfNeeded, boolean yIfNeeded) {
HtmlBlockPanel htmlBlock = this.htmlBlockPanel;
if(htmlBlock != null) {
htmlBlock.scrollTo(bounds, xIfNeeded, yIfNeeded);
}
}
/**
* Scrolls the body area to the node given, if it is
* part of the current document.
*
* This method should be called from the GUI thread.
* @param node A DOM node.
*/
public void scrollTo(org.w3c.dom.Node node) {
HtmlBlockPanel htmlBlock = this.htmlBlockPanel;
if(htmlBlock != null) {
htmlBlock.scrollTo(node);
}
}
/**
* Gets the root
* Note: This method should be invoked in the GUI thread.
* @return A
* This method may be called outside of the GUI Thread.
* @param x The x coordinate.
* @param y The y coordinate.
*/
public void scroll(final int x, final int y) {
if(EventQueue.isDispatchThread()) {
this.scrollImpl(x, y);
}
else {
EventQueue.invokeLater(new Runnable() {
public void run() {
scrollImpl(x, y);
}
});
}
}
public void scrollBy(final int x, final int y) {
if(EventQueue.isDispatchThread()) {
this.scrollByImpl(x, y);
}
else {
EventQueue.invokeLater(new Runnable() {
public void run() {
scrollByImpl(x, y);
}
});
}
}
private void scrollImpl(int x, int y) {
this.scrollTo(new Rectangle(x, y, 16, 16), false, false);
}
private void scrollByImpl(int xOffset, int yOffset) {
HtmlBlockPanel bp = this.htmlBlockPanel;
if(bp != null) {
bp.scrollBy(xOffset, yOffset);
}
}
/**
* Clears the current document if any.
* If called outside the GUI thread, the operation
* will be scheduled to be performed in the GUI
* thread.
*/
public void clearDocument() {
if(java.awt.EventQueue.isDispatchThread()) {
this.clearDocumentImpl();
}
else {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
HtmlPanel.this.clearDocumentImpl();
}
});
}
}
private void clearDocumentImpl() {
HTMLDocumentImpl prevDocument = (HTMLDocumentImpl) this.rootNode;
if(prevDocument != null) {
prevDocument.removeDocumentNotificationListener(this.notificationListener);
}
NodeRenderer nr = this.nodeRenderer;
if(nr != null) {
nr.setRootNode(null);
}
this.rootNode = null;
this.htmlBlockPanel = null;
this.nodeRenderer = null;
this.isFrameSet = false;
this.removeAll();
this.revalidate();
this.repaint();
}
/**
* Sets an HTML DOM node and invalidates the component so it is
* rendered as soon as possible in the GUI thread.
*
* If this method is called from a thread that is not the GUI
* dispatch thread, the document is scheduled to be set later.
* Note that {@link #setPreferredWidth(int) preferred size}
* calculations should be done in the GUI dispatch thread for
* this reason.
* @param node This should
* normally be a Document instance obtained with
* {@link org.lobobrowser.html.parser.DocumentBuilderImpl}.
*
* @param rcontext A renderer context.
* @see org.lobobrowser.html.parser.DocumentBuilderImpl#parse(org.xml.sax.InputSource)
* @see org.lobobrowser.html.test.SimpleHtmlRendererContext
*/
public void setDocument(final Document node, final HtmlRendererContext rcontext) {
if(java.awt.EventQueue.isDispatchThread()) {
this.setDocumentImpl(node, rcontext);
}
else {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
HtmlPanel.this.setDocumentImpl(node, rcontext);
}
});
}
}
/**
* Scrolls to the element identified by the given ID in
* the current document.
*
* If this method is invoked outside the GUI thread,
* the operation is scheduled to be performed as soon
* as possible in the GUI thread.
* @param nameOrId The name or ID of the element in the document.
*/
public void scrollToElement(final String nameOrId) {
if(EventQueue.isDispatchThread()) {
this.scrollToElementImpl(nameOrId);
}
else {
EventQueue.invokeLater(new Runnable() {
public void run() {
scrollToElementImpl(nameOrId);
}
});
}
}
private void scrollToElementImpl(String nameOrId) {
NodeImpl node = this.rootNode;
if(node instanceof HTMLDocumentImpl) {
HTMLDocumentImpl doc = (HTMLDocumentImpl) node;
org.w3c.dom.Element element = doc.getElementById(nameOrId);
if(element != null) {
this.scrollTo(element);
}
}
}
private void setDocumentImpl(Document node, HtmlRendererContext rcontext) {
// Expected to be called in the GUI thread.
if(!(node instanceof HTMLDocumentImpl)) {
throw new IllegalArgumentException("Only nodes of type HTMLDocumentImpl are currently supported. Use DocumentBuilderImpl.");
}
HTMLDocumentImpl prevDocument = (HTMLDocumentImpl) this.rootNode;
if(prevDocument != null) {
prevDocument.removeDocumentNotificationListener(this.notificationListener);
}
HTMLDocumentImpl nodeImpl = (HTMLDocumentImpl) node;
nodeImpl.addDocumentNotificationListener(this.notificationListener);
this.rootNode = nodeImpl;
NodeImpl fsrn = this.getFrameSetRootNode(nodeImpl);
boolean newIfs = fsrn != null;
if(newIfs != this.isFrameSet || this.getComponentCount() == 0) {
this.isFrameSet = newIfs;
if(newIfs) {
this.setUpFrameSet(fsrn);
}
else {
this.setUpAsBlock(rcontext.getUserAgentContext(), rcontext);
}
}
NodeRenderer nr = this.nodeRenderer;
if(nr != null) {
// These subcomponents should take care
// of revalidation.
if(newIfs) {
nr.setRootNode(fsrn);
}
else {
nr.setRootNode(nodeImpl);
}
}
else {
this.invalidate();
this.validate();
this.repaint();
}
}
/**
* Renders HTML given as a string.
* @param htmlSource The HTML source code.
* @param uri A base URI used to resolve item URIs.
* @param rcontext The {@link HtmlRendererContext} instance.
* @see org.lobobrowser.html.test.SimpleHtmlRendererContext
* @see #setDocument(Document, HtmlRendererContext)
*/
public void setHtml(String htmlSource, String uri, HtmlRendererContext rcontext) {
try {
DocumentBuilderImpl builder = new DocumentBuilderImpl(rcontext.getUserAgentContext(), rcontext);
Reader reader = new StringReader(htmlSource);
try {
InputSourceImpl is = new InputSourceImpl(reader, uri);
Document document = builder.parse(is);
this.setDocument(document, rcontext);
} finally {
reader.close();
}
} catch(java.io.IOException ioe) {
throw new IllegalStateException("Unexpected condition.", ioe);
} catch(org.xml.sax.SAXException se) {
throw new IllegalStateException("Unexpected condition.", se);
}
}
/**
* Gets the HTML DOM node currently rendered if any.
*/
public NodeImpl getRootNode() {
return this.rootNode;
}
private boolean resetIfFrameSet() {
NodeImpl nodeImpl = this.rootNode;
NodeImpl fsrn = this.getFrameSetRootNode(nodeImpl);
boolean newIfs = fsrn != null;
if(newIfs != this.isFrameSet || this.getComponentCount() == 0) {
this.isFrameSet = newIfs;
if(newIfs) {
this.setUpFrameSet(fsrn);
NodeRenderer nr = this.nodeRenderer;
nr.setRootNode(fsrn);
// Set proper bounds and repaint.
this.validate();
this.repaint();
return true;
}
}
return false;
}
private NodeImpl getFrameSetRootNode(NodeImpl node) {
if(node instanceof Document) {
ElementImpl element = (ElementImpl) ((Document) node).getDocumentElement();
if(element != null && "HTML".equalsIgnoreCase(element.getTagName())) {
return this.getFrameSet(element);
}
else {
return this.getFrameSet(node);
}
}
else {
return null;
}
}
private NodeImpl getFrameSet(NodeImpl node) {
NodeImpl[] children = node.getChildrenArray();
if(children == null) {
return null;
}
int length = children.length;
NodeImpl frameSet = null;
for(int i = 0; i < length; i++) {
NodeImpl child = children[i];
if(child instanceof Text) {
// Ignore
}
else if(child instanceof ElementImpl) {
String tagName = child.getNodeName();
if("HEAD".equalsIgnoreCase(tagName) ||
"NOFRAMES".equalsIgnoreCase(tagName) ||
"TITLE".equalsIgnoreCase(tagName) ||
"META".equalsIgnoreCase(tagName) ||
"SCRIPT".equalsIgnoreCase(tagName) ||
"NOSCRIPT".equalsIgnoreCase(tagName)) {
// ignore it
}
else if("FRAMESET".equalsIgnoreCase(tagName)) {
frameSet = child;
break;
}
else {
if(this.hasSomeHtml((ElementImpl) child)) {
return null;
}
}
}
}
return frameSet;
}
private boolean hasSomeHtml(ElementImpl element) {
String tagName = element.getTagName();
if("HEAD".equalsIgnoreCase(tagName) || "TITLE".equalsIgnoreCase(tagName) || "META".equalsIgnoreCase(tagName)) {
return false;
}
NodeImpl[] children = element.getChildrenArray();
if(children != null) {
int length = children.length;
for(int i = 0; i < length; i++) {
NodeImpl child = children[i];
if(child instanceof Text) {
String textContent = ((Text) child).getTextContent();
if(textContent != null && !"".equals(textContent.trim())) {
return false;
}
}
else if(child instanceof ElementImpl) {
if(this.hasSomeHtml((ElementImpl) child)) {
return false;
}
}
}
}
return true;
}
/**
* Internal method used to expand the selection to the given point.
*
* Note: This method should be invoked in the GUI thread.
*/
public void expandSelection(RenderableSpot rpoint) {
HtmlBlockPanel block = this.htmlBlockPanel;
if(block != null) {
block.setSelectionEnd(rpoint);
block.repaint();
this.selectionDispatch.fireEvent(new SelectionChangeEvent(this, block.isSelectionAvailable()));
}
}
/**
* Internal method used to reset the selection so that
* it is empty at the given point. This is what is called
* when the user clicks on a point in the document.
*
* Note: This method should be invoked in the GUI thread.
*/
public void resetSelection(RenderableSpot rpoint) {
HtmlBlockPanel block = this.htmlBlockPanel;
if(block != null) {
block.setSelectionStart(rpoint);
block.setSelectionEnd(rpoint);
block.repaint();
}
this.selectionDispatch.fireEvent(new SelectionChangeEvent(this, false));
}
/**
* Gets the selection text.
*
* Note: This method should be invoked in the GUI thread.
*/
public String getSelectionText() {
HtmlBlockPanel block = this.htmlBlockPanel;
if(block == null) {
return null;
}
else {
return block.getSelectionText();
}
}
/**
* Gets a DOM node enclosing the selection. The node returned should
* be the inner-most node that encloses both selection start and end
* points. Note that the selection end point may be just outside of
* the selection.
*
* Note: This method should be invoked in the GUI thread.
* @return A node enclosing the current selection, or
* This method has no effect on FRAMESETs.
* @param insets The default margin insets.
*/
public void setDefaultMarginInsets(Insets insets) {
this.defaultMarginInsets = insets;
HtmlBlockPanel block = this.htmlBlockPanel;
if(block != null) {
block.setDefaultMarginInsets(insets);
}
}
/**
* Sets the default horizontal overflow.
*
* This method has no effect on FRAMESETs.
* @param overflow See {@link org.lobobrowser.html.style.RenderState}.
*/
public void setDefaultOverflowX(int overflow) {
this.defaultOverflowX = overflow;
HtmlBlockPanel block = this.htmlBlockPanel;
if(block != null) {
block.setDefaultOverflowX(overflow);
}
}
/**
* Sets the default vertical overflow.
*
* This method has no effect on FRAMESETs.
* @param overflow See {@link org.lobobrowser.html.style.RenderState}.
*/
public void setDefaultOverflowY(int overflow) {
this.defaultOverflowY = overflow;
HtmlBlockPanel block = this.htmlBlockPanel;
if(block != null) {
block.setDefaultOverflowY(overflow);
}
}
private ArrayList notifications = new ArrayList(1);
private void addNotification(DocumentNotification notification) {
// This can be called in a random thread.
ArrayList notifs = this.notifications;
synchronized(notifs) {
notifs.add(notification);
}
if(EventQueue.isDispatchThread()) {
// In this case we want the notification to be processed
// immediately. However, we don't want potential recursions
// to occur when a Javascript property is set in the GUI thread.
// Additionally, many property values may be set in one
// event block.
EventQueue.invokeLater(this.notificationImmediateAction);
}
else {
this.notificationTimer.restart();
}
}
/**
* Invalidates the layout of the given node and schedules it
* to be layed out later. Multiple invalidations may be
* processed in a single document layout.
*/
public void delayedRelayout(NodeImpl node) {
ArrayList notifs = this.notifications;
synchronized(notifs) {
notifs.add(new DocumentNotification(DocumentNotification.SIZE, node));
}
this.notificationTimer.restart();
}
private void processNotifications() {
// This is called in the GUI thread.
ArrayList notifs = this.notifications;
DocumentNotification[] notifsArray;
synchronized(notifs) {
int size = notifs.size();
if(size == 0) {
return;
}
notifsArray = new DocumentNotification[size];
notifsArray = (DocumentNotification[]) notifs.toArray(notifsArray);
notifs.clear();
}
int length = notifsArray.length;
for(int i = 0; i < length; i++) {
DocumentNotification dn = notifsArray[i];
if(dn.node instanceof HTMLFrameSetElement && this.htmlBlockPanel != null) {
if(this.resetIfFrameSet()) {
// Revalidation already taken care of.
return;
}
}
}
HtmlBlockPanel blockPanel = this.htmlBlockPanel;
if(blockPanel != null) {
blockPanel.processDocumentNotifications(notifsArray);
}
FrameSetPanel frameSetPanel = this.frameSetPanel;
if(frameSetPanel != null) {
frameSetPanel.processDocumentNotifications(notifsArray);
}
}
private class SelectionDispatch extends EventDispatch2 {
/* (non-Javadoc)
* @see org.xamjwg.util.EventDispatch2#dispatchEvent(java.util.EventListener, java.util.EventObject)
*/
protected void dispatchEvent(EventListener listener, EventObject event) {
((SelectionChangeListener) listener).selectionChanged((SelectionChangeEvent) event);
}
}
private class LocalDocumentNotificationListener implements DocumentNotificationListener {
public void allInvalidated() {
HtmlPanel.this.addNotification(new DocumentNotification(DocumentNotification.GENERIC, null));
}
public void invalidated(NodeImpl node) {
HtmlPanel.this.addNotification(new DocumentNotification(DocumentNotification.GENERIC, node));
}
public void lookInvalidated(NodeImpl node) {
HtmlPanel.this.addNotification(new DocumentNotification(DocumentNotification.LOOK, node));
}
public void positionInvalidated(NodeImpl node) {
HtmlPanel.this.addNotification(new DocumentNotification(DocumentNotification.POSITION, node));
}
public void sizeInvalidated(NodeImpl node) {
HtmlPanel.this.addNotification(new DocumentNotification(DocumentNotification.SIZE, node));
}
public void externalScriptLoading(NodeImpl node) {
// Ignorable here.
}
public void nodeLoaded(NodeImpl node) {
HtmlPanel.this.addNotification(new DocumentNotification(DocumentNotification.GENERIC, node));
}
public void structureInvalidated(NodeImpl node) {
HtmlPanel.this.addNotification(new DocumentNotification(DocumentNotification.GENERIC, node));
}
}
private class NotificationTimerAction implements java.awt.event.ActionListener {
public void actionPerformed(ActionEvent e) {
HtmlPanel.this.processNotifications();
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/gui/SelectionChangeEvent.java 0000644 0001750 0001750 00000002503 10726473510 027557 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.gui;
import java.util.EventObject;
/**
* Event associated with {@link SelectionChangeListener}.
*/
public class SelectionChangeEvent extends EventObject {
private final boolean hasSelection;
public SelectionChangeEvent(Object source, boolean hasSelection) {
super(source);
this.hasSelection = hasSelection;
}
public boolean isSelectionAvailable() {
return this.hasSelection;
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/gui/SelectionChangeListener.java 0000644 0001750 0001750 00000002641 10726473506 030273 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.gui;
import java.util.EventListener;
/**
* Receives selection change events.
* @author J. H. S.
* @see org.lobobrowser.html.gui.HtmlPanel#addSelectionChangeListener(SelectionChangeListener)
*/
public interface SelectionChangeListener extends EventListener {
/**
* Receives a selection change event. This method
* may be assumed to execute in the GUI thread.
* @param event A {@link SelectionChangeEvent} instance.
*/
public void selectionChanged(SelectionChangeEvent event);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/gui/package.html 0000644 0001750 0001750 00000000204 10712365564 025140 0 ustar twerner twerner HtmlBlockPanel
minus Swing
* borders).
*/
public Rectangle getNodeBounds(Node node, boolean relativeToScrollable) {
RBlock block = this.rblock;
if(block == null) {
return null;
}
// Find UINode first
Node currentNode = node;
UINode uiNode = null;
while(currentNode != null) {
if(currentNode instanceof HTMLElementImpl) {
HTMLElementImpl element = (HTMLElementImpl) currentNode;
uiNode = element.getUINode();
if(uiNode != null) {
break;
}
}
currentNode = currentNode.getParentNode();
}
if(uiNode == null) {
return null;
}
RCollection relativeTo = relativeToScrollable ? (RCollection) block.getRBlockViewport() : (RCollection) block;
if(node == currentNode) {
BoundableRenderable br = (BoundableRenderable) uiNode;
Point guiPoint = br.getOriginRelativeTo(relativeTo);
Dimension size = br.getSize();
return new Rectangle(guiPoint, size);
}
else {
return this.scanNodeBounds((RCollection) uiNode, node, relativeTo);
}
}
/**
* Gets an aggregate of the bounds of renderer leaf nodes.
*/
private Rectangle scanNodeBounds(RCollection root, Node node, RCollection relativeTo) {
Iterator i = root.getRenderables();
Rectangle resultBounds = null;
BoundableRenderable prevBoundable = null;
if(i != null) {
while(i.hasNext()) {
Renderable r = (Renderable) i.next();
Rectangle subBounds = null;
if(r instanceof RCollection) {
RCollection rc = (RCollection) r;
prevBoundable = rc;
subBounds = this.scanNodeBounds(rc, node, relativeTo);
}
else if(r instanceof BoundableRenderable) {
BoundableRenderable br = (BoundableRenderable) r;
prevBoundable = br;
if(Nodes.isSameOrAncestorOf(node, (Node) r.getModelNode())) {
Point origin = br.getOriginRelativeTo(relativeTo);
Dimension size = br.getSize();
subBounds = new Rectangle(origin, size);
}
}
else {
// This would have to be a RStyleChanger. We rely on these
// when the target node has blank content.
if(Nodes.isSameOrAncestorOf(node, (Node) r.getModelNode())) {
int xInRoot = prevBoundable == null ? 0 : prevBoundable.getX() + prevBoundable.getWidth();
Point rootOrigin = root.getOriginRelativeTo(relativeTo);
subBounds = new Rectangle(rootOrigin.x + xInRoot, rootOrigin.y, 0, root.getHeight());
}
}
if(subBounds != null) {
if(resultBounds == null) {
resultBounds = subBounds;
}
else {
resultBounds = subBounds.union(resultBounds);
}
}
}
}
return resultBounds;
}
public BoundableRenderable getRootRenderable() {
return this.rblock;
}
/**
* Allows {@link #getPreferredSize()} to render the HTML block
* in order to determine the preferred size of this component.
* Note that getPreferredSize()
is a potentially time-consuming
* operation if the preferred width is set.
* @param width The preferred blocked width. Use
-1
to unset.
*/
public void setPreferredWidth(int width) {
this.preferredWidth = width;
}
/**
* If the preferred size has been set with {@link #setPreferredSize(Dimension)},
* then that size is returned. Otherwise a preferred size is calculated by
* rendering the HTML DOM, provided one is available and a preferred width other
* than -1
has been set with {@link #setPreferredWidth(int)}.
* An arbitrary preferred size is returned in other scenarios.
*/
public Dimension getPreferredSize() {
// Expected to be invoked in the GUI thread.
if(this.isPreferredSizeSet()) {
return super.getPreferredSize();
}
final int pw = this.preferredWidth;
if(pw != -1) {
final RBlock block = this.rblock;
if(block != null) {
// Layout should always be done in the GUI thread.
if(EventQueue.isDispatchThread()) {
block.layout(pw, 0, false, false, RenderState.OVERFLOW_VISIBLE, RenderState.OVERFLOW_VISIBLE, true);
}
else {
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
block.layout(pw, 0, false, false, RenderState.OVERFLOW_VISIBLE, RenderState.OVERFLOW_VISIBLE, true);
}
});
} catch(Exception err) {
logger.log(Level.SEVERE, "Unable to do preferred size layout.", err);
}
}
// Adjust for permanent vertical scrollbar.
int newPw = Math.max(block.width + block.getVScrollBarWidth(), pw);
return new Dimension(newPw, block.height);
}
}
return new Dimension(600, 400);
}
public void finalize() throws Throwable {
super.finalize();
}
public boolean copy() {
String selection = HtmlBlockPanel.this.getSelectionText();
if(selection != null) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(selection), HtmlBlockPanel.this);
return true;
}
else {
return false;
}
}
// public void setDefaultPaddingInsets(Insets insets) {
// this.defaultPaddingInsets = insets;
// RBlock block = this.rblock;
// if(block != null) {
// block.setDefaultPaddingInsets(insets);
// }
// }
public int getFirstLineHeight() {
RBlock block = this.rblock;
return block == null ? 0 : block.getFirstLineHeight();
}
public void setSelectionEnd(RenderableSpot rpoint) {
this.endSelection = rpoint;
}
public void setSelectionStart(RenderableSpot rpoint) {
this.startSelection = rpoint;
}
public boolean isSelectionAvailable() {
RenderableSpot start = this.startSelection;
RenderableSpot end = this.endSelection;
return start != null && end != null && !start.equals(end);
}
public org.w3c.dom.Node getSelectionNode() {
RenderableSpot start = this.startSelection;
RenderableSpot end = this.endSelection;
if(start != null && end != null) {
return Nodes.getCommonAncestor((Node) start.renderable.getModelNode(), (Node) end.renderable.getModelNode());
}
else {
return null;
}
}
/**
* Sets the root node to render. This method should
* be invoked in the GUI dispatch thread.
*/
public void setRootNode(NodeImpl node) {
if(node != null) {
RBlock block = new RBlock(node, 0, this.ucontext, this.rcontext, this.frameContext, this);
block.setDefaultMarginInsets(this.defaultMarginInsets);
//block.setDefaultPaddingInsets(this.defaultPaddingInsets);
block.setDefaultOverflowX(this.defaultOverflowX);
block.setDefaultOverflowY(this.defaultOverflowY);
node.setUINode(block);
this.rblock = block;
}
else {
this.rblock = null;
}
this.invalidate();
this.validateAll();
this.repaint();
}
protected void validateAll() {
Component toValidate = this;
for(;;) {
Container parent = toValidate.getParent();
if(parent == null || parent.isValid()) {
break;
}
toValidate = parent;
}
toValidate.validate();
}
protected void revalidatePanel() {
// Called in the GUI thread.
this.invalidate();
this.validate();
//TODO: Could be paintImmediately.
this.repaint();
}
public NodeImpl getRootNode() {
RBlock block = this.rblock;
return block == null ? null : (NodeImpl) block.getModelNode();
}
private void onMouseClick(MouseEvent event) {
// Rely on AWT mouse-click only for double-clicks
RBlock block = this.rblock;
if(block != null) {
int button = event.getButton();
int clickCount = event.getClickCount();
if(button == MouseEvent.BUTTON1 && clickCount > 1) {
//TODO: Double-click must be revised. It generates
//a single click via mouse release.
Point point = event.getPoint();
block.onDoubleClick(event, point.x, point.y);
}
else if(button == MouseEvent.BUTTON3 && clickCount == 1) {
block.onRightClick(event, event.getX(), event.getY());
}
}
}
private BoundableRenderable mousePressTarget;
private void onMousePressed(MouseEvent event) {
this.requestFocus();
RBlock block = this.rblock;
if(block != null) {
Point point = event.getPoint();
this.mousePressTarget = block;
int rx = point.x;
int ry = point.y;
block.onMousePressed(event, point.x, point.y);
RenderableSpot rp = block.getLowestRenderableSpot(rx, ry);
if(rp != null) {
this.frameContext.resetSelection(rp);
}
else {
this.frameContext.resetSelection(null);
}
}
}
private void onMouseReleased(MouseEvent event) {
RBlock block = this.rblock;
if(block != null) {
Point point = event.getPoint();
int rx = point.x;
int ry = point.y;
if(event.getButton() == MouseEvent.BUTTON1) {
// TODO: This will be raised twice on a double-click.
block.onMouseClick(event, rx, ry);
}
block.onMouseReleased(event, rx, ry);
BoundableRenderable oldTarget = this.mousePressTarget;
if(oldTarget != null) {
this.mousePressTarget = null;
if(oldTarget != block) {
oldTarget.onMouseDisarmed(event);
}
}
}
else {
this.mousePressTarget = null;
}
}
private void onMouseExited(MouseEvent event) {
BoundableRenderable oldTarget = this.mousePressTarget;
if(oldTarget != null) {
this.mousePressTarget = null;
oldTarget.onMouseDisarmed(event);
}
}
private void onMouseWheelMoved(MouseWheelEvent mwe) {
RBlock block = this.rblock;
if(block != null) {
switch(mwe.getScrollType()) {
case MouseWheelEvent.WHEEL_UNIT_SCROLL:
int units = mwe.getWheelRotation() * mwe.getScrollAmount();
block.scrollByUnits(JScrollBar.VERTICAL, units);
break;
}
}
}
private void onMouseDragged(MouseEvent event) {
RBlock block = this.rblock;
if(block != null) {
Point point = event.getPoint();
RenderableSpot rp = block.getLowestRenderableSpot(point.x, point.y);
if(rp != null) {
this.frameContext.expandSelection(rp);
}
block.ensureVisible(point);
}
}
private void onMouseMoved(MouseEvent event) {
RBlock block = this.rblock;
if(block != null) {
Point point = event.getPoint();
block.onMouseMoved(event, point.x, point.y, false, null);
}
}
/* (non-Javadoc)
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
*/
//protected void paintComponent(Graphics g) {
public void paint(Graphics g) {
// We go against Sun's advice and override
// paint() instead of paintComponent(). Scrollbars
// do not repaint correctly if we use
// paintComponent.
if(this.isOpaque()) {
// Background not painted by default in JComponent.
Rectangle clipBounds = g.getClipBounds();
g.setColor(this.getBackground());
g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
}
if(g instanceof Graphics2D) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
RBlock block = this.rblock;
if(block != null) {
boolean liflag = loggableInfo;
long time1 = liflag ? System.currentTimeMillis() : 0;
block.paint(g);
if(liflag) {
long time2 = System.currentTimeMillis();
Node rootNode = this.getRootNode();
String uri = rootNode instanceof Document ? ((Document) rootNode).getDocumentURI() : "";
logger.info("paintComponent(): URI=[" + uri + "]. Block paint elapsed: " + (time2 - time1) + " ms.");
}
// Paint FrameContext selection
RenderableSpot start = this.startSelection;
RenderableSpot end = this.endSelection;
if(start != null && end != null && !start.equals(end)) {
block.paintSelection(g, false, start, end);
}
}
}
public void doLayout() {
try {
Dimension size = this.getSize();
boolean liflag = loggableInfo;
long time1 = 0;
if(liflag) {
time1 = System.currentTimeMillis();
}
this.clearComponents();
RBlock block = this.rblock;
if(block != null) {
ModelNode rootNode = block.getModelNode();
block.layout(size.width, size.height, true, true, null, false);
//Only set origin
block.setOrigin(0, 0);
block.updateWidgetBounds(0, 0);
this.updateGUIComponents();
if(liflag) {
long time2 = System.currentTimeMillis();
String uri = rootNode instanceof Document ? ((Document) rootNode).getDocumentURI() : "";
logger.info("doLayout(): URI=[" + uri + "]. Block layout elapsed: " + (time2 - time1) + " ms. Component count: " + this.getComponentCount() + ".");
}
}
else {
if(this.getComponentCount() > 0) {
this.removeAll();
}
}
} catch(Throwable thrown) {
logger.log(Level.SEVERE, "Unexpected error in layout engine. Document is " + this.getRootNode(), thrown);
}
}
/**
* Implementation of UINode.repaint().
*/
public void repaint(ModelNode modelNode) {
//this.rblock.invalidateRenderStyle();
this.repaint();
}
public String getSelectionText() {
RenderableSpot start = this.startSelection;
RenderableSpot end = this.endSelection;
if(start != null && end != null) {
StringBuffer buffer = new StringBuffer();
this.rblock.extractSelectionText(buffer, false, start, end);
return buffer.toString();
}
else {
return null;
}
}
public boolean hasSelection() {
RenderableSpot start = this.startSelection;
RenderableSpot end = this.endSelection;
if(start != null && end != null && !start.equals(end)) {
return true;
}
else {
return false;
}
}
protected void paintChildren(Graphics g) {
// Overridding with NOP. For various reasons,
// the regular mechanism for painting children
// needs to be handled by Cobra.
}
public Color getPaintedBackgroundColor() {
return this.isOpaque() ? this.getBackground() : null;
}
/* (non-Javadoc)
* @see java.awt.datatransfer.ClipboardOwner#lostOwnership(java.awt.datatransfer.Clipboard, java.awt.datatransfer.Transferable)
*/
public void lostOwnership(Clipboard arg0, Transferable arg1) {
}
public void relayout() {
// Expected to be called in the GUI thread.
// Renderable branch should be invalidated at this
// point, but this GUI component not necessarily.
this.revalidatePanel();
}
public void invalidateLayoutUpTree() {
// Called when renderable branch is invalidated.
// We shouldn't do anything here. Changes in renderer
// tree do not have any bearing on validity of GUI
// component.
}
public void updateAllWidgetBounds() {
this.rblock.updateWidgetBounds(0, 0);
}
public Point getGUIPoint(int clientX, int clientY) {
// This is the GUI!
return new Point(clientX, clientY);
}
public void focus() {
this.grabFocus();
}
private boolean processingDocumentNotification = false;
void processDocumentNotifications(DocumentNotification[] notifications) {
// Called in the GUI thread.
if(this.processingDocumentNotification) {
// This should not be possible. Even if
// Javascript modifies the DOM during
// parsing, this should be executed in
// the GUI thread, not the parser thread.
throw new IllegalStateException("Recursive");
}
this.processingDocumentNotification = true;
try {
//Note: It may be assumed that usually only generic
//notifications come in batches. Other types
//of noitifications probably come one by one.
boolean topLayout = false;
java.util.ArrayList repainters = null;
int length = notifications.length;
for(int i = 0; i < length; i++) {
DocumentNotification dn = notifications[i];
int type = dn.type;
switch(type) {
case DocumentNotification.GENERIC:
case DocumentNotification.SIZE: {
NodeImpl node = dn.node;
if(node == null) {
// This is all-invalidate (new style sheet)
if(loggableInfo) {
logger.info("processDocumentNotifications(): Calling invalidateLayoutDeep().");
}
this.rblock.invalidateLayoutDeep();
//this.rblock.invalidateRenderStyle();
}
else {
UINode uiNode = node.findUINode();
if(uiNode != null) {
RElement relement = (RElement) uiNode;
relement.invalidateLayoutUpTree();
// if(type == DocumentNotification.GENERIC) {
// relement.invalidateRenderStyle();
// }
}
else {
if(loggableInfo) {
logger.info("processDocumentNotifications(): Unable to find UINode for " + node);
}
}
}
topLayout = true;
break;
}
case DocumentNotification.POSITION: {
//TODO: Could be more efficient.
NodeImpl node = dn.node;
NodeImpl parent = (NodeImpl) node.getParentNode();
if(parent != null) {
UINode uiNode = parent.findUINode();
if(uiNode != null) {
RElement relement = (RElement) uiNode;
relement.invalidateLayoutUpTree();
}
}
topLayout = true;
break;
}
case DocumentNotification.LOOK: {
NodeImpl node = dn.node;
UINode uiNode = node.findUINode();
if(uiNode != null) {
if(repainters == null) {
repainters = new ArrayList(1);
}
RElement relement = (RElement) uiNode;
//relement.invalidateRenderStyle();
repainters.add(relement);
}
break;
}
default:
break;
}
}
if(topLayout) {
this.revalidatePanel();
}
else {
if(repainters != null) {
Iterator i = repainters.iterator();
while(i.hasNext()) {
RElement element = (RElement) i.next();
element.repaint();
}
}
}
} finally {
this.processingDocumentNotification = false;
}
}
public void addDelayedPair(DelayedPair pair) {
// NOP
}
public RenderableContainer getParentContainer() {
return null;
}
public Collection getDelayedPairs() {
return null;
}
public void clearDelayedPairs() {
}
private Set components;
private void clearComponents() {
Set c = this.components;
if(c != null) {
c.clear();
}
}
public Component addComponent(Component component) {
Set c = this.components;
if(c == null) {
c = new HashSet();
this.components = c;
}
if(c.add(component)) {
return component;
}
else {
return null;
}
}
private void updateGUIComponents() {
// We use this method, instead of removing all components and
// adding them back, because removal of components can cause
// them to lose focus.
Set c = this.components;
if(c == null) {
if(this.getComponentCount() != 0) {
this.removeAll();
}
}
else {
// Remove children not in the set.
Set workingSet = new HashSet();
workingSet.addAll(c);
int count = this.getComponentCount();
for(int i = 0; i < count;) {
Component component = this.getComponent(i);
if(!c.contains(component)) {
this.remove(i);
count = this.getComponentCount();
}
else {
i++;
workingSet.remove(component);
}
}
// Add components in set that were not previously children.
Iterator wsi = workingSet.iterator();
while(wsi.hasNext()) {
Component component = (Component) wsi.next();
this.add(component);
}
}
}
public Insets getDefaultMarginInsets() {
return defaultMarginInsets;
}
/**
* Sets the default margin insets. Note that in the root block,
* the margin behaves like padding.
* @param defaultMarginInsets The default margin insets.
*/
public void setDefaultMarginInsets(Insets defaultMarginInsets) {
if(!Objects.equals(this.defaultMarginInsets, defaultMarginInsets)) {
this.defaultMarginInsets = defaultMarginInsets;
RBlock block = this.rblock;
if(block != null) {
block.setDefaultMarginInsets(defaultMarginInsets);
block.relayoutIfValid();
}
}
}
// public Insets getDefaultPaddingInsets() {
// return defaultPaddingInsets;
// }
//
public int getDefaultOverflowX() {
return defaultOverflowX;
}
public void setDefaultOverflowX(int defaultOverflowX) {
if(defaultOverflowX != this.defaultOverflowX) {
this.defaultOverflowX = defaultOverflowX;
RBlock block = this.rblock;
if(block != null) {
block.setDefaultOverflowX(defaultOverflowX);
block.relayoutIfValid();
}
}
}
public int getDefaultOverflowY() {
return defaultOverflowY;
}
public void setDefaultOverflowY(int defaultOverflowY) {
if(this.defaultOverflowY != defaultOverflowY) {
this.defaultOverflowY = defaultOverflowY;
RBlock block = this.rblock;
if(block != null) {
block.setDefaultOverflowY(defaultOverflowY);
block.relayoutIfValid();
}
}
}
} libcobra-java-0.98.4.orig/src/org/lobobrowser/html/gui/HtmlPanel.java 0000644 0001750 0001750 00000060757 11134671124 025420 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Nov 19, 2005
*/
package org.lobobrowser.html.gui;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.*;
import java.io.*;
import javax.swing.*;
import org.lobobrowser.html.*;
import org.lobobrowser.html.domimpl.*;
import org.lobobrowser.html.parser.*;
import org.lobobrowser.html.renderer.*;
import org.lobobrowser.html.style.RenderState;
import org.lobobrowser.util.EventDispatch2;
import org.lobobrowser.util.gui.WrapperLayout;
import org.w3c.dom.Document;
import org.w3c.dom.Text;
import org.w3c.dom.html2.*;
/**
* The HtmlPanel
class is a Swing
* component that can render a HTML DOM. It uses
* either {@link HtmlBlockPanel} or {@link FrameSetPanel}
* internally, depending on whether the document
* is determined to be a FRAMESET or not.
* HtmlPanel
.
*/
public HtmlPanel() {
super();
this.setLayout(WrapperLayout.getInstance());
this.setOpaque(false);
this.notificationTimer = new javax.swing.Timer(NOTIF_TIMER_DELAY, new NotificationTimerAction());
this.notificationTimer.setRepeats(false);
this.notificationListener = new LocalDocumentNotificationListener();
this.notificationImmediateAction = new Runnable() {
public void run() {
processNotifications();
}
};
}
/**
* Sets a preferred width that serves as a hint in calculating
* the preferred size of the HtmlPanel
. Note that
* the preferred size can only be calculated when a document is
* available, and it will vary during incremental rendering.
* -1
) will negatively impact performance.
*
* @param width The preferred width, or -1
to unset.
*/
public void setPreferredWidth(int width) {
this.preferredWidth = width;
HtmlBlockPanel htmlBlock = this.htmlBlockPanel;
if(htmlBlock != null) {
htmlBlock.setPreferredWidth(width);
}
}
/**
* If the current document is not a FRAMESET,
* this method scrolls the body area to the given location.
* Renderable
of
* the HTML block. It returns null
* for FRAMESETs.
*/
public BoundableRenderable getBlockRenderable() {
HtmlBlockPanel htmlBlock = this.htmlBlockPanel;
return htmlBlock == null ? null : htmlBlock.getRootRenderable();
}
/**
* Gets an instance of {@link FrameSetPanel} in case
* the currently rendered page is a FRAMESET.
* FrameSetPanel
instance or null
* if the document currently rendered is not a FRAMESET.
*/
public FrameSetPanel getFrameSetPanel() {
int componentCount = this.getComponentCount();
if(componentCount == 0) {
return null;
}
Object c = this.getComponent(0);
if(c instanceof FrameSetPanel) {
return (FrameSetPanel) c;
}
return null;
}
private void setUpAsBlock(UserAgentContext ucontext, HtmlRendererContext rcontext) {
HtmlBlockPanel shp = this.createHtmlBlockPanel(ucontext, rcontext);
shp.setPreferredWidth(this.preferredWidth);
shp.setDefaultMarginInsets(this.defaultMarginInsets);
shp.setDefaultOverflowX(this.defaultOverflowX);
shp.setDefaultOverflowY(this.defaultOverflowY);
this.htmlBlockPanel = shp;
this.frameSetPanel = null;
this.removeAll();
this.add(shp);
this.nodeRenderer = shp;
}
private void setUpFrameSet(NodeImpl fsrn) {
this.isFrameSet = true;
this.htmlBlockPanel = null;
FrameSetPanel fsp = this.createFrameSetPanel();
this.frameSetPanel = fsp;
this.nodeRenderer = fsp;
this.removeAll();
this.add(fsp);
fsp.setRootNode(fsrn);
}
/**
* Method invoked internally to create a {@link HtmlBlockPanel}.
* It is made available so it can be overridden.
*/
protected HtmlBlockPanel createHtmlBlockPanel(UserAgentContext ucontext, HtmlRendererContext rcontext) {
return new HtmlBlockPanel(java.awt.Color.WHITE, true, ucontext, rcontext, this);
}
/**
* Method invoked internally to create a {@link FrameSetPanel}.
* It is made available so it can be overridden.
*/
protected FrameSetPanel createFrameSetPanel() {
return new FrameSetPanel();
}
/**
* Scrolls the document such that x and y coordinates
* are placed in the upper-left corner of the panel.
* null
* if there is no such node. It also returns null
* for FRAMESETs.
*/
public org.w3c.dom.Node getSelectionNode() {
HtmlBlockPanel block = this.htmlBlockPanel;
if(block == null) {
return null;
}
else {
return block.getSelectionNode();
}
}
/**
* Returns true only if the current block has a selection.
* This method has no effect in FRAMESETs at the moment.
*/
public boolean hasSelection() {
HtmlBlockPanel block = this.htmlBlockPanel;
if(block == null) {
return false;
}
else {
return block.hasSelection();
}
}
/**
* Copies the current selection, if any, into the clipboard.
* This method has no effect in FRAMESETs at the moment.
*/
public boolean copy() {
HtmlBlockPanel block = this.htmlBlockPanel;
if(block != null) {
return block.copy();
}
else {
return false;
}
}
/**
* Adds listener of selection changes. Note that it does
* not have any effect on FRAMESETs.
* @param listener An instance of {@link SelectionChangeListener}.
*/
public void addSelectionChangeListener(SelectionChangeListener listener) {
this.selectionDispatch.addListener(listener);
}
/**
* Removes a listener of selection changes that was
* previously added.
*/
public void removeSelectionChangeListener(SelectionChangeListener listener) {
this.selectionDispatch.removeListener(listener);
}
/**
* Sets the default margin insets. Note that in the root block,
* the margin behaves like padding.
* Context.enter
.
* @param codeSource
* @param ucontext
*/
public static Context createContext(java.net.URL codeSource, UserAgentContext ucontext) {
Context prev = Context.getCurrentContext();
Context ctx = Context.enter();
ctx.setOptimizationLevel(ucontext.getScriptingOptimizationLevel());
if(prev == null) {
// If there was a previous context, this one must be nested.
// We still need to create a context because of exit() but
// we cannot set a new security controller.
ctx.setSecurityController(new SecurityControllerImpl(codeSource, ucontext.getSecurityPolicy()));
}
return ctx;
}
public static boolean executeFunction(NodeImpl element, Function f, Event event) {
return Executor.executeFunction(element, element, f, event);
}
public static boolean executeFunction(NodeImpl element, Object thisObject, Function f, Event event) {
Document doc = element.getOwnerDocument();
if(doc == null) {
throw new IllegalStateException("Element does not belong to a document.");
}
Context ctx = createContext(element.getDocumentURL(), element.getUserAgentContext());
try {
Scriptable scope = (Scriptable) doc.getUserData(Executor.SCOPE_KEY);
if(scope == null) {
throw new IllegalStateException("Scriptable (scope) instance was expected to be keyed as UserData to document using " + Executor.SCOPE_KEY);
}
JavaScript js = JavaScript.getInstance();
Scriptable thisScope = (Scriptable) js.getJavascriptObject(thisObject, scope);
try {
Scriptable eventScriptable = (Scriptable) js.getJavascriptObject(event, thisScope);
ScriptableObject.defineProperty(thisScope, "event", eventScriptable, ScriptableObject.READONLY);
Object result = f.call(ctx, thisScope, thisScope, new Object[0]);
if(!(result instanceof Boolean)) {
return true;
}
return ((Boolean) result).booleanValue();
} catch(Throwable thrown) {
logger.log(Level.WARNING, "executeFunction(): There was an error in Javascript code.", thrown);
return true;
}
} finally {
Context.exit();
}
}
public static boolean executeFunction(Scriptable thisScope, Function f, java.net.URL codeSource, UserAgentContext ucontext) {
Context ctx = createContext(codeSource, ucontext);
try {
try {
Object result = f.call(ctx, thisScope, thisScope, new Object[0]);
if(!(result instanceof Boolean)) {
return true;
}
return ((Boolean) result).booleanValue();
} catch(Throwable err) {
logger.log(Level.WARNING, "executeFunction(): Unable to execute Javascript function " + f.getClassName() + ".", err);
return true;
}
} finally {
Context.exit();
}
}
/**
* A document UserData
key used
* to map Javascript scope in the HTML document.
*/
public static final String SCOPE_KEY = "cobra.js.scope";
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/js/FilteredObjectList.java 0000644 0001750 0001750 00000004004 10726473500 027070 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Oct 9, 2005
*/
package org.lobobrowser.html.js;
import java.util.*;
import org.lobobrowser.js.*;
public class FilteredObjectList extends AbstractScriptableDelegate {
private final Collection sourceNodeList;
private final ObjectFilter filter;
private final Object lock;
/**
* @param filter
* @param list
*/
public FilteredObjectList(ObjectFilter filter, Collection list, Object lock) {
super();
this.filter = filter;
sourceNodeList = list;
this.lock = lock;
}
public Object item(int index) {
synchronized(this.lock) {
int count = 0;
Iterator i = this.sourceNodeList.iterator();
while(i.hasNext()) {
Object node = (Object) i.next();
if(this.filter.accept(node)) {
if(count == index) {
return node;
}
count++;
}
}
return null;
}
}
public int getLength() {
synchronized(this.lock) {
int count = 0;
Iterator i = this.sourceNodeList.iterator();
while(i.hasNext()) {
Object node = (Object) i.next();
if(this.filter.accept(node)) {
count++;
}
}
return count;
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/js/History.java 0000644 0001750 0001750 00000005315 11127104412 025003 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The XAMJ Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.js;
import org.lobobrowser.html.*;
import org.lobobrowser.js.AbstractScriptableDelegate;
public class History extends AbstractScriptableDelegate {
private final Window window;
History(Window window) {
this.window = window;
}
public String getCurrent() {
HtmlRendererContext ctx = this.window.getHtmlRendererContext();
return ctx != null ? ctx.getCurrentURL() : null;
}
public String getNext() {
HtmlRendererContext ctx = this.window.getHtmlRendererContext();
return ctx != null ? ctx.getNextURL() : null;
}
public String getPrevious() {
HtmlRendererContext ctx = this.window.getHtmlRendererContext();
return ctx != null ? ctx.getPreviousURL() : null;
}
public int getLength() {
HtmlRendererContext ctx = this.window.getHtmlRendererContext();
return ctx != null ? ctx.getHistoryLength() : 0;
}
public void back() {
HtmlRendererContext ctx = this.window.getHtmlRendererContext();
if(ctx != null) {
ctx.back();
}
}
public void forward() {
HtmlRendererContext ctx = this.window.getHtmlRendererContext();
if(ctx != null) {
ctx.forward();
}
}
public void go(int offset) {
HtmlRendererContext ctx = this.window.getHtmlRendererContext();
if(ctx != null) {
ctx.moveInHistory(offset);
}
}
public void go(String url) {
HtmlRendererContext ctx = this.window.getHtmlRendererContext();
if(ctx != null) {
ctx.goToHistoryURL(url);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/js/Location.java 0000644 0001750 0001750 00000006444 11126716716 025135 0 ustar twerner twerner package org.lobobrowser.html.js;
import org.lobobrowser.html.*;
import org.lobobrowser.html.domimpl.*;
import org.lobobrowser.js.*;
import org.w3c.dom.Document;
import java.net.*;
import java.util.logging.*;
public class Location extends AbstractScriptableDelegate {
private static final Logger logger = Logger.getLogger(Location.class.getName());
private final Window window;
Location(final Window window) {
this.window = window;
}
private URL getURL() {
URL url;
try {
Document document = this.window.getDocumentNode();
url = document == null ? null : new URL(document.getDocumentURI());
} catch(java.net.MalformedURLException mfu) {
url = null;
}
return url;
}
public String getHash() {
URL url = this.getURL();
return url == null ? null : url.getRef();
}
public String getHost() {
URL url = this.getURL();
if(url == null) {
return null;
}
return url.getHost() + (url.getPort() == -1 ? "" : ":" + url.getPort());
}
public String getHostname() {
URL url = this.getURL();
if(url == null) {
return null;
}
return url.getHost();
}
public String getPathname() {
URL url = this.getURL();
return url == null ? null : url.getPath();
}
public String getPort() {
URL url = this.getURL();
if(url == null) {
return null;
}
int port = url.getPort();
return port == -1 ? null : String.valueOf(port);
}
public String getProtocol() {
URL url = this.getURL();
if(url == null) {
return null;
}
return url.getProtocol() + ":";
}
public String getSearch() {
URL url = this.getURL();
String query = url == null ? null : url.getQuery();
// Javascript requires "?" in its search string.
return query == null ? "" : "?" + query;
}
private String target;
public String getTarget() {
return this.target;
}
public void setTarget(String value) {
this.target = value;
}
public String getHref() {
Document document = this.window.getDocumentNode();
return document == null ? null : document.getDocumentURI();
}
public void setHref(String uri) {
HtmlRendererContext rcontext = this.window.getHtmlRendererContext();
if(rcontext != null) {
try {
URL url;
Document document = this.window.getDocumentNode();
if(document instanceof HTMLDocumentImpl) {
HTMLDocumentImpl docImpl = (HTMLDocumentImpl) document;
url = docImpl.getFullURL(uri);
} else {
url = new URL(uri);
}
rcontext.navigate(url, this.target);
} catch(java.net.MalformedURLException mfu) {
logger.log(Level.WARNING, "setHref(): Malformed location: [" + uri + "].", mfu);
}
}
}
public void reload() {
//TODO: This is not really reload.
Document document = this.window.getDocumentNode();
if(document instanceof HTMLDocumentImpl) {
HTMLDocumentImpl docImpl = (HTMLDocumentImpl) document;
HtmlRendererContext rcontext = docImpl.getHtmlRendererContext();
if(rcontext != null) {
rcontext.reload();
}
else {
docImpl.warn("reload(): No renderer context in Location's document.");
}
}
}
public void replace(String href) {
this.setHref(href);
}
public String toString() {
// This needs to be href. Callers
// rely on that.
return this.getHref();
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/js/Navigator.java 0000644 0001750 0001750 00000004656 11126716726 025323 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.js;
import org.lobobrowser.html.*;
import org.lobobrowser.js.*;
public class Navigator extends AbstractScriptableDelegate {
private final UserAgentContext context;
/**
* @param context
*/
Navigator(UserAgentContext context) {
super();
this.context = context;
}
public String getAppCodeName() {
return this.context.getAppCodeName();
}
public String getAppName() {
return this.context.getAppName();
}
public String getAppVersion() {
return this.context.getAppVersion();
}
public String getAppMinorVersion() {
return this.context.getAppMinorVersion();
}
public String getPlatform() {
return this.context.getPlatform();
}
public String getUserAgent() {
return this.context.getUserAgent();
}
public String getVendor() {
return this.context.getVendor();
}
public String getProduct() {
return this.context.getProduct();
}
public boolean javaEnabled() {
// True always?
return true;
}
private MimeTypesCollection mimeTypes;
public MimeTypesCollection getMimeTypes() {
synchronized(this) {
MimeTypesCollection mt = this.mimeTypes;
if(mt == null) {
mt = new MimeTypesCollection();
this.mimeTypes = mt;
}
return mt;
}
}
public class MimeTypesCollection {
// Class must be public to allow JavaScript access
public int getLength() {
return 0;
}
public Object item(int index) {
return null;
}
public Object namedItem(String name) {
return null;
}
}
} libcobra-java-0.98.4.orig/src/org/lobobrowser/html/js/ObjectFilter.java 0000644 0001750 0001750 00000002031 10726473506 025727 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Nov 12, 2005
*/
package org.lobobrowser.html.js;
public interface ObjectFilter {
public boolean accept(Object target);
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/js/Screen.java 0000644 0001750 0001750 00000003056 11126716752 024600 0 ustar twerner twerner package org.lobobrowser.html.js;
import java.awt.*;
import org.lobobrowser.js.*;
public class Screen extends AbstractScriptableDelegate {
private final GraphicsEnvironment graphicsEnvironment;
private final GraphicsDevice graphicsDevice;
/**
* @param context
*/
Screen() {
super();
if (GraphicsEnvironment.isHeadless()) {
this.graphicsEnvironment = null;
this.graphicsDevice = null;
}
else {
this.graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
this.graphicsDevice = this.graphicsEnvironment.getDefaultScreenDevice();
}
}
public int getHeight() {
GraphicsDevice gd = this.graphicsDevice;
return gd == null ? 0 : gd.getDisplayMode().getHeight();
}
public int getPixelDepth() {
return this.getColorDepth();
}
public int getWidth() {
GraphicsEnvironment ge = this.graphicsEnvironment;
if(ge == null) {
return 0;
}
GraphicsDevice gd = ge.getDefaultScreenDevice();
return gd.getDisplayMode().getWidth();
}
public int getAvailHeight() {
GraphicsEnvironment ge = this.graphicsEnvironment;
if(ge == null) {
return 0;
}
return ge.getMaximumWindowBounds().height;
}
public int getAvailWidth() {
GraphicsEnvironment ge = this.graphicsEnvironment;
if(ge == null) {
return 0;
}
return ge.getMaximumWindowBounds().width;
}
public int getColorDepth() {
GraphicsDevice gd = this.graphicsDevice;
if(gd == null) {
return 0;
}
return gd.getDisplayMode().getBitDepth();
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/js/SecurityControllerImpl.java 0000644 0001750 0001750 00000005426 10726473500 030055 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
package org.lobobrowser.html.js;
import org.mozilla.javascript.*;
import java.security.*;
public class SecurityControllerImpl extends SecurityController {
private final java.net.URL url;
private final java.security.Policy policy;
private final CodeSource codesource;
public SecurityControllerImpl(java.net.URL url, Policy policy) {
this.url = url;
this.policy = policy;
this.codesource = new CodeSource(this.url, (java.security.cert.Certificate[]) null);
}
public Object callWithDomain(Object securityDomain, final Context ctx, final Callable callable, final Scriptable scope, final Scriptable thisObj, final Object[] args) {
if(securityDomain == null) {
return callable.call(ctx, scope, thisObj, args);
}
else {
PrivilegedAction action = new PrivilegedAction() {
public Object run() {
return callable.call(ctx, scope, thisObj, args);
}
};
AccessControlContext acctx = new AccessControlContext(new ProtectionDomain[] { (ProtectionDomain) securityDomain });
return AccessController.doPrivileged(action, acctx);
}
}
public GeneratedClassLoader createClassLoader(ClassLoader parent, Object staticDomain) {
return new LocalSecureClassLoader(parent);
}
public Object getDynamicSecurityDomain(Object securityDomain) {
Policy policy = this.policy;
if(policy == null) {
return null;
}
else {
PermissionCollection permissions = this.policy.getPermissions(codesource);
return new ProtectionDomain(codesource, permissions);
}
}
private class LocalSecureClassLoader extends SecureClassLoader implements GeneratedClassLoader {
public LocalSecureClassLoader(ClassLoader parent) {
super(parent);
}
public Class defineClass(String name, byte[] b) {
return this.defineClass(name, b, 0, b.length, codesource);
}
public void linkClass(Class clazz) {
super.resolveClass(clazz);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/js/Window.java 0000644 0001750 0001750 00000062636 11134561070 024627 0 ustar twerner twerner /*
GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2006 The Lobo Project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Contact info: lobochief@users.sourceforge.net
*/
/*
* Created on Nov 12, 2005
*/
package org.lobobrowser.html.js;
import java.util.*;
import java.lang.ref.*;
import javax.swing.Timer;
import java.awt.event.*;
import java.util.logging.*;
import org.lobobrowser.html.*;
import org.lobobrowser.html.domimpl.*;
import org.lobobrowser.js.*;
import org.lobobrowser.util.ID;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.w3c.dom.Document;
import org.w3c.dom.html2.*;
import org.w3c.dom.views.*;
import org.w3c.dom.css.*;
public class Window extends AbstractScriptableDelegate implements AbstractView {
private static final Logger logger = Logger.getLogger(Window.class.getName());
private static final Map CONTEXT_WINDOWS = new WeakHashMap();
//private static final JavaClassWrapper IMAGE_WRAPPER = JavaClassWrapperFactory.getInstance().getClassWrapper(Image.class);
private static final JavaClassWrapper XMLHTTPREQUEST_WRAPPER = JavaClassWrapperFactory.getInstance().getClassWrapper(XMLHttpRequest.class);
private static int timerIdCounter = 0;
private final HtmlRendererContext rcontext;
private final UserAgentContext uaContext;
private Navigator navigator;
private Screen screen;
private Location location;
private Map taskMap;
private volatile HTMLDocumentImpl document;
public Window(HtmlRendererContext rcontext, UserAgentContext uaContext) {
//TODO: Probably need to create a new Window instance
//for every document. Sharing of Window state between
//different documents is not correct.
this.rcontext = rcontext;
this.uaContext = uaContext;
}
private static int generateTimerID() {
synchronized(logger) {
return timerIdCounter++;
}
}
public HtmlRendererContext getHtmlRendererContext() {
return this.rcontext;
}
public UserAgentContext getUserAgentContext() {
return this.uaContext;
}
private void clearState() {
Scriptable s = this.getWindowScope();
if(s != null) {
Object[] ids = s.getIds();
for(int i = 0; i < ids.length; i++) {
Object id = ids[i];
if(id instanceof String) {
s.delete((String) id);
}
else if(id instanceof Integer) {
s.delete(((Integer) id).intValue());
}
}
}
}
public void setDocument(HTMLDocumentImpl document) {
Document prevDocument = this.document;
if(prevDocument != document) {
// Should clearing of the state be done
// when window "unloads"?
if(prevDocument != null) {
// Only clearing when the previous document was not null
// because state might have been set on the window before
// the very first document is added.
this.clearState();
}
this.initWindowScope(document);
this.forgetAllTasks();
Function onunload = this.onunload;
if(onunload != null) {
HTMLDocumentImpl oldDoc = (HTMLDocumentImpl) this.document;
Executor.executeFunction(this.getWindowScope(), onunload, oldDoc.getDocumentURL(), this.uaContext);
this.onunload = null;
}
this.document = document;
}
}
public DocumentView getDocument() {
return this.document;
}
public Document getDocumentNode() {
return this.document;
}
private void putAndStartTask(Integer timeoutID, Timer timer, Object retained) {
TaskWrapper oldTaskWrapper = null;
synchronized(this) {
Map taskMap = this.taskMap;
if(taskMap == null) {
taskMap = new HashMap(4);
this.taskMap = taskMap;
}
else {
oldTaskWrapper = (TaskWrapper) taskMap.get(timeoutID);
}
taskMap.put(timeoutID, new TaskWrapper(timer, retained));
}
// Do this outside synchronized block, just in case.
if(oldTaskWrapper != null) {
oldTaskWrapper.timer.stop();
}
timer.start();
}
private void forgetTask(Integer timeoutID, boolean cancel) {
TaskWrapper oldTimer = null;
synchronized(this) {
Map taskMap = this.taskMap;
if(taskMap != null) {
oldTimer = (TaskWrapper) taskMap.remove(timeoutID);
}
}
if(oldTimer != null && cancel) {
oldTimer.timer.stop();
}
}
private void forgetAllTasks() {
TaskWrapper[] oldTaskWrappers = null;
synchronized(this) {
Map taskMap = this.taskMap;
if(taskMap != null) {
oldTaskWrappers = (TaskWrapper[]) taskMap.values().toArray(new TaskWrapper[0]);
this.taskMap = null;
}
}
if(oldTaskWrappers != null) {
for(int i = 0; i < oldTaskWrappers.length; i++) {
TaskWrapper taskWrapper = oldTaskWrappers[i];
taskWrapper.timer.stop();
}
}
}
// private Timer getTask(Long timeoutID) {
// synchronized(this) {
// Map taskMap = this.taskMap;
// if(taskMap != null) {
// return (Timer) taskMap.get(timeoutID);
// }
// }
// return null;
// }
/**
* @param aFunction
* Javascript function to invoke on each loop.
* @param aTimeInMs
* Time in millisecund between each loop.
* @return Return the timer ID to use as reference
* @see Window.setInterval interface
* definition
* @todo Make proper and refactore with {@link Window#setTimeout(Function, double)}.
*/
public int setInterval(final Function aFunction, final double aTimeInMs)
{
if (aTimeInMs > Integer.MAX_VALUE || aTimeInMs < 0)
{
throw new IllegalArgumentException("Timeout value " + aTimeInMs + " is not supported.");
}
final int timeID = generateTimerID();
final Integer timeIDInt = new Integer(timeID);
ActionListener task = new FunctionTimerTask(this, timeIDInt, aFunction, false);
int t = (int) aTimeInMs;
if(t < 1) {
t = 1;
}
Timer timer = new Timer(t, task);
timer.setRepeats(true); // The only difference with setTimeout
this.putAndStartTask(timeIDInt, timer, aFunction);
return timeID;
}
/**
* @param aExpression
* Javascript expression to invoke on each loop.
* @param aTimeInMs
* Time in millisecund between each loop.
* @return Return the timer ID to use as reference
* @see Window.setInterval interface
* definition
* @todo Make proper and refactore with {@link Window#setTimeout(String, double)}.
*/
public int setInterval(final String aExpression, double aTimeInMs)
{
if (aTimeInMs > Integer.MAX_VALUE || aTimeInMs < 0)
{
throw new IllegalArgumentException("Timeout value " + aTimeInMs + " is not supported.");
}
final int timeID = generateTimerID();
final Integer timeIDInt = new Integer(timeID);
ActionListener task = new ExpressionTimerTask(this, timeIDInt, aExpression, false);
int t = (int) aTimeInMs;
if(t < 1) {
t = 1;
}
Timer timer = new Timer(t, task);
timer.setRepeats(false); // The only difference with setTimeout
this.putAndStartTask(timeIDInt, timer, null);
return timeID;
}
/**
* @param aTimerID
* Timer ID to stop.
* @see Window.clearInterval interface Definition
*/
public void clearInterval(int aTimerID)
{
Integer key = new Integer(aTimerID);
this.forgetTask(key, true);
}
public void alert(String message) {
if(this.rcontext != null) {
this.rcontext.alert(message);
}
}
public void back() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
rcontext.back();
}
}
public void blur() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
rcontext.blur();
}
}
public void clearTimeout(int timeoutID) {
Integer key = new Integer(timeoutID);
this.forgetTask(key, true);
}
public void close() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
rcontext.close();
}
}
public boolean confirm(String message) {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
return rcontext.confirm(message);
}
else {
return false;
}
}
public Object eval(String javascript) {
HTMLDocumentImpl document = (HTMLDocumentImpl) this.document;
if(document == null) {
throw new IllegalStateException("Cannot evaluate if document is not set.");
}
Context ctx = Executor.createContext(document.getDocumentURL(), this.uaContext);
try {
Scriptable scope = this.getWindowScope();
if(scope == null) {
throw new IllegalStateException("Scriptable (scope) instance was expected to be keyed as UserData to document using " + Executor.SCOPE_KEY);
}
String scriptURI = "window.eval";
if(logger.isLoggable(Level.INFO)) {
logger.info("eval(): javascript follows...\r\n" + javascript);
}
return ctx.evaluateString(scope, javascript, scriptURI, 1, null);
} finally {
Context.exit();
}
}
public void focus() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
rcontext.focus();
}
}
private void initWindowScope(final Document doc) {
// Special Javascript class: XMLHttpRequest
final Scriptable ws = this.getWindowScope();
JavaInstantiator xi = new JavaInstantiator() {
public Object newInstance() {
Document d = doc;
if(d == null) {
throw new IllegalStateException("Cannot perform operation when document is unset.");
}
HTMLDocumentImpl hd;
try {
hd = (HTMLDocumentImpl) d;
} catch(ClassCastException err) {
throw new IllegalStateException("Cannot perform operation with documents of type " + d.getClass().getName() + ".");
}
return new XMLHttpRequest(uaContext, hd.getDocumentURL(), ws);
}
};
Function xmlHttpRequestC = JavaObjectWrapper.getConstructor("XMLHttpRequest", XMLHTTPREQUEST_WRAPPER, ws, xi);
ScriptableObject.defineProperty(ws, "XMLHttpRequest", xmlHttpRequestC, ScriptableObject.READONLY);
// HTML element classes
this.defineElementClass(ws, doc, "Image", "img", HTMLImageElementImpl.class);
this.defineElementClass(ws, doc, "Script", "script", HTMLScriptElementImpl.class);
this.defineElementClass(ws, doc, "IFrame", "iframe", HTMLIFrameElementImpl.class);
this.defineElementClass(ws, doc, "Option", "option", HTMLOptionElementImpl.class);
this.defineElementClass(ws, doc, "Select", "select", HTMLSelectElementImpl.class);
}
private ScriptableObject windowScope;
public Scriptable getWindowScope() {
synchronized(this) {
ScriptableObject windowScope = this.windowScope;
if(windowScope != null) {
return windowScope;
}
// Context.enter() OK in this particular case.
Context ctx = Context.enter();
try {
// Window scope needs to be top-most scope.
windowScope = (ScriptableObject) JavaScript.getInstance().getJavascriptObject(this, null);
ctx.initStandardObjects(windowScope);
this.windowScope = windowScope;
return windowScope;
} finally {
Context.exit();
}
}
}
private final void defineElementClass(Scriptable scope, final Document document, final String jsClassName, final String elementName, Class javaClass) {
JavaInstantiator ji = new JavaInstantiator() {
public Object newInstance() {
Document d = document;
if(d == null) {
throw new IllegalStateException("Document not set in current context.");
}
return d.createElement(elementName);
}
};
JavaClassWrapper classWrapper = JavaClassWrapperFactory.getInstance().getClassWrapper(javaClass);
Function constructorFunction = JavaObjectWrapper.getConstructor(jsClassName, classWrapper, scope, ji);
ScriptableObject.defineProperty(scope, jsClassName, constructorFunction, ScriptableObject.READONLY);
}
public static Window getWindow(HtmlRendererContext rcontext) {
if(rcontext == null) {
return null;
}
synchronized(CONTEXT_WINDOWS) {
Reference wref = (Reference) CONTEXT_WINDOWS.get(rcontext);
if(wref != null) {
Window window = (Window) wref.get();
if(window != null) {
return window;
}
}
Window window = new Window(rcontext, rcontext.getUserAgentContext());
CONTEXT_WINDOWS.put(rcontext, new WeakReference(window));
return window;
}
}
public Window open(String relativeUrl, String windowName, String windowFeatures, boolean replace) {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
java.net.URL url;
Object document = this.document;
if(document instanceof HTMLDocumentImpl) {
url = ((HTMLDocumentImpl) document).getFullURL(relativeUrl);
}
else {
try {
url = new java.net.URL(relativeUrl);
} catch(java.net.MalformedURLException mfu) {
throw new IllegalArgumentException("Malformed URI: " + relativeUrl);
}
}
HtmlRendererContext newContext = rcontext.open(url, windowName, windowFeatures, replace);
return getWindow(newContext);
}
else {
return null;
}
}
public Window open(String url) {
return this.open(url, "window:" + String.valueOf(ID.generateLong()));
}
public Window open(String url, String windowName) {
return this.open(url, windowName, "", false);
}
public Window open(String url, String windowName, String windowFeatures) {
return this.open(url, windowName, windowFeatures, false);
}
public String prompt(String message) {
return this.prompt(message, "");
}
public String prompt(String message, int inputDefault) {
return this.prompt(message, String.valueOf(inputDefault));
}
public String prompt(String message, String inputDefault) {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
return rcontext.prompt(message, inputDefault);
}
else {
return null;
}
}
public void scrollTo(int x, int y) {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
rcontext.scroll(x, y);
}
}
public void scrollBy(int x, int y) {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
rcontext.scrollBy(x, y);
}
}
public void resizeTo(int width, int height) {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
rcontext.resizeTo(width, height);
}
}
public void resizeBy(int byWidth, int byHeight) {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
rcontext.resizeBy(byWidth, byHeight);
}
}
public int setTimeout(final String expr, double millis) {
if(millis > Integer.MAX_VALUE || millis < 0) {
throw new IllegalArgumentException("Timeout value " + millis + " is not supported.");
}
final int timeID = generateTimerID();
final Integer timeIDInt = new Integer(timeID);
ActionListener task = new ExpressionTimerTask(this, timeIDInt, expr, true);
int t = (int) millis;
if(t < 1) {
t = 1;
}
Timer timer = new Timer(t, task);
timer.setRepeats(false);
this.putAndStartTask(timeIDInt, timer, null);
return timeID;
}
public int setTimeout(final Function function, double millis) {
if(millis > Integer.MAX_VALUE || millis < 0) {
throw new IllegalArgumentException("Timeout value " + millis + " is not supported.");
}
final int timeID = generateTimerID();
final Integer timeIDInt = new Integer(timeID);
ActionListener task = new FunctionTimerTask(this, timeIDInt, function, true);
int t = (int) millis;
if(t < 1) {
t = 1;
}
Timer timer = new Timer(t, task);
timer.setRepeats(false);
this.putAndStartTask(timeIDInt, timer, function);
return timeID;
}
public boolean isClosed() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
return rcontext.isClosed();
}
else {
return false;
}
}
public String getDefaultStatus() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
return rcontext.getDefaultStatus();
}
else {
return null;
}
}
public HTMLCollection getFrames() {
Document doc = this.document;
if(doc instanceof HTMLDocumentImpl) {
return ((HTMLDocumentImpl) doc).getFrames();
}
return null;
}
private int length;
private boolean lengthSet = false;
/**
* Gets the number of frames.
*/
public int getLength() {
if(this.lengthSet) {
return this.length;
}
else {
HTMLCollection frames = this.getFrames();
return frames == null ? 0 : frames.getLength();
}
}
public void setLength(int length) {
this.lengthSet = true;
this.length = length;
}
public String getName() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
return rcontext.getName();
}
else {
return null;
}
}
public Window getParent() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
return Window.getWindow(rcontext.getParent());
}
else {
return null;
}
}
public Window getOpener() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
return Window.getWindow(rcontext.getOpener());
}
else {
return null;
}
}
public void setOpener(Window opener) {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
if(opener == null) {
rcontext.setOpener(null);
}
else {
rcontext.setOpener(opener.rcontext);
}
}
}
public Window getSelf() {
return this;
}
public String getStatus() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
return rcontext.getStatus();
}
else {
return null;
}
}
public void setStatus(String message) {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
rcontext.setStatus(message);
}
}
public Window getTop() {
HtmlRendererContext rcontext = this.rcontext;
if(rcontext != null) {
return Window.getWindow(rcontext.getTop());
}
else {
return null;
}
}
public Window getWindow() {
return this;
}
public Navigator getNavigator() {
synchronized(this) {
Navigator nav = this.navigator;
if(nav == null) {
nav = new Navigator(this.uaContext);
this.navigator = nav;
}
return nav;
}
}
public Screen getScreen() {
synchronized(this) {
Screen nav = this.screen;
if(nav == null) {
nav = new Screen();
this.screen = nav;
}
return nav;
}
}
public Location getLocation() {
synchronized(this) {
Location location = this.location;
if(location == null) {
location = new Location(this);
this.location = location;
}
return location;
}
}
public void setLocation(String location) {
this.getLocation().setHref(location);
}
private History history;
public History getHistory() {
synchronized(this) {
History history = this.history;
if(history == null) {
history = new History(this);
this.history = history;
}
return history;
}
}
public CSS2Properties getComputedStyle(HTMLElement element, String pseudoElement) {
if(element instanceof HTMLElementImpl) {
return ((HTMLElementImpl) element).getComputedStyle(pseudoElement);
}
else {
throw new java.lang.IllegalArgumentException("Element implementation unknown: " + element);
}
}
public Function getOnload() {
Document doc = this.document;
if(doc instanceof HTMLDocumentImpl) {
return ((HTMLDocumentImpl) doc).getOnloadHandler();
}
else {
return null;
}
}
public void setOnload(Function onload) {
//Note that body.onload overrides
//window.onload.
Document doc = this.document;
if(doc instanceof HTMLDocumentImpl) {
((HTMLDocumentImpl) doc).setOnloadHandler(onload);
}
}
private Function onunload;
public Function getOnunload() {
return onunload;
}
public void setOnunload(Function onunload) {
this.onunload = onunload;
}
public org.w3c.dom.Node namedItem(String name) {
// Bug 1928758: Element IDs are named objects in context.
HTMLDocumentImpl doc = this.document;
if(doc == null) {
return null;
}
org.w3c.dom.Node node = doc.getElementById(name);
if(node != null) {
return node;
}
return null;
}
public void forceGC() {
System.gc();
}
private static abstract class WeakWindowTask implements ActionListener {
private final WeakReference windowRef;
public WeakWindowTask(Window window) {
this.windowRef = new WeakReference(window);
}
protected Window getWindow() {
WeakReference ref = this.windowRef;
return ref == null ? null : (Window) ref.get();
}
}
private static class FunctionTimerTask extends WeakWindowTask {
// Implemented as a static WeakWindowTask to allow the Window
// to get garbage collected, especially in infinite loop
// scenarios.
private final Integer timeIDInt;
private final WeakReference functionRef;
private final boolean removeTask;
public FunctionTimerTask(Window window, Integer timeIDInt, Function function, boolean removeTask) {
super(window);
this.timeIDInt = timeIDInt;
this.functionRef = new WeakReference(function);
this.removeTask = removeTask;
}
public void actionPerformed(ActionEvent e) {
// This executes in the GUI thread and that's good.
try {
Window window = this.getWindow();
if(window == null) {
if(logger.isLoggable(Level.INFO)) {
logger.info("actionPerformed(): Window is no longer available.");
}
return;
}
if(this.removeTask) {
window.forgetTask(this.timeIDInt, false);
}
HTMLDocumentImpl doc = (HTMLDocumentImpl) window.getDocument();
if(doc == null) {
throw new IllegalStateException("Cannot perform operation when document is unset.");
}
Function function = (Function) this.functionRef.get();
if(function == null) {
throw new IllegalStateException("Cannot perform operation. Function is no longer available.");
}
Executor.executeFunction(window.getWindowScope(), function, doc.getDocumentURL(), window.getUserAgentContext());
} catch(Throwable err) {
logger.log(Level.WARNING, "actionPerformed()", err);
}
}
}
private static class ExpressionTimerTask extends WeakWindowTask {
// Implemented as a static WeakWindowTask to allow the Window
// to get garbage collected, especially in infinite loop
// scenarios.
private final Integer timeIDInt;
private final String expression;
private final boolean removeTask;
public ExpressionTimerTask(Window window, Integer timeIDInt, String expression, boolean removeTask) {
super(window);
this.timeIDInt = timeIDInt;
this.expression = expression;
this.removeTask = removeTask;
}
public void actionPerformed(ActionEvent e) {
// This executes in the GUI thread and that's good.
try {
Window window = this.getWindow();
if(window == null) {
if(logger.isLoggable(Level.INFO)) {
logger.info("actionPerformed(): Window is no longer available.");
}
return;
}
if(this.removeTask) {
window.forgetTask(this.timeIDInt, false);
}
HTMLDocumentImpl doc = (HTMLDocumentImpl) window.getDocument();
if(doc == null) {
throw new IllegalStateException("Cannot perform operation when document is unset.");
}
window.eval(this.expression);
} catch(Throwable err) {
logger.log(Level.WARNING, "actionPerformed()", err);
}
}
}
private static class TaskWrapper {
public final Timer timer;
private final Object retained;
public TaskWrapper(Timer timer, Object retained) {
super();
this.timer = timer;
this.retained = retained;
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/js/XMLHttpRequest.java 0000644 0001750 0001750 00000007332 10753354760 026235 0 ustar twerner twerner package org.lobobrowser.html.js;
import java.net.*;
import org.w3c.dom.Document;
import org.lobobrowser.html.*;
import org.lobobrowser.util.*;
import org.lobobrowser.js.*;
import org.mozilla.javascript.*;
import java.util.logging.*;
public class XMLHttpRequest extends AbstractScriptableDelegate {
//TODO: See reference: http://www.xulplanet.com/references/objref/XMLHttpRequest.html
private static final Logger logger = Logger.getLogger(XMLHttpRequest.class.getName());
private final HttpRequest request;
private final UserAgentContext pcontext;
private final Scriptable scope;
private final java.net.URL codeSource;
public XMLHttpRequest(UserAgentContext pcontext, java.net.URL codeSource, Scriptable scope) {
this.request = pcontext.createHttpRequest();
this.pcontext = pcontext;
this.scope = scope;
this.codeSource = codeSource;
}
public void abort() {
request.abort();
}
public String getAllResponseHeaders() {
return request.getAllResponseHeaders();
}
public int getReadyState() {
return request.getReadyState();
}
public byte[] getResponseBytes() {
return request.getResponseBytes();
}
public String getResponseHeader(String headerName) {
return request.getResponseHeader(headerName);
}
public String getResponseText() {
return request.getResponseText();
}
public Document getResponseXML() {
return request.getResponseXML();
}
public int getStatus() {
return request.getStatus();
}
public String getStatusText() {
return request.getStatusText();
}
private URL getFullURL(String relativeUrl) throws java.net.MalformedURLException {
return Urls.createURL(this.codeSource, relativeUrl);
}
public void open(String method, String url, boolean asyncFlag, String userName, String password) throws java.io.IOException {
request.open(method, this.getFullURL(url), asyncFlag, userName, password);
}
public void open(String method, String url, boolean asyncFlag, String userName) throws java.io.IOException {
request.open(method, this.getFullURL(url), asyncFlag, userName);
}
public void open(String method, String url, boolean asyncFlag) throws java.io.IOException {
request.open(method, this.getFullURL(url), asyncFlag);
}
public void open(String method, String url) throws java.io.IOException {
request.open(method, this.getFullURL(url));
}
public void send(String content) throws java.io.IOException {
request.send(content);
}
private Function onreadystatechange;
private boolean listenerAdded;
public Function getOnreadystatechange() {
synchronized(this) {
return this.onreadystatechange;
}
}
public void setOnreadystatechange(final Function value) {
synchronized(this) {
this.onreadystatechange = value;
if(value != null && !this.listenerAdded) {
this.request.addReadyStateChangeListener(new ReadyStateChangeListener() {
public void readyStateChanged() {
// Not called in GUI thread to ensure consistency of readyState.
executeReadyStateChange();
}
});
this.listenerAdded = true;
}
}
}
private void executeReadyStateChange() {
// Not called in GUI thread to ensure consistency of readyState.
try {
Function f = XMLHttpRequest.this.getOnreadystatechange();
if(f != null) {
Context ctx = Executor.createContext(this.codeSource, this.pcontext);
try {
Scriptable newScope = (Scriptable) JavaScript.getInstance().getJavascriptObject(XMLHttpRequest.this, this.scope);
f.call(ctx, newScope, newScope, new Object[0]);
} finally {
Context.exit();
}
}
} catch(Exception err) {
logger.log(Level.WARNING, "Error processing ready state change.", err);
}
}
}
libcobra-java-0.98.4.orig/src/org/lobobrowser/html/package.html 0000644 0001750 0001750 00000000145 10445351614 024352 0 ustar twerner twerner Context interfaces that need to be implemented in order
to use the parser and renderer.