Package org.fao.geonet.kernel.schema

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


    String xmlData = metadata.getData();
    Element metadataXml = Xml.loadString(xmlData, false);

    if (!isIndexingTask) {
            ServiceContext context = ServiceContext.get();
            MetadataSchema mds = _dataManager.getSchema(metadata.getDataInfo().getSchemaId());

            // Check if a filter is defined for this schema
            // for the editing operation ie. user who can not edit
            // will not see those elements.
            Pair<String, Element> editXpathFilter = mds.getOperationFilter(ReservedOperation.editing);
            boolean filterEditOperationElements = editXpathFilter != null;
            List<Namespace> namespaces = mds.getNamespaces();
            if(context != null) {
                GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
                AccessManager am = gc.getBean(AccessManager.class);
                if (editXpathFilter != null) {
                    boolean canEdit = am.canEdit(context, id);
                    if(canEdit) {
                        filterEditOperationElements = false;
                    }
                }
                Pair<String, Element> downloadXpathFilter = mds.getOperationFilter(ReservedOperation.download);
                if (downloadXpathFilter != null) {
                    boolean canDownload = am.canDownload(context, id);
                    if(!canDownload) {
                        removeFilteredElement(metadataXml, downloadXpathFilter, namespaces);
                    }
                }
                Pair<String, Element> dynamicXpathFilter = mds.getOperationFilter(ReservedOperation.dynamic);
                if (dynamicXpathFilter != null) {
                    boolean canDynamic = am.canDynamic(context, id);
                    if(!canDynamic) {
                      removeFilteredElement(metadataXml, dynamicXpathFilter, namespaces);
                    }
View Full Code Here


      Schema schema = hmSchemas.get(name);

      if (schema == null)
        throw new IllegalArgumentException("Schema not registered : " + name);

      final MetadataSchema mds = schema.getMetadataSchema();
      return mds;
    } finally {
      afterRead();
    }
  }
View Full Code Here

      Schema schema = hmSchemas.get(name);

      if (schema == null)
        throw new IllegalArgumentException("Schema not registered : " + name);

      MetadataSchema mds = schema.getMetadataSchema();
      return mds.getNS(prefix);
    } finally {
      afterRead();
    }
  }
View Full Code Here

      Schema schema = hmSchemas.get(name);

      if (schema == null)
        throw new IllegalArgumentException("Schema not registered : " + name);

      MetadataSchema mds = schema.getMetadataSchema();
      StringBuilder sb = new StringBuilder();
      for (Namespace ns : mds.getSchemaNS()) {
        if (ns.getPrefix().length() != 0 && ns.getURI().length() != 0) {
          sb.append("xmlns:"+ns.getPrefix()+"=\""+ns.getURI()+"\" ");
        }
      }
      return sb.toString().trim();
View Full Code Here

   */
  private String checkNamespace(Element md, String schema) {
    String result = null;

    try {
      MetadataSchema mds = getSchema(schema);
      if (mds != null) {
        String primeNs = mds.getPrimeNS();
                if(Log.isDebugEnabled(Geonet.SCHEMA_MANAGER))
                    Log.debug(Geonet.SCHEMA_MANAGER,"  primeNs "+primeNs+" for schema "+schema);
        if (md.getNamespace().getURI().equals(primeNs)) {
          result = schema;
        } else {
View Full Code Here

            Xml.resetResolver();
        }

        SchematronRepository schemaRepo = applicationContext.getBean(SchematronRepository.class);
        SchematronCriteriaGroupRepository criteriaGroupRepository = applicationContext.getBean(SchematronCriteriaGroupRepository.class);
        MetadataSchema mds = new SchemaLoader().load(xmlSchemaFile, xmlSubstitutionsFile, schemaRepo, criteriaGroupRepository);

        mds.setName(name);
        mds.setSchemaDir(path);
        mds.loadSchematronRules(basePath);

        // -- add cached xml files (schema codelists and label files)
        // -- as Jeeves XmlFile objects (they need not exist)

        String base = fromAppPath + name + FS + "loc";
        Map<String, XmlFile> xfMap = new HashMap<String, XmlFile>();

        for (String fname : fnames) {
            String filePath = path + FS + "loc" + FS + defaultLang + FS + fname;
            if (Log.isDebugEnabled(Geonet.SCHEMA_MANAGER))
                Log.debug(Geonet.SCHEMA_MANAGER, "Searching for " + filePath);
            if (new File(filePath).exists()) {
                Element config = new Element("xml");
                config.setAttribute("name", name);
                config.setAttribute("base", base);
                config.setAttribute("file", fname);
                if (Log.isDebugEnabled(Geonet.SCHEMA_MANAGER))
                    Log.debug(Geonet.SCHEMA_MANAGER, "Adding XmlFile " + Xml.getString(config));
                XmlFile xf = new XmlFile(config, defaultLang, true);
                xfMap.put(fname, xf);
            } else {
                Log.warning(Geonet.SCHEMA_MANAGER, "Unable to load loc file: " + filePath);
            }
        }


        Pair<String, String> idInfo = extractIdInfo(xmlIdFile, name);

        mds.setReadwriteUUID(extractReadWriteUuid(xmlIdFile));
        mds.setOperationFilters(extractOperationFilters(xmlIdFile));
        Log.debug(Geonet.SCHEMA_MANAGER, "  UUID is read/write mode: " + mds.isReadwriteUUID());

        putSchemaInfo(
                name,
                idInfo.one(), // uuid of schema
                idInfo.two(), // version of schema
View Full Code Here

        String schema = metadata.getDataInfo().getSchemaId();
        if (schema.contains("iso19139") && !schema.equals("iso19139")) {
            // ie. this is an ISO profil.
            GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
            DataManager dm = gc.getBean(DataManager.class);
            MetadataSchema metadataSchema = dm.getSchema(schema);
            String path = metadataSchema.getSchemaDir() + "/convert/to19139.xsl";

            String data19139 = formatData(metadata, true, path);
            return Collections.singleton(Pair.read(FILE_METADATA_19139, data19139));
        }
View Full Code Here

     * @throws Exception
     * @throws IllegalStateException Fail to parse the fragment.
     */
    public void addFragment(String schema, Element el, String qname, String fragment, boolean removeExisting) throws Exception {
       
        MetadataSchema mdSchema = scm.getSchema(schema);
        String parentName = getParentNameFromChild(el);
        Element fragElt;

        if(Log.isDebugEnabled(Geonet.EDITORADDELEMENT))
            Log.debug(Geonet.EDITORADDELEMENT, "Add XML fragment for element name:" + qname + ", parent: " + parentName);
       
        try {
            fragElt = Xml.loadString(fragment, false);
        }
        catch (JDOMException e) {
            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++) {
View Full Code Here

    //

        boolean hasContent = false;
    Vector<Element> holder = new Vector<Element>();

    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;
View Full Code Here

            expandElements(schema, child);
        }
 
    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++) {
View Full Code Here

TOP

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

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.