Kleine Änderung beim RelationAttributeImporter: Einzelne RelationAttributes können jetzt auch per Kommandozeile, ohne XML Datei, angelegt werden.
git-svn-id: https://svn.libreccm.org/ccm/trunk@573 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
e994fe7bda
commit
cb6af4338c
|
|
@ -34,7 +34,8 @@ import org.xml.sax.SAXException;
|
|||
/**
|
||||
* <p>
|
||||
* A simple import tool for {@link RelationAttribute}s. This tool imports the
|
||||
* relation attributes from a simple XML file, which looks like this:
|
||||
* relation attributes from a simple XML file or from parameters at the
|
||||
* commandline. The XML file format:
|
||||
* </p>
|
||||
* <pre>
|
||||
* <?xml version="1.0"?>
|
||||
|
|
@ -46,6 +47,7 @@ import org.xml.sax.SAXException;
|
|||
* <name>...</name>
|
||||
* <description>...</description>
|
||||
* </relationAttribute>
|
||||
* ...
|
||||
* </relationAttributes>
|
||||
* </pre>
|
||||
* <p>
|
||||
|
|
@ -53,10 +55,22 @@ import org.xml.sax.SAXException;
|
|||
* to import is needed. With tools-ng and ECDC, the line for calling the
|
||||
* <code>RelationAttributeImporter</code> would like the following:
|
||||
* </p>
|
||||
* <p>
|
||||
* With a XML file:
|
||||
* </p>
|
||||
* <pre>
|
||||
* ant -Dccm.classname="com.arsdigita.cms.relationattributeimporter.RelationAttributeImporter" -Dccm.parameters="/path/to/relation/attribute/file.xml" ccm-run
|
||||
* </pre>
|
||||
* <p>
|
||||
* With command line parameters:
|
||||
* </p>
|
||||
* <pre>
|
||||
* ant -Dccm.classname="com.arsdigita.cms.relationattributeimporter.RelationAttributeImporter" -Dccm.parameters="attribute key lang name [description]" ccm-run
|
||||
* </pre>
|
||||
* <p>
|
||||
* The description parameter is optional.
|
||||
* </p>
|
||||
* <p>
|
||||
* You have to add the <code>RelationAttributeImporter</code> to add to your
|
||||
* environment, of course.
|
||||
* </p>
|
||||
|
|
@ -68,11 +82,15 @@ import org.xml.sax.SAXException;
|
|||
public class RelationAttributeImporter extends Program {
|
||||
|
||||
public RelationAttributeImporter() {
|
||||
super("Relation Attribute Importer", "0.1.0", "FILE");
|
||||
super("Relation Attribute Importer",
|
||||
"0.1.0",
|
||||
"FILE | ATTRIBUTE KEY LANG NAME [DESCRIPTION]");
|
||||
}
|
||||
|
||||
public RelationAttributeImporter(boolean startup) {
|
||||
super("Relation Attribute Importer", "0.1.0", "FILE", startup);
|
||||
super("Relation Attribute Importer",
|
||||
"0.1.0",
|
||||
"FILE | ATTRIBUTE KEY LANG NAME [DESCRIPTION]", startup);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -84,11 +102,7 @@ public class RelationAttributeImporter extends Program {
|
|||
SAXParser saxParser = null;
|
||||
RelationAttributeParser parser;
|
||||
args = cmdLine.getArgs();
|
||||
if (args.length != 1) {
|
||||
help(System.err);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
System.out.printf("Using file %s.", args[0]);
|
||||
relAttrFile = new File(args[0]);
|
||||
if (!relAttrFile.exists()) {
|
||||
|
|
@ -104,11 +118,13 @@ public class RelationAttributeImporter extends Program {
|
|||
try {
|
||||
saxParser = saxFactory.newSAXParser();
|
||||
} catch (ParserConfigurationException ex) {
|
||||
System.err.printf("Error creating SAXParser: %s", ex.getMessage());
|
||||
System.err.printf("Error creating SAXParser: %s",
|
||||
ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
System.exit(-1);
|
||||
} catch (SAXException ex) {
|
||||
System.err.printf("Error creating SAXParser: %s", ex.getMessage());
|
||||
System.err.printf("Error creating SAXParser: %s",
|
||||
ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
|
@ -131,8 +147,26 @@ public class RelationAttributeImporter extends Program {
|
|||
System.out.println(
|
||||
"Parsed XML file successfully. Creating ACSObjects...");
|
||||
for (int i = 0; i < parser.getRelAttrs().size(); i++) {
|
||||
System.out.printf("%d of %d...", (i + 1), parser.getRelAttrs().size());
|
||||
createACSObject(parser.getRelAttrs().get(i), i);
|
||||
System.out.printf("%d of %d...", (i + 1), parser.getRelAttrs().
|
||||
size());
|
||||
createACSObject(parser.getRelAttrs().get(i));
|
||||
}
|
||||
} else if ((args.length == 4) || (args.length == 5)) {
|
||||
RelAttrBean relAttr;
|
||||
|
||||
relAttr = new RelAttrBean();
|
||||
relAttr.setAttribute(args[0]);
|
||||
relAttr.setKey(args[1]);
|
||||
relAttr.setLang(args[2]);
|
||||
relAttr.setName(args[3]);
|
||||
if (args.length == 5) {
|
||||
relAttr.setDescription(args[4]);
|
||||
}
|
||||
|
||||
createACSObject(relAttr);
|
||||
} else {
|
||||
help(System.err);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +177,7 @@ public class RelationAttributeImporter extends Program {
|
|||
* @param relAttr
|
||||
* @param index
|
||||
*/
|
||||
private void createACSObject(final RelAttrBean relAttr, int index) {
|
||||
private void createACSObject(final RelAttrBean relAttr) {
|
||||
|
||||
/*System.out.printf("\tattribute = %s\n", relAttr.getAttribute());
|
||||
System.out.printf("\tkey = %s\n", relAttr.getKey());
|
||||
|
|
@ -152,6 +186,7 @@ public class RelationAttributeImporter extends Program {
|
|||
System.out.printf("\tdescription = %s\n", relAttr.getDescription());*/
|
||||
|
||||
Transaction transaction = new Transaction() {
|
||||
|
||||
@Override
|
||||
public void doRun() {
|
||||
RelationAttribute attr;
|
||||
|
|
|
|||
Loading…
Reference in New Issue