public String addPolicy(File policyFile) throws Exception { byte[] policy = DataUtils.loadFile(policyFile.getAbsolutePath()); String policyId = getPolicyId(policy); String policyFileName = "file:///" + policyFile.getAbsolutePath(); // escape any pid namespace character if (policyId.contains(":")) { policyId = policyId.replace(":", "%3A"); } String pid = "demo:" + policyId; StringBuilder foxml = new StringBuilder(); // basic empty object foxml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); foxml.append( "<foxml:digitalObject VERSION=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); foxml.append(" xmlns:foxml=\"info:fedora/fedora-system:def/foxml#\"\n"); foxml.append( " xsi:schemaLocation=\"" + Constants.FOXML.uri + " " + Constants.FOXML1_1.xsdLocation + "\""); foxml.append("\n PID=\"" + StreamUtility.enc(pid) + "\">\n"); foxml.append(" <foxml:objectProperties>\n"); foxml.append( " <foxml:property NAME=\"info:fedora/fedora-system:def/model#state\" VALUE=\"A\"/>\n"); foxml.append( " <foxml:property NAME=\"info:fedora/fedora-system:def/model#label\" VALUE=\"" + StreamUtility.enc("test policy object") + "\"/>\n"); foxml.append(" </foxml:objectProperties>\n"); foxml.append( "<foxml:datastream ID=\"" + FedoraPolicyStore.POLICY_DATASTREAM + "\" CONTROL_GROUP=\"M\">"); foxml.append( "<foxml:datastreamVersion ID=\"POLICY.0\" MIMETYPE=\"text/xml\" LABEL=\"XACML policy datastream\">"); foxml.append(" <foxml:contentLocation REF=\"" + policyFileName + "\" TYPE=\"URL\"/>"); // foxml.append(" <foxml:xmlContent>"); // foxml.append(policy); // foxml.append(" </foxml:xmlContent>"); foxml.append(" </foxml:datastreamVersion>"); foxml.append("</foxml:datastream>"); foxml.append("</foxml:digitalObject>"); apim.ingest(foxml.toString().getBytes("UTF-8"), FOXML1_1.uri, "ingesting new foxml object"); return policyId; }
private void appendDisseminators(DigitalObject obj, PrintWriter writer) throws ObjectIntegrityException { Iterator<String> dissIdIter = obj.disseminatorIdIterator(); while (dissIdIter.hasNext()) { String did = dissIdIter.next(); Disseminator diss = DOTranslationUtility.setDisseminatorDefaults(obj.disseminators(did).get(0)); writer.print("<"); writer.print(METS.prefix); writer.print(":behaviorSec ID=\""); writer.print(did); writer.print("\" STATUS=\""); writer.print(diss.dissState); writer.print("\">\n"); for (int i = 0; i < obj.disseminators(did).size(); i++) { diss = DOTranslationUtility.setDisseminatorDefaults(obj.disseminators(did).get(i)); writer.print("<"); writer.print(METS.prefix); writer.print(":serviceBinding ID=\""); writer.print(diss.dissVersionID); writer.print("\" STRUCTID=\""); writer.print(diss.dsBindMapID); writer.print("\" BTYPE=\""); writer.print(diss.bDefID); writer.print("\" CREATED=\""); writer.print(DateUtility.convertDateToString(diss.dissCreateDT)); writer.print("\""); if (diss.dissLabel != null && !diss.dissLabel.equals("")) { writer.print(" LABEL=\""); writer.print(StreamUtility.enc(diss.dissLabel)); writer.print("\""); } writer.print(">\n"); writer.print("<"); writer.print(METS.prefix); writer.print(":interfaceMD LOCTYPE=\"URN\" "); writer.print(XLINK.prefix); writer.print(":href=\""); writer.print(diss.bDefID); writer.print("\"/>\n"); writer.print("<"); writer.print(METS.prefix); writer.print(":serviceBindMD LOCTYPE=\"URN\" "); writer.print(XLINK.prefix); writer.print(":href=\""); writer.print(diss.sDepID); writer.print("\"/>\n"); writer.print("</"); writer.print(METS.prefix); writer.print(":serviceBinding>\n"); } writer.print("</"); writer.print(METS.prefix); writer.print(":behaviorSec>\n"); } }
@Override public Object getValue() { if (m_fromTextRadioButton.isSelected()) { return m_textField.getText().getBytes(); } else { File f = new File(m_fileField.getText()); if (!f.exists() || f.isDirectory()) { System.out.println("returning null..file doesnt exist"); return null; } try { ByteArrayOutputStream out = new ByteArrayOutputStream(); FileInputStream in = new FileInputStream(f); StreamUtility.pipeStream(in, out, 4096); return out.toByteArray(); } catch (IOException ioe) { System.out.println("ioexecption getting filestream: " + ioe.getMessage()); return null; } } }
public void getDatastreamDissemination( String pid, String dsId, String asOfDateTime, OutputStream out) throws IOException { InputStream in = getDatastreamDissemination(pid, dsId, asOfDateTime); StreamUtility.pipeStream(in, out, 4096); }
/** * Get data via HTTP and write it to an OutputStream, following redirects, and supplying * credentials if the host is the Fedora server. */ public void get(String url, OutputStream out) throws IOException { InputStream in = get(url); StreamUtility.pipeStream(in, out, 4096); }
/** This method executes the thread. */ @Override public void run() { if (pw != null) { try { pw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); pw.write("<objectMethods"); pw.write(" pid=\"" + PID + "\""); if (versDateTime != null) { pw.write(" asOfDateTime=\""); pw.write(DateUtility.convertDateToString(versDateTime)); pw.write("\""); } pw.write(" baseURL=\""); StreamUtility.enc(fedoraServerProtocol, pw); pw.write("://"); StreamUtility.enc(m_fedoraServerHost, pw); pw.write(':'); StreamUtility.enc(fedoraServerPort, pw); pw.write("/" + fedoraAppServerContext + "/\""); pw.write(" xmlns=\"" + OBJ_METHODS1_0.namespace.uri + "\" "); pw.write(" xmlns:xsi=\"" + XSI.uri + "\" "); pw.write(" xsi:schemaLocation=\"" + OBJ_METHODS1_0.namespace.uri); pw.write(" " + OBJ_METHODS1_0.xsdLocation + "\">"); // ObjectMethodsDef SERIALIZATION String nextSdef = "null"; String currentSdef = ""; for (int i = 0; i < methodDefs.length; i++) { currentSdef = methodDefs[i].sDefPID; if (!currentSdef.equalsIgnoreCase(nextSdef)) { if (i != 0) { pw.write("</sDef>"); } pw.write("<sDef pid=\""); StreamUtility.enc(methodDefs[i].sDefPID, pw); pw.write("\" >"); } pw.write("<method name=\""); StreamUtility.enc(methodDefs[i].methodName, pw); pw.write("\" >"); MethodParmDef[] methodParms = methodDefs[i].methodParmDefs; for (MethodParmDef element : methodParms) { pw.write("<methodParm parmName=\""); StreamUtility.enc(element.parmName, pw); pw.write("\" parmDefaultValue=\""); StreamUtility.enc(element.parmDefaultValue, pw); pw.write("\" parmRequired=\"" + element.parmRequired + "\" parmLabel=\""); StreamUtility.enc(element.parmLabel, pw); pw.write("\" >"); if (element.parmDomainValues.length > 0) { pw.write("<methodParmDomain>"); for (String element2 : element.parmDomainValues) { pw.write("<methodParmValue>"); StreamUtility.enc(element2, pw); pw.write("</methodParmValue>"); } pw.write("</methodParmDomain>"); } pw.write("</methodParm>"); } pw.write("</method>"); nextSdef = currentSdef; } pw.write("</sDef>"); pw.write("</objectMethods>"); pw.flush(); pw.close(); } catch (IOException ioe) { logger.error("WriteThread error", ioe); } finally { try { if (pw != null) { pw.close(); } } catch (IOException ioe) { logger.error("WriteThread error", ioe); } } } }
private void appendStructMaps(DigitalObject obj, PrintWriter writer) throws ObjectIntegrityException { Iterator<String> dissIdIter = obj.disseminatorIdIterator(); while (dissIdIter.hasNext()) { String did = dissIdIter.next(); Iterator<Disseminator> dissIter = obj.disseminators(did).iterator(); while (dissIter.hasNext()) { Disseminator diss = DOTranslationUtility.setDisseminatorDefaults(dissIter.next()); writer.print("<"); writer.print(METS.prefix); writer.print(":structMap ID=\""); writer.print(diss.dsBindMapID); writer.print("\" TYPE=\"fedora:dsBindingMap\">\n"); writer.print("<"); writer.print(METS.prefix); writer.print(":div TYPE=\""); writer.print(diss.sDepID); writer.print("\""); if (diss.dsBindMap.dsBindMapLabel != null && !diss.dsBindMap.dsBindMapLabel.equals("")) { writer.print(" LABEL=\""); writer.print(StreamUtility.enc(diss.dsBindMap.dsBindMapLabel)); writer.print("\""); } writer.print(">\n"); DSBinding[] bindings = diss.dsBindMap.dsBindings; for (int i = 0; i < bindings.length; i++) { if (bindings[i].bindKeyName == null || bindings[i].bindKeyName.equals("")) { throw new ObjectIntegrityException( "Object's disseminator" + " binding map binding must have a binding key name."); } writer.print("<"); writer.print(METS.prefix); writer.print(":div TYPE=\""); writer.print(bindings[i].bindKeyName); if (bindings[i].bindLabel != null && !bindings[i].bindLabel.equals("")) { writer.print("\" LABEL=\""); writer.print(StreamUtility.enc(bindings[i].bindLabel)); } if (bindings[i].seqNo != null && !bindings[i].seqNo.equals("")) { writer.print("\" ORDER=\""); writer.print(bindings[i].seqNo); } if (bindings[i].datastreamID == null || bindings[i].datastreamID.equals("")) { throw new ObjectIntegrityException( "Object's disseminator" + " binding map binding must point to a datastream."); } writer.print("\">\n<"); writer.print(METS.prefix); writer.print(":fptr FILEID=\""); writer.print(bindings[i].datastreamID); writer.print("\"/>\n"); writer.print("</"); writer.print(METS.prefix); writer.print(":div>\n"); } writer.print("</"); writer.print(METS.prefix); writer.print(":div>\n"); writer.print("</"); writer.print(METS.prefix); writer.print(":structMap>\n"); } } }
private void appendFileSecs(DigitalObject obj, PrintWriter writer) throws ObjectIntegrityException, StreamIOException { Iterator<String> iter = obj.datastreamIdIterator(); boolean didFileSec = false; while (iter.hasNext()) { Datastream ds = DOTranslationUtility.setDatastreamDefaults( obj.datastreams(iter.next()).iterator().next()); if (!ds.DSControlGrp.equals("X")) { if (!didFileSec) { didFileSec = true; writer.print("<"); writer.print(METS.prefix); writer.print(":fileSec>\n"); writer.print("<"); writer.print(METS.prefix); writer.print(":fileGrp ID=\"DATASTREAMS\">\n"); } writer.print("<"); writer.print(METS.prefix); writer.print(":fileGrp ID=\""); writer.print(ds.DatastreamID); writer.print("\" STATUS=\""); writer.print(ds.DSState); writer.print("\" VERSIONABLE=\""); writer.print(ds.DSVersionable); writer.print("\">\n"); Iterator<Datastream> contentIter = obj.datastreams(ds.DatastreamID).iterator(); while (contentIter.hasNext()) { Datastream dsc = DOTranslationUtility.setDatastreamDefaults(contentIter.next()); writer.print("<"); writer.print(METS.prefix); writer.print(":file ID=\""); writer.print(dsc.DSVersionID); writer.print("\""); if (dsc.DSCreateDT != null) { writer.print(" CREATED=\""); writer.print(DateUtility.convertDateToString(dsc.DSCreateDT)); writer.print("\""); } writer.print(" MIMETYPE=\""); writer.print(StreamUtility.enc(dsc.DSMIME)); writer.print("\""); if (dsc.DSSize != 0) { writer.print(" SIZE=\"" + dsc.DSSize + "\""); } if (dsc.DSFormatURI != null && !dsc.DSFormatURI.equals("")) { writer.print(" FORMAT_URI=\""); writer.print(StreamUtility.enc(dsc.DSFormatURI)); writer.print("\""); } String altIds = DOTranslationUtility.oneString(dsc.DatastreamAltIDs); if (altIds != null && !altIds.equals("")) { writer.print(" ALT_IDS=\""); writer.print(StreamUtility.enc(altIds)); writer.print("\""); } String csType = ds.DSChecksumType; if (csType != null && csType.length() > 0 && !csType.equals(Datastream.CHECKSUMTYPE_DISABLED)) { writer.print(" CHECKSUM=\""); writer.print(StreamUtility.enc(ds.DSChecksum)); writer.print("\""); writer.print(" CHECKSUMTYPE=\""); writer.print(StreamUtility.enc(csType)); writer.print("\""); } writer.print(" OWNERID=\""); writer.print(dsc.DSControlGrp); writer.print("\">\n"); if (m_transContext == DOTranslationUtility.SERIALIZE_EXPORT_ARCHIVE && dsc.DSControlGrp.equalsIgnoreCase("M")) { serializeDatastreamContent(dsc, writer); } else { writer.print("<"); writer.print(METS.prefix); writer.print(":FLocat"); if (dsc.DSLabel != null && !dsc.DSLabel.equals("")) { writer.print(" "); writer.print(XLINK.prefix); writer.print(":title=\""); writer.print(StreamUtility.enc(dsc.DSLabel)); writer.print("\""); } writer.print(" LOCTYPE=\"URL\" "); writer.print(XLINK.prefix); writer.print(":href=\""); writer.print( StreamUtility.enc( DOTranslationUtility.normalizeDSLocationURLs(obj.getPid(), dsc, m_transContext) .DSLocation)); writer.print("\"/>\n"); } writer.print("</"); writer.print(METS.prefix); writer.print(":file>\n"); } writer.print("</"); writer.print(METS.prefix); writer.print(":fileGrp>\n"); } } if (didFileSec) { writer.print("</"); writer.print(METS.prefix); writer.print(":fileGrp>\n"); writer.print("</"); writer.print(METS.prefix); writer.print(":fileSec>\n"); } }
private void appendMDSec( DigitalObject obj, String outerName, String innerName, Iterable<Datastream> XMLMetadata, PrintWriter writer, String encoding) throws ObjectIntegrityException, UnsupportedEncodingException, StreamIOException { DatastreamXMLMetadata first = (DatastreamXMLMetadata) DOTranslationUtility.setDatastreamDefaults(XMLMetadata.iterator().next()); writer.print("<"); writer.print(METS.prefix); writer.print(":"); writer.print(outerName); writer.print(" ID=\""); writer.print(first.DatastreamID); writer.print("\" STATUS=\""); writer.print(first.DSState); writer.print("\" VERSIONABLE=\""); writer.print(first.DSVersionable); writer.print("\">\n"); for (Datastream d : XMLMetadata) { DatastreamXMLMetadata ds = (DatastreamXMLMetadata) DOTranslationUtility.setDatastreamDefaults(d); writer.print("<"); writer.print(METS.prefix); writer.print(":"); writer.print(innerName); writer.print(" ID=\""); writer.print(ds.DSVersionID); writer.print("\""); if (ds.DSCreateDT != null) { writer.print(" CREATED=\""); writer.print(DateUtility.convertDateToString(ds.DSCreateDT)); writer.print("\""); } writer.print(">\n"); writer.print("<"); writer.print(METS.prefix); writer.print(":mdWrap MIMETYPE=\""); writer.print(StreamUtility.enc(ds.DSMIME)); writer.print("\" MDTYPE=\""); String mdType = ds.DSInfoType; if (!mdType.equals("MARC") && !mdType.equals("EAD") && !mdType.equals("DC") && !mdType.equals("NISOIMG") && !mdType.equals("LC-AV") && !mdType.equals("VRA") && !mdType.equals("TEIHDR") && !mdType.equals("DDI") && !mdType.equals("FGDC")) { writer.print("OTHER\" OTHERMDTYPE=\""); writer.print(StreamUtility.enc(mdType)); } else { writer.print(mdType); } writer.print("\" "); if (ds.DSLabel != null && !ds.DSLabel.equals("")) { writer.print(" LABEL=\""); writer.print(StreamUtility.enc(ds.DSLabel)); writer.print("\""); } if (ds.DSFormatURI != null && !ds.DSFormatURI.equals("")) { writer.print(" FORMAT_URI=\""); writer.print(StreamUtility.enc(ds.DSFormatURI)); writer.print("\""); } String altIds = DOTranslationUtility.oneString(ds.DatastreamAltIDs); if (altIds != null && !altIds.equals("")) { writer.print(" ALT_IDS=\""); writer.print(StreamUtility.enc(altIds)); writer.print("\""); } // CHECKSUM and CHECKSUMTYPE are also optional String csType = ds.DSChecksumType; if (csType != null && csType.length() > 0 && !csType.equals(Datastream.CHECKSUMTYPE_DISABLED)) { writer.print(" CHECKSUM=\""); writer.print(StreamUtility.enc(ds.DSChecksum)); writer.print("\" CHECKSUMTYPE=\""); writer.print(StreamUtility.enc(csType)); writer.print("\""); } writer.print(">\n"); writer.print("<"); writer.print(METS.prefix); writer.print(":xmlData>\n"); // If WSDL or SERVICE-PROFILE datastream (in SDep) // make sure that any embedded URLs are encoded // appropriately for either EXPORT or STORE. if (obj.hasContentModel(SERVICE_DEPLOYMENT_3_0) && ds.DatastreamID.equals("SERVICE-PROFILE") || ds.DatastreamID.equals("WSDL")) { writer.print( DOTranslationUtility.normalizeInlineXML( new String(ds.xmlContent, "UTF-8").trim(), m_transContext)); } else { DOTranslationUtility.appendXMLStream(ds.getContentStream(), writer, encoding); } writer.print("\n</"); writer.print(METS.prefix); writer.print(":xmlData>"); writer.print("</"); writer.print(METS.prefix); writer.print(":mdWrap>\n"); writer.print("</"); writer.print(METS.prefix); writer.print(":"); writer.print(innerName); writer.print(">\n"); } writer.print("</"); writer.print(METS.prefix); writer.print(":"); writer.print(outerName); writer.print(">\n"); }
private void appendRootElementStart(DigitalObject obj, PrintWriter writer) throws ObjectIntegrityException { writer.print("<"); writer.print(METS.METS.qName); if (m_format.equals(METS_EXT1_1)) { writer.print(" "); writer.print(METS_EXT.EXT_VERSION.localName); writer.print("=\"1.1\""); } writer.print(" "); writer.print(METS.OBJID.localName); writer.print("=\""); writer.print(obj.getPid()); writer.print("\""); if (m_format.equals(METS_EXT1_0) && DOTranslationUtility.getTypeAttribute(obj) != null) { writer.print(" "); writer.print(METS.TYPE.localName); writer.print("=\""); writer.print(DOTranslationUtility.getTypeAttribute(obj).localName); writer.print("\""); } writer.print("\n"); String label = obj.getLabel(); if (label != null && label.length() > 0) { writer.print(METS.LABEL.localName); writer.print("=\""); writer.print(StreamUtility.enc(label)); writer.print("\"\n"); } writer.print("xmlns:"); writer.print(METS.prefix); writer.print("=\""); writer.print(METS.uri); writer.print("\"\n"); if (m_format.equals(METS_EXT1_0)) { writer.print("xmlns:"); writer.print(XLINK.prefix); writer.print("=\""); writer.print(OLD_XLINK.uri); writer.print("\"\n"); } else { writer.print("xmlns:"); writer.print(XLINK.prefix); writer.print("=\""); writer.print(XLINK.uri); writer.print("\"\n"); } writer.print("xmlns:"); writer.print(XSI.prefix); writer.print("=\""); writer.print(XSI.uri); writer.print("\"\n"); writer.print(XSI.SCHEMA_LOCATION.qName); writer.print("=\""); writer.print(METS.uri); writer.print(" "); writer.print(m_format.xsdLocation); writer.print("\">\n"); }