private String getDSControlGroup(DigitalObject obj, Entry entry) throws ObjectIntegrityException { List<Category> controlGroups = entry.getCategories(MODEL.CONTROL_GROUP.uri); // Try to infer the control group if not provided if (controlGroups.isEmpty() || controlGroups.size() > 1) { if (entry.getContentType() != null) { if (entry.getContentType().equals(Content.Type.XML)) { return "X"; } else { // only XML can be inline return "M"; } } if (entry.getContentSrc() != null) { return "M"; } // TODO other cases // link alts, link enclosures else { throw new ObjectIntegrityException("No control group provided by " + obj.getPid()); } } else { return controlGroups.get(0).getTerm(); } }
public StreamWriter startContent(Content.Type type, String src) { return startContent(type.name().toLowerCase(), src); }
protected Content.Type getContentType() { Content.Type ctype = Content.Type.TEXT; String type = parser.getAttributeValue(null, LN_TYPE); String src = parser.getAttributeValue(null, LN_SRC); if (type != null) { ctype = Content.Type.typeFromString(type); if (ctype == null) throw new FOMUnsupportedContentTypeException(type); } else if (type == null && src != null) { ctype = Content.Type.MEDIA; } return ctype; }
Content content = (Content)element; Content.Type contenttype = content.getContentType(); if (contenttype.equals(Content.Type.TEXT) && !needToWriteLanguageFields(content)) { jstream.writeQuoted(content.getValue()); } else { case HTML: case XHTML: jstream.writeField("type", contenttype.name().toLowerCase()); break; case MEDIA:
removeAttribute(SRC); if (value != null) { if (Type.TEXT.equals(type)) { _removeAllChildren(); setText(type, value); } else if (Type.HTML.equals(type)) { _removeAllChildren(); setText(type, value); } else if (Type.XHTML.equals(type)) { IRI baseUri = null; Element element = null; } else if (Type.XML.equals(type)) { IRI baseUri = null; Element element = null; } catch (Exception e) { } else if (Type.MEDIA.equals(type)) { _removeAllChildren(); setText(type, value);
private String getDSControlGroup(DigitalObject obj, Entry entry) throws ObjectIntegrityException { List<Category> controlGroups = entry.getCategories(MODEL.CONTROL_GROUP.uri); // Try to infer the control group if not provided if (controlGroups.isEmpty() || controlGroups.size() > 1) { if (entry.getContentType() != null) { if (entry.getContentType().equals(Content.Type.XML)) { return "X"; } else { // only XML can be inline return "M"; } } if (entry.getContentSrc() != null) { return "M"; } // TODO other cases // link alts, link enclosures else { throw new ObjectIntegrityException("No control group provided by " + obj.getPid()); } } else { return controlGroups.get(0).getTerm(); } }
public <T extends Element> Content setValueElement(T value) { complete(); if (value != null) { if (this.getFirstElement() != null) this.getFirstElement().discard(); MimeType mtype = this.getMimeType(); if (mtype == null) { String mt = getFactory().getMimeType(value); if (mt != null) { setMimeType(mt); mtype = getMimeType(); } } if (value instanceof Div && !type.equals(Content.Type.XML)) init(Content.Type.XHTML); else { if (mtype == null) { init(Content.Type.XML); } } OMElement el = (OMElement)(value instanceof ElementWrapper ? ((ElementWrapper)value).getInternal() : value); this.setFirstChild(el); } else { _removeAllChildren(); } return this; }
public DataHandler getDataHandler() { if (!Type.MEDIA.equals(type)) throw new UnsupportedOperationException(Localizer.get("DATA.HANDLER.NOT.SUPPORTED")); MimeType type = getMimeType(); java.net.URL src = null; try { src = getSrc().toURL(); } catch (Exception e) { } DataHandler dh = null; if (src == null) { dh = (DataHandler)DataHandlerUtils .getDataHandlerFromText(getText(), (type != null) ? type.toString() : null); } else { dh = new DataHandler(new URLDataSource(src)); } return dh; }
public String getValue() { String val = null; if (Type.TEXT.equals(type)) { val = getText(); } else if (Type.HTML.equals(type)) { val = getText(); } else if (Type.XHTML.equals(type)) { FOMDiv div = (FOMDiv)this.getFirstChildWithName(Constants.DIV); if (div != null) val = div.getInternalValue(); } else if (Type.XML.equals(type)) { OMElement el = this.getFirstElement(); if (el != null) val = el.toString(); } else if (Type.MEDIA.equals(type)) { val = getText(); } return val; }
public Content setWrappedValue(String wrappedValue) { complete(); if (Type.XHTML.equals(type)) { IRI baseUri = null; Element element = null; try { baseUri = getResolvedBaseUri(); element = _parse(wrappedValue, baseUri); } catch (Exception e) { } if (element != null && element instanceof Div) setValueElement((Div)element); } else { ((Element)this).setText(wrappedValue); } return this; }
@Override public IRI getBaseUri() { if (Type.XHTML.equals(type)) { Element el = getValueElement(); if (el != null) { if (el.getAttributeValue(BASE) != null) { if (getAttributeValue(BASE) != null) return super.getBaseUri().resolve(el.getAttributeValue(BASE)); else return _getUriValue(el.getAttributeValue(BASE)); } } } return super.getBaseUri(); }
private void init(Type type) { this.type = type; if (Type.TEXT.equals(type)) setAttributeValue(TYPE, "text"); else if (Type.HTML.equals(type)) setAttributeValue(TYPE, "html"); else if (Type.XHTML.equals(type)) setAttributeValue(TYPE, "xhtml"); else if (Type.XML.equals(type)) setAttributeValue(TYPE, "application/xml"); else { removeAttribute(TYPE); } }
public Content setDataHandler(DataHandler dataHandler) { complete(); if (!Type.MEDIA.equals(type)) throw new IllegalArgumentException(); if (dataHandler.getContentType() != null) { try { setMimeType(dataHandler.getContentType()); } catch (Exception e) { } } _removeAllChildren(); addChild(factory.createOMText(dataHandler, true)); return this; }
@Override public IRI getResolvedBaseUri() { if (Type.XHTML.equals(type)) { Element el = getValueElement(); if (el != null) { if (el.getAttributeValue(BASE) != null) { return super.getResolvedBaseUri().resolve(el.getAttributeValue(BASE)); } } } return super.getResolvedBaseUri(); }
public Content newContent(Type type, Element parent) { if (type == null) type = Content.Type.TEXT; Content content = new FOMContent(type, (OMContainer)parent, this); if (type.equals(Content.Type.XML)) content.setMimeType(XML_MEDIA_TYPE); return content; }
@Override public String getLanguage() { if (Type.XHTML.equals(type)) { Element el = getValueElement(); if (el.getAttributeValue(LANG) != null) return el.getAttributeValue(LANG); } return super.getLanguage(); }
public StreamWriter startContent( Content.Type type, String src) { return startContent(type.name().toLowerCase(),src); }
public String getWrappedValue() { if (Type.XHTML.equals(type)) { return this.getFirstChildWithName(Constants.DIV).toString(); } else { return getText(); } }