From: Wolfgang M. M. <wol...@us...> - 2004-07-27 16:38:10
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/storage/serializers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31309/src/org/exist/storage/serializers Modified Files: Serializer.java Log Message: Fixed: relative stylesheet paths containing .. were not resolved. Index: Serializer.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/serializers/Serializer.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Serializer.java 2 Jul 2004 16:53:54 -0000 1.25 --- Serializer.java 27 Jul 2004 16:38:01 -0000 1.26 *************** *** 25,28 **** --- 25,29 ---- import java.io.IOException; import java.io.StringWriter; + import java.net.URI; import java.util.Enumeration; import java.util.Hashtable; *************** *** 697,742 **** // if stylesheet is relative, add path to the // current collection ! if (stylesheet.indexOf('/') < 0 && doc != null) ! stylesheet = doc.getCollection().getName() + '/' + stylesheet; ! // load stylesheet from eXist ! DocumentImpl xsl = null; ! try { ! xsl = (DocumentImpl) broker.getDocument(stylesheet); ! } catch (PermissionDeniedException e) { ! LOG.debug("permission denied to read stylesheet"); ! } ! if (xsl == null) { ! LOG.debug("stylesheet not found"); ! return; ! } ! if(!xsl.getPermissions().validate(broker.getUser(), Permission.READ)) { ! LOG.debug("Permission denied to read stylesheet doc."); ! return; ! } ! if (xsl.getCollection() != null) { ! factory.setURIResolver( ! new InternalURIResolver(xsl.getCollection().getName())); ! } ! ! // save handlers ! ContentHandler oldHandler = contentHandler; ! LexicalHandler oldLexical = lexicalHandler; ! ! // compile stylesheet ! TemplatesHandler handler = factory.newTemplatesHandler(); ! contentHandler = handler; ! try { ! this.toSAX(xsl); ! } catch (SAXException e) { ! LOG.warn("SAXException while creating template", e); ! } ! templates = handler.getTemplates(); ! ! // restore handlers ! contentHandler = oldHandler; ! lexicalHandler = oldLexical; ! factory.setURIResolver(null); } LOG.debug( --- 698,744 ---- // if stylesheet is relative, add path to the // current collection ! URI base = URI.create(doc.getCollection().getName() + "/"); ! URI uri = URI.create(stylesheet); ! stylesheet = base.resolve(uri).toString(); ! // load stylesheet from eXist ! DocumentImpl xsl = null; ! try { ! xsl = (DocumentImpl) broker.getDocument(stylesheet); ! } catch (PermissionDeniedException e) { ! LOG.debug("permission denied to read stylesheet"); ! } ! if (xsl == null) { ! LOG.debug("stylesheet not found"); ! return; ! } ! if(!xsl.getPermissions().validate(broker.getUser(), Permission.READ)) { ! LOG.debug("Permission denied to read stylesheet doc."); ! return; ! } ! if (xsl.getCollection() != null) { ! factory.setURIResolver( ! new InternalURIResolver(xsl.getCollection().getName())); ! } ! ! // save handlers ! ContentHandler oldHandler = contentHandler; ! LexicalHandler oldLexical = lexicalHandler; ! ! // compile stylesheet ! TemplatesHandler handler = factory.newTemplatesHandler(); ! contentHandler = handler; ! try { ! this.toSAX(xsl); ! } catch (SAXException e) { ! LOG.warn("SAXException while creating template", e); ! } ! templates = handler.getTemplates(); ! ! // restore handlers ! contentHandler = oldHandler; ! lexicalHandler = oldLexical; ! factory.setURIResolver(null); } LOG.debug( *************** *** 862,866 **** * *@author Wolfgang Meier <me...@if...> - *@created 20. April 2002 */ private class InternalURIResolver implements URIResolver { --- 864,867 ---- *************** *** 868,888 **** private String collectionId = null; - /** - * Constructor for the InternalURIResolver object - * - *@param collection Description of the Parameter - */ public InternalURIResolver(String collection) { collectionId = collection; } - /** - * Description of the Method - * - *@param href Description of the Parameter - *@param base Description of the Parameter - *@return Description of the Return Value - *@exception TransformerException Description of the Exception - */ public Source resolve(String href, String base) throws TransformerException { LOG.debug("resolving stylesheet ref " + href); --- 869,876 ---- *************** *** 890,896 **** // href is an URL pointing to an external resource return null; ! if ((!href.startsWith("/")) && collectionId != null) ! href = ! (collectionId.equals("/") ? '/' + href : collectionId + '/' + href); Serializer serializer = broker.newSerializer(); return new SAXSource(serializer, new InputSource(href)); --- 878,884 ---- // href is an URL pointing to an external resource return null; ! URI baseURI = URI.create(collectionId + '/'); ! URI uri = URI.create(href); ! href = baseURI.resolve(uri).toString(); Serializer serializer = broker.newSerializer(); return new SAXSource(serializer, new InputSource(href)); |