1. petermr
  2. jumbo-lensfield

Commits

petermr  committed 9476abb

added CMLMerger

  • Participants
  • Parent commits 8fc4086
  • Branches default

Comments (0)

Files changed (2)

File src/main/java/uk/ac/cam/ch/wwmm/jumbolensfield/AtomSiteMerger.java

View file
+package uk.ac.cam.ch.wwmm.jumbolensfield;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import nu.xom.Document;
+import nu.xom.Element;
+import nu.xom.ParsingException;
+import nu.xom.Serializer;
+import nu.xom.ValidityException;
+
+import org.lensfield.api.LensfieldInput;
+import org.lensfield.api.LensfieldOutput;
+import org.lensfield.api.LensfieldParameter;
+import org.xmlcml.cml.base.CMLBuilder;
+
+public class AtomSiteMerger {
+
+//	@LensfieldParameter
+//	private String xpath;
+	
+	@LensfieldInput(name="atomsite")
+	private InputStream atomsite;
+	
+	@LensfieldInput(name="calculation")
+	private InputStream calculation;
+	
+	@LensfieldOutput
+	private OutputStream output;
+	
+	public void run() throws ValidityException, ParsingException, IOException {
+		CMLBuilder builder = new CMLBuilder();
+		
+		Document atomsiteDoc = builder.build(atomsite);
+		Document calculationDoc = builder.build(calculation);
+		
+		// merge together
+		Document doc = new Document((Element) atomsiteDoc.getRootElement().copy());
+		
+		Serializer ser = new Serializer(output);
+		ser.write(doc);
+	}
+	
+}

File src/main/java/uk/ac/cam/ch/wwmm/jumbolensfield/CMLMerger.java

View file
+package uk.ac.cam.ch.wwmm.jumbolensfield;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import nu.xom.Document;
+import nu.xom.Element;
+import nu.xom.ParsingException;
+import nu.xom.Serializer;
+import nu.xom.ValidityException;
+
+import org.lensfield.api.LensfieldInput;
+import org.lensfield.api.LensfieldOutput;
+import org.xmlcml.cml.base.CMLBuilder;
+import org.xmlcml.cml.element.CMLCml;
+
+public class CMLMerger {
+
+	@LensfieldInput(name="stream1")
+	private InputStream stream1;
+	
+	@LensfieldInput(name="stream2")
+	private InputStream stream2;
+	
+	@LensfieldOutput
+	private OutputStream output;
+	
+	public void run() throws ValidityException, ParsingException, IOException {
+		CMLBuilder builder = new CMLBuilder();
+		
+		Document doc1 = builder.build(stream1);
+		Document doc2 = builder.build(stream2);
+		
+		// merge together
+		CMLCml cmlOut = new CMLCml();
+		cmlOut.appendChild(doc1.getRootElement().copy());
+		cmlOut.appendChild(doc2.getRootElement().copy());
+		
+		Serializer ser = new Serializer(output);
+		ser.write(new Document(cmlOut));
+
+	}
+	
+}