Verschiedener Kleinkram, hauptsächlich Formatierungen und @Override-Annotiationen

git-svn-id: https://svn.libreccm.org/ccm/trunk@2142 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-04-24 11:47:31 +00:00
parent 0c7dca5463
commit 50bb1a275b
3 changed files with 86 additions and 70 deletions

View File

@ -42,37 +42,54 @@ import org.w3c.dom.Attr;
*/ */
public class Element { public class Element {
private static final Logger s_log = Logger.getLogger private static final Logger s_log = Logger.getLogger(Element.class.getName());
(Element.class.getName());
protected org.w3c.dom.Element m_element; protected org.w3c.dom.Element m_element;
/* DOM element that is being wrapped */ /* DOM element that is being wrapped */
/** /**
* owner document * owner document
*/ */
private org.w3c.dom.Document m_doc; private org.w3c.dom.Document m_doc;
private static ThreadLocal s_localDocument = new ThreadLocal() { private static ThreadLocal s_localDocument = new ThreadLocal() {
@Override @Override
public Object initialValue() { public Object initialValue() {
try { try {
DocumentBuilderFactory builder = DocumentBuilderFactory builder =
DocumentBuilderFactory.newInstance(); DocumentBuilderFactory.newInstance();
builder.setNamespaceAware(true); builder.setNamespaceAware(true);
return builder.newDocumentBuilder().newDocument(); return builder.newDocumentBuilder().newDocument();
} catch ( ParserConfigurationException e ) { } catch (ParserConfigurationException e) {
s_log.error(e); s_log.error(e);
throw new UncheckedWrapperException throw new UncheckedWrapperException("INTERNAL: Could not create thread local DOM document.", e);
("INTERNAL: Could not create thread local DOM document.", e);
}
} }
}; }
};
private static org.w3c.dom.Document getDocument() { private static org.w3c.dom.Document getDocument() {
return (org.w3c.dom.Document) s_localDocument.get(); return (org.w3c.dom.Document) s_localDocument.get();
} }
// public org.w3c.dom.Document getOwnerDocument() {
// if (null == m_doc) {
// m_doc = (org.w3c.dom.Document) s_localDocument.get();
// }
//
// return m_doc;
// }
// public void importElement(final Element element) {
// element.m_element = (org.w3c.dom.Element) this.m_element.getOwnerDocument().importNode(element.m_element, true);
// }
public void syncDocs() {
if (m_doc == null) {
m_doc = (org.w3c.dom.Document) s_localDocument.get();
}
if (!m_element.getOwnerDocument().equals(m_doc)) {
m_element = (org.w3c.dom.Element) m_doc.importNode(m_element, true);
}
}
/** /**
* Protected constructor to set up factories, etc. Does not actually * Protected constructor to set up factories, etc. Does not actually
* create a new element. Used if we are programatically setting the * create a new element. Used if we are programatically setting the
@ -86,7 +103,7 @@ public class Element {
* *
* @param name the name of the element * @param name the name of the element
*/ */
public Element( String name ) { public Element(String name) {
this(); this();
Assert.exists(name, String.class); Assert.exists(name, String.class);
@ -101,11 +118,11 @@ public class Element {
* @param name the name of the element * @param name the name of the element
* @param uri the URI for the namespace definition * @param uri the URI for the namespace definition
*/ */
public Element( String name, String uri ) { public Element(String name, String uri) {
Assert.exists(name, String.class); Assert.exists(name, String.class);
Assert.exists(uri, String.class); Assert.exists(uri, String.class);
m_element = getDocument().createElementNS( uri, name ); m_element = getDocument().createElementNS(uri, name);
} }
/** /**
@ -175,8 +192,7 @@ public class Element {
} }
Element copyTo = new Element(); Element copyTo = new Element();
copyTo.m_element = m_doc.createElementNS copyTo.m_element = m_doc.createElementNS(copyFrom.m_element.getNamespaceURI(), copyFrom.getName());
(copyFrom.m_element.getNamespaceURI(), copyFrom.getName());
this.m_element.appendChild(copyTo.m_element); this.m_element.appendChild(copyTo.m_element);
newChildElementHelper(copyFrom, copyTo); newChildElementHelper(copyFrom, copyTo);
return copyTo; return copyTo;
@ -235,6 +251,7 @@ public class Element {
} }
} }
/** /**
* Adds an attribute to the element. * Adds an attribute to the element.
* *
@ -242,10 +259,10 @@ public class Element {
* @param value the value of the attribute * @param value the value of the attribute
* @return this element. * @return this element.
*/ */
public Element addAttribute( String name, String value ) { public Element addAttribute(String name, String value) {
Assert.exists(name, String.class); Assert.exists(name, String.class);
m_element.setAttribute( name, value ); m_element.setAttribute(name, value);
return this; return this;
} }
@ -267,7 +284,7 @@ public class Element {
* @param newContent the new child element * @param newContent the new child element
* @return this element. * @return this element.
*/ */
public Element addContent( Element newContent ) { public Element addContent(Element newContent) {
Assert.exists(newContent, Element.class); Assert.exists(newContent, Element.class);
newContent.importInto(m_element.getOwnerDocument()); newContent.importInto(m_element.getOwnerDocument());
@ -284,7 +301,7 @@ public class Element {
* @param text the text to include * @param text the text to include
* @return this element. * @return this element.
*/ */
public Element setText( String text ) { public Element setText(String text) {
if (text == null) { if (text == null) {
// This converts the null to the empty string because // This converts the null to the empty string because
// org.w3c.dom does not like null and HTML does not // org.w3c.dom does not like null and HTML does not
@ -293,7 +310,7 @@ public class Element {
text = ""; text = "";
} }
org.w3c.dom.Text textElem = org.w3c.dom.Text textElem =
m_element.getOwnerDocument().createTextNode(text); m_element.getOwnerDocument().createTextNode(text);
m_element.appendChild(textElem); m_element.appendChild(textElem);
return this; return this;
@ -327,7 +344,7 @@ public class Element {
} }
org.w3c.dom.CDATASection cdataSection = org.w3c.dom.CDATASection cdataSection =
m_element.getOwnerDocument().createCDATASection(cdata); m_element.getOwnerDocument().createCDATASection(cdata);
m_element.appendChild(cdataSection); m_element.appendChild(cdataSection);
@ -381,18 +398,17 @@ public class Element {
org.w3c.dom.Node n = nl.item(i); org.w3c.dom.Node n = nl.item(i);
if (n instanceof org.w3c.dom.Element) { if (n instanceof org.w3c.dom.Element) {
Element elt = new Element(); Element elt = new Element();
elt.m_element = (org.w3c.dom.Element)n; elt.m_element = (org.w3c.dom.Element) n;
retval.add(elt); retval.add(elt);
} }
} }
return retval; return retval;
} }
public java.util.Map getAttributes() { public java.util.Map getAttributes() {
// Retrieve the attributes of the DOM Element // Retrieve the attributes of the DOM Element
org.w3c.dom.NamedNodeMap attributeNodeMap = org.w3c.dom.NamedNodeMap attributeNodeMap =
m_element.getAttributes(); m_element.getAttributes();
// Create the HashMap that we will return the attributes // Create the HashMap that we will return the attributes
// in // in
@ -431,7 +447,6 @@ public class Element {
return m_element.getTagName(); return m_element.getTagName();
} }
/** /**
* Functions to allow this class to interact appropriately with the * Functions to allow this class to interact appropriately with the
* Document class (for example, allows nodes to be moved around, * Document class (for example, allows nodes to be moved around,
@ -439,7 +454,7 @@ public class Element {
* *
* @return the internal DOM Element. * @return the internal DOM Element.
*/ */
protected final org.w3c.dom.Element getInternalElement( ) { protected final org.w3c.dom.Element getInternalElement() {
return m_element; return m_element;
} }
@ -450,15 +465,15 @@ public class Element {
* *
* @param doc the org.w3c.dom.Document to import into * @param doc the org.w3c.dom.Document to import into
*/ */
protected void importInto( org.w3c.dom.Document doc ) { protected void importInto(org.w3c.dom.Document doc) {
/* /*
Exception e = new Exception(); Exception e = new Exception();
java.io.StringWriter sw = new java.io.StringWriter(); java.io.StringWriter sw = new java.io.StringWriter();
e.printStackTrace(new java.io.PrintWriter(sw)); e.printStackTrace(new java.io.PrintWriter(sw));
System.out.println(sw.toString().substring(0, 300)); System.out.println(sw.toString().substring(0, 300));
*/ */
m_element = (org.w3c.dom.Element)doc.importNode(m_element, true); m_element = (org.w3c.dom.Element) doc.importNode(m_element, true);
} }
/** /**
@ -476,13 +491,13 @@ public class Element {
org.w3c.dom.NamedNodeMap nnm = node.getAttributes(); org.w3c.dom.NamedNodeMap nnm = node.getAttributes();
if (nnm != null) { if (nnm != null) {
for (int i = 0; i < nnm.getLength(); i++) { for (int i = 0; i < nnm.getLength(); i++) {
org.w3c.dom.Attr attr = (org.w3c.dom.Attr)nnm.item(i); org.w3c.dom.Attr attr = (org.w3c.dom.Attr) nnm.item(i);
attr.getValue(); attr.getValue();
} }
} }
org.w3c.dom.NodeList nl = node.getChildNodes(); org.w3c.dom.NodeList nl = node.getChildNodes();
if (nl != null) { if (nl != null) {
for (int i = 0; i < nl.getLength() ; i++) { for (int i = 0; i < nl.getLength(); i++) {
visitAllAttributes(nl.item(i)); visitAllAttributes(nl.item(i));
} }
} }
@ -540,36 +555,36 @@ public class Element {
@Override @Override
public int hashCode() { public int hashCode() {
Date start = new Date(); Date start = new Date();
String hashString = getXMLHashString(); String hashString = getXMLHashString();
s_log.debug( s_log.debug(
"hashCode: getXMLString took " "hashCode: getXMLString took "
+ (new Date().getTime() - start.getTime()) + (new Date().getTime() - start.getTime())
+ " millisecs"); + " millisecs");
return hashString.hashCode(); return hashString.hashCode();
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
s_log.debug("equals invoked"); s_log.debug("equals invoked");
Date start = new Date(); Date start = new Date();
if (other == null) { if (other == null) {
return false; return false;
}
if (!other.getClass().equals(Element.class)) {
return false;
}
Element otherElement = (Element) other;
String thisXML = getXMLHashString();
String otherXML = otherElement.getXMLHashString();
s_log.debug(
"Equals: getXMLString twice took "
+ (new Date().getTime() - start.getTime())
+ " millisecs");
return thisXML.equals(otherXML);
} }
if (!other.getClass().equals(Element.class)) {
return false;
}
Element otherElement = (Element) other;
String thisXML = getXMLHashString();
String otherXML = otherElement.getXMLHashString();
s_log.debug(
"Equals: getXMLString twice took "
+ (new Date().getTime() - start.getTime())
+ " millisecs");
return thisXML.equals(otherXML);
}
} }

View File

@ -8,8 +8,8 @@
ccmVersion="6.1" ccmVersion="6.1"
name="scientificcms" name="scientificcms"
prettyName="Scientific CMS" prettyName="Scientific CMS"
version="2-0-0" version="2-1-0"
release="devel" release="SNAPSHOT-r2136"
webxml="web-sci.xml" webxml="web-sci.xml"
webapp="ROOT" webapp="ROOT"
xsi:schemaLocation="http://ccm.redhat.com/ccm-project file:tools-ng/common/xsd/project.xsd"> xsi:schemaLocation="http://ccm.redhat.com/ccm-project file:tools-ng/common/xsd/project.xsd">

View File

@ -27,6 +27,7 @@ public class PublicationExtraXmlGenerator implements ExtraXMLGenerator {
private boolean listMode; private boolean listMode;
@Override
public void generateXML(final ContentItem item, public void generateXML(final ContentItem item,
final Element element, final Element element,
final PageState state) { final PageState state) {