| Method from org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector Detail: |
public void addComponent(Object hint,
Class clazz,
Configuration config) throws ComponentException {
super.addComponent(hint, clazz, config);
// Add to known hints
this.knownHints.add(hint);
if (this.roleId == SERIALIZER || this.roleId == READER) {
// Get mime-type
String mimeType = config.getAttribute("mime-type", null);
if (mimeType != null) {
this.hintMimeTypes.put(hint, mimeType);
}
}
String label = config.getAttribute("label", null);
if (label != null) {
// Empty '' attribute will result in empty array,
// overriding all labels on the component declared in the parent.
StringTokenizer st = new StringTokenizer(label, " ,", false);
String[] labels = new String[st.countTokens()];
for (int i = 0; i < labels.length; i++) {
labels[i] = st.nextToken();
}
this.hintLabels.put(hint, labels);
}
String pipelineHint = config.getAttribute("hint", null);
this.pipelineHints.put(hint, pipelineHint);
}
Add a component in this selector. If needed, also register it's MIME type. |
public void configure(Configuration config) throws ConfigurationException {
// Who are we ?
String role = getRoleName(config);
this.roleId = UNKNOWN; // unknown
for (int i = 0; i < SELECTOR_ROLES.length; i++) {
if (SELECTOR_ROLES[i].equals(role)) {
this.roleId = i;
break;
}
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("Setting up sitemap component selector for " +
role + " (role id = " + this.roleId + ")");
}
// Only matchers and serializers can have a MIME type
if (this.roleId == SERIALIZER || this.roleId == READER) {
this.hintMimeTypes = new HashMap();
}
this.hintLabels = new HashMap();
this.pipelineHints = new HashMap();
super.configure(config);
}
|
public void dispose() {
super.dispose();
this.parentSitemapSelector = null;
}
|
protected String getClassAttributeName() {
return (this.roleId == UNKNOWN) ? "class" : "src";
}
Get the attribute for class names. This is "src" for known roles, and
"class" (the default) for other roles. |
protected String getComponentInstanceName() {
return (this.roleId == UNKNOWN) ? null : COMPONENT_NAMES[this.roleId];
}
Return the component instance name according to the selector role
(e.g. "action" for "org.apache.cocoon.acting.Action"). |
public String[] getLabels(Object hint) {
// If this hint is declared locally, use its labels (if any), otherwise inherit
// those of the parent.
if (this.hasDeclaredComponent(hint)) {
return (String[])this.hintLabels.get(hint);
} else if (this.parentSitemapSelector != null) {
return parentSitemapSelector.getLabels(hint);
} else {
return null;
}
}
|
public String getMimeTypeForHint(Object hint) {
if (this.hintMimeTypes == null) {
// Not a component that has mime types
return null;
} else {
if (this.hasDeclaredComponent(hint)) {
return (String)this.hintMimeTypes.get(hint);
} else if (this.parentSitemapSelector != null) {
return this.parentSitemapSelector.getMimeTypeForHint(hint);
} else {
return null;
}
}
}
Get the MIME type for a given hint. |
public String getPipelineHint(Object hint) {
// If this hint is declared locally, use its hints (if any), otherwise inherit
// those of the parent.
if (this.hasDeclaredComponent(hint)) {
return (String)this.pipelineHints.get(hint);
} else if (this.parentSitemapSelector != null) {
return this.parentSitemapSelector.getPipelineHint(hint);
} else {
return null;
}
}
|
public boolean hasLabel(Object hint,
String label) {
String[] labels = this.getLabels(hint);
if (labels != null) {
for (int i = 0; i < labels.length; i++) {
if (labels[i].equals(label))
return true;
}
}
return false;
}
|
public void initialize() {
// FIXME : need to catch exceptions since ECS doesn't propagate the throws clause of Initializable
try {
DefaultConfiguration config = null;
// Ensure all system-defined hints exist.
// NOTE : checking this here means they can be user-defined in the sitemap
switch(this.roleId) {
case GENERATOR :
config = new DefaultConfiguration(COMPONENT_NAMES[GENERATOR], "autogenerated");
config.setAttribute("name", "< notifier >");
ensureExists("< notifier >",
org.apache.cocoon.sitemap.NotifyingGenerator.class, config);
config = new DefaultConfiguration(COMPONENT_NAMES[GENERATOR], "autogenerated");
config.setAttribute("name", "< aggregator >");
ensureExists("< aggregator >",
org.apache.cocoon.sitemap.ContentAggregator.class, config);
break;
case TRANSFORMER :
config = new DefaultConfiguration(COMPONENT_NAMES[TRANSFORMER], "autogenerated");
config.setAttribute("name", "< translator >");
ensureExists("< translator >",
org.apache.cocoon.sitemap.LinkTranslator.class, config);
config = new DefaultConfiguration(COMPONENT_NAMES[TRANSFORMER], "autogenerated");
config.setAttribute("name", "< gatherer >");
ensureExists("< gatherer >",
org.apache.cocoon.sitemap.LinkGatherer.class, config);
break;
}
super.initialize();
// Don't keep known hints (they're no more needed)
this.knownHints = null;
} catch(Exception e) {
throw new CascadingRuntimeException("Cannot setup default components", e);
}
}
Ensure system-defined components exist (e.g. <aggregator>) and initialize
the selector. |
public void setParentLocator(ComponentLocator locator) throws ComponentException {
/* (non-Javadoc)
* @see org.apache.cocoon.components.ParentAware#setParentInformation(org.apache.avalon.framework.component.ComponentManager, java.lang.String)
*/
super.setParentLocator(locator);
if (super.parentSelector instanceof SitemapComponentSelector) {
this.parentSitemapSelector = (SitemapComponentSelector)super.parentSelector;
}
}
|