streamlet examples: documentation v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 29 Jan 2020 20:50:12 +0100
branchv_0
changeset 74 a2aa84f310a5
parent 73 1a067a217454
child 75 ecbf6504915c
streamlet examples: documentation
streamlet-examples/JarInfo.java
streamlet-examples/xpath.cpp
--- a/streamlet-examples/JarInfo.java	Wed Jan 29 18:41:42 2020 +0100
+++ b/streamlet-examples/JarInfo.java	Wed Jan 29 20:50:12 2020 +0100
@@ -21,8 +21,27 @@
 import java.util.List;
 import java.util.jar.JarFile;
 
+/**
+ * <p>
+ * This streamlet provides metadata from JAR (or ZIP) files.</p>
+ *
+ * <p>
+ * With no options it returns the main class (if any) and number of entries (files and directories) in the archive.</p>
+ *
+ * <p>
+ * Specific attributes can be selected using options – e.g. --option 'attribute' '…' Supported attributes are:</p>
+ *
+ * <ul>
+ * <li>comment</li>
+ * <li>entries</li>
+ * <li>main_class</li>
+ * </ul>
+ */
 public class JarInfo extends Streamlet {
 
+	// TODO: total size 
+	// TODO: OSGi metadata etc.
+	// TODO: more OOP, move to separate repository, proper Maven project, clean-up, stabilize API
 	public static final String ATTRIBUTE_COMMENT = "comment";
 	public static final String ATTRIBUTE_ENTRIES = "entries";
 	public static final String ATTRIBUTE_MAIN_CLASS = "main_class";
@@ -33,14 +52,6 @@
 		JarInfo s = new JarInfo();
 		int status = s.run();
 		System.exit(status);
-
-		// TODO: return real values:
-		JarFile jar = new JarFile(new File(args[0]));
-		String mainClass = jar.getManifest() == null ? null : jar.getManifest().getMainAttributes().getValue("Main-Class");
-		System.out.println("Name:       " + jar.getName());
-		System.out.println("Comment:    " + jar.getComment());
-		System.out.println("Entries:    " + jar.stream().count());
-		System.out.println("Main class: " + mainClass);
 	}
 
 	protected List<Streamlet.AttributeMetadata> getOutputAttributesMetadata() {
--- a/streamlet-examples/xpath.cpp	Wed Jan 29 18:41:42 2020 +0100
+++ b/streamlet-examples/xpath.cpp	Wed Jan 29 20:50:12 2020 +0100
@@ -21,6 +21,27 @@
 #include <regex>
 #include <libxml++-2.6/libxml++/libxml++.h>
 
+/**
+ * This streamlet provides values from XML files.
+ * It uses the XPath language to define, what portion of XML should be returned.
+ * 
+ * With no options it does not provide any attributes.
+ * 
+ * XPath expressions are passed as 'attribute' options.
+ * e.g. --option 'attribute' 'name()' will return single attribute with the name of the root node.
+ * 
+ * Attributes can be renamed using aliases: --option 'attribute' 'name()' --as 'name'. Otherwise the full XPath expression is used as a name.
+ * Number of aliases should match the number of attributes (otherwise only first attributes are renamed, because aliases are global, not relative to the --option).
+ * 
+ * Like relpipe-in-xmltable, this streamlet supports several modes:
+ *  - string
+ *  - boolean
+ *  - raw-xml
+ *  - line-number
+ *  - xpath
+ * 
+ * TODO: more OOP, move to separate repository, proper CMake project, clean-up, stabilize API
+ */
 class XPathStreamlet : public Streamlet {
 private:
 	xmlpp::Node::PrefixNsMap ns;