diff --git a/src/main/java/org/cip4/jdflib/core/KElement.java b/src/main/java/org/cip4/jdflib/core/KElement.java index 567045e46..34160cd22 100644 --- a/src/main/java/org/cip4/jdflib/core/KElement.java +++ b/src/main/java/org/cip4/jdflib/core/KElement.java @@ -224,7 +224,7 @@ public XMLDoc getOwnerDocument_KElement() } /** - * searches for the first attribute occurence in this element or any ancestors + * searches for the first attribute occurrence in this element or any ancestors * * @param attrib the attribute name * @param nameSpaceURI the XML-namespace @@ -238,7 +238,7 @@ public String getInheritedAttribute(final String attrib, final String nameSpaceU } /** - * searches for the first attribute occurence in this element or any ancestors + * searches for the first attribute occurrence in this element or any ancestors * * @param attrib the attribute name * @param nameSpaceURI the XML-namespace diff --git a/src/main/java/org/cip4/jdflib/extensions/XJDFSchemaWalker.java b/src/main/java/org/cip4/jdflib/extensions/XJDFSchemaWalker.java index 061475dc7..a5d1fac8e 100644 --- a/src/main/java/org/cip4/jdflib/extensions/XJDFSchemaWalker.java +++ b/src/main/java/org/cip4/jdflib/extensions/XJDFSchemaWalker.java @@ -2,7 +2,7 @@ * The CIP4 Software License, Version 1.0 * * - * Copyright (c) 2001-2010 The International Cooperation for the Integration of + * Copyright (c) 2001-2024 The International Cooperation for the Integration of * Processes in Prepress, Press and Postpress (CIP4). All rights * reserved. * @@ -68,35 +68,23 @@ */ package org.cip4.jdflib.extensions; -import java.io.File; import java.util.HashMap; +import java.util.Map; import org.cip4.jdflib.core.KElement; -import org.cip4.jdflib.core.XMLDoc; +import org.cip4.jdflib.datatypes.JDFAttributeMap; import org.cip4.jdflib.elementwalker.BaseElementWalker; import org.cip4.jdflib.elementwalker.BaseWalker; import org.cip4.jdflib.elementwalker.BaseWalkerFactory; -import org.cip4.jdflib.util.FileUtil; /** * - * most extremely very prototypical skeleton schema converter
- * TODO: we may want to simply generate from autoclasses rather than from the existing schema...
- * or forget the walker pattern and simply loop^ + * the old implementattion was obsolete this implementation extracts more data from the xml schema that can be injected into the json schema * - * Schema policies: Retain substitutiongroups (elements of resource/parameter) - * make local elements local - there is only one remaining element definition - * make attribute definitions local but retain global attribute type definitions - think about unique enumerations -probably local - * - * @author Dr. Rainer Prosi, Heidelberger Druckmaschinen AG - * - * June 3, 2009 - * @deprecated - schema is created with @see XJDFSchemaCreator */ -@Deprecated public class XJDFSchemaWalker extends BaseElementWalker { - protected HashMap newSchemaMap; + private final JDFAttributeMap typeMap; /** * @@ -104,42 +92,7 @@ public class XJDFSchemaWalker extends BaseElementWalker public XJDFSchemaWalker() { super(new BaseWalkerFactory()); - init(); - } - - /** - * @param in - * @param out - * @throws IllegalArgumentException if no output is declared - */ - public void newFile(final File in, final File out) - { - if (!in.canRead()) - { - throw new IllegalArgumentException("need a valid input file"); - } - if (!out.canWrite()) - { - FileUtil.createNewFile(out); - if (!out.canWrite()) - { - throw new IllegalArgumentException("need a valid output file"); - } - } - final XMLDoc dIn = XMLDoc.parseFile(in); - final KElement rootIn = dIn.getRoot(); - final XMLDoc dOut = new XMLDoc(rootIn.getNodeName(), rootIn.getNamespaceURI()); - final KElement rootOut = dOut.getRoot(); - walkTree(rootIn, rootOut); - dOut.write2File(out, 2, false); - } - - /** - * - */ - private void init() - { - newSchemaMap = new HashMap(); + typeMap = new JDFAttributeMap(); } /** @@ -149,7 +102,6 @@ private void init() */ protected class WalkElement extends BaseWalker { - @SuppressWarnings("synthetic-access") public WalkElement() { super(getFactory()); @@ -163,21 +115,20 @@ public WalkElement() @Override public KElement walk(final KElement in, final KElement out) { - final KElement eNew = out.copyElement(in, null); - eNew.removeChildren(null, null, null); - return eNew; + return in; } } /** * any matching class will be removed with extreme prejudice... + * * @author Rainer Prosi, Heidelberger Druckmaschinen * */ - protected class WalkIgnore extends WalkElement + protected class WalkAttribute extends WalkElement { - public WalkIgnore() + public WalkAttribute() { super(); } @@ -187,8 +138,12 @@ public WalkIgnore() * @return true if must continue */ @Override - public KElement walk(final KElement jdf, final KElement xjdf) + public KElement walk(final KElement a, final KElement xjdf) { + final String typ = a.getNonEmpty("type"); + final String parent = a.getParentNode_KElement().getInheritedAttribute("name", null, null); + final String name = a.getNonEmpty("name"); + typeMap.putNotNull(parent + "/" + name, typ); return null; } @@ -200,65 +155,81 @@ public KElement walk(final KElement jdf, final KElement xjdf) @Override public boolean matches(final KElement toCheck) { - final String elmName = toCheck.getLocalName(); - if (elmName == null) - { - return false; - } - if ("complexType".equals(elmName)) - { - final String name = toCheck.getAttribute("name"); - boolean b = name.endsWith("_rp"); - b = b || name.endsWith("_r"); - return b; - } - if ("element".equals(elmName)) + return "xs:attribute".equals(toCheck.getNodeName()); + } + } + + public JDFAttributeMap getTypeMap() + { + return typeMap; + } + + public Map getLengthMap() + { + final Map ret = new HashMap<>(); + for (final String key : typeMap.getKeyList()) + { + final int l = getLength(key); + if (l > 0) { - final String name = toCheck.getAttribute("name"); - boolean b = name.equals("Identical"); - b = b || name.endsWith("Update"); - return b; + ret.put(key, Integer.valueOf(l)); } - if ("xs:annotation".equals(elmName)) + } + return ret; + } + + public int getLength(final String path) + { + final String typ = typeMap.get(path); + if (typ != null) + switch (typ) { - return true; + case "XYPair": + return 2; + case "shape": + case "LabColor": + case "sRGBColor": + return 3; + case "rectangle": + case "CMYKColor": + return 4; + case "matrix": + return 6; + default: } - return false; - } + return 0; + } - /** - * any matching class will be removed with extreme prejudice... - * @author Rainer Prosi, Heidelberger Druckmaschinen - * - */ - protected class WalkComplexType extends WalkElement + public Integer getMin(final String path) { + final String typ = typeMap.get(path); + if (typ != null) + switch (typ) + { + case "shape": + case "sRGBColor": + case "CMYKColor": + return 0; + default: + } + return null; - public WalkComplexType() - { - super(); - } + } - /** - * @param xjdf - * @return true if must continue - */ - @Override - public KElement walk(final KElement jdf, final KElement xjdf) - { - return null; - } + public Integer getMax(final String path) + { + final String typ = typeMap.get(path); + if (typ != null) + switch (typ) + { + case "sRGBColor": + case "CMYKColor": + return 1; + default: + } + return null; - /** - * @see org.cip4.jdflib.elementwalker.BaseWalker#matches(org.cip4.jdflib.core.KElement) - * @param toCheck - * @return true if it matches - */ - @Override - public boolean matches(final KElement toCheck) - { - return "xs:complexType".equals(toCheck.getLocalName()); - } } + }