Package org.exist.xquery.value

Examples of org.exist.xquery.value.AnyURIValue


                dataParams[2] = storeParam;
                entryDataFunctionResult = entryDataFunction.evalFunction(contextSequence, null, dataParams);
               
                String path = entryDataFunctionResult.itemAt(0).getStringValue();
               
                Collection root = new LocalCollection(context.getUser(), context.getBroker().getBrokerPool(), new AnyURIValue("/db").toXmldbURI(), context.getAccessContext());

          if (isDirectory){
                 
                  XMLDBAbstractCollectionManipulator.createCollection(root, path);
                 
View Full Code Here


    Sequence result;
    if (namespace == null)
            {result = Sequence.EMPTY_SEQUENCE;}           
        else
            {result = new AnyURIValue(namespace);}
           
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
       
        return result; 
View Full Code Here

            if (value.getImplementationType() == NodeValue.PERSISTENT_NODE) {
                final NodeProxy node = (NodeProxy) value;
                //Returns the empty sequence if the node is not a document node.
                if (node.isDocument()) {
                    final XmldbURI path = node.getDocument().getURI();
                    result = new AnyURIValue(path);
                }
            } else {
                if (value instanceof DocumentImpl &&
                    ((DocumentImpl)value).getDocumentURI() != null) {
                    result = new AnyURIValue(((DocumentImpl)value).getDocumentURI());
                }
            }
        }
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
View Full Code Here

        }
       
    if (contextItem != null)
        {contextSequence = contextItem.toSequence();}
   
    AnyURIValue base;   
    if (getArgumentCount() == 1) {
      if (!context.isBaseURIDeclared())
        {throw new XPathException(this, ErrorCodes.FONS0005,
          "base URI of the static context has not been assigned a value.");}
      base = context.getBaseURI();
    } else {
      try {
        final Item item = getArgument(1).eval(contextSequence).itemAt(0).convertTo(Type.ANY_URI);
        base = (AnyURIValue)item;
      } catch (final XPathException e) {
            throw new XPathException(this, ErrorCodes.FORG0002, "invalid argument to fn:resolve-uri(): " + e.getMessage(), null, e);
      }
    }
   
    Sequence result;

    final Sequence seq = getArgument(0).eval(contextSequence);
    if (seq.isEmpty()) {     
      result = Sequence.EMPTY_SEQUENCE;
    } else {
      AnyURIValue relative;
      try {
        final Item item = seq.itemAt(0).convertTo(Type.ANY_URI);
        relative = (AnyURIValue)item;
      } catch (final XPathException e) {       
            throw new XPathException(this, ErrorCodes.FORG0002, "invalid argument to fn:resolve-uri(): " + e.getMessage(), seq, e);
      }     
      URI relativeURI;
      URI baseURI;
      try {
        relativeURI = new URI(relative.getStringValue());
        baseURI = new URI(base.getStringValue() );
      } catch (final URISyntaxException e) {
        throw new XPathException(this, ErrorCodes.FORG0009, "unable to resolve a relative URI against a base URI in fn:resolve-uri(): " + e.getMessage(), null, e);
      }
      if (relativeURI.isAbsolute()) {
        result = relative;
            } else {
        result = new AnyURIValue(baseURI.resolve(relativeURI));
            }
        }
       
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
View Full Code Here

                //If the value of the default collection is undefined an error is raised [err:FODC0002].
                docs = context.getStaticallyKnownDocuments();
            } else {
                MutableDocumentSet ndocs = new DefaultDocumentSet();
                for (final String next : args) {
                    final XmldbURI uri = new AnyURIValue(next).toXmldbURI();
                    final Collection coll = context.getBroker().getCollection(uri);
                    if (coll == null) {
                        if (context.isRaiseErrorOnFailedRetrieval()) {
                            throw new XPathException("FODC0002: can not access collection '" + uri + "'");
                        }
View Full Code Here

            if(!Type.subTypeOf(item.getType(), Type.NODE))
                {throw new XPathException(this, ErrorCodes.XPTY0004, "Context item is not a node; got: " +
                        Type.getTypeName(item.getType()));}
            //TODO : how to improve performance ?
            final Node n = ((NodeValue)item).getNode();
            result = new AnyURIValue(n.getNamespaceURI());
        }
       
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
       
View Full Code Here

    if (args[0].isEmpty()) {
      return Sequence.EMPTY_SEQUENCE;
    }

    AnyURIValue picturePath = (AnyURIValue) args[0].itemAt(0);
    if (picturePath.getStringValue().startsWith("xmldb:exist://")) {
      picturePath = new AnyURIValue(picturePath.getStringValue()
          .substring(14));
    }

    AnyURIValue thumbPath = null;
    if (args[1].isEmpty()) {
      thumbPath = new AnyURIValue(picturePath.toXmldbURI().append(
          THUMBPATH));
      isSaveToDataBase = true;
    } else {
      thumbPath = (AnyURIValue) args[1].itemAt(0);
      if (thumbPath.getStringValue().startsWith("file:")) {
        isSaveToDataBase = false;
        thumbPath = new AnyURIValue(thumbPath.getStringValue().substring(5));
      } else {
        isSaveToDataBase = true;
        try {
          XmldbURI thumbsURI = XmldbURI.xmldbUriFor(thumbPath.getStringValue());
          if (!thumbsURI.isAbsolute())
            thumbsURI = picturePath.toXmldbURI().append(thumbPath.toString());
          thumbPath = new AnyURIValue(thumbsURI.toString());
        } catch (URISyntaxException e) {
          throw new XPathException(this, e.getMessage());
        }
      }
    }

    // result.add(new StringValue(picturePath.getStringValue()));
    // result.add(new StringValue(thumbPath.getStringValue() + " isDB?= "
    // + isSaveToDataBase));

    int maxThumbHeight = MAXTHUMBHEIGHT;
    int maxThumbWidth = MAXTHUMBWIDTH;

    if (!args[2].isEmpty()) {
      maxThumbHeight = ((IntegerValue) args[2].itemAt(0)).getInt();
      if (args[2].hasMany())
        maxThumbWidth = ((IntegerValue) args[2].itemAt(1)).getInt();
    }

    String prefix = THUMBPREFIX;

    if (!args[3].isEmpty()) {
      prefix = args[3].itemAt(0).getStringValue();

    }

    // result.add(new StringValue("maxThumbHeight = " + maxThumbHeight
    // + ", maxThumbWidth = " + maxThumbWidth));

    DBBroker dbbroker = context.getBroker();

    BrokerPool pool = null;
    try {
      pool = BrokerPool.getInstance();
    } catch (Exception e) {
      result.add(new StringValue(e.getMessage()));
      return result;
    }
    TransactionManager transact = pool.getTransactionManager();

    // Start transaction
    Txn transaction = transact.beginTransaction();

    Collection thumbCollection = null;
    File thumbDir = null;
    if (isSaveToDataBase) {
      try {
        thumbCollection = dbbroker.getOrCreateCollection(transaction,
            thumbPath.toXmldbURI());
        dbbroker.saveCollection(transaction, thumbCollection);
      } catch (Exception e) {
        throw new XPathException(this, e.getMessage());
      }
    } else {
      thumbDir = new File(thumbPath.toString());
      if (!thumbDir.isDirectory())
        try {
          thumbDir.mkdirs();
        } catch (Exception e) {
          throw new XPathException(this, e.getMessage());
        }

    }

                Collection allPictures = null;
                Collection existingThumbsCol = null;
                File[] existingThumbsArray = null;
                try {
                    allPictures = dbbroker.getCollection(picturePath.toXmldbURI());

                    if (allPictures == null) {
                            return Sequence.EMPTY_SEQUENCE;
                    }

                    if (isSaveToDataBase) {
                            existingThumbsCol = dbbroker.getCollection(thumbPath.toXmldbURI());
                    } else {
                            existingThumbsArray = thumbDir.listFiles(new FilenameFilter() {
                                    public boolean accept(File dir, String name) {
                                            return (name.endsWith(".jpeg") || name.endsWith(".jpg"));
                                    }
                            });
                    }
                } catch (PermissionDeniedException pde) {
                    throw new XPathException(pde.getMessage(), pde);
                }

    DocumentImpl docImage = null;
    BinaryDocument binImage = null;
    @SuppressWarnings("unused")
    BinaryDocument doc = null;
    BufferedImage bImage = null;
    @SuppressWarnings("unused")
    byte[] imgData = null;
    Image image = null;
    ByteArrayOutputStream os = null;

                try {
    Iterator<DocumentImpl> i = allPictures.iterator(dbbroker);

    while (i.hasNext()) {
      docImage = (DocumentImpl) i.next();
      // is not already existing??
      if (!((fileExist(context.getBroker(), existingThumbsCol, docImage, prefix)) || (fileExist(
          existingThumbsArray, docImage, prefix)))) {
        if (docImage.getResourceType() == DocumentImpl.BINARY_FILE)
          // TODO maybe extends for gifs too.
          if (docImage.getMetadata().getMimeType().startsWith(
              "image/jpeg")) {

            binImage = (BinaryDocument) docImage;

            // get a byte array representing the image

            try {
                                                   InputStream is = dbbroker.getBinaryResource(binImage);
              image = ImageIO.read(is);
            } catch (IOException ioe) {
              throw new XPathException(this,ioe.getMessage());
            }

            try {
              bImage = ImageModule.createThumb(image, maxThumbHeight,
                  maxThumbWidth);
            } catch (Exception e) {
              throw new XPathException(this, e.getMessage());
            }

            if (isSaveToDataBase) {
              os = new ByteArrayOutputStream();
              try {
                ImageIO.write(bImage, "jpg", os);
              } catch (Exception e) {
                throw new XPathException(this, e.getMessage());
              }
              try {
                doc = thumbCollection.addBinaryResource(
                    transaction, dbbroker,
                    XmldbURI.create(prefix
                        + docImage.getFileURI()), os
                        .toByteArray(), "image/jpeg");
              } catch (Exception e) {
                throw new XPathException(this, e.getMessage());
              }
              // result.add(new
              // StringValue(""+docImage.getFileURI()+"|"+thumbCollection.getURI()+THUMBPREFIX
              // + docImage.getFileURI()));
            } else {
              try {
                ImageIO
                    .write(
                        bImage,
                        "jpg",
                        new File(thumbPath.toString()
                            + "/" + prefix
                            + docImage.getFileURI()));
              } catch (Exception e) {
                throw new XPathException(this, e.getMessage());
              }
View Full Code Here

  public Sequence evalWithCollection(Collection collection, Sequence[] args, Sequence contextSequence)
  throws XPathException {

    try {
      final UserManagementService ums = (UserManagementService) collection.getService("UserManagementService", "1.0");
      final Resource res = collection.getResource(new AnyURIValue(args[1].getStringValue()).toXmldbURI().toString());
      if (res != null) {
        final String lockUser = ums.hasUserLock(res);
        if (lockUser != null && isCalledAs("clear-lock")) {
          ums.unlockResource(res);
        }
View Full Code Here

    this.errorIfAbsent = errorIfAbsent;
  }
 
  protected LocalCollection createLocalCollection(String name) throws XMLDBException {
    try {
      return new LocalCollection(context.getSubject(), context.getBroker().getBrokerPool(), new AnyURIValue(name).toXmldbURI(), context.getAccessContext());
    } catch(final XPathException e) {
      throw new XMLDBException(ErrorCodes.INVALID_URI,e);
    }
  }
View Full Code Here

        return child;
    }
   
    static public final Collection createCollectionPath(Collection parentColl, String relPath) throws XMLDBException, XPathException {
        Collection current = parentColl;
        final StringTokenizer tok = new StringTokenizer(new AnyURIValue(relPath).toXmldbURI().toString(), "/");
        while (tok.hasMoreTokens()) {
            final String token = tok.nextToken();
            current = createCollection(current, token);
        }
        return current;
View Full Code Here

TOP

Related Classes of org.exist.xquery.value.AnyURIValue

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.