public JSClient(Client c) { this.id = c.getClientId(); this.name = c.getName(); this.userAgentPattern = c.getUserAgentPattern(); this.version = c.getVersion(); this.model = c.getModel(); this.evalOrder = c.getEvalOrder(); this.manufacturer = c.getManufacturer(); capabilities = new ArrayList(); mimeTypes = new ArrayList(); }
public JSMediaType(MediaType c) { this.id = c.getMediatypeId(); this.name = c.getName(); this.characterSet = c.getCharacterSet(); this.title = c.getTitle(); this.description = c.getDescription(); capabilities = new ArrayList(); mimeTypes = new ArrayList(); }
/** Add Mimetype to the MimetypeMap */ public void addMimetype(MimeType mimetype) { if (mimetype != null) // avoid null due to duplicates in database this.mimeTypeMap.put(mimetype.getName(), mimetype); }
try cm = capabilities.getCapabilityMap(agent); throw new PipelineException("Falied to create capabilitied: "+e.getMessage(), e); MediaType mediaType = cm.getPreferredMediaType(); MimeType mimeType = cm.getPreferredType(); if (encoding == null) if (mediaType != null && mediaType.getCharacterSet() != null) encoding = mediaType.getCharacterSet(); log.debug("MediaType: " + mediaType.getName()); log.debug("Encoding: " + encoding); log.debug("Mimetype: " + mimeType.getName()); request.setMediaType(mediaType.getName()); request.setMimeType(mimeType.getName()); StringBuffer contentType = new StringBuffer(mimeType.getName()); if (encoding != null)
public void invoke( RequestContext request, ValveContext context ) throws PipelineException { CapabilityMap cm = request.getCapabilityMap(); if (cm != null && this.clientToMediaTypeMap != null) { Client client = cm.getClient(); String mediaTypeName = (String) this.clientToMediaTypeMap.get(client.getName()); if (mediaTypeName != null) { MediaType mediaType = this.capabilities.getMediaType(mediaTypeName); cm.setPreferredMediaType(mediaType); request.setMediaType(mediaTypeName); } } // Pass control to the next Valve in the Pipeline context.invokeNext(request); }
Iterator list = caps.getMediaTypes(); JSMediaType jsMediaType = new JSMediaType(mediaType); Iterator mimeTypeIterator = mediaType.getMimetypes().iterator(); while (mimeTypeIterator.hasNext()) JSMimeType jsMimeType = (JSMimeType) refs.mimeMap.get(mimeType.getName()); if (jsMimeType != null) jsMediaType.getMimeTypes().add(jsMimeType); Iterator iterator = mediaType.getCapabilities().iterator(); while (iterator.hasNext()) .getName()); if (jsCapability != null) jsMediaType.getCapabilities().add(jsCapability);
/** * exstract the mime types anmd save in snapshot file * * @throws SerializerException */ private void exportMimeTypes(Refs refs, JSSnapshot snapshot, Map<String,Object> settings, Logger log) throws SerializerException { Iterator list = caps.getMimeTypes(); while (list.hasNext()) { try { MimeType _mt = (MimeType) list.next(); JSMimeType _jsM = new JSMimeType(); _jsM.setName(_mt.getName()); refs.mimeMap.put(_jsM.getName(), _jsM); refs.mimeMapInt.put(new Integer(_mt.getMimetypeId()), _jsM); snapshot.getMimeTypes().add(_jsM); } catch (Exception e) { throw new SerializerException( SerializerException.CREATE_SERIALIZED_OBJECT_FAILED .create(new String[] { "MimeType", e.getMessage()})); } } return; }
/** Add MediaType to the MediaTypeMap */ public void addMediaType(MediaType mediatype) { if (mediatype != null) // avoid null due to duplicates in database this.mediaTypeMap.put(mediatype.getName(), mediatype); }
/** * extract the capabilities and save in snapshot file * * @throws SerializerException */ private void exportCapabilites(Refs refs, JSSnapshot snapshot, Map<String,Object> settings, Logger log) throws SerializerException { Iterator list = caps.getCapabilities(); while (list.hasNext()) { try { Capability _cp = (Capability) list.next(); JSCapability _jsC = new JSCapability(); _jsC.setName(_cp.getName()); refs.capabilityMap.put(_jsC.getName(), _jsC); refs.capabilityMapInt.put(new Integer(_cp.getCapabilityId()), _jsC); snapshot.getCapabilities().add(_jsC); } catch (Exception e) { throw new SerializerException( SerializerException.CREATE_SERIALIZED_OBJECT_FAILED .create(new String[] { "C", e.getMessage()})); } } return; }
/** Returns the preferred MIME type for the current user-agent */ public MimeType getPreferredType() { // Return the value that matches the preferredMimeType defined in the Client int prefMimeTypeId = this.client.getPreferredMimeTypeId(); MimeType mt = null; Iterator e = this.mimeTypeMap.values().iterator(); while (e.hasNext()) { mt = (MimeType) e.next(); if (mt.getMimetypeId() == prefMimeTypeId) return mt; } log.error("Could not find preferred Mime Type for " + prefMimeTypeId); // Should never reach this point. A preferred value needs to be set return null; }
/** Add capability to the CapabilityMap */ public void addCapability(Capability capability) { if (capability != null) // avoid null due to duplicates in database this.capabilityMap.put(capability.getName(), capability); }
/** * Checks to see if the current agent has the specified capability */ public boolean hasCapability(int capability) { Iterator capabilities = capabilityMap.values().iterator(); while (capabilities.hasNext()) { if (((Capability) capabilities.next()).getCapabilityId() == capability) { return true; } } return false; }
/** * Return true if this CapabilityMap supports the given media type * * @param media the name of a media type registered in the * MediaType registry * * @return true is the capabilities of this agent at least match those * required by the media type */ public boolean supportsMediaType(String media) { Iterator<MediaType> mediatypes = mediaTypeMap.values().iterator(); while (mediatypes.hasNext()) { if (mediatypes.next().getName().equals(media)) { return true; } } return false; }
public void addMimetype(MimeType mimeType) { if (mimetypes == null) mimetypes = new ArrayList(); if (!mimetypes.contains(mimeType.getName())) { mimetypes.add(mimeType); } }
public void addCapability(Capability capability) { if (capabilities == null) capabilities = new ArrayList(); if (!capabilities.contains(capability.getName())) { capabilities.add(capability); } }
/** * Implements the equals operation so that 2 elements are equal if * all their member values are equal. * * * @param object to compare this one with * @return true if both objects represent the same (logical) content */ public boolean equals(Object object) { if (!(object instanceof MimeType)) { return false; } if (this == object) return true; // Don't check the ID - id is only set through OJB so this would not recognize equality correctly /* if (mimeTypeId != ((MimeType)object).getMimetypeId()) return false; */ String oName = ((MimeType)object).getName(); if (oName != null && name != null) { return oName.equals(name); } else if (oName == null && name == null) { return true; } else { return false; } }
/** * Implements the equals operation so that 2 elements are equal if all their member values are equal. * * @param object to compare this one with * @return true if both objects represent the same (logical) content */ public boolean equals(Object object) { if (!(object instanceof Capability)) { return false; } if (this == object) { return true; } // Don't check the ID - id is only set through OJB so this would not recognize equality correctly /* if (this.capabilityId != ((Capability)object).getCapabilityId()) return false; */ String oName = ((Capability) object).getName(); if (oName != null && name != null) { return oName.equals(name); } else if (oName == null && name == null) { return true; } else { return false; } } }
/** Return true if this CapabilityMap supports the given MimeType */ public boolean supportsMimeType(MimeType mimeType) { Iterator<MimeType> mimetypes = mimeTypeMap.values().iterator(); while (mimetypes.hasNext()) { if (mimetypes.next().getName().equals(mimeType.getName())) { return true; } } return false; }
/** * Checks to see if the current agent has the specified capability */ public boolean hasCapability(String capability) { Iterator capabilities = capabilityMap.values().iterator(); while (capabilities.hasNext()) { if (((Capability) capabilities.next()).getName().equals(capability)) { return true; } } return false; }