public static DataThing fetchFromURL(URL url) throws IOException { URLConnection conn = url.openConnection(); conn.connect(); String contentType = conn.getContentType(); Object content = conn.getContent(); DataThing dt = new DataThing(content); dt.getMetadata().setMIMETypes( Arrays.asList(new String[] { contentType })); return dt; }
getMetadata().addMIMEType("text/plain"); } else if (o instanceof byte[]) { getMetadata().addMIMEType("application/octet-stream"); } else { getMetadata().clearMIMETypes(); getMetadata().addMIMEType("java/" + o.getClass().getName()); for (Iterator i = getMetadata().getMIMETypeList().iterator(); i .hasNext();) { sb.append((String) i.next());
public InputDataThingNode(Port port, DataThing thing) { super(thing.getDataObject()); this.port = port; this.thing = thing; this.mimeTypes = thing.getMetadata().getMIMETypeList(); }
public boolean canMakeFacets(DataThing dataThing) { return !(dataThing.getDataObject() instanceof String) || dataThing.getMetadata().getMIMETypes().length != 0; }
public boolean canHandle(RendererRegistry renderers, DataThing dataThing) { String[] mimeTypes = dataThing.getMetadata().getMIMETypes(); Object dataObject = dataThing.getDataObject(); if(mimeTypes.length == 0) { if(dataObject instanceof Number || dataObject instanceof CharSequence || dataObject instanceof Image || dataObject instanceof Icon) { return true; } } return false; }
public DataThing getDataThing() { DataThing newThing = DataThingFactory.bake(getUserObject()); if (thing != null) { newThing.getMetadata().setMIMETypes(mimeTypes); newThing.copyMetadataFrom(thing); } else { newThing.getMetadata().setMIMETypes(mimeTypes); } thing = newThing; return thing; }
/** * Build a DataThing from the supplied Element object, the Element in this * case is the 'myGridDataDocument' element. */ public static Object configureDataThing(Element rootElement, DataThing theDataThing) { // Configure semantic markup object for the DataThing Element semanticMarkupElement = rootElement.getChild("metadata", XScufl.XScuflNS); // Get the LSID for the entire datathing String lsid = rootElement.getAttributeValue("lsid"); if (lsid != null) { theDataThing.setLSID(theDataThing, lsid); } if (semanticMarkupElement != null) { theDataThing.getMetadata().configureFromElement( semanticMarkupElement); } return objectForElement(rootElement, theDataThing, rootElement); }
public JComponent getComponent(RendererRegistry renderers, DataThing dataThing) throws RendererException { DataThing copy = new DataThing(dataThing); copy.getMetadata().setMIMETypes( Arrays.asList(strip(dataThing.getMetadata().getMIMETypes()))); try { return new XMLTree((String) dataThing.getDataObject()); } catch (Exception ex) { throw new RendererException(ex); } } }
public final boolean canHandle(RendererRegistry renderers, DataThing dataThing) { String[] mimeTypes = dataThing.getMetadata().getMIMETypes(); Object userObject = dataThing.getDataObject(); for (int i = 0; i < mimeTypes.length; i++) { if (canHandle(renderers, userObject, mimeTypes[i])) { return true; } } return false; }
public final boolean canHandle(RendererRegistry renderers, DataThing dataThing) { String semanticType = dataThing.getMetadata().getSemanticType(); Object userObject = dataThing.getDataObject(); if (canHandle(renderers, userObject, semanticType)) { return true; } return false; }
/** * Return an XML Jdom Element object for the DataThing supplied as the * argument */ public static Element getElement(DataThing theDataThing) { Element rootElement = new Element("myGridDataDocument", namespace); rootElement.setAttribute("lsid", theDataThing.getLSID(theDataThing)); rootElement.setAttribute("syntactictype", theDataThing .getSyntacticType()); rootElement.addContent(theDataThing.getMetadata() .getConfigurationElement()); rootElement.addContent(elementForObject(theDataThing.getDataObject(), theDataThing)); return rootElement; }
/** map LSIDs in "s */ protected DataThing mapLSIDs(Map fileNames, DataThing value) { Object newValue = replaceLSIDsInDataThingValues(fileNames, value, value.getDataObject(), 0); DataThing newdt = new DataThing(newValue); try { // work around copyMetadataFrom not taking account of having a different data object SemanticMarkup markup = value.getMetadata(); newdt.copyMetadataFrom(value); if (markup!=null) { SemanticMarkup newMarkup = newdt.getMetadata(); if (markup.getSemanticType()!=null) newMarkup.setSemanticType(markup.getSemanticType()); String [] mimeTypes = markup.getMIMETypes(); for (int i=0; mimeTypes!=null && i<mimeTypes.length; i++) { //System.out.println("copy mime type "+mimeTypes[i]+" ["+i+"]"); newMarkup.addMIMEType(mimeTypes[i]); } } } catch (Exception e) { System.err.println("ERROR copying semantic markup while mapping lsids: "+e); e.printStackTrace(System.err); } return newdt; } /** replace lsids in String values */
theDataThing.getMetadata().addMIMEType(portMIMETypes[i]); theDataThing.getMetadata().setSemanticType( portMarkup.getSemanticType()); theDataThing.getMetadata().addMIMEType(portMIMETypes[i]);