Skip to content

Commit

Permalink
Updating portal framework
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/cocoon/trunk@24455 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cziegeler committed May 19, 2003
1 parent 2c11f11 commit 8a9cfb1
Show file tree
Hide file tree
Showing 34 changed files with 2,340 additions and 128 deletions.
7 changes: 5 additions & 2 deletions src/blocks/portal/conf/portal.xconf
Expand Up @@ -123,7 +123,10 @@
</component>

<component class="org.apache.cocoon.components.persistance.CastorSourceConverter" role="org.apache.cocoon.components.persistance.CastorSourceConverter">
<mapping-source>context://samples/portal/profiles/mapping/layout.xml</mapping-source>
<mapping-source source="layout">context://samples/portal/profiles/mapping/layout.xml</mapping-source>
<mapping-source source="copletbasedata">context://samples/portal/profiles/mapping/copletbasedata.xml</mapping-source>
<mapping-source source="copletdata">context://samples/portal/profiles/mapping/copletdata.xml</mapping-source>
<mapping-source source="copletinstancedata">context://samples/portal/profiles/mapping/copletinstancedata.xml</mapping-source>
</component>
<component class="org.apache.cocoon.portal.profile.impl.ParameterSourceAdapter" role="org.apache.cocoon.portal.profile.impl.ParameterSourceAdapter" />
<component class="org.apache.cocoon.portal.profile.impl.MapSourceAdapter" role="org.apache.cocoon.portal.profile.impl.MapSourceAdapter" />
</xconf>
Expand Up @@ -50,6 +50,14 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
*/
package org.apache.cocoon.components.persistance;

import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
Expand All @@ -61,44 +69,62 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.excalibur.source.ModifiableSource;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.xml.UnmarshalHandler;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.xml.sax.InputSource;

