Skip to content

Commit

Permalink
added media type to resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw committed May 9, 2024
1 parent 95d9990 commit bc0b42d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public class TikaProcessor {
documentTypeMap.put("image/svg+xml", Document.Type.STANDARD);
// org.apache.tika.parser.xml.FictionBookParser
documentTypeMap.put("application/x-fictionbook+xml", Document.Type.STANDARD);
// OTHERS
documentTypeMap.put("application/x-sh", Document.Type.STANDARD);
documentTypeMap.put("application/x-bat", Document.Type.STANDARD);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class SimpleXmlClaimReporter extends AbstractReport {
private static final String NOTES = "notes";
private static final String SAMPLE = "sample";
private static final String TYPE = "type";

private static final String MEDIA = "media";
private static final String ID = "id";

private final IXmlWriter writer;
Expand Down Expand Up @@ -72,7 +74,7 @@ private void writeLicenseClaims(ILicense license, MetaData metaData) throws IOEx
private void writeDocumentClaims(final Document subject) throws IOException {
final MetaData metaData = subject.getMetaData();
writer.openElement(RESOURCE).attribute(NAME, subject.getName()).attribute(TYPE,
metaData.getDocumentType().toString());
metaData.getDocumentType().toString()).attribute(MEDIA,metaData.getMediaType().toString());
for (Iterator<ILicense> iter = metaData.licenses().iterator(); iter.hasNext();) {
writeLicenseClaims(iter.next(), metaData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:string" name="type" use="required"/>
<xs:attribute type="xs:string" name="media" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void setUp() throws Exception {
@Test
public void standardTypeAnalyser() throws Exception {
String[] expected = {
"<resource name='src/test/resources/elements/Text.txt' type='STANDARD'>"
"<resource name='src/test/resources/elements/Text.txt' type='STANDARD' media='text/plain'>"
+ "<license id='?????' name='Unknown license' approval='false' family='?????'/>"
+ "<sample><![CDATA[ /*", //
" * Licensed to the Apache Software Foundation (ASF) under one", //
Expand Down Expand Up @@ -91,7 +91,7 @@ public void noteTypeAnalyser() throws Exception {
Resources.getResourceFile("/elements/LICENSE"));
analyser.analyse(document);
reporter.report(document);
assertEquals("<resource name='src/test/resources/elements/LICENSE' type='NOTICE'/>", out.toString());
assertEquals("<resource name='src/test/resources/elements/LICENSE' type='NOTICE' media='text/plain'/>", out.toString());
}

@Test
Expand All @@ -100,7 +100,7 @@ public void binaryTypeAnalyser() throws Exception {
Resources.getResourceFile("/elements/Image.png"));
analyser.analyse(document);
reporter.report(document);
assertEquals("<resource name='src/test/resources/elements/Image.png' type='BINARY'/>", out.toString());
assertEquals("<resource name='src/test/resources/elements/Image.png' type='BINARY' media='image/png'/>", out.toString());
}

@Test
Expand All @@ -114,7 +114,7 @@ public void archiveTypeAnalyserTest() throws Exception {
analyser = DefaultAnalyserFactory.createDefaultAnalyser(config);
analyser.analyse(document);
reporter.report(document);
assertEquals("<resource name='src/test/resources/elements/dummy.jar' type='ARCHIVE'/>", out.toString());
assertEquals("<resource name='src/test/resources/elements/dummy.jar' type='ARCHIVE' media='application/java-archive'/>", out.toString());
}

@Test
Expand All @@ -130,7 +130,7 @@ public void archivesAbsenceTest() throws Exception {
analyser.analyse(document);
reporter.report(document);
String result = out.toString();
TextUtils.assertContains("<resource name='src/test/resources/elements/dummy.jar' type='ARCHIVE'>", out.toString());
TextUtils.assertContains("<resource name='src/test/resources/elements/dummy.jar' type='ARCHIVE' media='application/java-archive'>", out.toString());
TextUtils.assertContains("<license id='?????' name='Unknown license' approval='false' family='?????'/>", out.toString());
TextUtils.assertContains("<license id='ASL' name='Applied Apache License Version 2.0' approval='false' family='AL '/>", out.toString());
}
Expand All @@ -148,7 +148,7 @@ public void archivesPresenceTest() throws Exception {
analyser.analyse(document);
reporter.report(document);
String result = out.toString();
TextUtils.assertContains("<resource name='src/test/resources/elements/dummy.jar' type='ARCHIVE'>", out.toString());
TextUtils.assertContains("<resource name='src/test/resources/elements/dummy.jar' type='ARCHIVE' media='application/java-archive'>", out.toString());
TextUtils.assertNotContains("<license id='?????' name='Unknown license' approval='false' family='?????'/>", out.toString());
TextUtils.assertContains("<license id='ASL' name='Applied Apache License Version 2.0' approval='false' family='AL '/>", out.toString());
}
Expand All @@ -159,7 +159,7 @@ public void archiveTypeAnalyser() throws Exception {
Resources.getResourceFile("/elements/dummy.jar"));
analyser.analyse(document);
reporter.report(document);
assertEquals("<resource name='src/test/resources/elements/dummy.jar' type='ARCHIVE'/>", out.toString());
assertEquals("<resource name='src/test/resources/elements/dummy.jar' type='ARCHIVE' media='application/java-archive'/>", out.toString());
}

@Test
Expand All @@ -168,7 +168,7 @@ public void RAT211_bmp_Test() throws Exception {
Resources.getResourceFile("/jira/RAT211/side_left.bmp"));
analyser.analyse(document);
reporter.report(document);
assertEquals("<resource name='src/test/resources/jira/RAT211/side_left.bmp' type='BINARY'/>", out.toString());
assertEquals("<resource name='src/test/resources/jira/RAT211/side_left.bmp' type='BINARY' media='image/bmp'/>", out.toString());
}

@Test
Expand All @@ -178,7 +178,7 @@ public void RAT211_dia_Test() throws Exception {
analyser.analyse(document);
reporter.report(document);
assertEquals(
"<resource name='src/test/resources/jira/RAT211/leader-election-message-arrives.dia' type='ARCHIVE'/>",
"<resource name='src/test/resources/jira/RAT211/leader-election-message-arrives.dia' type='ARCHIVE' media='application/gzip'/>",
out.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SPDX-License-Identifier: Apache-2.0
</pathconvert>
<property name="expectedOutput" value=" S ${file.name}" />
<property name="expectedOutputXML"
value='&lt;resource name="${file.name}"' />
value='&lt;resource media="application/xml" name="${file.name}"' />
<property name="expectedOutputXML2" value='family="AL "' />
</target>

Expand Down

0 comments on commit bc0b42d

Please sign in to comment.