/*************************************************************************** $RCSfile: xsd_list.c,v $ ------------------- cvs : $Id: xsd_list.c,v 1.3 2004/12/22 17:02:04 aquamaniac Exp $ begin : Sat Jun 28 2003 copyright : (C) 2003 by Martin Preuss email : martin@libchipcard.de *************************************************************************** * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * * MA 02111-1307 USA * * * ***************************************************************************/ #ifdef HAVE_CONFIG_H # include #endif /*#define DISABLE_DEBUGLOG */ #include "xsd_p.h" #include "xml_l.h" #include "gwenhywfar/debug.h" #include "gwenhywfar/misc.h" #include "gwenhywfar/text.h" #include #include #include #include #include #ifdef HAVE_SYS_STAT_H # include #endif #ifdef HAVE_FCNTL_H # include #endif #include #include int GWEN_XSD__ListSequence(GWEN_XSD_ENGINE *e, GWEN_XMLNODE *n, GWEN_BUFFER *outBuffer, int indent){ GWEN_XMLNODE *nn; int i; nn=GWEN_XMLNode_GetFirstTag(n); while(nn) { const char *tagName; int minOccur; int maxOccur; const char *x; char numbuf[16]; assert(n); x=GWEN_XMLNode_GetProperty(n, "minOccurs", "1"); if (1!=sscanf(x, "%i", &minOccur)) { if (strcasecmp(x, "unbounded")==0) minOccur=0; else { DBG_ERROR(GWEN_LOGDOMAIN, "Bad minOccurrs property"); return -1; } } x=GWEN_XMLNode_GetProperty(n, "maxOccurs", "1"); if (1!=sscanf(x, "%i", &maxOccur)) { if (strcasecmp(x, "unbounded")==0) maxOccur=0; else { DBG_ERROR(GWEN_LOGDOMAIN, "Bad maxOccurrs property"); return -1; } } tagName=GWEN_XMLNode_GetData(nn); assert(tagName); GWEN_Buffer_AppendString(outBuffer, "\n"); for (i=0; irootNode, nType, xpath); DBG_ERROR(GWEN_LOGDOMAIN, "Undeclared type in \"%s\"", GWEN_Buffer_GetStart(xpath)); GWEN_Buffer_free(xpath); return -1; } } if (isSimple==1) { int i; int rv; GWEN_XSD_FACETS *xf; const char *p; /* simple type */ xf=GWEN_XSD_Facets_new(); rv=GWEN_XSD__GetTypeFacets(e, nType, xf); if (rv) { GWEN_XSD_Facets_free(xf); DBG_INFO(GWEN_LOGDOMAIN, "here"); return rv; } for (i=0; ibaseType) { for (i=0; ibaseType, ':'); if (p) p++; else p=xf->baseType; GWEN_Buffer_AppendByte(outBuffer, '\"'); GWEN_Buffer_AppendString(outBuffer, p); GWEN_Buffer_AppendByte(outBuffer, '\"'); } else GWEN_Buffer_AppendString(outBuffer, "(unknown)"); GWEN_Buffer_AppendByte(outBuffer, ' '); GWEN_Buffer_AppendString(outBuffer, "\n"); /* facets */ for (i=0; ilength) { char numbuf[16]; for (i=0; ilength); GWEN_Buffer_AppendString(outBuffer, numbuf); GWEN_Buffer_AppendString(outBuffer, "\n"); } /* minLength */ if (xf->minLength) { char numbuf[16]; for (i=0; iminLength); GWEN_Buffer_AppendString(outBuffer, numbuf); GWEN_Buffer_AppendString(outBuffer, "\n"); } /* maxLength */ if (xf->maxLength) { char numbuf[16]; for (i=0; imaxLength); GWEN_Buffer_AppendString(outBuffer, numbuf); GWEN_Buffer_AppendString(outBuffer, "\n"); } /* maxInclusive */ if (xf->maxInclusive) { char numbuf[16]; for (i=0; imaxInclusive); GWEN_Buffer_AppendString(outBuffer, numbuf); GWEN_Buffer_AppendString(outBuffer, "\n"); } /* maxExclusive */ if (xf->maxExclusive) { char numbuf[16]; for (i=0; imaxExclusive); GWEN_Buffer_AppendString(outBuffer, numbuf); GWEN_Buffer_AppendString(outBuffer, "\n"); } /* minInclusive */ if (xf->minInclusive) { char numbuf[16]; for (i=0; iminInclusive); GWEN_Buffer_AppendString(outBuffer, numbuf); GWEN_Buffer_AppendString(outBuffer, "\n"); } /* minExclusive */ if (xf->minExclusive) { char numbuf[16]; for (i=0; iminExclusive); GWEN_Buffer_AppendString(outBuffer, numbuf); GWEN_Buffer_AppendString(outBuffer, "\n"); } /* totalDigits */ if (xf->totalDigits) { char numbuf[16]; for (i=0; itotalDigits); GWEN_Buffer_AppendString(outBuffer, numbuf); GWEN_Buffer_AppendString(outBuffer, "\n"); } /* fractionDigits */ if (xf->fractionDigits) { char numbuf[16]; for (i=0; ifractionDigits); GWEN_Buffer_AppendString(outBuffer, numbuf); GWEN_Buffer_AppendString(outBuffer, "\n"); } /* enumeration */ if (GWEN_StringList_Count(xf->enumeration)) { GWEN_STRINGLISTENTRY *se; for (i=0; ienumeration); assert(se); while(se) { const char *el; el=GWEN_StringListEntry_Data(se); assert(el); for (i=0; ipattern)) { GWEN_STRINGLISTENTRY *se; for (i=0; ipattern); assert(se); while(se) { const char *el; el=GWEN_StringListEntry_Data(se); assert(el); for (i=0; irootNode, nElement, xpath); DBG_ERROR(GWEN_LOGDOMAIN, "Undeclared element in \"%s\"", GWEN_Buffer_GetStart(xpath)); GWEN_Buffer_free(xpath); return -1; } } rv=GWEN_XSD__ListElementType(e, nElement, nType, eName, outBuffer, indent); if (rv) return rv; return 0; } int GWEN_XSD__ListGroupTypes(GWEN_XSD_ENGINE *e, GWEN_XMLNODE *nGroup, GWEN_BUFFER *outBuffer, int indent){ int rv; const char *eName; eName=GWEN_XMLNode_GetProperty(nGroup, "name", 0); if (eName) { int i; const char *p; for (i=0; inameSpaces, nameSpace); if (!ns) { DBG_ERROR(GWEN_LOGDOMAIN, "Namespace \"%s\" not found", nameSpace); return -1; } nbuf=GWEN_Buffer_new(0, 32, 0, 1); GWEN_Buffer_AppendString(nbuf, ns->id); GWEN_Buffer_AppendString(nbuf, ":"); GWEN_Buffer_AppendString(nbuf, name); rv=GWEN_XSD__ListTypes(e, GWEN_Buffer_GetStart(nbuf), outBuffer, 0); GWEN_Buffer_free(nbuf); return rv; }