/* nsISimpleEnumerator GetTargets (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue); */
NS_IMETHODIMP
nsRDFDataSourceDataSource::GetTargets(nsIRDFResource *aSource,
                                      nsIRDFResource *aProperty,
                                      bool aTruthValue,
                                      nsISimpleEnumerator **_retval)
{
  nsXPIDLCString sourceval;
  aSource->GetValue(getter_Copies(sourceval));
  nsXPIDLCString propval;
  aProperty->GetValue(getter_Copies(propval));
#ifdef DEBUG_alecf
  printf("GetTargets(%s, %s,..)\n", (const char*)sourceval,
         (const char*)propval);
#endif
  
  nsresult rv;
  bool isProp;
  nsCOMPtr<nsISupportsArray> arcs;
  nsISimpleEnumerator *enumerator;
  
  if (NS_SUCCEEDED(aProperty->EqualsNode(kNC_Child, &isProp)) &&
      isProp) {

    // here we need to determine if we need to extract out the source
    // or use aSource?
    if (StringBeginsWith(sourceval, NS_LITERAL_CSTRING("dsresource:"))) {
      // somehow get the source
      // XXX ? rv = mDataSource->ArcLabelsOut(realsource, &enumerator);      
      rv = mDataSource->ArcLabelsOut(aSource, &enumerator);      
    } else {
      rv = mDataSource->ArcLabelsOut(aSource, &enumerator);
    }
    // enumerate all the children and create the composite resources
    bool hasMoreArcs=false;

    rv = enumerator->HasMoreElements(&hasMoreArcs);
    while (NS_SUCCEEDED(rv) && hasMoreArcs) {
      
      // get the next arc
      nsCOMPtr<nsISupports> arcSupports;
      rv = enumerator->GetNext(getter_AddRefs(arcSupports));
      nsCOMPtr<nsIRDFResource> arc = do_QueryInterface(arcSupports, &rv);

      // get all the resources on the ends of the arc arcs
      nsCOMPtr<nsISimpleEnumerator> targetEnumerator;
      rv = mDataSource->GetTargets(aSource, arc, true,
                                   getter_AddRefs(targetEnumerator));

      bool hasMoreTargets;
      rv = targetEnumerator->HasMoreElements(&hasMoreTargets);
      while (NS_SUCCEEDED(rv) && hasMoreTargets) {
        // get the next target
        nsCOMPtr<nsISupports> targetSupports;
        rv = enumerator->GetNext(getter_AddRefs(targetSupports));
        nsCOMPtr<nsIRDFResource> target=do_QueryInterface(targetSupports, &rv);

        // now we have an (arc, target) tuple that will be our node
        // arc will become #Name
        // target will become #Value
#ifdef DEBUG_alecf
        nsXPIDLString arcValue;
        nsXPIDLString targetValue;

        arc->GetValue(getter_Copies(arcValue));
        target->GetValue(getter_Copies(targetValue));
        printf("#child of %s:\n\t%s = %s\n",
               (const char*)sourceval
#endif

      }
      
      rv = enumerator->HasMoreElements(&hasMoreArcs);
    }
    
  } else if (NS_SUCCEEDED(aProperty->EqualsNode(kNC_Name, &isProp)) &&
Ejemplo n.º 2
0
void rdf_printArcLabels(nsCOMPtr<nsIRDFResource> currentResource)
{
    if (!currentResource) {
        if (prLogModuleInfo) {
            PR_LOG(prLogModuleInfo, 3, ("resource: null\n"));
        }
        return;
    }
        
    nsCOMPtr<nsISimpleEnumerator> labels;
    nsCOMPtr<nsISupports> supportsResult;
    nsCOMPtr<nsIRDFResource> resourceResult;
    nsresult rv;
    PRBool result;
    const char *arcLabel;
    const char *currentResourceValue;

    rv = currentResource->GetValueConst(&currentResourceValue);
    if (NS_SUCCEEDED(rv)) {
        if (prLogModuleInfo) {
            PR_LOG(prLogModuleInfo, 3, 
                   ("resource: %s\n", currentResourceValue));
        }
    }
    else {
        if (prLogModuleInfo) {
            PR_LOG(prLogModuleInfo, 3, 
                   ("printArcLabels: can't get value from current resource.\n"));
        }
    }

    rv = gBookmarksDataSource->ArcLabelsOut(currentResource, 
                                            getter_AddRefs(labels));

    if (NS_FAILED(rv)) {
        if (prLogModuleInfo) {
            PR_LOG(prLogModuleInfo, 3, 
                   ("printArcLabels: currentResource has no outgoing arcs.\n"));
        }
        return;
    }
    
    rv = labels->HasMoreElements(&result);
    if (NS_FAILED(rv)) {
        if (prLogModuleInfo) {
            PR_LOG(prLogModuleInfo, 3, 
                   ("printArcLabels: can't get elements from currentResource's enum.\n"));
        }
        return;
    }

    while (result) {
        rv = labels->GetNext(getter_AddRefs(supportsResult));
        if (NS_FAILED(rv)) {
            if (prLogModuleInfo) {
                PR_LOG(prLogModuleInfo, 3, 
                       ("printArcLabels: Can't get next arc from enumerator.\n"));
            }
            return;
        }
        
        // make sure it's an RDFResource
        rv = supportsResult->QueryInterface(NS_GET_IID(nsIRDFResource), 
                                            getter_AddRefs(resourceResult));
        if (NS_SUCCEEDED(rv)) {
            rv = resourceResult->GetValueConst(&arcLabel);
            if (NS_SUCCEEDED(rv)) {
                if (prLogModuleInfo) {
                    PR_LOG(prLogModuleInfo, 3, 
                           ("\tarc label: %s\n", arcLabel));
                }
            }
            else {
                if (prLogModuleInfo) {
                    PR_LOG(prLogModuleInfo, 3, 
                           ("printArcLabels: can't get value from current arc.\n"));
                }
            }
        }
        else {
            if (prLogModuleInfo) {
                PR_LOG(prLogModuleInfo, 3, 
                       ("printArcLabels: next arc from enumerator is not an nsIRDFResource.\n"));
            }
        }
        rv = labels->HasMoreElements(&result);
        if (NS_FAILED(rv)) {
            if (prLogModuleInfo) {
                PR_LOG(prLogModuleInfo, 3, 
                       ("printArcLabels: can't get elements from currentResource's enum.\n"));
            }
            return;
        }
    }
}