Examples of AnyURIValue


Examples of net.sf.saxon.value.AnyURIValue

            // Michael Kay's done the heavy lifting and made the method public, so let's just
            // do that!
            try {
                URI abs = net.sf.saxon.functions.ResolveURI.makeAbsolute(relativeURI, baseURI);
                String resolvedURI = abs.toASCIIString();
                return new AnyURIValue(resolvedURI);
            } catch (URISyntaxException use) {
                throw new XProcException(use);
            }
        }
View Full Code Here

Examples of net.sf.saxon.value.AnyURIValue

            }

            // In 0.9.20, I removed the trailing slash from cwd().
            // The community didn't like that, so I put it back.
            String cwd = runtime.getStaticBaseURI().toASCIIString();
            return new AnyURIValue(cwd);
        }
View Full Code Here

Examples of net.sf.saxon.value.AnyURIValue

                NodeInfo item = (NodeInfo) xPathContext.getContextItem();
                baseURI = item.getBaseURI();
            }

            if (baseURI == null) {
                return new AnyURIValue("");
            }

            return new AnyURIValue(baseURI);
        }
View Full Code Here

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

Examples of org.exist.xquery.value.AnyURIValue

    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

Examples of org.exist.xquery.value.AnyURIValue

            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

Examples of org.exist.xquery.value.AnyURIValue

        }
       
    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

Examples of org.exist.xquery.value.AnyURIValue

                //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

Examples of org.exist.xquery.value.AnyURIValue

            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

Examples of org.exist.xquery.value.AnyURIValue

    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
TOP
Copyright © 2018 www.massapi.com. 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.