| Method from org.apache.cocoon.portal.transformation.HTMLEventLinkTransformer Detail: |
protected void createAnchorEvent(Attributes attributes) throws SAXException {
AttributesImpl newAttributes = new AttributesImpl(attributes);
newAttributes.removeAttribute("href");
newAttributes.removeAttribute("external");
String link = attributes.getValue("href");
CopletInstanceData cid = this.getCopletInstanceData();
link = this.getLink((String)cid.getTemporaryAttribute(this.attributeName), link);
newAttributes.addCDATAAttribute("path", this.jxPath);
newAttributes.addCDATAAttribute("value", link);
newAttributes.addCDATAAttribute("coplet", cid.getId());
newAttributes.addCDATAAttribute("format", "html-link");
this.xmlConsumer.startPrefixMapping("coplet", CopletTransformer.NAMESPACE_URI);
this.xmlConsumer.startElement(CopletTransformer.NAMESPACE_URI,
CopletTransformer.LINK_ELEM,
"coplet:" + CopletTransformer.LINK_ELEM,
newAttributes);
}
|
protected void createFormEvent(Attributes attributes) throws SAXException {
AttributesImpl newAttributes = new AttributesImpl(attributes);
newAttributes.removeAttribute("action");
String link = attributes.getValue("action");
CopletInstanceData cid = this.getCopletInstanceData();
link = this.getLink((String)cid.getTemporaryAttribute(this.attributeName), link);
newAttributes.addCDATAAttribute("path", this.jxPath);
newAttributes.addCDATAAttribute("value", link);
newAttributes.addCDATAAttribute("coplet", cid.getId());
newAttributes.addCDATAAttribute("format", "html-form");
if ( newAttributes.getIndex("method") == -1 ) {
newAttributes.addCDATAAttribute("method", "POST");
}
this.xmlConsumer.startPrefixMapping("coplet", CopletTransformer.NAMESPACE_URI);
this.xmlConsumer.startElement(CopletTransformer.NAMESPACE_URI,
CopletTransformer.LINK_ELEM,
"coplet:" + CopletTransformer.LINK_ELEM,
newAttributes);
}
|
public void endElement(String uri,
String name,
String raw) throws SAXException {
boolean processed = false;
if ( "a".equals(name) ) {
final Boolean converted = (Boolean)this.stack.pop();
if ( converted.booleanValue() ) {
this.xmlConsumer.endElement(CopletTransformer.NAMESPACE_URI,
CopletTransformer.LINK_ELEM,
"coplet:" + CopletTransformer.LINK_ELEM);
this.xmlConsumer.endPrefixMapping("coplet");
processed = true;
}
} else if ( "form".equals(name) ) {
final Boolean converted = (Boolean)this.stack.pop();
if ( converted.booleanValue() ) {
this.xmlConsumer.endElement(CopletTransformer.NAMESPACE_URI,
CopletTransformer.LINK_ELEM,
"coplet:" + CopletTransformer.LINK_ELEM);
this.xmlConsumer.endPrefixMapping("coplet");
processed = true;
}
}
if ( !processed ) {
super.endElement(uri, name, raw);
}
}
|
protected String getLink(String base,
String link) {
final String v = SourceUtil.absolutize(base, link);
return v;
}
|
protected boolean isRemoteAnchor(Attributes attributes) {
String link = attributes.getValue("href");
// no empty link to current document
if (link != null && link.trim().length() > 0) {
// check reference to document fragment
if (!link.trim().startsWith("#")) {
return true;
}
}
return false;
}
Determine if the element is an url and if the url points to some
remote source. |
public void setup(SourceResolver resolver,
Map objectModel,
String src,
Parameters par) throws IOException, SAXException, ProcessingException {
super.setup(resolver, objectModel, src, par);
this.attributeName = par.getParameter("attribute-name", "application-uri");
this.jxPath = "temporaryAttributes/" + this.attributeName;
}
|
public void startElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
boolean processed = false;
if ("a".equals(name) ) {
final AttributesImpl a = this.getMutableAttributes(attr);
attr = a;
boolean convert = false;
final boolean isRemoteAnchor = this.isRemoteAnchor(attr);
if ( isRemoteAnchor ) {
convert = !this.isExternalLink(a);
}
this.stack.push(convert ? Boolean.TRUE: Boolean.FALSE);
if ( convert ) {
this.createAnchorEvent(attr);
processed = true;
}
} else if ("form".equals(name) ) {
final AttributesImpl a = this.getMutableAttributes(attr);
attr = a;
boolean convert = !this.isExternalForm(a);
this.stack.push(convert ? Boolean.TRUE: Boolean.FALSE);
if ( convert ) {
this.createFormEvent(attr);
processed = true;
}
}
if ( !processed ) {
super.startElement(uri, name, raw, attr);
}
}
|