From cb6af4338c0e8e46eb310575976d9322b1ff794b Mon Sep 17 00:00:00 2001 From: jensp Date: Fri, 15 Oct 2010 08:50:14 +0000 Subject: [PATCH] =?UTF-8?q?Kleine=20=C3=84nderung=20beim=20RelationAttribu?= =?UTF-8?q?teImporter:=20Einzelne=20RelationAttributes=20k=C3=B6nnen=20jet?= =?UTF-8?q?zt=20auch=20per=20Kommandozeile,=20ohne=20XML=20Datei,=20angele?= =?UTF-8?q?gt=20werden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@573 8810af33-2d31-482b-a856-94f89814c4df --- .../RelationAttributeImporter.java | 137 +++++++++++------- 1 file changed, 86 insertions(+), 51 deletions(-) diff --git a/ccm-cms-relationattributeimporter/src/com/arsdigita/cms/relationattributeimporter/RelationAttributeImporter.java b/ccm-cms-relationattributeimporter/src/com/arsdigita/cms/relationattributeimporter/RelationAttributeImporter.java index 71ceeb6e8..4d8c44a5f 100644 --- a/ccm-cms-relationattributeimporter/src/com/arsdigita/cms/relationattributeimporter/RelationAttributeImporter.java +++ b/ccm-cms-relationattributeimporter/src/com/arsdigita/cms/relationattributeimporter/RelationAttributeImporter.java @@ -34,7 +34,8 @@ import org.xml.sax.SAXException; /** *

* 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: *

*
  * <?xml version="1.0"?>
@@ -46,6 +47,7 @@ import org.xml.sax.SAXException;
  *         <name>...</name>
  *         <description>...</description>
  *     </relationAttribute>
+ *     ...
  * </relationAttributes>
  * 
*

@@ -53,10 +55,22 @@ import org.xml.sax.SAXException; * to import is needed. With tools-ng and ECDC, the line for calling the * RelationAttributeImporter would like the following: *

+ *

+ * With a XML file: + *

*
  * ant -Dccm.classname="com.arsdigita.cms.relationattributeimporter.RelationAttributeImporter" -Dccm.parameters="/path/to/relation/attribute/file.xml" ccm-run
  * 
*

+ * With command line parameters: + *

+ *
+ * ant -Dccm.classname="com.arsdigita.cms.relationattributeimporter.RelationAttributeImporter" -Dccm.parameters="attribute key lang name [description]" ccm-run
+ * 
+ *

+ * The description parameter is optional. + *

+ *

* You have to add the RelationAttributeImporter to add to your * environment, of course. *

@@ -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,56 +102,72 @@ public class RelationAttributeImporter extends Program { SAXParser saxParser = null; RelationAttributeParser parser; args = cmdLine.getArgs(); - if (args.length != 1) { + if (args.length == 1) { + System.out.printf("Using file %s.", args[0]); + relAttrFile = new File(args[0]); + if (!relAttrFile.exists()) { + System.err.printf("ERROR: File %s does not exist.", args[0]); + System.exit(-1); + } + if (!relAttrFile.isFile()) { + System.err.printf("ERROR: Path %s does not point to a file.", + args[0]); + System.exit(-1); + } + saxFactory = SAXParserFactory.newInstance(); + try { + saxParser = saxFactory.newSAXParser(); + } catch (ParserConfigurationException ex) { + 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()); + ex.printStackTrace(); + System.exit(-1); + } + parser = new RelationAttributeParser(); + try { + saxParser.parse(relAttrFile, parser); + } catch (SAXException ex) { + System.err.printf("Error parsing file %s: %s", + args[0], + ex.getMessage()); + ex.printStackTrace(); + System.exit(-1); + } catch (IOException ex) { + System.err.printf("Error parsing file %s: %s", + args[0], ex.getMessage()); + ex.printStackTrace(); + System.exit(-1); + } + + 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)); + } + } 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); } - - System.out.printf("Using file %s.", args[0]); - relAttrFile = new File(args[0]); - if (!relAttrFile.exists()) { - System.err.printf("ERROR: File %s does not exist.", args[0]); - System.exit(-1); - } - if (!relAttrFile.isFile()) { - System.err.printf("ERROR: Path %s does not point to a file.", - args[0]); - System.exit(-1); - } - saxFactory = SAXParserFactory.newInstance(); - try { - saxParser = saxFactory.newSAXParser(); - } catch (ParserConfigurationException ex) { - 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()); - ex.printStackTrace(); - System.exit(-1); - } - parser = new RelationAttributeParser(); - try { - saxParser.parse(relAttrFile, parser); - } catch (SAXException ex) { - System.err.printf("Error parsing file %s: %s", - args[0], - ex.getMessage()); - ex.printStackTrace(); - System.exit(-1); - } catch (IOException ex) { - System.err.printf("Error parsing file %s: %s", - args[0], ex.getMessage()); - ex.printStackTrace(); - System.exit(-1); - } - - 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); - } } /** @@ -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;