Skip to content

Commit

Permalink
Update getTag and getMCID for GFOpMarkedContent
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Nov 13, 2023
1 parent f92ee47 commit 1f20b95
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* @author Timur Kamalov
*/
public abstract class GFOpMarkedContent extends GFOperator implements OpMarkedContent {

private static final Logger LOGGER = Logger.getLogger(GFOpMarkedContent.class.getCanonicalName());

/** Name of link to the tag name */
public static final String TAG = "tag";
/** Name of link to the properties dictionary */
Expand Down Expand Up @@ -90,17 +94,25 @@ public List<? extends Object> getLinkedObjects(String link) {
}
}

public List<CosName> getTag() {
if (this.arguments.size() > 1) {
COSBase name = this.arguments.get(this.arguments.size() - 2);
if (name.getType() == COSObjType.COS_NAME) {
List<CosName> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new GFCosName((COSName) name));
return Collections.unmodifiableList(list);
}
public List<CosName> getLinkTag() {
COSName tag = getTag();
if (tag != null) {
List<CosName> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new GFCosName(tag));
return Collections.unmodifiableList(list);
}
return Collections.emptyList();
}

public COSName getTag() {
if (this.arguments.size() > 1) {
COSBase name = this.arguments.get(this.arguments.size() - 2);
if (name.getType() == COSObjType.COS_NAME) {
return (COSName) name;
}
}
return null;
}

protected List<CosDict> getPropertiesDict() {
if (this.propertiesDict != null) {
Expand All @@ -122,10 +134,10 @@ public List<CosLang> getLang() {
}

public String getParentsTags() {
List<CosName> tagList = getTag();
COSName tagName = getTag();
String tag = "";
if (tagList.size() != 0) {
tag = tagList.get(0).getinternalRepresentation();
if (tagName != null) {
tag = tagName.getString();
}
String parentsTags = "";
if (markedContent != null) {
Expand Down Expand Up @@ -190,7 +202,15 @@ public COSString getAlt() {
*/
public Long getMCID() {
COSObject mcid = getAttribute(ASAtom.MCID, COSObjType.COS_INTEGER);
return mcid == null ? null : mcid.getInteger();
if (mcid == null) {
return null;
}
COSName tag = getTag();
if (tag != null && ASAtom.ARTIFACT == tag.get()) {
LOGGER.log(Level.WARNING, "Property list for the Artifact tag contains the MCID entry");
return null;
}
return mcid.getInteger();
}

private COSObject getAttribute(ASAtom attributeName, COSObjType expectedType) {
Expand Down Expand Up @@ -241,13 +261,7 @@ public COSString getInheritedStringAttribute(ASAtom key) {
if (string != null) {
return string;
}
if (markedContent != null) {
string = markedContent.getInheritedStringAttribute(key);
if (string != null) {
return string;
}
}
return null;
return markedContent != null ? markedContent.getInheritedStringAttribute(key) : null;
}

public COSString getStringAttribute(ASAtom key) {
Expand All @@ -261,13 +275,7 @@ public Long getInheritedMCID() {
if (mcid != null) {
return mcid;
}
if (markedContent != null) {
mcid = markedContent.getInheritedMCID();
if (mcid != null) {
return mcid;
}
}
return null;
return markedContent != null ? markedContent.getInheritedMCID() : null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<? extends Object> getLinkedObjects(
String link) {
switch (link) {
case TAG:
return this.getTag();
return this.getLinkTag();
case PROPERTIES:
return this.getPropertiesDict();
case LANG:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public GFOp_BMC(List<COSBase> arguments, GFOpMarkedContent markedContent, String
public List<? extends Object> getLinkedObjects(String link) {
switch (link) {
case TAG:
return this.getTag();
return this.getLinkTag();
case PROPERTIES:
return this.getPropertiesDict();
default:
Expand All @@ -58,16 +58,14 @@ public List<? extends Object> getLinkedObjects(String link) {
}

@Override
public List<CosName> getTag() {
if (!this.arguments.isEmpty()) {
COSBase name = this.arguments.get(this.arguments.size() - 1);
if (name.getType() == COSObjType.COS_NAME) {
List<CosName> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new GFCosName((COSName) name));
return Collections.unmodifiableList(list);
}
}
return Collections.emptyList();
}
public COSName getTag() {
if (!this.arguments.isEmpty()) {
COSBase name = this.arguments.get(this.arguments.size() - 1);
if (name.getType() == COSObjType.COS_NAME) {
return (COSName) name;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public List<? extends Object> getLinkedObjects(
String link) {
switch (link) {
case TAG:
return this.getTag();
return this.getLinkTag();
case PROPERTIES:
return this.getPropertiesDict();
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,21 @@ public GFOp_MP(List<COSBase> arguments) {
}

@Override
public List<? extends Object> getLinkedObjects(
String link) {
public List<? extends Object> getLinkedObjects(String link) {
if (TAG.equals(link)) {
return this.getTag();
return this.getLinkTag();
}
return super.getLinkedObjects(link);
}

@Override
public List<CosName> getTag() {
public COSName getTag() {
if (!this.arguments.isEmpty()) {
COSBase name = this.arguments.get(this.arguments.size() - 1);
if (name.getType() == COSObjType.COS_NAME) {
List<CosName> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS);
list.add(new GFCosName((COSName) name));
return Collections.unmodifiableList(list);
return (COSName) name;
}
}
return Collections.emptyList();
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.verapdf.gf.model.impl.pd.gfse.contents;

import org.verapdf.as.ASAtom;
import org.verapdf.cos.COSName;
import org.verapdf.cos.COSObject;
import org.verapdf.cos.COSString;
import org.verapdf.gf.model.impl.operator.inlineimage.GFOp_EI;
Expand Down Expand Up @@ -140,11 +141,8 @@ public String getExtraContext() {

@Override
public String gettag() {
List<CosName> tag = operator.getTag();
if (tag != null && tag.size() != 0) {
return tag.get(0).getinternalRepresentation();
}
return null;
COSName tag = operator.getTag();
return tag != null ? tag.getString() : null;
}

@Override
Expand Down

0 comments on commit 1f20b95

Please sign in to comment.