/** * This work was created by participants in the DataONE project, and is * jointly copyrighted by participating institutions in DataONE. For * more information on DataONE, see our web site at http://dataone.org. * * Copyright ${year} * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.dataone.integration; import java.util.Vector; /** * Utility for generating EML test data. */ public class EMLBuilderUtils { protected final static String EML2_0_0 = "EML2_0_0"; protected final static String EML2_0_1 = "EML2_0_1"; protected final static String EML2_1_0 = "EML2_1_0"; protected static final String ALLOWFIRST = "allowFirst"; protected static final String DENYFIRST = "denyFirst"; // header blocks protected final static String testEml_200_Header = ""; protected final static String testEml_201_Header = ""; protected final static String testEml_210_Header = ""; protected final static String testEmlCreatorBlock = " " + " " + " Smith " + " " + " "; protected final static String testEmlContactBlock = " " + " " + " Jackson " + " " + " "; protected final static String testEmlInlineBlock1 = " " + " " + " " + " Operator " + " PSI " + " " + " " + " "; protected final static String testEmlInlineBlock2 = " " + " " + " LCQ " + " " + " " + " " + " "; /* * Returns an access block base on params passed and the default perm order - * allow first */ protected static String getAccessBlock(String principal, boolean grantAccess, boolean read, boolean write, boolean changePermission, boolean all) { return getAccessBlock(principal, grantAccess, read, write, changePermission, all, ALLOWFIRST); } /** * This function returns an access block based on the params passed */ protected static String getAccessBlock(String principal, boolean grantAccess, boolean read, boolean write, boolean changePermission, boolean all, String permOrder) { String accessBlock = ""; accessBlock += generateOneAccessRule(principal, grantAccess, read, write, changePermission, all); accessBlock += ""; return accessBlock; } /* * Gets eml access block base on given acccess rules and perm order */ protected static String getAccessBlock(Vector accessRules, String permOrder) { String accessBlock = ""; // adding rules if (accessRules != null && !accessRules.isEmpty()) { for (int i = 0; i < accessRules.size(); i++) { String rule = (String) accessRules.elementAt(i); accessBlock += rule; } } accessBlock += ""; return accessBlock; } /* * Generates a access rule for given parameter. Note this xml portion * doesn't include */ protected static String generateOneAccessRule(String principal, boolean grantAccess, boolean read, boolean write, boolean changePermission, boolean all) { String accessBlock = ""; if (grantAccess) { accessBlock = ""; } else { accessBlock = ""; } accessBlock = accessBlock + "" + principal + ""; if (all) { accessBlock += "all"; } else { if (read) { accessBlock += "read"; } if (write) { accessBlock += "write"; } if (changePermission) { accessBlock += "changePermission"; } } if (grantAccess) { accessBlock += ""; } else { accessBlock += ""; } return accessBlock; } /** * This function returns a valid eml document with no access rules */ protected static String generateEmlDocument(String title, String emlVersion, String inlineData1, String inlineData2, String onlineUrl1, String onlineUrl2, String docAccessBlock, String inlineAccessBlock1, String inlineAccessBlock2, String onlineAccessBlock1, String onlineAccessBlock2) { // debug("getTestEmlDoc(): title=" + title + " inlineData1=" + inlineData1 // + " inlineData2=" + inlineData2 + " onlineUrl1=" + onlineUrl1 // + " onlineUrl2=" + onlineUrl2 + " docAccessBlock=" + docAccessBlock // + " inlineAccessBlock1=" + inlineAccessBlock1 + " inlineAccessBlock2=" // + inlineAccessBlock2 + " onlineAccessBlock1=" + onlineAccessBlock1 // + " onlineAccessBlock2=" + onlineAccessBlock2); String testDocument = ""; String header; if (emlVersion == EML2_0_0) { header = testEml_200_Header; } else if (emlVersion == EML2_0_1) { header = testEml_201_Header; } else { header = testEml_210_Header; } testDocument += header; // if this is a 2.1.0+ document, the document level access block sits // at the same level and before the dataset element. if (docAccessBlock != null && emlVersion.equals(EML2_1_0)) { testDocument += docAccessBlock; } testDocument += "" + title + "" + testEmlCreatorBlock; if (inlineData1 != null) { testDocument = testDocument + "" + inlineData1 + ""; } if (inlineData2 != null) { testDocument = testDocument + "" + inlineData2 + ""; } if (onlineUrl1 != null) { testDocument = testDocument + "" + "" + onlineUrl1 + ""; } if (onlineUrl2 != null) { testDocument = testDocument + "" + "" + onlineUrl2 + ""; } testDocument += testEmlContactBlock; // if this is a 2.0.X document, the document level access block sits // inside the dataset element. if (docAccessBlock != null && (emlVersion.equals(EML2_0_0) || emlVersion.equals(EML2_0_1))) { testDocument += docAccessBlock; } testDocument += ""; if (inlineAccessBlock1 != null) { testDocument += ""; testDocument += "inlineEntity1"; testDocument += inlineAccessBlock1; testDocument += ""; } if (inlineAccessBlock2 != null) { testDocument += ""; testDocument += "inlineEntity2"; testDocument += inlineAccessBlock2; testDocument += ""; } if (onlineAccessBlock1 != null) { testDocument += ""; testDocument += "onlineEntity1"; testDocument += onlineAccessBlock1; testDocument += ""; } if (onlineAccessBlock2 != null) { testDocument += ""; testDocument += "onlineEntity2"; testDocument += onlineAccessBlock2; testDocument += ""; } testDocument += ""; // System.out.println("Returning following document" + testDocument); return testDocument; } }