Package org.fao.geonet.kernel.schema

Examples of org.fao.geonet.kernel.schema.MetadataType


    String typeName = mdSchema.getElementType(el.getQualifiedName(),parentName);

        if(Log.isDebugEnabled(Geonet.EDITORADDELEMENT))
            Log.debug(Geonet.EDITORADDELEMENT,"#### - type name = " + typeName);

     MetadataType type = mdSchema.getTypeInfo(typeName);

        if(Log.isDebugEnabled(Geonet.EDITORADDELEMENT))
            Log.debug(Geonet.EDITORADDELEMENT,"#### - metadata tpe = " + type);

    //--- collect all children, adding the new one at the end of the others

    Vector<Element> children = new Vector<Element>();

    for(int i=0; i<type.getElementCount(); i++) {
      List<Element> list = getChildren(el, type.getElementAt(i));

            if(Log.isDebugEnabled(Geonet.EDITORADDELEMENT))
                Log.debug(Geonet.EDITORADDELEMENT,"####   - child of type " + type.getElementAt(i) + " list size = " + list.size());
            for (Element aChild : list) {
                children.add(aChild);
                if(Log.isDebugEnabled(Geonet.EDITORADDELEMENT))
                    Log.debug(Geonet.EDITORADDELEMENT, "####    - add child " + aChild.toString());
            }

      if (qname.equals(type.getElementAt(i)))
        children.add(child);
    }
    //--- remove everything and then add all collected children to the element to assure a correct position for the
    // new one
View Full Code Here


            Log.error(Geonet.EDITORADDELEMENT, "EditLib : Error parsing XML fragment " + fragment);
            throw new IllegalStateException("EditLib : Error when loading XML fragment, " + e.getMessage());
        }
       
        String typeName = mdSchema.getElementType(el.getQualifiedName(), parentName);
        MetadataType type = mdSchema.getTypeInfo(typeName);
       
        // --- collect all children, adding the new one at the end of the others
        Vector<Element> children = new Vector<Element>();
       
        for (int i = 0; i < type.getElementCount(); i++) {
            // Add existing children of all types
            List<Element> list = getChildren(el, type.getElementAt(i));
            if (qname.equals(type.getElementAt(i)) && removeExisting) {
                // Remove all existing children of the type of element to add
            } else {
                for (Element aList : list) {
                    children.add(aList);
                }
            }
            if (qname.equals(type.getElementAt(i)))
                children.add(fragElt);
        }
        // --- remove everything and then add all collected children to the element
        // --- to assure a correct position for the new one
        el.removeContent();
View Full Code Here

        // Nothing to fill - eg. gco:CharacterString
        if (isSimpleElement) {
            return;
        }
       
        MetadataType type = schema.getTypeInfo(schema.getElementType(elemName, parentName));
        boolean hasSuggestion = sugg.hasSuggestion(elemName, type.getElementList());