/**
*
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
* @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
* @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
*
* @version CVS $Id: CastorSourceConverter.java,v 1.1 2003/05/07 06:22:30 cziegeler Exp $
* @version CVS $Id: CastorSourceConverter.java,v 1.2 2003/05/19 09:14:11 cziegeler Exp $
*/
public class CastorSourceConverter
extends AbstractLogEnabled
implements Component, Composable, Configurable, Initializable, ThreadSafe {

public static final String ROLE = CastorSourceConverter.class.getName();

private String mappingSource;
private Map mappingSources = new HashMap();
private ComponentManager manager;
private Mapping mapping;
private Map mappings = new HashMap();

public Object getObject(Source source) throws ConverterException {
public Object getObject(Source source, String name) throws ConverterException {
try {
Unmarshaller unmarshaller = new Unmarshaller(mapping);
UnmarshalHandler handler = unmarshaller.createHandler();

SourceUtil.toSAX(source, Unmarshaller.getContentHandler(handler));
return handler.getObject();
InputStream stream = source.getInputStream();
Unmarshaller unmarshaller = new Unmarshaller((Mapping)this.mappings.get(name));
Object result = unmarshaller.unmarshal(new InputSource(stream));
stream.close();
return result;
} catch (MappingException e) {
throw new ConverterException("can't create Unmarshaller", e);
} catch (Exception e) {
throw new ConverterException(e.getMessage(), e);
}
}

public void storeObject(ModifiableSource source, String name, Object object) throws ConverterException {
try {
Writer writer = new OutputStreamWriter(source.getOutputStream());
Marshaller marshaller = new Marshaller(writer);
Mapping mapping = new Mapping();
marshaller.setMapping((Mapping)this.mappings.get(name));
marshaller.marshal(object);
writer.close();
} catch (MappingException e) {
throw new ConverterException("can't create Unmarshaller", e);
} catch (Exception e) {
throw new ConverterException(e.getMessage(), e);
}
}

/* (non-Javadoc)
* @see org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
*/
Expand All @@ -110,7 +136,11 @@ public void compose(ComponentManager manager) throws ComponentException {
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration config) throws ConfigurationException {
mappingSource = config.getChild("mapping-source").getValue();
Configuration[] children = config.getChildren("mapping-source");
for (int i=0; i<children.length; i++) {
Configuration mappingSource = children[i];
this.mappingSources.put(mappingSource.getAttribute("source"), mappingSource.getValue());
}
}

/* (non-Javadoc)
Expand All @@ -120,9 +150,21 @@ public void initialize() throws Exception {
SourceResolver resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
Source source = null;
try {
source = resolver.resolveURI(mappingSource);
mapping = new Mapping();
mapping.loadMapping(SourceUtil.getInputSource(source));
Entry entry;
String name;
String mappingSource;
Mapping mapping;
Iterator iterator = this.mappingSources.entrySet().iterator();
while (iterator.hasNext()) {
entry = (Map.Entry)iterator.next();
name = (String)entry.getKey();
mappingSource = (String)entry.getValue();

source = resolver.resolveURI(mappingSource);
mapping = new Mapping();
mapping.loadMapping(SourceUtil.getInputSource(source));
this.mappings.put(name, mapping);
}
} finally {
if (source != null) {
resolver.release(source);
Expand Down
Expand Up @@ -53,25 +53,31 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
import java.util.HashMap;
import java.util.Map;

import org.exolab.castor.mapping.MapItem;

/**
*
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
* @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
* @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
*
* @version CVS $Id: CopletBaseData.java,v 1.1 2003/05/07 06:22:29 cziegeler Exp $
* @version CVS $Id: CopletBaseData.java,v 1.2 2003/05/19 09:14:07 cziegeler Exp $
*/
public final class CopletBaseData {
public final class CopletBaseData
// extending MapItem used for Castor map workaround
extends MapItem {

private Map copletConfig;
private Map copletConfig = new HashMap();

private String name;

private String copletAdapterName;
private String copletAdapterName = null;

private String defaultRendererName;
private String defaultRendererName = null;

public CopletBaseData() {
this.copletConfig = new HashMap();
// used for Castor map workaround
this.setValue(this);
}

public String getName() {
Expand All @@ -80,6 +86,9 @@ public String getName() {

public void setName(String name) {
this.name = name;

// used for Castor map workaround
this.setKey(name);
}

public String getCopletAdapterName() {
Expand Down
116 changes: 104 additions & 12 deletions src/blocks/portal/java/org/apache/cocoon/portal/coplet/CopletData.java
Expand Up @@ -51,24 +51,32 @@ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
package org.apache.cocoon.portal.coplet;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.cocoon.portal.util.DeltaApplicable;
import org.exolab.castor.mapping.MapItem;

/**
*
* @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
* @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
* @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
*
* @version CVS $Id: CopletData.java,v 1.1 2003/05/07 06:22:29 cziegeler Exp $
* @version CVS $Id: CopletData.java,v 1.2 2003/05/19 09:14:07 cziegeler Exp $
*/
public class CopletData {
public class CopletData
//extending MapItem used for Castor map workaround
extends MapItem
implements DeltaApplicable {

protected String name;

protected String title;

protected boolean maxpageable;
protected Boolean maxpageable;

protected boolean removable;
protected Boolean removable;

protected CopletBaseData copletBaseData;

Expand All @@ -78,8 +86,8 @@ public class CopletData {
* Constructor
*/
public CopletData() {
this.maxpageable = true;
this.removable = true;
// used for Castor map workaround
this.setValue(this);
}

public String getName() {
Expand All @@ -88,38 +96,65 @@ public String getName() {

public void setName(String name) {
this.name = name;

// used for Castor map workaround
this.setKey(name);
}

/**
* Returns the maxpageable.
* Returns the maxpageable as boolean. If it has not been set "true" is returned.
* @return boolean
*/
public boolean isMaxpageable() {
return maxpageable;
if (this.maxpageable == null) {
return true;
} else {
return this.maxpageable.booleanValue();
}
}

/**
* Returns the removable.
* Returns the removable as boolean. If it has not been set "true" is returned.
* @return boolean
*/
public boolean isRemovable() {
return removable;
if (this.removable == null) {
return true;
} else {
return this.removable.booleanValue();
}
}

/**
* Returns the maxpageable as Boolean.
* @return boolean
*/
public Boolean getMaxpageable() {
return this.maxpageable;
}

/**
* Returns the removable as Boolean.
* @return boolean
*/
public Boolean getRemovable() {
return this.removable;
}

/**
* Sets the maxpageable.
* @param maxpageable The maxpageable to set
*/
public void setMaxpageable(boolean maxpageable) {
this.maxpageable = maxpageable;
this.maxpageable = new Boolean(maxpageable);
}

/**
* Sets the removable.
* @param removable The removable to set
*/
public void setRemovable(boolean removable) {
this.removable = removable;
this.removable = new Boolean(removable);
}

/**
Expand Down Expand Up @@ -161,4 +196,61 @@ public Object getAttribute(String key) {
public void setAttribute(String key, Object value) {
this.attributes.put(key, value);
}

public Map getAttributes() {
return this.attributes;
}

/**
* Applies the specified delta.
* @throws ClassCastException If the object is not of the expected type.
*/
public boolean applyDelta(Object object) {
CopletData data = (CopletData)object;

Boolean maxpageable = data.maxpageable;
if (maxpageable != null)
this.maxpageable = maxpageable;

Boolean removable = data.removable;
if (removable != null)
this.removable = removable;

String title = data.getTitle();
if (title != null)
this.setTitle(title);

CopletBaseData copletBaseData = data.getCopletBaseData();
if (copletBaseData != null) {
this.setCopletBaseData(copletBaseData);
}

Iterator iterator = data.getAttributes().entrySet().iterator();
Object attribute, delta;
String key;
Map.Entry entry;
while (iterator.hasNext()) {
entry = (Map.Entry)iterator.next();
key = (String)entry.getKey();
delta = entry.getValue();

attribute = this.getAttribute(key);
if (attribute == null) {
// add new attribute
this.setAttribute(key, delta);
} else if (attribute instanceof DeltaApplicable) {
// apply delta
boolean success = ((DeltaApplicable)attribute).applyDelta(delta);
if (!success) {
// replace attribute
this.setAttribute(key, delta);
}
} else {
// replace attribute
this.setAttribute(key, delta);
}
}

return true;
}
}

0 comments on commit 8a9cfb1

Please sign in to comment.