public void startTransformingElement(String uri,
String name,
String raw,
Attributes attributes) throws SAXException {
if (!EVENT_ELEM.equals(name)) {
throw new SAXException("Unknown element encountered: " + name);
}
String attributeName = attributes.getValue(ATTRIBUTE_ATTR);
String elementName = attributes.getValue(ELEMENT_ATTR);
if (attributeName == null) {
throw new SAXException(
"Element "
+ EVENT_ELEM
+ " must have an attribute "
+ ATTRIBUTE_ATTR
+ ".");
}
if (elementName == null) {
throw new SAXException(
"Element "
+ EVENT_ELEM
+ " must have an attribute "
+ ELEMENT_ATTR
+ ".");
}
// remove ATTRIBUTE_ATTR, "coplet" and ELEMENT_ATTR from attributes
AttributesImpl newAttributes = this.getMutableAttributes(attributes);
newAttributes.removeAttribute(ELEMENT_ATTR);
newAttributes.removeAttribute(ATTRIBUTE_ATTR);
newAttributes.removeAttribute("coplet");
int index = newAttributes.getIndex(attributeName);
String link = newAttributes.getValue(index);
boolean formSpecialTreatment = false;
if ("form".equals(elementName)) {
//cut all query parameters from actions with method get, as these will be normaly ignored!
formSpecialTreatment = true;
if ("GET".equalsIgnoreCase(newAttributes.getValue("method"))
&& link.indexOf('?") > 0) {
link = link.substring(0, link.indexOf('?"));
}
}
String portalAction = null;
String portalEvent = null;
// if attribute found that contains a link
if (link != null) {
CopletInstanceData cid = this.getCopletInstanceData(attributes.getValue("coplet"));
// create event link
CopletLinkEvent event = new CopletLinkEvent(cid, link);
String eventLink = this.portalService.getComponentManager().getLinkService().getLinkURI(event);
//form elements need hidden inputs to change request parameters
if (formSpecialTreatment) {
int pos = eventLink.indexOf("cocoon-portal-action=");
if ( pos != -1 ) {
int begin = pos + "cocoon-portal-action=".length();
int end = eventLink.indexOf('&", begin);
if (end == -1) {
end = eventLink.length();
}
portalAction = eventLink.substring(begin, end);
}
pos = eventLink.indexOf("cocoon-portal-event=");
if ( pos != -1 ) {
int begin = pos + "cocoon-portal-event=".length();
int end = eventLink.indexOf('&", begin);
if (end == -1) {
end = eventLink.length();
}
portalEvent = eventLink.substring(begin, end);
}
pos = eventLink.indexOf('?");
if ( pos != -1 ) {
eventLink = eventLink.substring(0, pos);
}
}
// insert event link
newAttributes.setValue(index, eventLink);
}
this.stack.push(elementName);
this.contentHandler.startElement(
"",
elementName,
elementName,
newAttributes);
//generate hidden inputs to add request parameters to the form action
if (formSpecialTreatment) {
this.sendHiddenFields(this.contentHandler, portalAction, portalEvent);
}
}
|