//        List<String> elementSuggestion = sugg.getSuggestedElements(elemName);
//        boolean hasSuggestion = elementSuggestion.size() != 0;
       
       
        if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
            Log.debug(Geonet.EDITORFILLELEMENT,"#### - Type:");
            Log.debug(Geonet.EDITORFILLELEMENT,"####   - name = " + type.getName());
            Log.debug(Geonet.EDITORFILLELEMENT,"####   - # attributes = " + type.getAttributeCount());
            Log.debug(Geonet.EDITORFILLELEMENT,"####   - # elements = " + type.getElementCount());
            Log.debug(Geonet.EDITORFILLELEMENT,"####   - # isOrType = " + type.isOrType());
            Log.debug(Geonet.EDITORFILLELEMENT,"####   - type = " + type);
            Log.debug(Geonet.EDITORFILLELEMENT,"#### - Has suggestion = " + hasSuggestion);
        }
       
       
        //-----------------------------------------------------------------------
        //--- handle attributes if mandatory or suggested
        //
        for(int i=0; i<type.getAttributeCount(); i++) {
            MetadataAttribute attr = type.getAttributeAt(i);
           
            if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
                Log.debug(Geonet.EDITORFILLELEMENT,"####   - " + i + " attribute = " + attr.name);
                Log.debug(Geonet.EDITORFILLELEMENT,"####     - required = " + attr.required);
                Log.debug(Geonet.EDITORFILLELEMENT,"####     - suggested = "+sugg.isSuggested(elemName, attr.name));
            }
           
            if (attr.required || sugg.isSuggested(elemName, attr.name)) {
                String value = "";
               
                if (attr.defValue != null) {
                    value = attr.defValue;
                    if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
                        Log.debug(Geonet.EDITORFILLELEMENT,"####     - value = " + attr.defValue);
                    }
                }
               
                String uname = getUnqualifiedName(attr.name);
                String ns     = getNamespace(attr.name, element, schema);
                String prefix = getPrefix(attr.name);
                if (!prefix.equals(""))
                    element.setAttribute(new Attribute(uname, value, Namespace.getNamespace(prefix,ns)));
                else
                    element.setAttribute(new Attribute(uname, value));
            }
        }
       
       
        //-----------------------------------------------------------------------
        //--- add mandatory children
        //
        //     isOrType if element has substitutes and one of them should be chosen
        if (!type.isOrType()) {
            for(int i=0; i<type.getElementCount(); i++) {
                String childName = type.getElementAt(i);
                boolean childIsMandatory = type.getMinCardinAt(i) > 0;
                boolean childIsSuggested = sugg.isSuggested(elemName, childName);
               
                if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
                    Log.debug(Geonet.EDITORFILLELEMENT,"####   - " + i + " element = " + childName);
                    Log.debug(Geonet.EDITORFILLELEMENT,"####     - suggested = " + childIsSuggested);
                    Log.debug(Geonet.EDITORFILLELEMENT,"####     - is mandatory = " + childIsMandatory);
                }
               
               
               
                if (childIsMandatory || childIsSuggested) {
                   
                    MetadataType elemType = schema.getTypeInfo(schema.getElementType(childName, elemName));
                    List<String> childSuggestion = sugg.getSuggestedElements(childName);
                    boolean childHasOneSuggestion = sugg.hasSuggestion(childName, elemType.getElementList()) && (CollectionUtils.intersection(elemType.getElementList(),childSuggestion).size()==1);
                    boolean childHasOnlyCharacterStringSuggestion = childSuggestion.size() == 1 && childSuggestion.contains("gco:CharacterString");
                   
                    if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
                        Log.debug(Geonet.EDITORFILLELEMENT,"####     - is or type = "+ elemType.isOrType());
                        Log.debug(Geonet.EDITORFILLELEMENT,"####     - has suggestion = "+ childHasOneSuggestion);
                        Log.debug(Geonet.EDITORFILLELEMENT,"####     - elem type list = " + elemType.getElementList());
                        Log.debug(Geonet.EDITORFILLELEMENT,"####     - suggested types list = " + sugg.getSuggestedElements(childName));
                    }
                   
                    //--- There can be 'or' elements with other 'or' elements inside them.
                    //--- In this case we cannot expand the inner 'or' elements so the
                    //--- only way to solve the problem is to avoid the creation of them
                    if (
                        schema.isSimpleElement(elemName, childName) ||  // eg. gco:Decimal
                        !elemType.isOrType() ||                         // eg. gmd:EX_Extent
                        (elemType.isOrType() && (                       // eg. depends on schema-suggestions.xml
                            childHasOneSuggestion ||                    //   expand the only one suggestion - TODO - this needs improvements
                            (childSuggestion.size() == 0 && elemType.getElementList().contains("gco:CharacterString")))
                                                                        //   expand element which have no suggestion
                                                                        // and have a gco:CharacterString substitute.
                                                                        // gco:CharacterString is the default.
                        )
                    ) {
                        // Create the element
                        String name   = getUnqualifiedName(childName);
                        String ns     = getNamespace(childName, element, schema);
                        String prefix = getPrefix(childName);
                       
                        Element child = new Element(name, prefix, ns);
                       
                        // Add it to the element
                        element.addContent(child);
                       
                        if (childHasOnlyCharacterStringSuggestion) {
                            child.addContent(new Element("CharacterString", Namespaces.GCO));
                        }
                       
                        // Continue ....
                        fillElement(schema, sugg, element, child);
                    } else {
                        // Logging some cases to avoid
                        if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
                            if (elemType.isOrType()) {
                                 if (elemType.getElementList().contains("gco:CharacterString")
                                         && !childHasOneSuggestion) {
                                    Log.debug(Geonet.EDITORFILLELEMENT,"####   - (INNER) Requested expansion of an OR element having gco:CharacterString substitute and no suggestion: " + element.getName());
                                 } else {
                                    Log.debug(Geonet.EDITORFILLELEMENT,"####   - WARNING (INNER): requested expansion of an OR element : " +childName);
                                }
View Full Code Here

    MetadataSchema mdSchema = scm.getSchema(schema);
    String chUQname = getUnqualifiedName(chName);
    String chPrefix = getPrefix(chName);
    String chNS     = getNamespace(chName, md, mdSchema);
    Element container = new Element(chUQname, chPrefix, chNS);
    MetadataType containerType = mdSchema.getTypeInfo(chName);
    for (int k=0;k<containerType.getElementCount();k++) { 
      String elemName = containerType.getElementAt(k);
            if(Log.isDebugEnabled(Geonet.EDITOR))
                Log.debug(Geonet.EDITOR,"    -- Searching for child "+elemName);
      List<Element> elems;
      if (elemName.contains(Edit.RootChild.GROUP)||
          elemName.contains(Edit.RootChild.SEQUENCE)||
View Full Code Here

 
    String name = md.getQualifiedName();
    String parentName = getParentNameFromChild(md);
    MetadataSchema mdSchema = scm.getSchema(schema);
    String typeName = mdSchema.getElementType(name,parentName);
    MetadataType thisType = mdSchema.getTypeInfo(typeName);

    if (thisType.hasContainers) {
      Vector<Content> holder = new Vector<Content>();
     
      for (int i=0;i<thisType.getElementCount();i++) {
        String chName = thisType.getElementAt(i);
        if (chName.contains(Edit.RootChild.CHOICE)||
            chName.contains(Edit.RootChild.GROUP)||
            chName.contains(Edit.RootChild.SEQUENCE)) {
          List<Element> elems = searchChildren(chName,md,schema);
          if (elems.size() > 0) {
View Full Code Here

    {
            if(Log.isDebugEnabled(Geonet.EDITOREXPANDELEMENT))
                Log.debug(Geonet.EDITOREXPANDELEMENT,"is simple element");
      return;
    }
    MetadataType type = schema.getTypeInfo(elemType);
        if(Log.isDebugEnabled(Geonet.EDITOREXPANDELEMENT))
            Log.debug(Geonet.EDITOREXPANDELEMENT,"Type = "+type);

    for (int i=0; i<type.getElementCount(); i++) {
      String childQName = type.getElementAt(i);

            if(Log.isDebugEnabled(Geonet.EDITOREXPANDELEMENT))
                Log.debug(Geonet.EDITOREXPANDELEMENT,"- childName = " + childQName);
      if (childQName == null) continue; // schema extensions cause null types; just skip

      String childName   = getUnqualifiedName(childQName);
      String childPrefix = getPrefix(childQName);
      String childNS     = getNamespace(childQName, md, schema);

            if(Log.isDebugEnabled(Geonet.EDITOREXPANDELEMENT)) {
                Log.debug(Geonet.EDITOREXPANDELEMENT,"- name      = " + childName);
                Log.debug(Geonet.EDITOREXPANDELEMENT,"- prefix    = " + childPrefix);
                Log.debug(Geonet.EDITOREXPANDELEMENT,"- namespace = " + childNS);
            }

      List<?> list = md.getChildren(childName, Namespace.getNamespace(childNS));
      if (list.size() == 0 && !(type.isOrType())) {
                if(Log.isDebugEnabled(Geonet.EDITOREXPANDELEMENT))
                    Log.debug(Geonet.EDITOREXPANDELEMENT,"- no children of this type already present");

        Element newElem = createElement(schema, elemName, childQName, childNS, type.getMinCardinAt(i), type.getMaxCardinAt(i));

        if (i == 0insertFirst(md, newElem);
        else {
          String prevQName = type.getElementAt(i-1);
          String prevName = getUnqualifiedName(prevQName);
          String prevNS   = getNamespace(prevQName, md, schema);
          insertLast(md, prevName, prevNS, newElem);
        }
      } else {
                if(Log.isDebugEnabled(Geonet.EDITOREXPANDELEMENT)){
                    Log.debug(Geonet.EDITOREXPANDELEMENT,"- " + list.size() + " children of this type already present");
                    Log.debug(Geonet.EDITOREXPANDELEMENT,"- min cardinality = " + type.getMinCardinAt(i));
                    Log.debug(Geonet.EDITOREXPANDELEMENT,"- max cardinality = " + type.getMaxCardinAt(i));
                }


        for (int j=0; j<list.size(); j++) {
          Element listChild = (Element) list.get(j);
          Element listElem  = listChild.getChild(Edit.RootChild.ELEMENT, Edit.NAMESPACE);
          listElem.setAttribute(new Attribute(Edit.Element.Attr.UUID, listChild.getQualifiedName()+"_"+UUID.randomUUID().toString()));
          listElem.setAttribute(new Attribute(Edit.Element.Attr.MIN, ""+type.getMinCardinAt(i)));
          listElem.setAttribute(new Attribute(Edit.Element.Attr.MAX, ""+type.getMaxCardinAt(i)));

          if (j > 0)
            listElem.setAttribute(new Attribute(Edit.Element.Attr.UP, Edit.Value.TRUE));

          if (j<list.size() -1)
            listElem.setAttribute(new Attribute(Edit.Element.Attr.DOWN, Edit.Value.TRUE));

          if (list.size() > type.getMinCardinAt(i))
            listElem.setAttribute(new Attribute(Edit.Element.Attr.DEL, Edit.Value.TRUE));

          if (j < type.getMaxCardinAt(i)-1)
            listElem.setAttribute(new Attribute(Edit.Element.Attr.ADD, Edit.Value.TRUE));
        }
        if (list.size() < type.getMaxCardinAt(i))
          insertLast(md, childName, childNS, createElement(schema, elemName, childQName, childNS, type.getMinCardinAt(i), type.getMaxCardinAt(i)));
      }
    }
    addAttribs(type, md, schema);
  }
View Full Code Here

  public Element createElement(String schema, Element child, Element parent) throws Exception {

    String childQName = child.getQualifiedName();

    MetadataSchema mds = scm.getSchema(schema);
    MetadataType mdt = getType(mds, parent);
   
    int min = -1, max = -1;

    for (int i=0; i<mdt.getElementCount(); i++) {
      if (childQName.equals(mdt.getElementAt(i))) {
        min = mdt.getMinCardinAt(i);
        max = mdt.getMaxCardinAt(i);
      }
    }
    return createElement(mds,parent.getQualifiedName(),child.getQualifiedName(), child.getNamespaceURI(), min, max);
  }
View Full Code Here

    String action = "replace"; // js adds new elements in place of this child
    if (!schema.isSimpleElement(qname,parent)) {
      String elemType = schema.getElementType(qname,parent);

      MetadataType type = schema.getTypeInfo(elemType);
      // Choice elements will be added if present in suggestion only.
      boolean useSuggestion = mdSugg.hasSuggestion(qname, type.getElementList());
     
      if (type.isOrType()) {
        // Here we handle elements with potential substitute suggested.
        // In most of the cases, elements have gco:CharacterString as one of the possible substitute.
        // gco:CharacterString is then used as a default substitute to use for those
        // elements. It could be a good idea to have that information in configuration file
        // (eg. like schema-substitute) in order to define the default substitute to use
        // for a type. TODO
        if (type.getElementList().contains("gco:CharacterString") && !useSuggestion) {
                    if(Log.isDebugEnabled(Geonet.EDITOR))
                        Log.debug(Geonet.EDITOR,"OR element having gco:CharacterString substitute and no suggestion: " + qname);

          Element newElem = createElement(schema, qname,
              "gco:CharacterString",
                            "http://www.isotc211.org/2005/gco", 1, 1);
          child.addContent(newElem);
        } else {
          action = "before"; // js adds new elements before this child
          for(int l=0; l<type.getElementCount(); l++) {
            String chElem = type.getElementAt(l);
            if (chElem.contains(Edit.RootChild.CHOICE)) {
              List<String> chElems = recurseOnNestedChoices(schema,chElem,parent);

                            for (String chElem1 : chElems) {
                                chElem = chElem1;
View Full Code Here

     * @throws Exception
     */
  private List<String> recurseOnNestedChoices(MetadataSchema schema,String chElem,String parent) throws Exception {
    List<String> chElems = new ArrayList<String>();
    String elemType = schema.getElementType(chElem,parent);
    MetadataType type = schema.getTypeInfo(elemType);
    for(int l=0; l<type.getElementCount(); l++) {
      String subChElem = type.getElementAt(l);
      if (subChElem.contains(Edit.RootChild.CHOICE)) {
        List<String> subChElems = recurseOnNestedChoices(schema,subChElem,chElem);
        chElems.addAll(subChElems);
      }
      else { chElems.add(subChElem); }
View Full Code Here

TOP

Related Classes of org.fao.geonet.kernel.schema.MetadataType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.