Changeset 27719 for main


Ignore:
Timestamp:
2013-06-27T17:01:15+12:00 (11 years ago)
Author:
sjm84
Message:

Some depositor updates

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r27617 r27719  
    11671167                        File file = new File(tempDir, current.getName());
    11681168                        current.write(file);
     1169
     1170                        queryMap.put("md___ex.Filesize", new String[] { "" + file.length() });
     1171                        queryMap.put("md___ex.Filename", new String[] { "" + current.getName() });
    11691172                    }
    11701173                }
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DepositorAction.java

    r27617 r27719  
    11package org.greenstone.gsdl3.action;
    22
     3import java.io.BufferedWriter;
    34import java.io.File;
    45import java.io.FileWriter;
     6import java.io.IOException;
    57import java.io.Serializable;
    68import java.util.ArrayList;
     
    1416import javax.xml.transform.stream.StreamResult;
    1517
     18import org.apache.commons.io.FileUtils;
    1619import org.greenstone.gsdl3.util.DerbyWrapper;
    1720import org.greenstone.gsdl3.util.GSConstants;
     
    2831    //Sub actions
    2932    private final String DE_RETRIEVE_WIZARD = "getWizard";
     33    private final String DE_DEPOSIT_FILE = "depositFile";
    3034
    3135    public Node process(Node message)
     
    4650
    4751        int pageNum = -1;
    48         boolean parseFail = false;
     52        boolean pageNumParseFail = false;
    4953        try
    5054        {
     
    5357        catch (Exception ex)
    5458        {
    55             parseFail = true;
    56             ex.printStackTrace();
     59            pageNumParseFail = true;
     60        }
     61
     62        int prevPageNum = -1;
     63        boolean prevPageNumFail = false;
     64        try
     65        {
     66            prevPageNum = Integer.parseInt(((String) params.get("currentPage")));
     67        }
     68        catch (Exception ex)
     69        {
     70            prevPageNumFail = true;
    5771        }
    5872
    5973        DerbyWrapper database = new DerbyWrapper();
    6074        database.connectDatabase(GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + this.config_params.get(GSConstants.SITE_NAME) + File.separatorChar + "etc" + File.separatorChar + "usersDB", false);
    61         if (parseFail)
     75        if (pageNumParseFail)
    6276        {
    6377            try
     
    105119                saveString.append("]");
    106120
    107                 database.addUserData(currentUsername, "DE___" + collection + "___" + pageNum + "___CACHED_VALUES", saveString.toString());
     121                if (!prevPageNumFail)
     122                {
     123                    database.addUserData(currentUsername, "DE___" + collection + "___" + prevPageNum + "___CACHED_VALUES", saveString.toString());
     124                }
    108125            }
    109126
     
    182199                {
    183200                    Element page = this.doc.createElement("pageCache");
    184                     page.setAttribute("pageNum", "" + pageNum);
     201                    page.setAttribute("pageNum", "" + i);
    185202                    String cachedValues = database.getUserData(currentUsername, "DE___" + collection + "___" + i + "___CACHED_VALUES");
    186                     page.appendChild(this.doc.createTextNode(cachedValues));
    187                     cachedValueElement.appendChild(page);
     203                    if (cachedValues != null)
     204                    {
     205                        page.appendChild(this.doc.createTextNode(cachedValues));
     206                        cachedValueElement.appendChild(page);
     207                    }
    188208                }
    189209            }
     
    212232            }
    213233            database.closeDatabase();
     234        }
     235        else if (subaction.equals(DE_DEPOSIT_FILE))
     236        {
     237            String fileToAdd = (String) params.get("fileToAdd");
     238            File tempFile = new File(GlobalProperties.getGSDL3Home() + File.separator + "tmp" + File.separator + fileToAdd);
     239            if (tempFile.exists())
     240            {
     241                File newFileLocationDir = new File(GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + this.config_params.get(GSConstants.SITE_NAME) + File.separator + "collect" + File.separator + collection + File.separator + "import" + File.separator + fileToAdd);
     242                if (!newFileLocationDir.exists())
     243                {
     244                    newFileLocationDir.mkdir();
     245                }
     246                File newFileLocation = new File(newFileLocationDir, fileToAdd);
     247
     248                try
     249                {
     250                    FileUtils.copyFile(tempFile, newFileLocation);
     251                }
     252                catch (Exception ex)
     253                {
     254                    ex.printStackTrace();
     255                    GSXML.addError(this.doc, responseMessage, "Failed to copy the deposited file into the collection.");
     256                    return responseMessage;
     257                }
     258
     259                String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!DOCTYPE DirectoryMetadata SYSTEM \"http://greenstone.org/dtd/DirectoryMetadata/1.0/DirectoryMetadata.dtd\"><DirectoryMetadata><FileSet>";
     260                xmlString += "<FileName>" + fileToAdd + "</FileName><Description>";
     261                Iterator<String> paramIter = params.keySet().iterator();
     262                while (paramIter.hasNext())
     263                {
     264                    String paramName = paramIter.next();
     265                    if (paramName.startsWith("md___"))
     266                    {
     267                        Object paramValue = params.get(paramName);
     268
     269                        if (paramValue instanceof String)
     270                        {
     271                            xmlString += "<Metadata name=\"" + paramName.substring(5) + "\" mode=\"accumulate\">" + (String) paramValue + "</Metadata>";
     272                        }
     273                        else if (paramValue instanceof HashMap)
     274                        {
     275                            HashMap<String, String> subMap = (HashMap<String, String>) paramValue;
     276                            Iterator<String> subKeyIter = subMap.keySet().iterator();
     277                            while (subKeyIter.hasNext())
     278                            {
     279                                String subName = subKeyIter.next();
     280                                xmlString += "<Metadata name=\"" + paramName.substring(5) + "." + subName + "\" mode=\"accumulate\">" + subMap.get(subName) + "</Metadata>";
     281                            }
     282                        }
     283                    }
     284                }
     285                xmlString += "</Description></FileSet><DirectoryMetadata>";
     286
     287                File metadataFile = new File(GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + this.config_params.get(GSConstants.SITE_NAME) + File.separator + "collect" + File.separator + collection + File.separator + "import" + File.separator + fileToAdd + File.separator + "metadata.xml");
     288
     289                try
     290                {
     291                    BufferedWriter bw = new BufferedWriter(new FileWriter(metadataFile));
     292                    bw.write(xmlString);
     293                    bw.close();
     294                }
     295                catch (Exception ex)
     296                {
     297                    ex.printStackTrace();
     298                }
     299
     300                Element buildMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
     301                Element buildRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, "ImportCollection", uc);
     302                buildMessage.appendChild(buildRequest);
     303
     304                Element paramListElem = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     305                buildRequest.appendChild(paramListElem);
     306
     307                Element collectionParam = this.doc.createElement(GSXML.PARAM_ELEM);
     308                paramListElem.appendChild(collectionParam);
     309                collectionParam.setAttribute(GSXML.NAME_ATT, GSXML.COLLECTION_ATT);
     310                collectionParam.setAttribute(GSXML.VALUE_ATT, collection);
     311
     312                Element documentsParam = this.doc.createElement(GSXML.PARAM_ELEM);
     313                paramListElem.appendChild(documentsParam);
     314                documentsParam.setAttribute(GSXML.NAME_ATT, "documents");
     315                documentsParam.setAttribute(GSXML.VALUE_ATT, fileToAdd);
     316
     317                Element buildResponseMessage = (Element) this.mr.process(buildMessage);
     318
     319                System.err.println("RESPONSE = " + GSXML.xmlNodeToString(buildResponseMessage));
     320               
     321                response.appendChild(this.doc.importNode(buildResponseMessage, true));
     322            }
     323        }
     324        else
     325        {
     326            Element depositorPage = this.doc.createElement("depositorPage");
     327            response.appendChild(depositorPage);
     328
     329            Element collList = getCollectionsInSite();
     330            depositorPage.appendChild(this.doc.importNode(collList, true));
    214331        }
    215332
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSParams.java

    r27087 r27719  
    165165    {
    166166        // p. is used to store previous settings
    167         if (name.startsWith("p."))
     167        if (name.startsWith("p.") || name.startsWith("md___"))
    168168            return false;
    169169        Param p = this.param_map.get(name);
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r27617 r27719  
    329329    public static HashMap<String, Serializable> extractParams(Element xml, boolean deep, String toFind)
    330330    {
     331        if (xml == null)
     332        {
     333            return null;
     334        }
    331335
    332336        if (!xml.getNodeName().equals(PARAM_ELEM + LIST_MODIFIER))
     
    750754            duplicate = owner.createElementNS(namespace_uri, element_name);
    751755        }
     756
    752757        // Copy element attributes
    753758        if (with_attributes)
     
    12941299            {
    12951300                String text = e.getNodeValue();
    1296                 text = text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("^[\\n\\r\\t\\s]*", "").replaceAll("[\\n\\r\\t\\s]*$", "");
    1297                 sb.append(text);
     1301                if (text != null)
     1302                {
     1303                    text = text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("^[\\n\\r\\t\\s]*", "").replaceAll("[\\n\\r\\t\\s]*$", "");
     1304                    sb.append(text);
     1305                }
    12981306            }
    12991307            return;
     
    13441352            if (children.item(i).getNodeType() == Node.TEXT_NODE && indent)
    13451353            {
    1346                 if (children.item(i).getNodeValue().trim().length() > 0)
     1354                if (children.item(i).getNodeValue() != null && children.item(i).getNodeValue().trim().length() > 0)
    13471355                {
    13481356                    indentSwapped = true;
Note: See TracChangeset for help on using the changeset viewer.