
org.cip4.jdflib.extensions.XJMFHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JDFLibJ Show documentation
Show all versions of JDFLibJ Show documentation
CIP4 JDF Library for JDF 1.x
/*
* The CIP4 Software License, Version 1.0
*
*
* Copyright (c) 2001-2023 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:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the The International Cooperation for
* the Integration of Processes in Prepress, Press and Postpress (www.cip4.org)" Alternately, this acknowledgment mrSubRefay appear in the software itself, if and wherever such third-party
* acknowledgments normally appear.
*
* 4. The names "CIP4" and "The International Cooperation for the Integration of Processes in Prepress, Press and Postpress" must not be used to endorse or promote products derived from this software
* without prior written permission. For written permission, please contact [email protected].
*
* 5. Products derived from this software may not be called "CIP4", nor may "CIP4" appear in their name, without prior writtenrestartProcesses() permission of the CIP4 organization
*
* Usage of this software in commercial products is subject to restrictions. For details please consult [email protected].
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE INTERNATIONAL COOPERATION FOR THE INTEGRATION OF PROCESSES IN PREPRESS, PRESS AND POSTPRESS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIrSubRefAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. ====================================================================
*
* This software consists of voluntary contributions made by many individuals on behalf of the The International Cooperation for the Integration of Processes in Prepress, Press and Postpress and was
* originally based on software restartProcesses() copyright (c) 1999-2001, Heidelberger Druckmaschinen AG copyright (c) 1999-2001, Agfa-Gevaert N.V.
*
* For more information on The International Cooperation for the Integration of Processes in Prepress, Press and Postpress , please see .
*
*/
package org.cip4.jdflib.extensions;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.cip4.jdflib.core.AttributeName;
import org.cip4.jdflib.core.JDFDoc;
import org.cip4.jdflib.core.JDFElement.EnumVersion;
import org.cip4.jdflib.core.KElement;
import org.cip4.jdflib.core.XMLDoc;
import org.cip4.jdflib.extensions.MessageHelper.EFamily;
import org.cip4.jdflib.extensions.xjdfwalker.IDRemover;
import org.cip4.jdflib.jmf.JDFMessage.EnumFamily;
import org.cip4.jdflib.jmf.JDFMessage.EnumType;
import org.cip4.jdflib.util.EnumUtil;
import org.cip4.jdflib.util.StringUtil;
public class XJMFHelper extends MessagePoolHelper
{
/**
*
* @param pool
*/
public XJMFHelper(final KElement pool)
{
super(pool);
}
/**
*
* default version - currently 2.0
*/
public void setVersion(final EnumVersion v)
{
setAttribute(AttributeName.VERSION, v == null ? XJDFHelper.defaultVersion().getName() : v.getName());
}
/**
*
* @return
*/
public List getMessageHelpers(final EFamily family)
{
final List vA = getMessageHelpers();
final List vM = new ArrayList<>();
for (final MessageHelper mh : vA)
{
if (family == null || family.equals(mh.getEFamily()))
vM.add(mh);
}
return vM;
}
/**
*
* @param pool
*/
public XJMFHelper()
{
super(null);
newXJMF(getDefaultVersion());
}
/**
* @return
*
*/
public XJMFHelper newXJMF(final EnumVersion v)
{
final JDFDoc doc = new JDFDoc(XJDFConstants.XJMF, v);
doc.setInitOnCreate(false);
theElement = doc.getRoot();
if (EnumUtil.aLessThanB(EnumVersion.Version_2_0, v))
{
theElement.setAttribute(AttributeName.VERSION, v.getName());
}
cleanUp();
return this;
}
/**
*
* @param family
* @param typ
* @return
*/
public MessageHelper appendMessage(final EnumFamily family, final EnumType typ)
{
if (family == null || typ == null)
return null;
return appendMessage(getMessageName(family, typ.getName()));
}
/**
*
* @param family
* @param typ
* @return
*/
public MessageHelper getCreateMessage(final EnumFamily family, final EnumType typ, int iSkip)
{
if (family == null || typ == null)
return null;
return getCreateMessage(getMessageName(family, typ.getName()), iSkip);
}
/**
*
* @param family
* @param typ
* @return
*/
public MessageHelper appendMessage(final EnumFamily family, final String typ)
{
final String messageName = getMessageName(family, typ);
return messageName == null ? null : appendMessage(messageName);
}
/**
*
* @param family
* @param typ
* @return
*/
String getMessageName(final EnumFamily family, final String typ)
{
if (StringUtil.isEmpty(typ) || family == null || EnumFamily.Acknowledge.equals(family) || EnumFamily.Registration.equals(family))
return null;
return family.getName() + typ;
}
/**
* @param file
* @return
*/
public boolean writeToFile(final String file)
{
cleanUp();
final boolean b = getRoot().getOwnerDocument_KElement().write2File(file, 2, false);
return b;
}
/**
* get the header of this - create if not there yet
*
* @return
*/
public KElement getHeader()
{
return MessageHelper.ensureHeader(theElement);
}
/**
*
* @see org.cip4.jdflib.extensions.BaseXJDFHelper#cleanUp()
*/
@Override
public void cleanUp()
{
super.cleanUp();
MessageHelper.ensureHeader(theElement);
new IDRemover().removeIDs(theElement);
}
/**
* @param os
* @throws IOException
*/
public void writeToStream(final OutputStream os) throws IOException
{
cleanUp();
getRoot().getOwnerDocument_KElement().write2Stream(os, 2, false);
}
/**
* factory to create a helper from an element
*
* @param root the element to parse if not an XJDF - search in ancestors of element
* @return the helper
*/
public static XJMFHelper getHelper(KElement root)
{
if (root == null)
return null;
if (!root.getLocalName().equals(XJDFConstants.XJMF))
root = root.getDeepParent(XJDFConstants.XJMF, 0);
return (root != null) ? new XJMFHelper(root) : null;
}
/**
*
* @param fileName
* @return
*/
public static XJMFHelper parseFile(final String fileName)
{
return getHelper(JDFDoc.parseFile(fileName));
}
/**
*
* @param fileName
* @return
*/
public static XJMFHelper parseFile(final File file)
{
return getHelper(JDFDoc.parseFile(file));
}
/**
* factory to create a helper from a doc
*
* @param doc the xmldoc to parse
* @return the helper
*/
public static XJMFHelper getHelper(final XMLDoc doc)
{
if (doc == null)
return null;
final KElement root = doc.getRoot();
return getHelper(root);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy