Exemplo n.º 1
0
  /**
   * buildDocument builds org.w3c.dom.Document from given properties using given metadata for a part
   *
   * @param partMeta
   * @param rootElementName
   * @param objectProps
   * @return Document
   * @throws Exception
   */
  public static org.dom4j.Element buildDocument(
      ObjectPartType partMeta, String rootElementName, Map<String, Object> objectProps)
      throws Exception {
    ObjectPartContentType partContentMeta = partMeta.getContent();
    XmlContentType xc = partContentMeta.getXmlContent();
    if (xc == null) {
      return null;
    }

    // FIXME: We support XML validation on the way in, so we should add it here (on the way out) as
    // well.
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = builder.newDocument();
    document.setXmlStandalone(
        true); // FIXME: REM - Can we set this to false since it is not really standalone?

    /*
     * JAXB unmarshaller recognizes the following kind of namespace
     * qualification only. More investigation is needed to use other prefix
     *
     * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     * <ns2:collectionobjects-common xmlns:ns2="http://collectionspace.org/services/collectionobject">
     * 		<objectNumber>objectNumber-1252960222412</objectNumber>
     * 		<objectName>objectName-1252960222412</objectName>
     * </ns2:collectionobjects-common>
     */

    String ns = "ns2";
    Element root = document.createElementNS(xc.getNamespaceURI(), ns + ":" + rootElementName);
    root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");

    //		String getSchemaLocation = xc.getSchemaLocation();					//FIXME: REM - w3c Document to DOM4j
    // Document mangles this attribute
    //		root.setAttribute("xsi:schemaLocation", xc.getSchemaLocation());

    String getNamespaceURI = xc.getNamespaceURI();
    root.setAttribute("xmlns:" + ns, xc.getNamespaceURI());
    document.appendChild(root);

    Schema schema = getSchemaFromName(partMeta.getLabel());

    buildDocument(document, root, objectProps, schema);
    String w3cDocumentStr = xmlToString(document);

    DOMReader reader = new DOMReader();
    org.dom4j.Document dom4jDoc = reader.read(document);
    org.dom4j.Element result = dom4jDoc.getRootElement();
    result.detach(); // return just the root element detached from the DOM document

    return result; // FIXME: REM - Add if (logger.isTraceEnabled() == true)
    // logger.trace(document.asXML());
  }
Exemplo n.º 2
0
  /**
   * Gets the xML schema.
   *
   * @param partMeta the part meta
   * @return the xML schema
   * @throws Exception the exception
   */
  private static File getXMLSchema(ObjectPartType partMeta) throws Exception {
    final String FILE_SEPARATOR = System.getProperty("file.separator");
    final String XML_SCHEMA_EXTENSION = ".xsd";
    final String SCHEMAS_DIR = "schemas";

    File schemaFile = null;

    //
    // Look for an XML Schema (.xsd) file for the incoming part payload
    //
    String serverRoot = ServiceMain.getInstance().getServerRootDir();
    String schemasDir = serverRoot + FILE_SEPARATOR + SCHEMAS_DIR + FILE_SEPARATOR;
    //
    // Send a warning to the log file if the XML Schema file is missing
    //
    String schemaName = schemasDir + partMeta.getLabel() + XML_SCHEMA_EXTENSION;
    try {
      schemaFile = new File(schemaName);
    } catch (Exception e) {
      if (logger.isWarnEnabled() == true) {
        logger.warn("Missing schema file for incoming payload: " + schemaName);
      }
    }

    return schemaFile;
  }
 /**
  * Filters out selected values supplied in an update request.
  *
  * <p>For example, filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure that the link to
  * the item's parent remains untouched.
  *
  * @param objectProps the properties filtered out from the update payload
  * @param partMeta metadata for the object to fill
  */
 @Override
 public void filterReadOnlyPropertiesForPart(
     Map<String, Object> objectProps, ObjectPartType partMeta) {
   super.filterReadOnlyPropertiesForPart(objectProps, partMeta);
   String commonPartLabel = getServiceContext().getCommonPartLabel();
   if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
     objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY);
     objectProps.remove(AuthorityItemJAXBSchema.CSID);
     objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
     objectProps.remove(AuthorityItemJAXBSchema.REF_NAME);
   }
 }
  /* (non-Javadoc)
   * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
   */
  @Override
  protected Map<String, Object> extractPart(
      DocumentModel docModel, String schema, ObjectPartType partMeta) throws Exception {
    Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);

    // Add the CSID to the common part, since they may have fetched via the shortId.
    if (partMeta.getLabel().equalsIgnoreCase(authorityItemCommonSchemaName)) {
      String csid = getCsid(docModel); // NuxeoUtils.extractId(docModel.getPathAsString());
      unQObjectProperties.put("csid", csid);
    }

    return unQObjectProperties;
  }
Exemplo n.º 5
0
  /**
   * Parses the properties.
   *
   * @param partMeta the part meta
   * @param document the document
   * @return the map
   */
  public static Map<String, Object> parseProperties(
      ObjectPartType partMeta, org.dom4j.Element document, ServiceContext ctx) throws Exception {
    Map<String, Object> result = null;
    String schemaName = partMeta.getLabel();
    Schema schema = getSchemaFromName(schemaName);

    //		org.dom4j.io.DOMReader xmlReader = new org.dom4j.io.DOMReader();
    //		org.dom4j.Document dom4jDocument = xmlReader.read(document);
    try {
      //                    result = loadSchema(schema, dom4jDocument.getRootElement(), ctx);
      result = loadSchema(schema, document, ctx);
    } catch (IllegalArgumentException iae) {
      throw iae;
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return result;
  }