Skip to content

Commit

Permalink
improved xjdf split
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-prosi committed Nov 15, 2024
1 parent 2b9ef8a commit 0ba2958
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 25 deletions.
36 changes: 34 additions & 2 deletions src/main/java/org/cip4/jdflib/extensions/ProcessXJDFSplit.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* The CIP4 Software License, Version 1.0
*
*
* Copyright (c) 2001-2020 The International Cooperation for the Integration of Processes in Prepress, Press and Postpress (CIP4). All rights reserved.
* Copyright (c) 2001-2024 The International Cooperation for the Integration of Processes in Prepress, Press and Postpress (CIP4). All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
Expand Down Expand Up @@ -41,8 +41,11 @@
import java.util.Vector;

import org.cip4.jdflib.core.AttributeName;
import org.cip4.jdflib.core.ElementName;
import org.cip4.jdflib.core.JDFConstants;
import org.cip4.jdflib.core.JDFResourceLink.EnumUsage;
import org.cip4.jdflib.core.VString;
import org.cip4.jdflib.datatypes.JDFIntegerList;
import org.cip4.jdflib.util.ContainerUtil;
import org.cip4.jdflib.util.StringUtil;

Expand Down Expand Up @@ -173,9 +176,10 @@ protected Vector<VString> splitTypes(final XJDFHelper root)
return null;
}
boolean hasProduct = false;
int pos = 0;
while (types.size() > 0)
{
final VString overlap = extractTypes(types);
final VString overlap = extractTypes(root, types, pos);
if (overlap.contains(XJDFConstants.Product))
{
ret.insertElementAt(overlap, 0);
Expand All @@ -185,6 +189,7 @@ protected Vector<VString> splitTypes(final XJDFHelper root)
{
ret.add(overlap);
}
pos += overlap.size();
}
if (!hasProduct && ret.size() > 1)
{
Expand All @@ -193,6 +198,33 @@ protected Vector<VString> splitTypes(final XJDFHelper root)
return ret.size() == 0 ? null : ret;
}

protected VString extractTypes(final XJDFHelper root, final VString types, final int pos)
{
final SetHelper niSet = root.getSet(ElementName.NODEINFO, EnumUsage.Input, null, pos);
if (niSet != null)
{
final JDFIntegerList cpi = niSet.getCombinedProcessIndex();
final VString found = new VString();
final int[] il = cpi.getIntArray();
int currentPos = pos;
for (final int ipos : il)
{
if (ipos == currentPos++)
{
found.add(types.get(ipos - pos));
}
else
{
return extractTypes(types);
}
}
for (int i = 0; i < il.length; i++)
types.remove(0);
return found;
}
return extractTypes(types);
}

/**
*
* @param types
Expand Down
35 changes: 14 additions & 21 deletions src/main/java/org/cip4/jdflib/resource/JDFPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* The CIP4 Software License, Version 1.0
*
*
* Copyright (c) 2001-2020 The International Cooperation for the Integration of Processes in Prepress, Press and Postpress (CIP4). All rights reserved.
* Copyright (c) 2001-2024 The International Cooperation for the Integration of Processes in Prepress, Press and Postpress (CIP4). All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
Expand Down Expand Up @@ -55,6 +55,7 @@
import org.cip4.jdflib.datatypes.VJDFAttributeMap;
import org.cip4.jdflib.extensions.XJDFConstants;
import org.cip4.jdflib.resource.JDFResource.EnumPartIDKey;
import org.cip4.jdflib.util.ContainerUtil;
import org.cip4.jdflib.util.StringUtil;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -152,9 +153,12 @@ public VString guessPartIDKeys()
return guessPartIDKeys(map);
}

private final static String[] partSequence = new String[] { AttributeName.SIGNATURENAME, AttributeName.SHEETNAME, AttributeName.SIDE, AttributeName.SEPARATION,
AttributeName.RUNSET, AttributeName.RUN };

public static VString guessPartIDKeys(final JDFAttributeMap map)
{
if (map == null || map.size() == 0)
if (ContainerUtil.isEmpty(map))
{
return null;
}
Expand All @@ -164,25 +168,13 @@ public static VString guessPartIDKeys(final JDFAttributeMap map)
}
final VString v = new VString();
final StringArray keys = map.getKeyList();
if (keys.contains(AttributeName.SIGNATURENAME))
{
v.add(AttributeName.SIGNATURENAME);
keys.remove(AttributeName.SIGNATURENAME);
}
if (keys.contains(AttributeName.SHEETNAME))
{
v.add(AttributeName.SHEETNAME);
keys.remove(AttributeName.SHEETNAME);
}
if (keys.contains(AttributeName.SIDE))
for (final String key : partSequence)
{
v.add(AttributeName.SIDE);
keys.remove(AttributeName.SIDE);
}
if (keys.contains(AttributeName.SEPARATION))
{
v.add(AttributeName.SEPARATION);
keys.remove(AttributeName.SEPARATION);
if (keys.contains(key))
{
v.add(key);
keys.remove(key);
}
}
v.addAll(keys);
return v;
Expand Down Expand Up @@ -284,7 +276,8 @@ public static boolean matchesPartVersion(final String resourceValue, final Strin
return false;

boolean b;
b = resourceValue.equals(linkValue) || KElement.isWildCard(resourceValue) || KElement.isWildCard(linkValue) || ALL.equalsIgnoreCase(linkValue) || ALL.equalsIgnoreCase(resourceValue);
b = resourceValue.equals(linkValue) || KElement.isWildCard(resourceValue) || KElement.isWildCard(linkValue) || ALL.equalsIgnoreCase(linkValue)
|| ALL.equalsIgnoreCase(resourceValue);
if (!b)
{
final int iResPos = resourceValue.indexOf(' ');
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/org/cip4/jdflib/extensions/ProcessXJDFSplitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import java.util.List;
import java.util.Vector;
import java.util.zip.DataFormatException;

import org.cip4.jdflib.JDFTestCaseBase;
import org.cip4.jdflib.auto.JDFAutoMedia.EnumMediaType;
Expand Down Expand Up @@ -466,6 +467,30 @@ void testSplitCategory()
d.write2File(sm_dirTestDataTemp + "splitxjdfCategory.jdf", 2, false);
}

/**
* @throws DataFormatException
*
*/
@Test
void testSplitNodeInfo() throws DataFormatException
{
final XJDFHelper h = new XJDFHelper("j1", "root", null);
h.setTypes("Screening ImageSetting ConventionalPrinting Cutting Folding Trimming");
h.appendSet(ElementName.NODEINFO, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("0 1"));
h.appendSet(ElementName.NODEINFO, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("2"));
h.appendSet(ElementName.NODEINFO, EnumUsage.Input).setCombinedProcessIndex(new JDFIntegerList("3 4 5"));

final ProcessXJDFSplit splitter = new ProcessXJDFSplit();

VString types = h.getTypes();
final VString t0 = splitter.extractTypes(h, types, 0);
assertEquals(2, t0.size());
final VString t1 = splitter.extractTypes(h, types, 2);
assertEquals(1, t1.size());
final VString t2 = splitter.extractTypes(h, types, 3);
assertEquals(3, t2.size());
}

/**
*
*/
Expand Down
20 changes: 18 additions & 2 deletions src/test/java/org/cip4/jdflib/resource/JDFPartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* The CIP4 Software License, Version 1.0
*
*
* Copyright (c) 2001-2022 The International Cooperation for the Integration of Processes in Prepress, Press and Postpress (CIP4). All rights reserved.
* Copyright (c) 2001-2024 The International Cooperation for the Integration of Processes in Prepress, Press and Postpress (CIP4). All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
Expand Down Expand Up @@ -86,6 +86,22 @@ void testSetPartMap()
assertEquals(part.getPartMap(), new JDFAttributeMap());
}

/**
*
*/
@Test
void testGuessPartIDKeys()
{
final JDFAttributeMap map = new JDFAttributeMap();
map.put("Option", "Back");
map.put("Run", "1");
part.setPartMap(map);
assertEquals(new VString("Run Option"), part.guessPartIDKeys());
map.put("SheetName", "S1");
part.setPartMap(map);
assertEquals(new VString("SheetName Run Option"), part.guessPartIDKeys());
}

/**
*
*/
Expand Down Expand Up @@ -119,7 +135,7 @@ void testPartIDConsistency()
final Iterator<EnumPartIDKey> it = EnumPartIDKey.iterator();
while (it.hasNext())
{
EnumPartIDKey next = it.next();
final EnumPartIDKey next = it.next();
if (!next.isXJDF())
{
final String name = next.getName();
Expand Down

0 comments on commit 0ba2958

Please sign in to comment.