Web API Reference | MapGuide Open Source

- Overview
- Modules
- Classes

ApplyResourcePackage
ChangeResourceOwner
CopyResource
DeleteResource
DeleteResourceData
EnumerateReferences
EnumerateResourceData
EnumerateResources
EnumerateResources
EnumerateUnmanagedData
GetRepositoryContent
GetRepositoryHeader
GetResourceContent
GetResourceData
GetResourceHeader
InheritPermissionsFrom
MoveResource
RenameResourceData
ResourceExists
SetResource
SetResourceData
UpdateRepository
virtual void MgResourceService::SetResource | ( | MgResourceIdentifier * | resource,
|  | MgByteReader * | content,
|  | MgByteReader * | header |
| ) |  |  | `[pure virtual]`
Adds a new resource to a resource repository, or updates an existing resource. .NET Syntax
`virtual void SetResource(MgResourceIdentifier resource, MgByteReader content, MgByteReader header);`
Java Syntax
`virtual void SetResource(MgResourceIdentifier resource, MgByteReader content, MgByteReader header);`
PHP Syntax
`virtual void SetResource(MgResourceIdentifier resource, MgByteReader content, MgByteReader header);`
  Parameters:
  | resource | (MgResourceIdentifier) Location where the resource will be placed in the repository. The extension of the location must match one of the types defined in MgResourceType . It is case sensitive. MapGuide Open Source will automatically create any folders required.
  | content | (MgByteReader) The resource content in XML format using the schema appropriate for the resource type. See XML Schemas . Or when updating an existing resource, this can be set to null, in which case the content is not changed.
  | header | (MgByteReader) The resource header in XML format. This uses ResourceFolderHeader_schema for folder resources and ResourceDocumentHeader for all other resources. Or, if you are updating an existing resource in the library, this can be set to null, in which case the permissions are set to be inherited from the parent folder.
Returns: Returns nothing. Example (PHP) To add a resource: 1) Prepare the resource's content XML file using the schema appropriate to the type. a) If the resource references other resources, use the `<uri>` elements to specify their paths in the repository. For example a map file, called World.MapDefinition, might look like this:
     <?xml version="1.0" encoding="UTF-8"?>
     <MapDefinition version="1.0.0">
       <Name>World</Name>
       <Layers>
         <Layer>
           <Name>Cities</Name>
           <ResourceId>Library://World/Layers/Cities.Layer</ResourceId>
         </Layer>
         <Layer>
           <Name>Countries</Name>
           <ResourceId>Library://World/Layers/Countries.Layer</ResourceId>
         </Layer>
       </Layers>
     </MapDefinition>
b) If the resource uses resource data, specify the path with `%MG_DATA_FILE_PATH%data_name` where `data_name` must match the name given to the associated data in step 5. It does not need to match the physical file name. The `%MG_DATA_FILE_PATH%` keyword specifies that the binary file, in this case a DWF, will be stored in the same folder as the XML file. For example, the content for a drawing source might look like this:
     <?xml version="1.0" encoding="UTF-8"?>
     <DrawingSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="DrawingSource-1.0.0.xsd">
         <SourceName>\%MG_DATA_FILE_PATH\%test.dwf</SourceName>
         <Password/>
         <CoordinateSpace>LL84</CoordinateSpace>
     </DrawingSource>
For more information on %MG_DATA_FILE_PATH% and other substitution tags, see MgResourceTag. 2) Prepare the resource's header XML file using the ResourceDocumentHeader schema.
     <?xml version="1.0" encoding="UTF-8"?>
     <ResourceDocumentHeader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="ResourceDocumentHeader-1.0.0.xsd">
         <Security>
             <Inherited>true</Inherited>
         </Security>
         <Dependency>
             <ResourceId>Library://World/Layers/Cities.LoadProcedure</ResourceId>
         </Dependency>
     </ResourceDocumentHeader>
3) Add the resource to the repository using those content and header files:
     $resourceID= new MgResourceIdentifier("Library://Geography/World.MapDefinition");

     $content  = "C:\Data\Maps\World.MapDefinition";
     $content_byteSource = new MgByteSource($content);
     $content_byteSource->setMimeType("text/xml");
     $content_byteReader = $content_byteSource->GetReader();

     $header   = "C:\Data\Maps\Resource\DocumentHeader.xml";
     $header_byteSource = new MgByteSource($header);
     $header_byteSource->setMimeType("text/xml");
     $header_byteReader = $header_byteSource->GetReader();

     // Assuming $resourceService is already initialized.
     $resourceService->SetResource($resourceID, $content_byteReader, $header_byteReader);
  4) If the resource references other resources, you must also add them. In the World.MapDefinition example above, you would add the XML file for Cities.Layer to the repository at the location `Library://World/Layers/Cities.Layer`. Similarly, you would add Countries.Layer to `Library://World/Layers/Countries.Layer`. 5) Set any necessary resource data. See SetResourceData. Exceptions:
  | MgInvalidResourceTypeException |
Note: You must be logged in as the Administrator or the resource's current owner to change the header. See also: GetResourceContent GetResourceHeader

Comments or suggestions? Send us feedback.