Thanks a lot, that's exactly the information I was looking for :) I'll dive into this and try to make a first prototype.
Thanks again :) On Thu, May 28, 2009 at 11:52 PM, Paul Mietz Egli <p...@obscure.com> wrote: > Regarding importing KML into JCR: > >> If that's what you meant, I didn't thought of this, why not... I need >> to think about it... >> search may be easier but that means I need to make some kind of >> automatic parsing transformation to jcr ,nodes ? > > Try using Session.importXML() first and see if that meets your needs: > > http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/Session.html#importXML(java.lang.String,%20java.io.InputStream,%20int) > > From the javadocs: > > "The tree of new items is built in the transient storage of the Session. In > order to persist the new content, save must be called. The advantage of this > through-the-session method is that (depending on what constraint checks the > implementation leaves until save) structures that violate node type > constraints can be imported, fixed and then saved. The disadvantage is that > a large import will result in a large cache of pending nodes in the session. > See Workspace.importXML(java.lang.String, java.io.InputStream, int) for a > version of this method that does not go through the Session." > >> On an architectural point of view, I thought about having a Sling >> server and a postgis database separate. >> - Sling: will actually store files and properties associated with them >> - Postgis: will store only a jcr path and 'geom' informations >> - Java: code some java component(s) (osgi bundle ?) to synchronize both > > > In Postgres, I'd suggest using a UUID of the root of the KML doc instead of > a JCR path since paths can change. You can then use Session.getNodeByUUID() > to look up the KML node. > >> Step n°1: I was thinking to use some kind of 'hook' on ressource >> creation/update to compute the geom and store a couple >> (path_in_jcr/geom) in postgres/postgis >> Should I do such a hook by "Extending the SlingPostServlet" describe >> in "Advanced Topic" (5) ?! > > Sounds like your KML is arriving in the body of an HTTP POST request. You > could extend the SlingPostServlet as described in the docs to handle > importing the KML (e.g. by passing the servlet input stream into > Session.importXML). If your geometry computations take more than a few > hundred milliseconds, you should consider doing them in a JCR EventListener > that gets called after your nodes are created rather than in-process with > the HTTP request. Rough code would be: > > > /** > * @scr.component metatype="false" enabled="true" immediate="true" > * @scr.service > interface="org.apache.sling.servlets.post.SlingPostOperation" > * @scr.property name="sling.post.operation" value="myoperation" > * > * @author Paul Mietz Egli > */ > public class MyPostOperation extends AbstractSlingPostOperation { > �...@override > protected void doRun(SlingHttpServletRequest request, HtmlResponse > response, List<Modification> changes) throws RepositoryException { > String basepath = "/content/kml"; // TODO use @scr.property to set > actual value > Session session = > request.getResourceResolver().adaptTo(Session.class); > session.importXML(basepath, request.getInputStream(), > ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); > // TODO maybe set a custom node type on the root of your KML doc that > you can use in the event listener > } > } > > * @scr.component metatype="true" enabled="true" immediate="true" > * @scr.service interface="javax.jcr.observation.EventListener" > * > * @author Paul Mietz Egli > */ > public class GeometryComputationEventListener implements EventListener { > /** > * @scr.reference > */ > private SlingRepository repository; > > protected void activate(ComponentContext context) { > try { > String path = "/content/kml"; > String[] nodeTypes = new String[] { "nt:unstructured" }; > session = repository.loginAdministrative(null); > ObservationManager observationManager = > session.getWorkspace().getObservationManager(); > observationManager.addEventListener(this, Event.NODE_ADDED, path, > true, null, nodeTypes, false); > } > catch (RepositoryException e) {} > } > > public void onEvent(EventIterator eventIterator) { > while (eventIterator.hasNext()) { > Event event = (Event) eventIterator.next(); > switch (event.getType()) { > case Event.NODE_ADDED: > // TODO test node type/location to make sure you're > seeing the root of the KML tree > // TODO pull placemarks out of KML tree and convert to > WKT for PostGIS > } > } > } > } > } > > > > > p.