Commit 33767395 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

compartment name is escaped against xml characters

parent 35e4ddd4
......@@ -11,6 +11,7 @@ import org.apache.commons.text.StringEscapeUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.geometry.ColorParser;
import lcsb.mapviewer.common.geometry.PointTransformation;
......@@ -338,7 +339,7 @@ public class ModelToGPML {
double x = ca.getCenterX(), y = ca.getCenterY(), h = ca.getHeight(), w = ca.getWidth();
String shape = ShapeMapping.getShape(ca.getClass()).getStringRepresentation();
comparments.append(" <Shape TextLabel=\"" + ca.getName() + "\" GraphId=\"" + ca.getElementId() + "\">\n");
comparments.append(" <Shape TextLabel=\"" + XmlParser.escapeXml(ca.getName()) + "\" GraphId=\"" + ca.getElementId() + "\">\n");
comparments.append(" <Comment>" + StringEscapeUtils.escapeXml11(getAllNames(ca)) + "</Comment>\n");
comparments.append(" <Attribute Key=\"org.pathvisio.CellularComponentProperty\" Value=\"Cell\" />\n");
comparments.append(" <Attribute Key=\"org.pathvisio.DoubleLineProperty\" Value=\"Double\" />\n");
......
......@@ -13,11 +13,10 @@ import org.apache.logging.log4j.Logger;
import org.junit.*;
import lcsb.mapviewer.common.geometry.PointTransformation;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.*;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.graphics.*;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.SquareCompartment;
import lcsb.mapviewer.model.map.model.*;
......@@ -58,9 +57,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testAnnotations() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
GenericProtein protein = createProtein();
protein.addMiriamData(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"));
......@@ -87,9 +84,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testHypoteticalComplex() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
Complex complex = createComplex();
complex.addSpecies(createProtein());
......@@ -121,9 +116,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testComplexName() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
Complex complex = createComplex();
complex.addSpecies(createProtein());
......@@ -147,9 +140,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testReactionColor() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
Protein p1 = createProtein();
Protein p2 = createProtein();
......@@ -174,9 +165,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testReversibleReaction() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
Protein p1 = createProtein();
Protein p2 = createProtein();
......@@ -227,9 +216,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testProteinModification() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
Protein p1 = createProtein();
p1.addResidue(createResidue(p1));
......@@ -355,14 +342,18 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
compartment.setX(1);
compartment.setY(1);
compartment.setZ(15);
compartment.setNamePoint(new Point2D.Double(1, 1));
compartment.setNameVerticalAlign(VerticalAlign.TOP);
compartment.setNameHorizontalAlign(HorizontalAlign.LEFT);
compartment.setThickness(0);
compartment.setOuterWidth(0);
compartment.setInnerWidth(0);
return compartment;
}
@Test
public void testExportHypothetical() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
Protein p1 = createProtein();
p1.setHypothetical(true);
......@@ -380,9 +371,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testExportUnknown() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
Species p1 = createUnknown();
......@@ -398,9 +387,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testMapNotes() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
model.setNotes("xyz");
lcsb.mapviewer.wikipathway.GpmlParser parser = new lcsb.mapviewer.wikipathway.GpmlParser();
......@@ -413,9 +400,7 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
@Test
public void testHtmlTagInNotes() throws Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createModel();
model.setNotes("a < b");
Species p1 = createProtein();
......@@ -430,10 +415,35 @@ public class ModelToGPMLTest extends WikipathwaysTestFunctions {
r.setNotes("<xml>tag</xml>");
model.addReaction(r);
Model model2 = serializeOverGpml(model);
assertEquals(0, new ModelComparator().compare(model, model2));
}
private Model serializeOverGpml(Model model)
throws InconsistentModelException, ConverterException, InvalidInputDataExecption {
lcsb.mapviewer.wikipathway.GpmlParser parser = new lcsb.mapviewer.wikipathway.GpmlParser();
String xml = parser.model2String(model);
Model model2 = parser.createModel(new ConverterParams().inputStream(new ByteArrayInputStream(xml.getBytes())));
return model2;
}
private Model createModel() {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
return model;
}
@Test
public void specialCharacterInComaprtmentName() throws Exception {
Model model = createModel();
Compartment compartment = createCompartment();
compartment.setName("hello&by");
model.addElement(compartment);
Model model2 = serializeOverGpml(model);
assertEquals(0, new ModelComparator().compare(model, model2));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment