ldn-importer ist jetzt mehrsprachenfähig und einige Formatierungen (und Log-Ausgaben).

git-svn-id: https://svn.libreccm.org/ccm/trunk@584 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2010-10-21 16:59:42 +00:00
parent 432acb6c36
commit 9f3d3ffc65
7 changed files with 225 additions and 141 deletions

View File

@ -272,6 +272,7 @@ public class ContentBundle extends ContentItem {
* @see #addInstance(ContentItem) * @see #addInstance(ContentItem)
*/ */
public final ContentItem getPrimaryInstance() { public final ContentItem getPrimaryInstance() {
System.out.printf("ContentBundle.getPrimaryInstance() for default lang %s\n", getDefaultLanguage());
return getInstance(getDefaultLanguage()); return getInstance(getDefaultLanguage());
} }

View File

@ -26,6 +26,7 @@ import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID; import com.arsdigita.persistence.OID;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.log4j.Logger;
/** /**
* This class provides a base type for building content types which represent * This class provides a base type for building content types which represent
@ -40,6 +41,7 @@ import java.math.BigDecimal;
*/ */
public class GenericOrganizationalUnit extends ContentPage { public class GenericOrganizationalUnit extends ContentPage {
private static final Logger logger = Logger.getLogger(GenericOrganizationalUnit.class);
//public final static String ORGAUNIT_NAME = "ORGAUNIT_NAME"; //public final static String ORGAUNIT_NAME = "ORGAUNIT_NAME";
public final static String ADDENDUM = "addendum"; public final static String ADDENDUM = "addendum";
public final static String CONTACTS = "contacts"; public final static String CONTACTS = "contacts";
@ -88,10 +90,12 @@ public class GenericOrganizationalUnit extends ContentPage {
public void addContact(GenericContact contact, String contactType) { public void addContact(GenericContact contact, String contactType) {
Assert.exists(contact, GenericContact.class); Assert.exists(contact, GenericContact.class);
logger.debug(String.format("Adding contact of type \"%s\"...", contactType));
DataObject link = add(CONTACTS, contact); DataObject link = add(CONTACTS, contact);
link.set(CONTACT_TYPE, contactType); link.set(CONTACT_TYPE, contactType);
link.set(CONTACT_ORDER, Integer.valueOf((int)getContacts().size())); link.set(CONTACT_ORDER, Integer.valueOf((int)getContacts().size()));
link.save();
} }
public void removeContact(GenericContact contact) { public void removeContact(GenericContact contact) {
@ -114,6 +118,7 @@ public class GenericOrganizationalUnit extends ContentPage {
DataObject link = add(PERSONS, person); DataObject link = add(PERSONS, person);
link.set(ROLE, role); link.set(ROLE, role);
link.save();
} }
public void removePerson(GenericPerson person) { public void removePerson(GenericPerson person) {

View File

@ -74,7 +74,7 @@ public class GenericOrganizationalUnitContactAddForm extends BasicItemForm {
add(new Label(ContenttypesGlobalizationUtil.globalize( add(new Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericorgaunit.contact.type"))); "cms.contenttypes.ui.genericorgaunit.contact.type")));
ParameterModel contactTypeParam = new StringParameter( ParameterModel contactTypeParam = new StringParameter(
GenericOrganizationalUnitContactCollection.CONTACT_TYPE); GenericOrganizationalUnit.CONTACT_TYPE);
SingleSelect contactType = new SingleSelect(contactTypeParam); SingleSelect contactType = new SingleSelect(contactTypeParam);
contactType.addValidationListener(new NotNullValidationListener()); contactType.addValidationListener(new NotNullValidationListener());
contactType.addOption(new Option("", new Label((String) ContenttypesGlobalizationUtil. contactType.addOption(new Option("", new Label((String) ContenttypesGlobalizationUtil.
@ -110,7 +110,7 @@ public class GenericOrganizationalUnitContactAddForm extends BasicItemForm {
if (this.getSaveCancelSection().getSaveButton().isSelected(state)) { if (this.getSaveCancelSection().getSaveButton().isSelected(state)) {
orgaunit.addContact((GenericContact) data.get(ITEM_SEARCH), orgaunit.addContact((GenericContact) data.get(ITEM_SEARCH),
(String) data.get( (String) data.get(
GenericOrganizationalUnitContactCollection.CONTACT_TYPE)); GenericOrganizationalUnit.CONTACT_TYPE));
} }
//init(fse); //init(fse);

View File

@ -163,6 +163,15 @@ public class GenericOrganizationalUnitContactTable extends Table implements
m_contacttypes.size())); m_contacttypes.size()));
switch (columnIndex) { switch (columnIndex) {
case 0: case 0:
s_log.debug(String.format(
"Getting human readable contact type for contact type \"%s\"...",
m_contactCollection.getContactType()));
s_log.debug(String.format(
"Human readable contact type is: \"%s\"...",
m_contacttypes.getRelationAttribute(
m_contactCollection.getContactType(),
DispatcherHelper.getNegotiatedLocale().
getLanguage())));
return m_contacttypes.getRelationAttribute( return m_contacttypes.getRelationAttribute(
m_contactCollection.getContactType(), m_contactCollection.getContactType(),
DispatcherHelper.getNegotiatedLocale(). DispatcherHelper.getNegotiatedLocale().

View File

@ -119,6 +119,8 @@ public class ParserDispatcher extends DefaultHandler {
s_log.debug("Processing start element: " + s_log.debug("Processing start element: " +
qname + " " + uri + " " + local); qname + " " + uri + " " + local);
} }
System.out.println("Processing start element: " +
qname + " " + uri + " " + local);
if (m_parsers.containsKey(getKey(local, uri))) { if (m_parsers.containsKey(getKey(local, uri))) {
TagParser current = getCurrentParser(); TagParser current = getCurrentParser();
@ -157,6 +159,8 @@ public class ParserDispatcher extends DefaultHandler {
s_log.debug("Processing end element: " + s_log.debug("Processing end element: " +
qname + " " + uri + " " + local); qname + " " + uri + " " + local);
} }
System.out.println("Processing end element: " +
qname + " " + uri + " " + local);
getCurrentParser().endElement(local, uri); getCurrentParser().endElement(local, uri);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.london.importer.cms; package com.arsdigita.london.importer.cms;
import java.io.File; import java.io.File;
@ -38,14 +37,33 @@ import com.arsdigita.london.importer.ParserDispatcher;
import com.arsdigita.london.util.Transaction; import com.arsdigita.london.util.Transaction;
import com.arsdigita.packaging.Program; import com.arsdigita.packaging.Program;
import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.util.UncheckedWrapperException;
import java.util.HashMap;
import java.util.Map;
/** /**
* <p>
* Standalone command-line tool which invokes the importer. * Standalone command-line tool which invokes the importer.
* It can be invoked by: * It can be invoked by:
* </p>
* <pre> * <pre>
* ccm-run com.arsdigita.london.importer.cms.ItemImportTool \ * ccm-run com.arsdigita.london.importer.cms.ItemImportTool \
* master-import.xml /dir/with/files/to/include /dir/containing/lobs content-section-name * master-import.xml /dir/with/files/to/include /dir/containing/lobs content-section-name
* </pre> * </pre>
* <p>
* <strong>Attention:</strong> The importer was modified to support import of
* items with more than one language version. The modifications for this are:
* </p>
* <ul>
* <li>A {@link Map} of the already created {@link ContentBundle}s is kept.</li>
* <li>To identify language versions, the imported content items must have a
* name of the following pattern: <code>name-language</code>, for example
* <code>about-de</code> and <code>about-en</code>.</li>
* <li>When the item is added, the importer now checks if there is
* already a content bundle for the item. If not a new one is created, if there
* is one, the item is added as an instance.</li>
* <li>For items with only one language version the importer should work as
* before.</li>
* </ul>
* *
* @see com.arsdigita.london.importer * @see com.arsdigita.london.importer
*/ */
@ -67,6 +85,7 @@ public class ItemImportTool extends Program {
} }
protected void doRun(CommandLine cmdLine) { protected void doRun(CommandLine cmdLine) {
try {
final String[] args = cmdLine.getArgs(); final String[] args = cmdLine.getArgs();
if (args.length != 4) { if (args.length != 4) {
help(System.err); help(System.err);
@ -83,6 +102,7 @@ public class ItemImportTool extends Program {
final List items = new ArrayList(); final List items = new ArrayList();
Transaction session = new Transaction() { Transaction session = new Transaction() {
public void doRun() { public void doRun() {
ParserDispatcher parser = new ParserDispatcher(); ParserDispatcher parser = new ParserDispatcher();
parser.addParser(new ImportParser(mapper)); parser.addParser(new ImportParser(mapper));
@ -94,12 +114,22 @@ public class ItemImportTool extends Program {
session.run(); session.run();
Iterator lazyItems = items.iterator(); Iterator lazyItems = items.iterator();
/*
* Extension to support import of items in more than one language
* Jens Pelzetter 2010-10-21
*/
final Map<String, ContentBundle> bundles;
bundles = new HashMap<String, ContentBundle>();
/*
* Extension end
*/
while (lazyItems.hasNext()) { while (lazyItems.hasNext()) {
Object[] entry = (Object[])lazyItems.next(); Object[] entry = (Object[]) lazyItems.next();
final Folder folder = (Folder)entry[0]; final Folder folder = (Folder) entry[0];
final String file = (String)entry[1]; final String file = (String) entry[1];
Transaction itemTransaction = new Transaction() { Transaction itemTransaction = new Transaction() {
public void doRun() { public void doRun() {
ItemParser itemParser = ItemParser itemParser =
new ItemParser(assetDir, mapper); new ItemParser(assetDir, mapper);
@ -107,8 +137,8 @@ public class ItemImportTool extends Program {
File itemFile = new File(itemDir, file); File itemFile = new File(itemDir, file);
if (s_log.isInfoEnabled()) { if (s_log.isInfoEnabled()) {
s_log.info("Loading " + file + s_log.info("Loading " + file + " into "
" into " + folder.getPath()); + folder.getPath());
} }
ParserDispatcher parser = new ParserDispatcher(); ParserDispatcher parser = new ParserDispatcher();
@ -120,7 +150,22 @@ public class ItemImportTool extends Program {
"cannot process file" + file, ex); "cannot process file" + file, ex);
} }
ContentItem item = (ContentItem)itemParser.getDomainObject(); ContentItem item =
(ContentItem) itemParser.getDomainObject();
/*
* Multi lang extension begin
*/
String itemName = item.getName();
String bundleName;
if (itemName.lastIndexOf('-') == -1) {
bundleName = itemName;
} else {
bundleName = itemName.substring(0, itemName.
lastIndexOf('-'));
}
/*
* Multi lang extension end
*/
// returning the null item indicates an item that // returning the null item indicates an item that
// has already been imported // has already been imported
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
@ -128,20 +173,50 @@ public class ItemImportTool extends Program {
} }
if (item != null) { if (item != null) {
// We have to place this item into language bundle // We have to place this item into language bundle
ContentBundle bundle = new ContentBundle(item); /*
* Multi lang extension start
*/
ContentBundle bundle;
if (itemName.lastIndexOf('-') == -1) {
bundle = new ContentBundle(item);
bundle.setParent(folder); bundle.setParent(folder);
bundle.setName(bundleName);
bundles.put(bundleName, bundle);
} else {
bundle = bundles.get(bundleName);
if (bundle == null) {
bundle = new ContentBundle(item);
bundle.setParent(folder);
bundle.setName(bundleName);
bundles.put(bundleName, bundle);
} else {
bundle.addInstance(item);
}
}
/*
* Extension end
*/
System.out.println("Set bundle " + bundle);
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.error("Set bundle " + bundle); s_log.debug("Set bundle " + bundle);
} }
} }
} }
}; };
itemTransaction.run(); itemTransaction.run();
} }
} catch (Exception ex) {
ex.printStackTrace();
}
} }
public static final void main(String[] args) { public static final void main(String[] args) {
try {
new ItemImportTool().run(args); new ItemImportTool().run(args);
} catch (Exception ex) {
ex.printStackTrace();
}
} }
/** /**
@ -161,11 +236,12 @@ public class ItemImportTool extends Program {
path.append("/"); path.append("/");
} }
final ContentSection section = (ContentSection)ContentSection final ContentSection section = (ContentSection) ContentSection.
.retrieveApplicationForPath(path.toString()); retrieveApplicationForPath(path.toString());
if (section == null) { if (section == null) {
throw new DataObjectNotFoundException("Content section not found with path " + path); throw new DataObjectNotFoundException("Content section not found with path "
+ path);
} }
return section; return section;
} }

View File

@ -5,6 +5,7 @@ import com.arsdigita.london.importer.DomainObjectMapper;
import com.arsdigita.cms.BinaryAsset; import com.arsdigita.cms.BinaryAsset;
import com.arsdigita.cms.CMS; import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentType; import com.arsdigita.cms.ContentType;
import com.arsdigita.domain.DomainObject; import com.arsdigita.domain.DomainObject;
@ -46,10 +47,9 @@ import sun.misc.BASE64Decoder;
* @see com.arsdigita.london.importer * @see com.arsdigita.london.importer
*/ */
public class ItemParser extends DomainObjectParser { public class ItemParser extends DomainObjectParser {
private static Logger s_log = private static Logger s_log =
Logger.getLogger(ItemParser.class); Logger.getLogger(ItemParser.class);
public static final String DEFAULT_DOMAIN_CLASS = "defaultDomainClass"; public static final String DEFAULT_DOMAIN_CLASS = "defaultDomainClass";
public static final String ID = "id"; public static final String ID = "id";
public static final String IS_DELETED = "isDeleted"; public static final String IS_DELETED = "isDeleted";
@ -62,7 +62,6 @@ public class ItemParser extends DomainObjectParser {
public static final String DEFAULT_ANCESTORS = "defaultAncestors"; public static final String DEFAULT_ANCESTORS = "defaultAncestors";
public static final String DISPLAY_NAME = "displayName"; public static final String DISPLAY_NAME = "displayName";
public static final String FILE = "file"; public static final String FILE = "file";
public static final String ENCODING_ATTR = "encoding"; public static final String ENCODING_ATTR = "encoding";
public static final String ENCODING_BASE64 = "base64"; public static final String ENCODING_BASE64 = "base64";
public static final String INDEX_ITEM_ATTR = "indexItem"; public static final String INDEX_ITEM_ATTR = "indexItem";
@ -72,45 +71,34 @@ public class ItemParser extends DomainObjectParser {
// if not found in database. // if not found in database.
public static final String AUTHOR_ATTR = "author"; public static final String AUTHOR_ATTR = "author";
public static final String END_OF_LIFE_ATTR = "eol"; public static final String END_OF_LIFE_ATTR = "eol";
/** /**
* Object types holding the "global" OIDs, i.e. those which don't * Object types holding the "global" OIDs, i.e. those which don't
* change from one CCM instance to another. Importer will not try * change from one CCM instance to another. Importer will not try
* to create any of those. * to create any of those.
*/ */
static final String[] GLOBAL_OID_TYPES = new String[] { static final String[] GLOBAL_OID_TYPES = new String[]{
"com.arsdigita.cms.MimeType", "com.arsdigita.cms.MimeType",
"com.arsdigita.cms.contenttypes.IsoCountry" "com.arsdigita.cms.contenttypes.IsoCountry"
}; };
// Some sequence of charactes that cannot be part of property name // Some sequence of charactes that cannot be part of property name
private static final String PLAIN_ATTRIBUTE = ":..just the plain attribute!..:"; private static final String PLAIN_ATTRIBUTE =
private static final String DO_NOT_SAVE = ":..please persistence don't save!..:"; ":..just the plain attribute!..:";
private static final String DO_NOT_SAVE =
":..please persistence don't save!..:";
private static final String COUNT_SUFFIX = "////"; private static final String COUNT_SUFFIX = "////";
// As we're traversing the XML tree, we keep the stack of parsed objects here // As we're traversing the XML tree, we keep the stack of parsed objects here
private Stack m_objectStack; private Stack m_objectStack;
// And we keep track of attributes here - you never know when you gonna need then // And we keep track of attributes here - you never know when you gonna need then
private Stack m_attributeStack; private Stack m_attributeStack;
private Map m_currentDataObject; private Map m_currentDataObject;
private int m_recursionLevel; private int m_recursionLevel;
private boolean m_write; private boolean m_write;
private static List s_ignoredProps; private static List s_ignoredProps;
// <launchDate>Wed Nov 12 00:00:00 CET 2003</launchDate> // <launchDate>Wed Nov 12 00:00:00 CET 2003</launchDate>
private static SimpleDateFormat s_formatter private static SimpleDateFormat s_formatter = new SimpleDateFormat(
= new SimpleDateFormat ("EEE MMM dd HH:mm:ss zzz yyyy"); "EEE MMM dd HH:mm:ss zzz yyyy");
private static byte[] s_byteArray = new byte[0]; private static byte[] s_byteArray = new byte[0];
private boolean m_begin; private boolean m_begin;
private boolean m_isIndexItem; private boolean m_isIndexItem;
private boolean m_relabelFolder; private boolean m_relabelFolder;
private String m_author; private String m_author;
@ -130,7 +118,8 @@ public class ItemParser extends DomainObjectParser {
} }
public ItemParser(File lobDir, DomainObjectMapper mapper) { public ItemParser(File lobDir, DomainObjectMapper mapper) {
this("item", CMS.CMS_XML_NS, ContentItem.BASE_DATA_OBJECT_TYPE, lobDir, mapper); this("item", CMS.CMS_XML_NS, ContentItem.BASE_DATA_OBJECT_TYPE, lobDir,
mapper);
} }
public ItemParser(String tagName, public ItemParser(String tagName,
@ -146,11 +135,13 @@ public class ItemParser extends DomainObjectParser {
m_write = true; m_write = true;
} }
protected ContentItem importItem() { protected ContentItem importItem() {
debugLog("Ending content item, write: " + m_write); debugLog("Ending content item, write: " + m_write);
if (m_write) { if (m_write) {
debugLog("--------------- About to persist ContentItem -------------------"); debugLog(
"--------------- About to persist ContentItem -------------------");
System.out.println(
"--------------- About to persist ContentItem -------------------");
return persistContentItem(m_currentDataObject); return persistContentItem(m_currentDataObject);
} }
return null; return null;
@ -175,14 +166,17 @@ public class ItemParser extends DomainObjectParser {
return; return;
} }
Assert.exists(m_currentDataObject, DataObject.class); Assert.exists(m_currentDataObject, DataObject.class);
OID currentOID = (OID)m_currentDataObject.get(OID_ATTR); OID currentOID = (OID) m_currentDataObject.get(OID_ATTR);
ObjectType ot = currentOID.getObjectType(); ObjectType ot = currentOID.getObjectType();
if (ot == null) { if (ot == null) {
throw new UncheckedWrapperException("no object type " + currentOID); throw new UncheckedWrapperException("no object type "
+ currentOID);
} }
Property prop = ot.getProperty(name); Property prop = ot.getProperty(name);
if (prop == null) { if (prop == null) {
throw new UncheckedWrapperException("no property " + name + " for " + ot.getQualifiedName()); throw new UncheckedWrapperException("no property " + name
+ " for " + ot.
getQualifiedName());
} }
if (prop.isAttribute()) { if (prop.isAttribute()) {
beginAttribute(m_currentDataObject, prop); beginAttribute(m_currentDataObject, prop);
@ -226,7 +220,6 @@ public class ItemParser extends DomainObjectParser {
m_currentDataObject = getDataObject(oid); m_currentDataObject = getDataObject(oid);
} }
/** /**
* Called whenever a start of block which represents the role * Called whenever a start of block which represents the role
* is encountered. * is encountered.
@ -244,7 +237,6 @@ public class ItemParser extends DomainObjectParser {
m_currentDataObject = getDataObject(oid); m_currentDataObject = getDataObject(oid);
} }
/** /**
* Called whenever CMS content item block is started with * Called whenever CMS content item block is started with
* &lt;cms:item&gt; element. * &lt;cms:item&gt; element.
@ -271,7 +263,8 @@ public class ItemParser extends DomainObjectParser {
} }
m_objectStack.push(m_currentDataObject); m_objectStack.push(m_currentDataObject);
} }
debugLog("Start of content item " + oid + " encountered, write=" + m_write); debugLog("Start of content item " + oid + " encountered, write="
+ m_write);
} }
/** /**
@ -285,7 +278,6 @@ public class ItemParser extends DomainObjectParser {
m_objectStack.push(PLAIN_ATTRIBUTE); m_objectStack.push(PLAIN_ATTRIBUTE);
} }
protected void endTag(String name, protected void endTag(String name,
String uri) { String uri) {
if (getTagName().equals(name)) { if (getTagName().equals(name)) {
@ -296,12 +288,14 @@ public class ItemParser extends DomainObjectParser {
// Ignore everything if DB writing is disabled // Ignore everything if DB writing is disabled
if (m_write) { if (m_write) {
if (PLAIN_ATTRIBUTE.equals(m_objectStack.peek())) { if (PLAIN_ATTRIBUTE.equals(m_objectStack.peek())) {
Property prop = ((OID) m_currentDataObject.get(OID_ATTR)).getObjectType().getProperty(name); Property prop = ((OID) m_currentDataObject.get(OID_ATTR)).
getObjectType().getProperty(name);
endAttribute(m_currentDataObject, prop, getTagBody()); endAttribute(m_currentDataObject, prop, getTagBody());
} else { } else {
// The current attribute is either role or association (collection) // The current attribute is either role or association (collection)
Map parentObject = (Map) m_objectStack.peek(); Map parentObject = (Map) m_objectStack.peek();
Property prop = ((OID) parentObject.get(OID_ATTR)).getObjectType().getProperty(name); Property prop = ((OID) parentObject.get(OID_ATTR)).getObjectType().
getProperty(name);
if (prop.isCollection()) { if (prop.isCollection()) {
endAssociation(parentObject, m_currentDataObject, prop); endAssociation(parentObject, m_currentDataObject, prop);
} else if (prop.isRole()) { } else if (prop.isRole()) {
@ -316,7 +310,6 @@ public class ItemParser extends DomainObjectParser {
} }
} }
/** /**
* @return true if newly imported item is index item. * @return true if newly imported item is index item.
*/ */
@ -342,27 +335,27 @@ public class ItemParser extends DomainObjectParser {
* @return the end of lifecycle date, might be null * @return the end of lifecycle date, might be null
*/ */
public Date getArchiveDate() { public Date getArchiveDate() {
return (Date)m_archiveDate.clone(); return (Date) m_archiveDate.clone();
} }
private ContentItem persistContentItem(Map itemMap) { private ContentItem persistContentItem(Map itemMap) {
OID srcOid = (OID) itemMap.get(OID_ATTR); OID srcOid = (OID) itemMap.get(OID_ATTR);
String type = srcOid.getObjectType().getQualifiedName(); String type = srcOid.getObjectType().getQualifiedName();
DataObject itemDataObject = SessionManager.getSession().create(type); DataObject itemDataObject = SessionManager.getSession().create(type);
ContentItem item = (ContentItem) createACSObject(itemDataObject, itemMap); ContentItem item =
if (item != null && (ContentItem) createACSObject(itemDataObject, itemMap);
item.getLanguage() == null) { if (item != null && item.getLanguage() == null) {
item.setLanguage("en"); item.setLanguage("en");
} }
getObjectMapper().setObject(srcOid, item); getObjectMapper().setObject(srcOid, item);
setAllProperties(item, itemDataObject, itemMap, 0); setAllProperties(item, itemDataObject, itemMap, 0);
s_log.info("Created item " + item.getOID() + " from " + srcOid); s_log.info("Created item " + item.getOID() + " from " + srcOid);
return item; return item;
} }
/** /**
* Called whenever a plain attribute (neither association nor role) element is ended. * Called whenever a plain attribute (neither association nor role) element is ended.
* *
@ -417,25 +410,25 @@ public class ItemParser extends DomainObjectParser {
String propName = property.getName(); String propName = property.getName();
debugLog("Ending role: " + propName + ": " + childObject); debugLog("Ending role: " + propName + ": " + childObject);
// don't set ContentType // don't set ContentType
if (!((OID) childObject.get(OID_ATTR)).getObjectType().getQualifiedName().equals(ContentType.BASE_DATA_OBJECT_TYPE)) { if (!((OID) childObject.get(OID_ATTR)).getObjectType().getQualifiedName().
equals(ContentType.BASE_DATA_OBJECT_TYPE)) {
parentObject.put(propName + COUNT_SUFFIX + "1", childObject); parentObject.put(propName + COUNT_SUFFIX + "1", childObject);
} }
m_currentDataObject = parentObject; m_currentDataObject = parentObject;
m_objectStack.pop(); m_objectStack.pop();
} }
/** /**
* Process the item recursively until we get all attributes set. * Process the item recursively until we get all attributes set.
*/ */
private void setAllProperties(ACSObject acs, DataObject dataObject, Map objectMap, int recursionLevel) { private void setAllProperties(ACSObject acs, DataObject dataObject,
Map objectMap, int recursionLevel) {
m_recursionLevel = recursionLevel; m_recursionLevel = recursionLevel;
debugLog("setAll on " + dataObject.getOID() + ": " + objectMap); debugLog("setAll on " + dataObject.getOID() + ": " + objectMap);
// Loop over all properties recorded in Map and set them appropriately // Loop over all properties recorded in Map and set them appropriately
for (Iterator it=objectMap.keySet().iterator(); it.hasNext(); ) { for (Iterator it = objectMap.keySet().iterator(); it.hasNext();) {
String key = (String) it.next(); String key = (String) it.next();
if (s_ignoredProps.contains(key)) { if (s_ignoredProps.contains(key)) {
@ -473,13 +466,15 @@ public class ItemParser extends DomainObjectParser {
} }
Property prop = dataObject.getObjectType().getProperty(propName); Property prop = dataObject.getObjectType().getProperty(propName);
if (prop.isCollection()) { if (prop.isCollection()) {
DataAssociation assoc = (DataAssociation) dataObject.get(propName); DataAssociation assoc = (DataAssociation) dataObject.get(
propName);
assoc.add(childObject); assoc.add(childObject);
} else { } else {
dataObject.set(propName, childObject); dataObject.set(propName, childObject);
} }
if (recurse) { if (recurse) {
setAllProperties(childAcs, childObject, childObjectMap, recursionLevel+1); setAllProperties(childAcs, childObject, childObjectMap, recursionLevel
+ 1);
m_recursionLevel = recursionLevel; m_recursionLevel = recursionLevel;
} }
} else if (pos == -1) { // We're dealing with simple property } else if (pos == -1) { // We're dealing with simple property
@ -490,7 +485,6 @@ public class ItemParser extends DomainObjectParser {
finalizeACSObject(acs, dataObject, objectMap); finalizeACSObject(acs, dataObject, objectMap);
} }
/** /**
* This methods guesses required properties not present in the import file. * This methods guesses required properties not present in the import file.
*/ */
@ -514,7 +508,8 @@ public class ItemParser extends DomainObjectParser {
OID mimeOid = new OID(MimeType.BASE_DATA_OBJECT_TYPE); OID mimeOid = new OID(MimeType.BASE_DATA_OBJECT_TYPE);
mimeOid.set(MimeType.MIME_TYPE, mimeString); mimeOid.set(MimeType.MIME_TYPE, mimeString);
DataObject mimeObj = SessionManager.getSession().retrieve(mimeOid); DataObject mimeObj = SessionManager.getSession().retrieve(mimeOid);
debugLog("Guessing mimetype from filename: " + filename + ", mime=" + mimeOid); debugLog("Guessing mimetype from filename: " + filename + ", mime="
+ mimeOid);
dobj.set(BinaryAsset.MIME_TYPE, mimeObj); dobj.set(BinaryAsset.MIME_TYPE, mimeObj);
} }
if (dobj.getObjectType().getProperty(DISPLAY_NAME) != null if (dobj.getObjectType().getProperty(DISPLAY_NAME) != null
@ -579,7 +574,6 @@ public class ItemParser extends DomainObjectParser {
return newDataObject; return newDataObject;
} }
private ACSObject createACSObject(DataObject dobj, Map properties) { private ACSObject createACSObject(DataObject dobj, Map properties) {
String domainClass = (String) properties.get(DEFAULT_DOMAIN_CLASS); String domainClass = (String) properties.get(DEFAULT_DOMAIN_CLASS);
if (domainClass == null) { if (domainClass == null) {
@ -589,8 +583,10 @@ public class ItemParser extends DomainObjectParser {
debugLog("Creating " + domainClass + " ..."); debugLog("Creating " + domainClass + " ...");
try { try {
Class classDef = Class.forName(domainClass); Class classDef = Class.forName(domainClass);
Constructor constructor = classDef.getConstructor(new Class[] {DataObject.class}); Constructor constructor = classDef.getConstructor(new Class[]{
ACSObject object = (ACSObject) constructor.newInstance(new Object[] {dobj}); DataObject.class});
ACSObject object = (ACSObject) constructor.newInstance(new Object[]{
dobj});
debugLog("Successfully created " + object.getOID()); debugLog("Successfully created " + object.getOID());
return object; return object;
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
@ -601,14 +597,11 @@ public class ItemParser extends DomainObjectParser {
throw new UncheckedWrapperException(e); throw new UncheckedWrapperException(e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new UncheckedWrapperException(e); throw new UncheckedWrapperException(e);
} catch (Exception e ) { } catch (Exception e) {
throw new UncheckedWrapperException(e); throw new UncheckedWrapperException(e);
} }
} }
private void setProperty(Map dobj, Property prop, String value) { private void setProperty(Map dobj, Property prop, String value) {
String key = prop.getName(); String key = prop.getName();
Class propertyClass = prop.getJavaClass(); Class propertyClass = prop.getJavaClass();
@ -638,7 +631,7 @@ public class ItemParser extends DomainObjectParser {
// explicitly provided as attr of <content> element. // explicitly provided as attr of <content> element.
Map atts = (Map) m_attributeStack.peek(); Map atts = (Map) m_attributeStack.peek();
if (atts != null && atts.get(FILE) != null) { if (atts != null && atts.get(FILE) != null) {
filename = (String)atts.get(FILE); filename = (String) atts.get(FILE);
// We will also use this attribute to populate "name" property // We will also use this attribute to populate "name" property
// (needed for mime-type guessing if none explicitly provided), // (needed for mime-type guessing if none explicitly provided),
// but only if such has not been set so far. If this property // but only if such has not been set so far. If this property
@ -696,12 +689,11 @@ public class ItemParser extends DomainObjectParser {
} }
} }
} else { } else {
s_log.warn("Don't know how to handle property " + s_log.warn("Don't know how to handle property " + key + ", type: " + propertyClass.
key + ", type: " + propertyClass.getName()); getName());
} }
} }
private void debugLog(String logString) { private void debugLog(String logString) {
s_log.debug(getPadding() + logString); s_log.debug(getPadding() + logString);
} }
@ -724,15 +716,12 @@ public class ItemParser extends DomainObjectParser {
return padding.toString(); return padding.toString();
} }
protected Map copyAttributes(Attributes atts) { protected Map copyAttributes(Attributes atts) {
Map map = new HashMap(); Map map = new HashMap();
for (int i = 0 ; i < atts.getLength() ; i++) { for (int i = 0; i < atts.getLength(); i++) {
map.put(atts.getQName(i), atts.getValue(i)); map.put(atts.getQName(i), atts.getValue(i));
} }
return map; return map;
} }
} }